Skip to content

Commit bc85611

Browse files
authored
flambda-backend: Zero alloc: refactor to remove "property" and improve naming (#2416)
* Remove "Lambda.property" and rename "Lambda.check_attribute" and propagate this name down to Cmm. * Rename files checkmach.ml to zero_alloc_checker.ml check_attribute.ml to zero_alloc_attribute.ml * Rename compilation flags "checkmach" to "zero-alloc-checker" * Update autogenerated dune.inc file * Refactoring: simplify zero_alloc_checker by removing unused functor * Format * Update depend * Fix upstream testsuite * Lots of fixes after rebase (makes separate commits useless) too much diff to fix up in the right commit * Regenerate dune.inc * Fix chamelon build * Rename [check] labelled arguments to [zero_alloc_attribute] * fix up [dune] to list more things alphabetically * Fix assorted typos and improve printing * Format * Remove unused copy of is_check_enabled
1 parent d59441e commit bc85611

26 files changed

+155
-189
lines changed

.depend

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,10 @@ utils/zero_alloc_annotations.cmx : \
293293
utils/zero_alloc_annotations.cmi
294294
utils/zero_alloc_annotations.cmi :
295295
utils/zero_alloc_utils.cmo : \
296+
utils/clflags.cmi \
296297
utils/zero_alloc_utils.cmi
297298
utils/zero_alloc_utils.cmx : \
299+
utils/clflags.cmx \
298300
utils/zero_alloc_utils.cmi
299301
utils/zero_alloc_utils.cmi :
300302
parsing/ast_helper.cmo : \
@@ -4321,6 +4323,7 @@ lambda/transl_list_comprehension.cmi : \
43214323
typing/jkind.cmi \
43224324
lambda/debuginfo.cmi
43234325
lambda/translattribute.cmo : \
4326+
utils/zero_alloc_utils.cmi \
43244327
utils/warnings.cmi \
43254328
typing/typedtree.cmi \
43264329
parsing/parsetree.cmi \
@@ -4330,6 +4333,7 @@ lambda/translattribute.cmo : \
43304333
parsing/builtin_attributes.cmi \
43314334
lambda/translattribute.cmi
43324335
lambda/translattribute.cmx : \
4336+
utils/zero_alloc_utils.cmx \
43334337
utils/warnings.cmx \
43344338
typing/typedtree.cmx \
43354339
parsing/parsetree.cmi \

driver/compile_common.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,6 @@ let implementation ~hook_parse_tree ~hook_typed_tree info ~backend =
143143
end;
144144
end;
145145
if not (Clflags.(should_stop_after Compiler_pass.Selection)) then
146-
Builtin_attributes.warn_unchecked_property ();
146+
Builtin_attributes.warn_unchecked_zero_alloc_attribute ();
147147
Warnings.check_fatal ();
148148
)

lambda/lambda.ml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -621,24 +621,19 @@ type local_attribute =
621621
| Never_local (* [@local never] *)
622622
| Default_local (* [@local maybe] or no [@local] attribute *)
623623

624-
type property = Builtin_attributes.property =
625-
| Zero_alloc
626-
627624
type poll_attribute =
628625
| Error_poll (* [@poll error] *)
629626
| Default_poll (* no [@poll] attribute *)
630627

