Skip to content

Commit 185c5a2

Browse files
authored
Use [@opaque] in flambda-backend tests instead of [@inline never][@Local never] (#4019)
This is because the reaper will still see through those attributes, which is not what we want here.
1 parent 61ae936 commit 185c5a2

File tree

9 files changed

+168
-84
lines changed

9 files changed

+168
-84
lines changed

flambda-backend/tests/backend/vectorizer/test1.ml

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ type t2 =
77
d1 : int
88
}
99

10-
let[@inline never] [@local never] add_pairs_immutable_record (a : t2) (b : t2) :
11-
t2 =
10+
let[@opaque] add_pairs_immutable_record (a : t2) (b : t2) : t2 =
1211
{ d0 = a.d0 + b.d0; d1 = a.d1 + b.d1 }
1312

1413
type t4 =
@@ -18,31 +17,27 @@ type t4 =
1817
d3 : int
1918
}
2019

21-
let[@inline never] [@local never] add_fours_immutable_record (a : t4) (b : t4) :
22-
t4 =
20+
let[@opaque] add_fours_immutable_record (a : t4) (b : t4) : t4 =
2321
{ d0 = a.d0 + b.d0; d1 = a.d1 + b.d1; d2 = a.d2 + b.d2; d3 = a.d3 + b.d3 }
2422

2523
(* Tuples *)
2624

27-
let[@inline never] [@local never] add_int_tuples ((a0, a1) : int * int)
28-
((b0, b1) : int * int) =
25+
let[@opaque] add_int_tuples ((a0, a1) : int * int) ((b0, b1) : int * int) =
2926
a0 + b0, a1 + b1
3027

31-
let[@inline never] [@local never] add_t2_to_t4 (a : t2) (b : t2) : t4 =
28+
let[@opaque] add_t2_to_t4 (a : t2) (b : t2) : t4 =
3229
{ d0 = a.d0 + b.d0; d1 = a.d1 + b.d1; d2 = a.d0 + b.d0; d3 = a.d1 + b.d1 }
3330

3431
(* CR gyorsh: can't vectorize, requires a shuffle because the order of the first
3532
vector access is not the same as the second. *)
36-
let[@inline never] [@local never] add_t2_to_t4_reordered (a : t2) (b : t2) : t4
37-
=
33+
let[@opaque] add_t2_to_t4_reordered (a : t2) (b : t2) : t4 =
3834
{ d0 = a.d0 + b.d0; d1 = a.d1 + b.d1; d3 = a.d0 + b.d0; d2 = a.d1 + b.d1 }
3935

40-
let[@inline never] [@local never] copy_t2_to_t4_immutable_record (a : t2) : t4 =
36+
let[@opaque] copy_t2_to_t4_immutable_record (a : t2) : t4 =
4137
{ d0 = a.d0; d1 = a.d1; d2 = a.d0; d3 = a.d1 }
4238

4339
(* CR gyorsh: can't vectorize same load. *)
44-
let[@inline never] [@local never] same_value_in_both_fields_immutable_record
45-
(a : t2) : t2 =
40+
let[@opaque] same_value_in_both_fields_immutable_record (a : t2) : t2 =
4641
let x = a.d0 in
4742
let y = a.d1 in
4843
let z = x + y in
@@ -53,15 +48,13 @@ type s2 =
5348
mutable f1 : int
5449
}
5550

56-
let[@inline never] [@local never] copy_pairs_mutable_record (a : s2) (b : s2) :
57-
unit =
51+
let[@opaque] copy_pairs_mutable_record (a : s2) (b : s2) : unit =
5852
b.f0 <- a.f0;
5953
b.f1 <- a.f1;
6054
()
6155

6256
(* CR gyorsh: dependency outside computation should only look at reg not mem *)
63-
let[@inline never] [@local never] copy_pairs_mutable_record_return (a : s2)
64-
(b : s2) : s2 =
57+
let[@opaque] copy_pairs_mutable_record_return (a : s2) (b : s2) : s2 =
6558
b.f0 <- a.f0;
6659
b.f1 <- a.f1;
6760
b
@@ -73,16 +66,14 @@ type s4 =
7366
mutable f3 : int
7467
}
7568

