Skip to content

Commit 3d5ca81

Browse files
authored
zero alloc: new payload supported in [@@@zero_alloc check...] to match flags (#2083)
1 parent f10979a commit 3d5ca81

13 files changed

+123
-2
lines changed

ocaml/parsing/builtin_attributes.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,14 @@ let zero_alloc_attribute (attr : Parsetree.attribute) =
585585
parse_attribute_with_ident_payload attr
586586
~name:"zero_alloc" ~f:(function
587587
| "check" -> Clflags.zero_alloc_check := Clflags.Annotations.Check_default
588+
| "check_opt" -> Clflags.zero_alloc_check := Clflags.Annotations.Check_opt_only
589+
| "check_all" -> Clflags.zero_alloc_check := Clflags.Annotations.Check_all
590+
| "check_none" -> Clflags.zero_alloc_check := Clflags.Annotations.No_check
588591
| "all" ->
589592
Clflags.zero_alloc_check_assert_all := true
590593
| _ ->
591594
warn_payload attr.attr_loc attr.attr_name.txt
592-
"Only 'check' and 'all' are supported")
595+
"Only 'all', 'check', 'check_opt', 'check_all', and 'check_none' are supported")
593596

594597
let afl_inst_ratio_attribute attr =
595598
clflags_attribute_with_int_payload attr

tests/backend/checkmach/dune.inc

+76
Original file line numberDiff line numberDiff line change
@@ -654,3 +654,79 @@
654654
(enabled_if (= %{context_name} "main"))
655655
(deps test_misplaced_attr.output test_misplaced_attr.output.corrected)
656656
(action (diff test_misplaced_attr.output test_misplaced_attr.output.corrected)))
657+
658+
(rule
659+
(enabled_if (= %{context_name} "main"))
660+
(targets test_attr_check.output.corrected)
661+
(deps (:ml test_attr_check.ml) filter.sh)
662+
(action
663+
(with-outputs-to test_attr_check.output.corrected
664+
(pipe-outputs
665+
(with-accepted-exit-codes 2
666+
(run %{bin:ocamlopt.opt} %{ml} -g -color never -error-style short -c
667+
-zero-alloc-check all -checkmach-details-cutoff 20 -O3))
668+
(run "./filter.sh")
669+
))))
670+
671+
(rule
672+
(alias runtest)
673+
(enabled_if (= %{context_name} "main"))
674+
(deps test_attr_check.output test_attr_check.output.corrected)
675+
(action (diff test_attr_check.output test_attr_check.output.corrected)))
676+
677+
(rule
678+
(enabled_if (= %{context_name} "main"))
679+
(targets test_attr_check_all.output.corrected)
680+
(deps (:ml test_attr_check_all.ml) filter.sh)
681+
(action
682+
(with-outputs-to test_attr_check_all.output.corrected
683+
(pipe-outputs
684+
(with-accepted-exit-codes 2
685+
(run %{bin:ocamlopt.opt} %{ml} -g -color never -error-style short -c
686+
-zero-alloc-check default -checkmach-details-cutoff 20 -O3))
687+
(run "./filter.sh")
688+
))))
689+
690+
(rule
691+
(alias runtest)
692+
(enabled_if (= %{context_name} "main"))
693+
(deps test_attr_check_all.output test_attr_check_all.output.corrected)
694+
(action (diff test_attr_check_all.output test_attr_check_all.output.corrected)))
695+
696+
(rule
697+
(enabled_if (= %{context_name} "main"))
698+
(targets test_attr_check_opt.output.corrected)
699+
(deps (:ml test_attr_check_opt.ml) filter.sh)
700+
(action
701+
(with-outputs-to test_attr_check_opt.output.corrected
702+
(pipe-outputs
703+
(with-accepted-exit-codes 2
704+
(run %{bin:ocamlopt.opt} %{ml} -g -color never -error-style short -c
705+
-zero-alloc-check default -checkmach-details-cutoff 20 -O3))
706+
(run "./filter.sh")
707+
))))
708+
709+
(rule
710+
(alias runtest)
711+
(enabled_if (= %{context_name} "main"))
712+
(deps test_attr_check_opt.output test_attr_check_opt.output.corrected)
713+
(action (diff test_attr_check_opt.output test_attr_check_opt.output.corrected)))
714+
715+
(rule
716+
(enabled_if (= %{context_name} "main"))
717+
(targets test_attr_check_none.output.corrected)
718+
(deps (:ml test_attr_check_none.ml) filter.sh)
719+
(action
720+
(with-outputs-to test_attr_check_none.output.corrected
721+
(pipe-outputs
722+
(with-accepted-exit-codes 0
723+
(run %{bin:ocamlopt.opt} %{ml} -g -color never -error-style short -c
724+
-zero-alloc-check default -checkmach-details-cutoff 20 -O3))
725+
(run "./filter.sh")
726+
))))
727+
728+
(rule
729+
(alias runtest)
730+
(enabled_if (= %{context_name} "main"))
731+
(deps test_attr_check_none.output test_attr_check_none.output.corrected)
732+
(action (diff test_attr_check_none.output test_attr_check_none.output.corrected)))

