forked from ocaml/ocaml
/
w53.ml
357 lines (256 loc) · 10.2 KB
/
w53.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
(* TEST
flags = "-w +A-60-70"
* setup-ocamlc.byte-build-env
** ocamlc.byte
compile_only = "true"
*** check-ocamlc.byte-output
*)
let h x = x [@inline] (* rejected *)
let h x = x [@ocaml.inline] (* rejected *)
let i x = x [@inlined] (* rejected *)
let j x = x [@ocaml.inlined] (* rejected *)
let k x = (h [@inlined]) x (* accepted *)
let k' x = (h [@ocaml.inlined]) x (* accepted *)
let l x = h x [@inlined] (* rejected *)
let m x = x [@tailcall] (* rejected *)
let n x = x [@ocaml.tailcall] (* rejected *)
let o x = (h [@tailcall]) x (* accepted *)
let p x = (h [@ocaml.tailcall]) x (* accepted *)
let q x = h x [@tailcall] (* rejected *)
module type E = sig end
module A(E:E) = struct end [@@inline] (* accepted *)
module A'(E:E) = struct end [@@ocaml.inline] (* accepted *)
module B = ((functor (E:E) -> struct end) [@inline]) (* accepted *)
module B' = ((functor (E:E) -> struct end) [@ocaml.inline]) (* accepted *)
module C = struct end [@@inline] (* rejected *)
module C' = struct end [@@ocaml.inline] (* rejected *)
module D = struct end [@@inlined] (* rejected *)
module D' = struct end [@@ocaml.inlined] (* rejected *)
module F = (A [@inlined])(struct end) (* accepted *)
module F' = (A [@ocaml.inlined])(struct end) (* accepted *)
module G = (A [@inline])(struct end) (* rejected *)
module G' = (A [@ocaml.inline])(struct end) (* rejected *)
module H = Set.Make [@inlined] (Int32) (* GPR#1808 *)
module I = Set.Make [@inlined]
module I' = Set.Make [@ocaml.inlined]
module J = Set.Make [@@inlined]
module J' = Set.Make [@@ocaml.inlined]
module type K = sig
val a1 : int [@deprecated] (* rejected *)
val a2 : int [@@deprecated] (* accepted *)
[@@@deprecated] (* accepted*)
end
let [@unrolled 42] rec test_unrolled x = (* rejected *)
match x with
| 0 -> ()
| n -> test_unrolled (n - 1)
let () = (test_unrolled [@unrolled 42]) 10 (* accepted *)
let test_ppwarning = 42 [@@ppwarning "warning"]
(* accepted (but issues its own warning *)
type test_literal_pattern =
| Lit_pat1 of int [@warn_on_literal_pattern] (* accepted *)
| Lit_pat2 of int [@@warn_on_literal_pattern] (* rejected *)
module type TestImmediate = sig
type t1 [@@immediate] (* accepted *)
type t2 [@@@immediate] (* rejected *)
type t3 [@@immediate64] (* accepted *)
type t4 [@@@immediate64] (* rejected *)
end
module TestImmediate2 = struct
let x = (4 [@immediate], 42 [@immediate64]) (* rejected *)
end
module type TestBoxed = sig
type t1 = {x : int} [@@boxed] (* accepted *)
type t2 = {x : int} [@@@boxed] (* rejected *)
type t3 = {x : int} [@@unboxed] (* accepted *)
type t4 = {x : int} [@@@unboxed] (* rejected *)
val x : int [@@unboxed] (* rejected *)
end
module TestBoxed2 = struct
let x = (5 [@unboxed], 42 [@boxed]) (* rejected *)
end
module type TestPrincipalSig = sig
type 'a t1 = 'a [@@principal] (* rejected *)
type 'a t2 = 'a [@@noprincipal] (* rejected *)
type s1 = Foo1 [@principal] (* rejected *)
type s2 = Foo2 [@noprincipal] (* rejected *)
val x : int [@principal] (* rejected *)
val y : int [@noprincipal] (* rejected *)
[@@@principal] (* accepted *)
[@@@noprincipal] (* accepted *)
end
module TestPrincipalStruct = struct
type 'a t1 = 'a [@@principal] (* rejected *)
type 'a t2 = 'a [@@noprincipal] (* rejected *)
type s1 = Foo1 [@principal] (* rejected *)
type s2 = Foo2 [@noprincipal] (* rejected *)
let x = 5 [@principal] (* rejected *)
let y = 42 [@noprincipal] (* rejected *)
[@@@principal] (* accepted *)
[@@@noprincipal] (* accepted *)
end
module type TestNolabelsSig = sig
type 'a t1 = 'a [@@nolabels] (* rejected *)
type s1 = Foo1 [@nolabels] (* rejected *)
val x : int [@nolabels] (* rejected *)
[@@@nolabels] (* accepted *)
end
module TestNolabelsStruct = struct
type 'a t1 = 'a [@@nolabels] (* rejected *)
type s1 = Foo1 [@nolabels] (* rejected *)
let x = 5 [@nolabels] (* rejected *)
[@@@nolabels] (* accepted *)
end
module type TestFlambdaSig = sig
type 'a t1 = 'a [@@flambda_o3] (* rejected *)
type 'a t2 = 'a [@@flambda_oclassic] (* rejected *)
type s1 = Foo1 [@flambda_o3] (* rejected *)
type s2 = Foo2 [@flambda_oclassic] (* rejected *)
val x : int [@flambda_o3] (* rejected *)
val y : int [@flambda_oclassic] (* rejected *)
[@@@flambda_o3] (* rejected *)
[@@@flambda_oclassic] (* rejected *)
end
module TestFlambdaStruct = struct
type 'a t1 = 'a [@@flambda_o3] (* rejected *)
type 'a t2 = 'a [@@flambda_oclassic] (* rejected *)
type s1 = Foo1 [@flambda_o3] (* rejected *)
type s2 = Foo2 [@flambda_oclassic] (* rejected *)
let x = 5 [@flambda_o3] (* rejected *)
let y = 42 [@flambda_oclassic] (* rejected *)
[@@@flambda_o3] (* accepted *)
[@@@flambda_oclassic] (* accepted *)
end
module type TestAflInstRatioSig = sig
type 'a t1 = 'a [@@afl_inst_ratio 42] (* rejected *)
type s1 = Foo1 [@afl_inst_ratio 42] (* rejected *)
val x : int [@afl_inst_ratio 42] (* rejected *)
[@@@afl_inst_ratio 42] (* rejected *)
end
module TestAflInstRatioStruct = struct
type 'a t1 = 'a [@@afl_inst_ratio 42] (* rejected *)
type s1 = Foo1 [@afl_inst_ratio 42] (* rejected *)
let x = 5 [@afl_inst_ratio 42] (* rejected *)
[@@@afl_inst_ratio 42] (* accepted *)
end
(* No "accepted" test for curry because the user shouldn't write it *)
module type TestCurry = sig
type 'a t1 = 'a [@@curry 42] (* rejected *)
type s1 = Foo1 [@curry 42] (* rejected *)
val x : int [@curry 42] (* rejected *)
[@@@curry 42] (* rejected *)
end
module TestCurryStruct = struct
type 'a t1 = 'a [@@curry 42] (* rejected *)
type s1 = Foo1 [@curry 42] (* rejected *)
let x = 5 [@curry 42] (* rejected *)
[@@@curry 42] (* rejected *)
end
(* No "accepted" test for include_functor because the user shouldn't write it *)
module type TestIncludeFunctor = sig
type 'a t1 = 'a [@@include_functor 42] (* rejected *)
type s1 = Foo1 [@include_functor 42] (* rejected *)
val x : int [@include_functor 42] (* rejected *)
[@@@include_functor 42] (* rejected *)
end
module TestIncludeFunctorStruct = struct
type 'a t1 = 'a [@@include_functor 42] (* rejected *)
type s1 = Foo1 [@include_functor 42] (* rejected *)
let x = 5 [@include_functor 42] (* rejected *)
[@@@include_functor 42] (* rejected *)
end
module type TestLocalOptSig = sig
type 'a t1 = 'a [@@local_opt] (* rejected *)
type s1 = Foo1 [@local_opt] (* rejected *)
val x : int64 [@@local_opt] (* rejected *)
external y : (int64 [@local_opt]) -> (int64 [@local_opt]) = "x" (* accepted *)
external z : int64 -> int64 = "x" [@@local_opt] (* rejected *)
end
module TestLocalOptStruct = struct
type 'a t1 = 'a [@@local_opt] (* rejected *)
type s1 = Foo1 [@local_opt] (* rejected *)
let x : int64 = 42L [@@local_opt] (* rejected *)
external y : (int64 [@local_opt]) -> (int64 [@local_opt]) = "x" (* accepted *)
external z : int64 -> int64 = "x" [@@local_opt] (* rejected *)
end
module type TestLocalGlobalSig = sig
type 'a t1 = 'a [@local] (* rejected *)
type 'a t1' = 'a [@global] (* rejected *)
type 'a t1'' = 'a [@nonlocal] (* rejected *)
type t2 = { x : int [@local] } (* rejected *)
type t2' = { x : int [@global] } (* accepted *)
type t2'' = { x : int [@nonlocal] } (* accepted *)
val x : 'a list -> ('a [@local]) list (* rejected *)
val x' : 'a list -> ('a [@global]) list (* rejected *)
val x'' : 'a list -> ('a [@nonlocal]) list (* rejected *)
val y : 'a -> f:(('a -> 'b) [@local]) -> 'b (* accepted *)
val y' : 'a -> f:(('a -> 'b) [@global]) -> 'b (* rejected *)
val y'' : 'a -> f:(('a -> 'b) [@nonlocal]) -> 'b (* rejected *)
val z : 'a [@@local] (* rejected *)
val z' : 'a [@@global] (* rejected *)
val z'' : 'a [@@nonlocal] (* rejected *)
val w : 'a [@@@local] (* rejected *)
val w' : 'a [@@@global] (* rejected *)
val w'' : 'a [@@@nonlocal] (* rejected *)
end
module TestLocalGlobalStruct = struct
type 'a t1 = 'a [@local] (* rejected *)
type 'a t1' = 'a [@global] (* rejected *)
type 'a t1'' = 'a [@nonlocal] (* rejected *)
type t2 = { x : int [@local] } (* rejected *)
type t2' = { x : int [@global] } (* accepted *)
type t2'' = { x : int [@nonlocal] } (* accepted *)
let f (a [@local]) = a (* accepted *)
let g (a [@global]) = a (* rejected *)
let h (a [@nonlocal]) = a (* rejected *)
end
module type TestTail = sig
type 'a t1 = 'a [@tail] (* rejected *)
type 'a t1' = 'a [@nontail] (* rejected *)
type t2 = { x : int [@tail] } (* rejected *)
type t2' = { x : int [@nontail] } (* rejected *)
val y : 'a -> f:(('a -> 'b) [@tail]) -> 'b (* rejected *)
val y' : 'a -> f:(('a -> 'b) [@nontail]) -> 'b (* rejected *)
val z : 'a [@@tail] (* rejected *)
val z' : 'a [@@nontail] (* rejected *)
[@@@tail] (* rejected *)
[@@@nontail] (* rejected *)
end
module TestTail = struct
let f (a [@tail]) = a (* rejected *)
let f' (a [@nontail]) = a (* rejected *)
let [@tail] g a = a (* rejected *)
let [@nontail] g' a = a (* rejected *)
let h a = a [@tail] (* rejected *)
let h' a = a [@nontail] (* rejected *)
let rec k x = k x [@tail] (* accepted *)
let rec k' x = k' x [@nontail] (* accepted *)
end
module type TestNoallocSig = sig
type 'a t1 = 'a [@@noalloc] (* rejected *)
type s1 = Foo1 [@noalloc] (* rejected *)
val x : int64 [@@noalloc] (* rejected *)
external y : (int64 [@noalloc]) -> (int64 [@noalloc]) = "x" (* rejected *)
external z : int64 -> int64 = "x" [@@noalloc] (* accepted *)
end
module TestNoallocStruct = struct
type 'a t1 = 'a [@@noalloc] (* rejected *)
type s1 = Foo1 [@noalloc] (* rejected *)
let x : int64 = 42L [@@noalloc] (* rejected *)
external y : (int64 [@noalloc]) -> (int64 [@noalloc]) = "x" (* rejected *)
external z : int64 -> int64 = "x" [@@noalloc] (* accepted *)
end
module type TestUntaggedSig = sig
type 'a t1 = 'a [@@untagged] (* rejected *)
type s1 = Foo1 [@untagged] (* rejected *)
val x : int [@@untagged] (* rejected *)
external y : (int [@untagged]) -> (int [@untagged]) = "x" "y" (* accepted *)
external z : int -> int = "x" "y" [@@untagged] (* accepted *)
end
module TestUntaggedStruct = struct
type 'a t1 = 'a [@@untagged] (* rejected *)
type s1 = Foo1 [@untagged] (* rejected *)
let x : int = 42 [@@untagged] (* rejected *)
external y : (int [@untagged]) -> (int [@untagged]) = "x" "y" (* accepted *)
external z : int -> int = "x" "y" [@@untagged] (* accepted *)
end