76-
let[@inline never] [@local never] copy_fours_mutable_record (a : s4) (b : s4) :
77-
unit =
69+
let[@opaque] copy_fours_mutable_record (a : s4) (b : s4) : unit =
7870
a.f0 <- b.f0;
7971
a.f1 <- b.f1;
8072
a.f2 <- b.f2;
8173
a.f3 <- b.f3;
8274
()
8375

84-
let[@inline never] [@local never] add_fours_mutable_record (a : s4) (b : s4) :
85-
unit =
76+
let[@opaque] add_fours_mutable_record (a : s4) (b : s4) : unit =
8677
a.f0 <- b.f0 + a.f0;
8778
a.f1 <- b.f1 + a.f1;
8879
a.f2 <- b.f2 + a.f2;

flambda-backend/tests/backend/vectorizer/test_float.ml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,22 @@ type t1 =
55
mutable d1 : float
66
}
77

8-
let[@inline never] [@local never] [@specialize never] add_mutable_record
9-
(a : t1) (b : t1) (c : t1) : t1 =
8+
let[@opaque] [@specialize never] add_mutable_record (a : t1) (b : t1) (c : t1) :
9+
t1 =
1010
c.d0 <- Float.add a.d0 b.d0;
1111
c.d1 <- Float.add a.d1 b.d1;
1212
c
1313

14-
let[@inline never] [@local never] [@specialize never] copy_mutable_record
15-
(a : t1) (b : t1) : t1 =
14+
let[@opaque] [@specialize never] copy_mutable_record (a : t1) (b : t1) : t1 =
1615
b.d0 <- a.d0;
1716
b.d1 <- a.d1;
1817
b
1918

20-
let[@inline never] [@local never] [@specialize never] add_mutable_record_fresh
21-
(a : t1) (b : t1) : t1 =
19+
let[@opaque] [@specialize never] add_mutable_record_fresh (a : t1) (b : t1) : t1
20+
=
2221
{ d0 = Float.add a.d0 b.d0; d1 = Float.add a.d1 b.d1 }
2322

24-
let[@inline never] [@local never] [@specialize never] copy_mutable_record_fresh
25-
(a : t1) : t1 =
23+
let[@opaque] [@specialize never] copy_mutable_record_fresh (a : t1) : t1 =
2624
{ d0 = a.d0; d1 = a.d1 }
2725

2826
type t4 =
@@ -32,20 +30,18 @@ type t4 =
3230
mutable d3 : float
3331
}
3432

35-
let[@inline never] [@local never] [@specialize never] add_mutable_record_t4
36-
(a : t1) (b : t1) (c : t4) : t4 =
33+
let[@opaque] [@specialize never] add_mutable_record_t4 (a : t1) (b : t1)
34+
(c : t4) : t4 =
3735
c.d0 <- Float.add a.d0 b.d0;
3836
c.d1 <- Float.add a.d1 b.d1;
3937
c.d2 <- Float.add a.d0 b.d0;
4038
c.d3 <- Float.add a.d1 b.d1;
4139
c
4240

43-
let[@inline never] [@local never] [@specialize never] copy_mutable_record_t4
44-
(a : t1) (b : t1) : t4 =
41+
let[@opaque] [@specialize never] copy_mutable_record_t4 (a : t1) (b : t1) : t4 =
4542
{ d0 = a.d0; d1 = a.d1; d2 = b.d0; d3 = b.d1 }
4643

47-
let[@inline never] [@local never] [@specialize never] dup_mutable_record_t4
48-
(a : t1) : t4 =
44+
let[@opaque] [@specialize never] dup_mutable_record_t4 (a : t1) : t4 =
4945
{ d0 = a.d0; d1 = a.d1; d2 = a.d0; d3 = a.d1 }
5046

5147
let print_t1 ppf (t1 : t1) =

flambda-backend/tests/backend/vectorizer/test_float_unboxed.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ type t1 = { mutable d0: float#;
1717
}
1818