631-
type check_attribute = Builtin_attributes.check_attribute =
632-
| Default_check
633-
| Ignore_assert_all of property
634-
| Check of { property: property;
635-
strict: bool;
628+
type zero_alloc_attribute = Builtin_attributes.zero_alloc_attribute =
629+
| Default_zero_alloc
630+
| Ignore_assert_all
631+
| Check of { strict: bool;
636632
opt: bool;
637633
arity: int;
638634
loc: Location.t;
639635
}
640-
| Assume of { property: property;
641-
strict: bool;
636+
| Assume of { strict: bool;
642637
never_returns_normally: bool;
643638
never_raises: bool;
644639
arity: int;
@@ -673,7 +668,7 @@ type function_attribute = {
673668
inline : inline_attribute;
674669
specialise : specialise_attribute;
675670
local: local_attribute;
676-
check : check_attribute;
671+
zero_alloc : zero_alloc_attribute;
677672
poll: poll_attribute;
678673
loop: loop_attribute;
679674
is_a_functor: bool;
@@ -896,7 +891,7 @@ let default_function_attribute = {
896891
inline = Default_inline;
897892
specialise = Default_specialise;
898893
local = Default_local;
899-
check = Default_check ;
894+
zero_alloc = Default_zero_alloc ;
900895
poll = Default_poll;
901896
loop = Default_loop;
902897
is_a_functor = false;
@@ -915,7 +910,7 @@ let default_function_attribute = {
915910
}
916911

917912
let default_stub_attribute =
918-
{ default_function_attribute with stub = true; check = Ignore_assert_all Zero_alloc }
913+
{ default_function_attribute with stub = true; zero_alloc = Ignore_assert_all }
919914

920915
let default_param_attribute = { unbox_param = false }
921916

lambda/lambda.mli

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -497,18 +497,14 @@ type local_attribute =
497497
| Never_local (* [@local never] *)
498498
| Default_local (* [@local maybe] or no [@local] attribute *)
499499

500-
type property = Builtin_attributes.property =
501-
| Zero_alloc
502-
503500
type poll_attribute =
504501
| Error_poll (* [@poll error] *)
505502
| Default_poll (* no [@poll] attribute *)
506503

507-
type check_attribute = Builtin_attributes.check_attribute =
508-
| Default_check
509-
| Ignore_assert_all of property
510-
| Check of { property: property;
511-
strict: bool;
504+
type zero_alloc_attribute = Builtin_attributes.zero_alloc_attribute =
505+
| Default_zero_alloc
506+
| Ignore_assert_all
507+
| Check of { strict: bool;
512508
(* [strict=true] property holds on all paths.
513509
[strict=false] if the function returns normally,
514510
then the property holds (but property violations on
@@ -518,8 +514,7 @@ type check_attribute = Builtin_attributes.check_attribute =
518514
arity: int;
519515
loc: Location.t;
520516
}
521-
| Assume of { property: property;
522-
strict: bool;
517+
| Assume of { strict: bool;
523518
never_returns_normally: bool;
524519
never_raises: bool;
525520
arity: int;
@@ -561,7 +556,7 @@ type function_attribute = {
561556
inline : inline_attribute;
562557
specialise : specialise_attribute;
563558
local: local_attribute;
564-
check : check_attribute;
559+
zero_alloc : zero_alloc_attribute;
565560
poll: poll_attribute;
566561
loop: loop_attribute;
567562
is_a_functor: bool;

lambda/printlambda.ml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -934,22 +934,18 @@ let name_of_primitive = function
934934
| Parray_to_iarray -> "Parray_to_iarray"
935935
| Pget_header _ -> "Pget_header"
936936

937-
let check_attribute ppf check =
938-
let check_property = function
939-
| Zero_alloc -> "zero_alloc"
940-
in
937+
let zero_alloc_attribute ppf check =
941938
match check with
942-
| Default_check -> ()
943-
| Ignore_assert_all p ->
944-
fprintf ppf "ignore assert all %s@ " (check_property p)
945-
| Assume {property=p; strict; never_returns_normally; loc = _} ->
946-
fprintf ppf "assume_%s%s%s@ "
947-
(check_property p)
939+
| Default_zero_alloc -> ()
940+
| Ignore_assert_all ->
941+
fprintf ppf "ignore assert all zero_alloc@ "
942+
| Assume {strict; never_returns_normally; loc = _} ->
943+
fprintf ppf "assume_zero_alloc%s%s@ "
948944
(if strict then "_strict" else "")
949945
(if never_returns_normally then "_never_returns_normally" else "")
950-
| Check {property=p; strict; loc = _; opt} ->
951-
fprintf ppf "assert_%s%s%s@ "
952-
(check_property p) (if opt then "_opt" else "")
946+
| Check {strict; loc = _; opt} ->
947+
fprintf ppf "assert_zero_alloc%s%s@ "
948+
(if opt then "_opt" else "")
953949
(if strict then "_strict" else "")
954950

955951
let function_attribute ppf t =
@@ -974,7 +970,7 @@ let function_attribute ppf t =
974970
| Always_local -> fprintf ppf "always_local@ "
975971
| Never_local -> fprintf ppf "never_local@ "
976972
end;
977-
check_attribute ppf t.check;
973+
zero_alloc_attribute ppf t.zero_alloc;
978974
if t.tmc_candidate then
979975
fprintf ppf "tail_mod_cons@ ";
980976
begin match t.loop with

lambda/printlambda.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ val record_rep : formatter -> Types.record_representation -> unit
4040
val print_bigarray :
4141
string -> bool -> Lambda.bigarray_kind -> formatter ->
4242
Lambda.bigarray_layout -> unit
43-
val check_attribute : formatter -> check_attribute -> unit
43+
val zero_alloc_attribute : formatter -> zero_alloc_attribute -> unit
4444
val alloc_mode : formatter -> alloc_mode -> unit
4545
val array_kind : array_kind -> string
4646

lambda/simplif.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ let split_default_wrapper ~id:fun_id ~kind ~params ~return ~body
877877
| _ -> assert orig_region
878878
end;
879879
let body, inner = aux [] false body in
880-
let attr = { default_stub_attribute with check = attr.check } in
880+
let attr = { default_stub_attribute with zero_alloc = attr.zero_alloc } in
881881
[{ id = fun_id;
882882
def = lfunction' ~kind ~params ~return ~body ~attr ~loc
883883
~mode ~ret_mode ~region:true };

lambda/translattribute.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ let get_opaque_attribute l =
195195
let attr = find_attribute is_opaque_attribute l in
196196
parse_opaque_attribute attr
197197

198-
199198
let get_poll_attribute l =
200199
let attr = find_attribute is_poll_attribute l in
201200
parse_poll_attribute attr

lambda/translcore.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ and transl_exp0 ~in_new_scope ~scopes sort e =
10301030
{ inline = Never_inline;
10311031
specialise = Always_specialise;
10321032
local = Never_local;
1033-
check = Default_check;
1033+
zero_alloc = Default_zero_alloc;
10341034
loop = Never_loop;
10351035
is_a_functor = false;
10361036
is_opaque = false;
@@ -1603,7 +1603,7 @@ and transl_function ~in_new_scope ~scopes e params body
16031603
~scopes e.exp_loc repr ~region params body)
16041604
in
16051605
let attr =
1606-
{ function_attribute_disallowing_arity_fusion with check = zero_alloc }
1606+
{ function_attribute_disallowing_arity_fusion with zero_alloc }
16071607
in
16081608
let loc = of_location ~scopes e.exp_loc in
16091609
let body = if region then maybe_region_layout return body else body in

lambda/translmod.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ and apply_coercion_result loc strict funct params args cc_res =
162162
~return:Lambda.layout_module
163163
~attr:{ default_function_attribute with
164164
is_a_functor = true;
165-
check = Ignore_assert_all Zero_alloc;
165+
zero_alloc = Ignore_assert_all;
166166
stub = true; }
167167
~loc
168168
~mode:alloc_heap
@@ -572,7 +572,7 @@ let rec compile_functor ~scopes mexp coercion root_path loc =
572572
loop = Never_loop;
573573
is_a_functor = true;
574574
is_opaque = false;
575-
check = Ignore_assert_all Zero_alloc;
575+
zero_alloc = Ignore_assert_all;
576576
stub = false;
577577
tmc_candidate = false;
578578
may_fuse_arity = true;

0 commit comments

Comments
 (0)