@@ -5056,6 +5056,44 @@ let add_check_attribute expr attributes =
5056
5056
end
5057
5057
| _ -> expr
5058
5058
5059
+ let zero_alloc_of_application ~num_args attrs funct =
5060
+ let zero_alloc =
5061
+ Builtin_attributes. get_property_attribute ~in_signature: false
5062
+ ~default_arity: num_args attrs Zero_alloc
5063
+ in
5064
+ let zero_alloc =
5065
+ match zero_alloc with
5066
+ | Assume _ | Ignore_assert_all _ | Check _ ->
5067
+ (* The user wrote a zero_alloc attribute on the application - keep it.
5068
+ (Note that `ignore` and `check` aren't really allowed here, and will be
5069
+ rejected by the call to `Builtin_attributes.assume_zero_alloc` below.)
5070
+ *)
5071
+ zero_alloc
5072
+ | Default_check ->
5073
+ (* We assume the call is zero_alloc if the function is known to be
5074
+ zero_alloc. If the function is zero_alloc opt, then we need to be sure
5075
+ that the opt checks were run to license this assumption. We judge
5076
+ whether the opt checks were run based on the argument to the
5077
+ [-zero-alloc-check] command line flag. *)
5078
+ let use_opt =
5079
+ match ! Clflags. zero_alloc_check with
5080
+ | Check_default | No_check -> false
5081
+ | Check_all | Check_opt_only -> true
5082
+ in
5083
+ match funct.exp_desc with
5084
+ | Texp_ident (_, _, { val_zero_alloc = (Check c); _ }, _, _)
5085
+ when c.arity = num_args && (use_opt || not c.opt) ->
5086
+ Builtin_attributes. Assume {
5087
+ property = Zero_alloc ;
5088
+ strict = c.strict;
5089
+ never_returns_normally = false ;
5090
+ arity = c.arity;
5091
+ loc = c.loc
5092
+ }
5093
+ | _ -> Builtin_attributes. Default_check
5094
+ in
5095
+ Builtin_attributes. assume_zero_alloc ~is_check_allowed: false zero_alloc
5096
+
5059
5097
let rec type_exp ?recarg env expected_mode sexp =
5060
5098
(* We now delegate everything to type_expect *)
5061
5099
type_expect ?recarg env expected_mode sexp
@@ -5384,12 +5422,8 @@ and type_expect_
5384
5422
type_application env loc expected_mode pm funct funct_mode sargs rt
5385
5423
in
5386
5424
let assume_zero_alloc =
5387
- let default_arity = List. length args in
5388
- let zero_alloc =
5389
- Builtin_attributes. get_property_attribute ~in_signature: false
5390
- ~default_arity sfunct.pexp_attributes Zero_alloc
5391
- in
5392
- Builtin_attributes. assume_zero_alloc ~is_check_allowed: false zero_alloc
5425
+ zero_alloc_of_application ~num_args: (List. length args)
5426
+ sfunct.pexp_attributes funct
5393
5427
in
5394
5428
5395
5429
rue {
0 commit comments