Debian Codegraph @

example/test.ml

raw symbols SCIP
1 type t =
2 | A
3 | B
4 [@@deriving enumerate]
5
6 let%test _ = all = [ A; B ]
7
8 type s =
9 | C
10 | D
11 [@@deriving enumerate]
12
13 let%test _ = all_of_s = [ C; D ]
14
15 type u =
16 | E
17 | F of s
18 [@@deriving enumerate]
19
20 let%test _ = all_of_u = [ E; F C; F D ]
21
22 module V = struct
23 type v =
24 | G of t
25 | H of u
26 [@@deriving enumerate]
27
28 let%test _ = all_of_v = [ G A; G B; H E; H (F C); H (F D) ]
29 end
30
31 type w = I of V.v [@@deriving enumerate]
32
33 let%test _ = all_of_w = [ I (V.G A); I (V.G B); I (V.H E); I (V.H (F C)); I (V.H (F D)) ]
34
35 type x =
36 [ `A
37 | `B of t
38 ]
39 [@@deriving enumerate]
40
41 let%test _ = all_of_x = [ `A; `B A; `B B ]
42
43 (* variant with multiple arguments are not special *)
44 type xx = [ `A of s * s ] [@@deriving enumerate]
45
46 let%test _ = all_of_xx = [ `A (C, C); `A (D, C); `A (C, D); `A (D, D) ]
47
48 type variant_inclusion =
49 [ x
50 | `C
51 | x
52 ]
53 [@@deriving enumerate]
54
55 let%test _ =
56 all_of_variant_inclusion
57 = (all_of_x :> variant_inclusion list) @ [ `C ] @ (all_of_x :> variant_inclusion list)
58 ;;
59
60 type y = J of t * s [@@deriving enumerate]
61
62 let%test _ = all_of_y = [ J (A, C); J (B, C); J (A, D); J (B, D) ]
63
64 type z = t * s [@@deriving enumerate]
65
66 let%test _ = all_of_z = [ A, C; B, C; A, D; B, D ]
67
68 type a =
69 { foo : t
70 ; bar : s
71 }
72 [@@deriving enumerate]
73
74 let%test _ =
75 all_of_a
76 = [ { foo = A; bar = C }
77 ; { foo = B; bar = C }
78 ; { foo = A; bar = D }
79 ; { foo = B; bar = D }
80 ]
81 ;;
82
83 type b = K of t * t * s [@@deriving enumerate]
84
85 let%test _ =
86 all_of_b
87 = [ K (A, A, C)
88 ; K (B, A, C)
89 ; K (A, B, C)
90 ; K (B, B, C)
91 ; K (A, A, D)
92 ; K (B, A, D)
93 ; K (A, B, D)
94 ; K (B, B, D)
95 ]
96 ;;
97
98 type c = t * t * s [@@deriving enumerate]
99
100 let%test _ =
101 all_of_c = [ A, A, C; B, A, C; A, B, C; B, B, C; A, A, D; B, A, D; A, B, D; B, B, D ]
102 ;;
103
104 type d =
105 { a : t
106 ; b : t
107 ; c : s
108 }
109 [@@deriving enumerate]
110
111 let%test _ =
112 all_of_d
113 = [ { a = A; b = A; c = C }
114 ; { a = B; b = A; c = C }
115 ; { a = A; b = B; c = C }
116 ; { a = B; b = B; c = C }
117 ; { a = A; b = A; c = D }
118 ; { a = B; b = A; c = D }
119 ; { a = A; b = B; c = D }
120 ; { a = B; b = B; c = D }
121 ]
122 ;;
123
124 type e = { foo : t } [@@deriving enumerate]
125
126 module M = struct
127 type nonrec e = { bar : e } [@@deriving enumerate]
128 end
129
130 let%test _ = M.all_of_e = [ { M.bar = { foo = A } }; { M.bar = { foo = B } } ]
131
132 type f = L of [ `A | `B ] [@@deriving enumerate]
133
134 let%test _ = all_of_f = [ L `A; L `B ]
135
136 type g = f [@@deriving enumerate]
137
138 let%test _ = all_of_g = all_of_f
139
140 type h =
141 | M
142 | N
143
144 type i = h =
145 | M
146 | N
147 [@@deriving enumerate]
148
149 let%test _ = all_of_i = [ M; N ]
150
151 type 'a j = 'a [@@deriving enumerate]
152 type k = i j [@@deriving enumerate]
153
154 let%test _ = all_of_k = [ M; N ]
155
156 let%test _ =
157 [%all: [ `A of [ `B | `C ] | `D of [ `E of [ `F ] ] ]] = [ `A `B; `A `C; `D (`E `F) ]
158 ;;
159
160 type l =
161 { baz : bool
162 ; quux : unit
163 }
164 [@@deriving enumerate]
165
166 let%test _ = all_of_l = [ { baz = false; quux = () }; { baz = true; quux = () } ]
167
168 type o = [ `A ] option [@@deriving enumerate]
169
170 let%test _ = all_of_o = [ None; Some `A ]
171
172 (* Check that enumerations are only computed once *)
173 type 'a count = 'a
174
175 let number_of_computations = ref 0
176
177 let all_of_count all_of_a =
178 incr number_of_computations;
179 all_of_a
180 ;;
181
182 type p =
183 { baz : bool count
184 ; quux : unit count
185 }
186 [@@deriving enumerate]
187
188 let%test _ = !number_of_computations = 2
189 let () = number_of_computations := 0
190
191 type p_nested =
192 [ `A of [ `B of unit count * unit count ] * [ `C of unit count * unit count ] ]
193 [@@deriving enumerate]
194
195 let%test _ = !number_of_computations = 4
196
197 (* checking the lack of unused value warning *)
198 type 'a phantom_variable = unit [@@deriving enumerate]
199 type empty
200
201 let%test _ = all_of_phantom_variable ([] : empty list) = [ () ]
202
203 (* check that the coercions happen correctly when nested *)
204 type q = [ x | `C ] option option [@@deriving enumerate]
205
206 let%test _ =
207 all_of_q
208 = [ None
209 ; Some None
210 ; Some (Some `A)
211 ; Some (Some (`B A))
212 ; Some (Some (`B B))
213 ; Some (Some `C)
214 ]
215 ;;
216
217 type 'tt tt =
218 [ `G of 'tt
219 | x
220 ]
221 [@@deriving enumerate]
222
223 let%test _ = all_of_tt [ () ] = [ `G (); `A; `B A; `B B ]
224
225 type ir =
226 | A of { foo : i }
227 | B
228 [@@deriving enumerate]
229
230 let%test _ = all_of_ir = [ A { foo = M }; A { foo = N }; B ]
231
232 (* Tricky case where the scoping of type variable prevents generalization. If the
233 constraints looked like (... :> [ a tt | `F ]) (instead of the same thing with s/a/'a/)
234 where there is a fun (type a) somewhere in scope it would work, but it is simpler to
235 remove variables than replace them by local types consistently. *)
236 type 'a nested_include_with_variable = [ 'a tt | `F ] option [@@deriving enumerate]
237 type +'a variance = 'a [@@deriving enumerate]
238
239 module Check_sigs = struct
240 module type S1 = sig
241 type t =
242 | A
243 | B
244 [@@deriving_inline enumerate]
245
246 include sig
247 [@@@ocaml.warning "-32"]
248
249 include Ppx_enumerate_lib.Enumerable.S with type t := t
250 end
251 [@@ocaml.doc "@inline"]
252
253 [@@@end]
254 end
255
256 module type S2 = sig
257 type t =
258 | A
259 | B
260
261 val all : t list
262 end
263
264 let _ =
265 fun (module M : S1) ->
266 let module M : S2 = M in
267 let module _ : S1 = M in
268 ()
269 ;;
270 end
271
272 module Check_sigs_with_params_and_variance = struct
273 module type S1 = sig
274 type (+'a, 'b) t =
275 | A of 'a
276 | B of 'b
277 [@@deriving enumerate]
278 end
279
280 module type S2 = sig
281 type ('a, +'b) t =
282 | A of 'a
283 | B of 'b
284
285 val all : 'a list -> 'b list -> ('a, 'b) t list
286 end
287
288 let _ =
289 fun (module M : S1) ->
290 let module M : S2 = M in
291 let module _ : S1 = M in
292 ()
293 ;;
294 end
295
296 (* if you remove the "~no_exhaustiveness_check" flag to enumerate, the compilation time
297 will noticeably spike. *)
298 type big_record =
299 { field1 : t
300 ; field2 : t
301 ; field3 : t
302 ; field4 : t
303 ; field5 : s
304 ; field6 : s
305 ; field7 : t
306 ; field8 : t
307 ; field9 : t
308 ; fielda : t
309 ; fieldb : t
310 ; fieldc : t
311 ; fieldd : t
312 ; fielde : t
313 ; fieldf : t
314 ; fieldg : u
315 ; fieldh : t
316 ; fieldi : t
317 ; fieldj : t
318 ; fieldk : t
319 ; fieldl : t
320 (* (* just keep adding fields to make things worse. *)
321 fieldm: t;
322 fieldn: t;
323 fieldo: s;
324 fieldp: t;
325 fieldq: s;
326 fieldr: s;
327 fields: u;
328 *)
329 }
330 [@@deriving enumerate ~no_exhaustiveness_check]
331
332 module Wildcard : sig
333 type 'a transparent =
334 | A
335 | B of bool
336 [@@deriving_inline enumerate]
337
338 include sig
339 [@@@ocaml.warning "-32"]
340
341 val all_of_transparent : 'a list -> 'a transparent list
342 end
343 [@@ocaml.doc "@inline"]
344
345 [@@@end]
346
347 type 'a opaque [@@deriving_inline enumerate]
348
349 include sig
350 [@@@ocaml.warning "-32"]
351
352 val all_of_opaque : 'a list -> 'a opaque list
353 end
354 [@@ocaml.doc "@inline"]
355
356 [@@@end]
357 end = struct
358 type _ transparent =
359 | A
360 | B of bool
361 [@@deriving enumerate]
362
363 let%test _ = all_of_transparent all_of_x = [ A; B false; B true ]
364
365 type 'a opaque = 'a option [@@deriving enumerate]
366
367 let%test _ = all_of_opaque all_of_x = [ None; Some `A; Some (`B A); Some (`B B) ]
368 end