1919

20-
let[@inline never] [@local never][@specialize never] copy_mutable_record (a : t1) (b: t1) : unit =
20+
let[@opaque][@specialize never] copy_mutable_record (a : t1) (b: t1) : unit =
2121
b.d0 <- a.d0;
2222
b.d1 <- a.d1;
2323
()
2424

2525
(* Currently, can't vectorize because of the specific floatmem operation (looks like
2626
it is treated overly conservatively. *)
27-
let[@inline never] [@local never][@specialize never] add_mutable_record (a : t1) (b: t1) (c : t1) : t1 =
27+
let[@opaque][@specialize never] add_mutable_record (a : t1) (b: t1) (c : t1) :
28+
t1 =
2829
c.d0 <- Float_u.add a.d0 b.d0;
2930
c.d1 <- Float_u.add a.d1 b.d1;
3031
c.d2 <- Float_u.add a.d2 b.d2;

flambda-backend/tests/backend/vectorizer/test_int64.ml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,24 @@ type t1 =
66
}
77

88
(* Can't vectorize because int64 are boxed. *)
9-
let[@inline never] [@local never] [@specialize never] add_mutable_record
10-
(a : t1) (b : t1) (c : t1) : t1 =
9+
let[@opaque] [@specialize never] add_mutable_record (a : t1) (b : t1) (c : t1) :
10+
t1 =
1111
c.d0 <- Int64.add a.d0 b.d0;
1212
c.d1 <- Int64.add a.d1 b.d1;
1313
c
1414

1515
(* Can't vectorize because memory write requires [caml_modify]. *)
16-
let[@inline never] [@local never] [@specialize never] copy_mutable_record
17-
(a : t1) (b : t1) : t1 =
16+
let[@opaque] [@specialize never] copy_mutable_record (a : t1) (b : t1) : t1 =
1817
b.d0 <- a.d0;
1918
b.d1 <- a.d1;
2019
b
2120

2221
(* Can't vectorize because int64 are boxed *)
23-
let[@inline never] [@local never] [@specialize never] add_mutable_record_fresh
24-
(a : t1) (b : t1) : t1 =
22+
let[@opaque] [@specialize never] add_mutable_record_fresh (a : t1) (b : t1) : t1
23+
=
2524
{ d0 = Int64.add a.d0 b.d0; d1 = Int64.add a.d1 b.d1 }
2625

27-
let[@inline never] [@local never] [@specialize never] copy_mutable_record_fresh
28-
(a : t1) : t1 =
26+
let[@opaque] [@specialize never] copy_mutable_record_fresh (a : t1) : t1 =
2927
{ d0 = a.d0; d1 = a.d1 }
3028

3129
type t4 =
@@ -36,20 +34,18 @@ type t4 =
3634
}
3735

3836
(* Can't vectorize because int64 are boxed. *)
39-
let[@inline never] [@local never] [@specialize never] add_mutable_record_t4
40-
(a : t1) (b : t1) (c : t4) : t4 =
37+
let[@opaque] [@specialize never] add_mutable_record_t4 (a : t1) (b : t1)
38+
(c : t4) : t4 =
4139
c.d0 <- Int64.add a.d0 b.d0;
4240
c.d1 <- Int64.add a.d1 b.d1;
4341
c.d2 <- Int64.add a.d0 b.d0;
4442
c.d3 <- Int64.add a.d1 b.d1;
4543
c
4644

47-
let[@inline never] [@local never] [@specialize never] copy_mutable_record_t4
48-
(a : t1) (b : t1) : t4 =
45+
let[@opaque] [@specialize never] copy_mutable_record_t4 (a : t1) (b : t1) : t4 =
4946
{ d0 = a.d0; d1 = a.d1; d2 = b.d0; d3 = b.d1 }
5047

51-
let[@inline never] [@local never] [@specialize never] dup_mutable_record_t4
52-
(a : t1) : t4 =
48+
let[@opaque] [@specialize never] dup_mutable_record_t4 (a : t1) : t4 =
5349
{ d0 = a.d0; d1 = a.d1; d2 = a.d0; d3 = a.d1 }
5450

5551
let print_t1 ppf (t1 : t1) =

flambda-backend/tests/backend/vectorizer/test_int64_unboxed.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ end
1212

1313
type t1 = { mutable d0 : int64# ; mutable d1: int64# }
1414

15-
let[@inline never] [@local never][@specialize never] add_mutable_record (a : t1) (b: t1) (c : t1) : t1 =
15+
let[@opaque][@specialize never] add_mutable_record (a : t1) (b: t1) (c : t1) :
16+
t1 =
1617
c.d0 <- Int64_u.add a.d0 b.d0;
1718
c.d1 <- Int64_u.add a.d1 b.d1;
1819
c
1920

20-
let[@inline never] [@local never][@specialize never] copy_mutable_record (a : t1) (b: t1) : unit =
21+
let[@opaque][@specialize never] copy_mutable_record (a : t1) (b: t1) : unit =
2122
b.d0 <- a.d0;
2223
b.d1 <- a.d1;
2324
()
@@ -28,7 +29,8 @@ type t2 = {
2829
mutable d2: int64# ;
2930
mutable d3: int64# }
3031

31-
let[@inline never] [@local never][@specialize never] add_fours_mutable_record (a : t1) (b: t1) (c : t2) : unit =
32+
let[@opaque][@specialize never] add_fours_mutable_record (a : t1) (b: t1)
33+
(c : t2) : unit =
3234
c.d0 <- Int64_u.add a.d0 b.d0;
3335
c.d1 <- Int64_u.add a.d1 b.d1;
3436
c.d2 <- Int64_u.add a.d0 b.d0;

flambda-backend/tests/backend/vectorizer/test_spill_valx2.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type s =
4848

4949
let ( + ) = Int64.add
5050

51-
let[@inline never] [@local never] foo a =
51+
let[@opaque] foo a =
5252
let f0 = a.f0 in
5353
let f1 = a.f1 in
5454
let f2 = a.f2 in

flambda-backend/tests/backend/zero_alloc_checker/test_inference.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ let[@zero_alloc] f_call_var x = M_alloc_var.f_alloc2 x
2222
Here we show that if we give it a signature that passes the typechecker (the
2323
mli has [val[@zero_alloc (arity 1)] f_arity_one : int -> int -> int]), it
2424
correctly gets checked and gives a zero_alloc backend error. *)
25-
let f_arity_one x y = x + y
25+
let f_arity_one x =
26+
let () = () in
27+
fun y -> x + y
2628

2729
(* Shadowing: the mli marks [f_shadow] zero_alloc. That check should only apply
2830
to the last such function in the file, so we get no error even though there
@@ -99,7 +101,7 @@ module type S = functor () -> sig
99101
end
100102

101103
module F () = struct
102-
let f x = Some x
104+
let[@opaque] f x = Some x
103105
end
104106

105107
module _ : S = F
Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,71 @@
1-
File "test_inference.ml", line 1:
2-
Error: The implementation test_inference.ml
3-
does not match the interface test_inference.cmi:
4-
Values do not match:
5-
val f_arity_one : int -> int -> int
6-
is not included in
7-
val f_arity_one : int -> int -> int [@@zero_alloc arity 1]
8-
zero_alloc arity mismatch:
9-
When using "zero_alloc" in a signature, the syntactic arity of
10-
the implementation must match the function type in the interface.
11-
Here the former is 2 and the latter is 1.
12-
File "test_inference.mli", line 11, characters 0-58:
13-
Expected declaration
14-
File "test_inference.ml", line 25, characters 4-15: Actual declaration
1+
File "test_inference.ml", line 6, characters 27-35:
2+
Error: Annotation check for zero_alloc failed on function Test_inference.f_alloc (camlTest_inference.f_alloc_HIDE_STAMP).
3+
4+
File "test_inference.ml", line 6, characters 31-35:
5+
Error: allocation of 24 bytes
6+
7+
File "test_inference.ml", line 15, characters 30-38:
8+
Error: Annotation check for zero_alloc failed on function Test_inference.M_alloc_var.f_alloc2 (camlTest_inference.f_alloc2_HIDE_STAMP).
9+
10+
File "test_inference.ml", line 15, characters 34-38:
11+
Error: allocation of 24 bytes
12+
13+
File "test_inference.ml", lines 25-27, characters 16-16:
14+
Error: Annotation check for zero_alloc failed on function Test_inference.f_arity_one (camlTest_inference.f_arity_one_HIDE_STAMP).
15+
16+
File "test_inference.ml", line 27, characters 2-16:
17+
Error: allocation of 32 bytes for closure
18+
19+
File "test_inference.ml", line 40, characters 19-27:
20+
Error: Annotation check for zero_alloc failed on function Test_inference.f_shadow_alloc (camlTest_inference.f_shadow_alloc_HIDE_STAMP).
21+
22+
File "test_inference.ml", line 40, characters 23-27:
23+
Error: allocation of 24 bytes
24+
25+
File "test_inference.ml", line 46, characters 24-36:
26+
Error: Annotation check for zero_alloc failed on function Test_inference.f_shadow_alloc_both (camlTest_inference.f_shadow_alloc_both_HIDE_STAMP).
27+
28+
File "test_inference.ml", line 46, characters 28-36:
29+
Error: allocation of 24 bytes
30+
31+
File "test_inference.ml", line 61, characters 17-25:
32+
Error: Annotation check for zero_alloc failed on function Test_inference.f_basic_fail (camlTest_inference.f_basic_fail_HIDE_STAMP).
33+
34+
File "test_inference.ml", line 61, characters 21-25:
35+
Error: allocation of 24 bytes
36+
37+
File "test_inference.ml", lines 66-71, characters 18-15:
38+
Error: Annotation check for zero_alloc strict failed on function Test_inference.f_strict_fail (camlTest_inference.f_strict_fail_HIDE_STAMP).
39+
40+
File "test_inference.ml", line 70, characters 12-35:
41+
Error: called function may allocate on a path to exceptional return (direct call camlCamlinternalFormat.make_printf_HIDE_STAMP) (test_inference.ml:70,12--35;printf.ml:48,18--43;printf.ml:46,2--31)
42+
43+
File "test_inference.ml", line 70, characters 12-35:
44+
Error: called function may allocate on a path to exceptional return (indirect call)
45+
46+
File "test_inference.ml", line 71, characters 10-15:
47+
Error: allocation of 24 bytes on a path to exceptional return
48+
49+
File "test_inference.ml", line 82, characters 15-23:
50+
Error: Annotation check for zero_alloc failed on function Test_inference.f_opt_fail (camlTest_inference.f_opt_fail_HIDE_STAMP).
51+
52+
File "test_inference.ml", line 82, characters 19-23:
53+
Error: allocation of 24 bytes
54+
55+
File "test_inference.ml", lines 88-93, characters 22-15:
56+
Error: Annotation check for zero_alloc strict failed on function Test_inference.f_strict_opt_fail (camlTest_inference.f_strict_opt_fail_HIDE_STAMP).
57+
58+
File "test_inference.ml", line 92, characters 12-35:
59+
Error: called function may allocate on a path to exceptional return (direct call camlCamlinternalFormat.make_printf_HIDE_STAMP) (test_inference.ml:92,12--35;printf.ml:48,18--43;printf.ml:46,2--31)
60+
61+
File "test_inference.ml", line 92, characters 12-35:
62+
Error: called function may allocate on a path to exceptional return (indirect call)
63+
64+
File "test_inference.ml", line 93, characters 10-15:
65+
Error: allocation of 24 bytes on a path to exceptional return
66+
67+
File "test_inference.ml", line 104, characters 17-27:
68+
Error: Annotation check for zero_alloc failed on function Test_inference.F.f (camlTest_inference.f_HIDE_STAMP).
69+
70+
File "test_inference.ml", line 104, characters 21-27:
71+
Error: allocation of 16 bytes

0 commit comments

Comments
 (0)