Skip to content

Commit 0ca2653

Browse files
authored
zero_alloc: refactor Translattribute.assume_zero_alloc slightly (#2148)
Refactor: explict [with_warnigns] for Translattribute.assume_zero_alloc
1 parent 4a0ab74 commit 0ca2653

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

ocaml/lambda/translattribute.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,15 @@ let assume_zero_alloc attributes =
468468
| Assume { property = Zero_alloc; _ } -> true
469469
| Check { property = Zero_alloc; _ } -> false
470470

471-
let assume_zero_alloc attributes =
472-
(* This function is used for "look-ahead" to find attributes
471+
let get_assume_zero_alloc ~with_warnings attributes =
472+
if with_warnings then
473+
assume_zero_alloc attributes
474+
else
475+
(* This function is used for "look-ahead" to find attributes
473476
that affect [Scoped_location] settings before translation
474477
of expressions in that scope.
475478
Warnings will be produced by [add_check_attribute]. *)
476-
Warnings.without_warnings (fun () -> assume_zero_alloc attributes)
479+
Warnings.without_warnings (fun () -> assume_zero_alloc attributes)
477480

478481
let add_check_attribute expr loc attributes =
479482
let to_string = function

ocaml/lambda/translattribute.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ val add_function_attributes
6565
-> Parsetree.attributes
6666
-> Lambda.lambda
6767

68-
val assume_zero_alloc : Parsetree.attributes -> bool
68+
val get_assume_zero_alloc : with_warnings:bool -> Parsetree.attributes -> bool

ocaml/lambda/translcore.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,9 @@ and transl_function ~in_new_scope ~scopes e alloc_mode param arg_mode arg_sort r
13631363
| (Texp_constraint _ | Texp_coerce _ | Texp_poly _) -> attrs)
13641364
e.exp_attributes e.exp_extra
13651365
in
1366-
let assume_zero_alloc = Translattribute.assume_zero_alloc attrs in
1366+
let assume_zero_alloc =
1367+
Translattribute.get_assume_zero_alloc ~with_warnings:false attrs
1368+
in
13671369
let scopes =
13681370
if in_new_scope then begin
13691371
if assume_zero_alloc then set_assume_zero_alloc ~scopes
@@ -1407,7 +1409,9 @@ and transl_bound_exp ~scopes ~in_structure pat sort expr loc attrs =
14071409
let lam =
14081410
match pat_bound_idents pat with
14091411
| (id :: _) when should_introduce_scope ->
1410-
let assume_zero_alloc = Translattribute.assume_zero_alloc attrs in
1412+
let assume_zero_alloc =
1413+
Translattribute.get_assume_zero_alloc ~with_warnings:false attrs
1414+
in
14111415
let scopes = enter_value_definition ~scopes ~assume_zero_alloc id in
14121416
transl_scoped_exp ~scopes sort expr
14131417
| _ -> transl_exp ~scopes sort expr

0 commit comments

Comments
 (0)