tests/backend/checkmach/gen/gen_dune.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,8 @@ let () =
128128
print_test_expected_output ~cutoff:default_cutoff ~flambda_only:false ~extra_dep:None ~exit_code:2 "test_assume_on_call";
129129
print_test_expected_output ~cutoff:default_cutoff ~flambda_only:false ~extra_dep:None ~exit_code:2 "test_misplaced_assume";
130130
print_test_expected_output ~cutoff:default_cutoff ~flambda_only:false ~extra_dep:None ~exit_code:0 "test_misplaced_attr";
131-
131+
print_test_expected_output ~extra_flags:"-zero-alloc-check all" ~cutoff:default_cutoff ~flambda_only:false ~extra_dep:None ~exit_code:2 "test_attr_check";
132+
print_test_expected_output ~cutoff:default_cutoff ~flambda_only:false ~extra_dep:None ~exit_code:2 "test_attr_check_all";
133+
print_test_expected_output ~cutoff:default_cutoff ~flambda_only:false ~extra_dep:None ~exit_code:2 "test_attr_check_opt";
134+
print_test_expected_output ~cutoff:default_cutoff ~flambda_only:false ~extra_dep:None ~exit_code:0 "test_attr_check_none";
132135
()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[@@@zero_alloc check]
2+
let[@zero_alloc] test x = (x,x)
3+
let[@zero_alloc opt] test_opt x = (x,x)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
File "test_attr_check.ml", line 2, characters 5-15:
2+
Error: Annotation check for zero_alloc failed on function Test_attr_check.test (camlTest_attr_check.test_HIDE_STAMP)
3+
4+
File "test_attr_check.ml", line 2, characters 26-31:
5+
Error: Unexpected allocation of 24 bytes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[@@@zero_alloc check_all]
2+
let[@zero_alloc] test x = (x,x)
3+
let[@zero_alloc opt] test_opt x = (x,x)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
File "test_attr_check_all.ml", line 2, characters 5-15:
2+
Error: Annotation check for zero_alloc failed on function Test_attr_check_all.test (camlTest_attr_check_all.test_HIDE_STAMP)
3+
4+
File "test_attr_check_all.ml", line 2, characters 26-31:
5+
Error: Unexpected allocation of 24 bytes
6+
7+
File "test_attr_check_all.ml", line 3, characters 5-15:
8+
Error: Annotation check for zero_alloc failed on function Test_attr_check_all.test_opt (camlTest_attr_check_all.test_opt_HIDE_STAMP)
9+
10+
File "test_attr_check_all.ml", line 3, characters 34-39:
11+
Error: Unexpected allocation of 24 bytes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[@@@zero_alloc check_none]
2+
let[@zero_alloc] test x = (x,x)
3+
let[@zero_alloc opt] test_opt x = (x,x)

tests/backend/checkmach/test_attr_check_none.output

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[@@@zero_alloc check_opt]
2+
let[@zero_alloc] test x = (x,x)
3+
let[@zero_alloc opt] test_opt x = (x,x)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
File "test_attr_check_opt.ml", line 3, characters 5-15:
2+
Error: Annotation check for zero_alloc failed on function Test_attr_check_opt.test_opt (camlTest_attr_check_opt.test_opt_HIDE_STAMP)
3+
4+
File "test_attr_check_opt.ml", line 3, characters 34-39:
5+
Error: Unexpected allocation of 24 bytes

tests/backend/checkmach/test_misplaced_attr.ml

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ let[@zero_alloc assume] foo =
55
let[@zero_alloc] bar =
66
let x = 42 in
77
fun z -> z + x
8+
9+
[@@@zero_alloc default]

tests/backend/checkmach/test_misplaced_attr.output

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
File "test_misplaced_attr.ml", line 9, characters 0-23:
2+
Warning 47 [attribute-payload]: illegal payload for attribute 'zero_alloc'.
3+
Only 'all', 'check', 'check_opt', 'check_all', and 'check_none' are supported
4+
15
File "test_misplaced_attr.ml", line 1, characters 5-15:
26
Warning 53 [misplaced-attribute]: the "zero_alloc" attribute cannot appear in this context
37

0 commit comments

Comments
 (0)