Skip to content

Commit 78f6cc2

Browse files
committed
Implement inference and add tests
1 parent a874bd6 commit 78f6cc2

File tree

19 files changed

+692
-182
lines changed

19 files changed

+692
-182
lines changed

native_toplevel/opttoploop.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ let name_expression ~loc ~attrs sort exp =
344344
val_kind = Val_reg;
345345
val_loc = loc;
346346
val_attributes = attrs;
347-
val_zero_alloc = Default_zero_alloc;
347+
val_zero_alloc = Zero_alloc.default;
348348
val_uid = Uid.internal_not_actually_unique; }
349349
in
350350
let sg = [Sig_value(id, vd, Exported)] in

ocaml/lambda/translcore.ml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,14 @@ let can_apply_primitive p pmode pos args =
352352

353353
let zero_alloc_of_application ~num_args annotation funct =
354354
let zero_alloc =
355-
match annotation with
356-
| Assume _ ->
355+
match annotation, funct.exp_desc with
356+
| Assume _, _ ->
357357
(* The user wrote a zero_alloc attribute on the application - keep it. *)
358358
annotation
359-
| Ignore_assert_all | Check _ ->
359+
| (Ignore_assert_all | Check _), _ ->
360360
(* These are rejected in typecore *)
361361
Misc.fatal_error "Translcore.zero_alloc_of_application: illegal attr"
362-
| Default_zero_alloc ->
362+
| Default_zero_alloc, Texp_ident (_, _, { val_zero_alloc; _ }, _, _) ->
363363
(* We assume the call is zero_alloc if the function is known to be
364364
zero_alloc. If the function is zero_alloc opt, then we need to be sure
365365
that the opt checks were run to license this assumption. We judge
@@ -370,18 +370,19 @@ let zero_alloc_of_application ~num_args annotation funct =
370370
| Check_default | No_check -> false
371371
| Check_all | Check_opt_only -> true
372372
in
373-
match funct.exp_desc with
374-
| Texp_ident (_, _, { val_zero_alloc = (Check c); _ }, _, _)
375-
when c.arity = num_args && (use_opt || not c.opt) ->
373+
begin match Zero_alloc.get_defaulting val_zero_alloc with
374+
| Check c when c.arity = num_args && (use_opt || not c.opt) ->
376375
Builtin_attributes.Assume {
377376
strict = c.strict;
378377
never_returns_normally = false;
379378
never_raises = false;
380379
arity = c.arity;
381380
loc = c.loc
382381
}
383-
| _ -> Builtin_attributes.Default_zero_alloc
384-
382+
| Check _ | Default_zero_alloc | Ignore_assert_all | Assume _ ->
383+
Builtin_attributes.Default_zero_alloc
384+
end
385+
| Default_zero_alloc, _ -> Builtin_attributes.Default_zero_alloc
385386
in
386387
Builtin_attributes.assume_zero_alloc zero_alloc
387388

@@ -1618,6 +1619,7 @@ and transl_function ~in_new_scope ~scopes e params body
16181619
~zero_alloc =
16191620
let attrs = e.exp_attributes in
16201621
let mode = transl_alloc_mode_r alloc_mode in
1622+
let zero_alloc = Zero_alloc.get_defaulting zero_alloc in
16211623
let assume_zero_alloc = Builtin_attributes.assume_zero_alloc zero_alloc in
16221624
let scopes =
16231625
if in_new_scope then

0 commit comments

Comments
 (0)