Skip to content

Commit 4de9d2f

Browse files
authored
Disable mixed blocks in extensible variants (#2652)
1 parent b2fe210 commit 4de9d2f

File tree

13 files changed

+133
-132
lines changed

13 files changed

+133
-132
lines changed

ocaml/testsuite/tests/mixed-blocks/constructor_args.ml

Lines changed: 9 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,6 @@ type t =
4343
| Mixed11 of float * int32# * float32# * float# * int64# * nativeint#
4444
| Uniform2 of float * float
4545

46-
type t_ext = ..
47-
48-
type t_ext +=
49-
| Ext_mixed1 of float#
50-
| Ext_mixed2 of float * float#
51-
| Ext_mixed3 of float * float# * float#
52-
| Ext_mixed4 of float * float# * int32#
53-
| Ext_mixed5 of float * float# * int * int32# * nativeint# * int64#
54-
| Ext_mixed6 of float * int32# * float#
55-
| Ext_mixed7 of float * int64# * float# * nativeint#
56-
| Ext_mixed8 of float * int32# * float# * int64# * float#
57-
| Ext_mixed9 of float * float# * float32#
58-
| Ext_mixed10 of float * float32# * float# * int64# * float#
59-
| Ext_mixed11 of float * int32# * float32# * float# * int64# * nativeint#
60-
6146
let sprintf = Printf.sprintf
6247

6348
let to_string = function
@@ -98,57 +83,18 @@ let to_string = function
9883
(Float_u.to_float x4) (Int64_u.to_int x5) (Nativeint_u.to_int x6)
9984
| Uniform2 (x1, x2) -> sprintf "Uniform2 (%f, %f)" x1 x2
10085

101-
let ext_to_string = function
102-
| Ext_mixed1 x -> sprintf "Ext_mixed1 %f" (Float_u.to_float x)
103-
| Ext_mixed2 (x1, x2) -> sprintf "Ext_mixed2 (%f, %f)" x1 (Float_u.to_float x2)
104-
| Ext_mixed3 (x1, x2, x3) ->
105-
sprintf "Ext_mixed3 (%f, %f, %f)"
106-
x1 (Float_u.to_float x2) (Float_u.to_float x3)
107-
| Ext_mixed4 (x1, x2, x3) ->
108-
sprintf "Ext_mixed4 (%f, %f, %i)"
109-
x1 (Float_u.to_float x2) (Int32_u.to_int x3)
110-
| Ext_mixed5 (x1, x2, x3, x4, x5, x6) ->
111-
sprintf "Mixed5 (%f, %f, %i, %i, %i, %i)"
112-
x1 (Float_u.to_float x2) x3 (Int32_u.to_int x4) (Nativeint_u.to_int x5)
113-
(Int64_u.to_int x6)
114-
| Ext_mixed6 (x1, x2, x3) ->
115-
sprintf "Ext_mixed6 (%f, %i, %f)"
116-
x1 (Int32_u.to_int x2) (Float_u.to_float x3)
117-
| Ext_mixed7 (x1, x2, x3, x4) ->
118-
sprintf "Ext_mixed7 (%f, %i, %f, %i)"
119-
x1 (Int64_u.to_int x2) (Float_u.to_float x3) (Nativeint_u.to_int x4)
120-
| Ext_mixed8 (x1, x2, x3, x4, x5) ->
121-
sprintf "Ext_mixed8 (%f, %i, %f, %i, %f)"
122-
x1 (Int32_u.to_int x2) (Float_u.to_float x3) (Int64_u.to_int x4)
123-
(Float_u.to_float x5)
124-
| Ext_mixed9 (x1, x2, x3) ->
125-
sprintf "Ext_mixed9 (%f, %f, %f)" x1 (Float_u.to_float x2)
126-
(Float_u.to_float (Float32_u.to_float x3))
127-
| Ext_mixed10 (x1, x2, x3, x4, x5) ->
128-
sprintf "Ext_mixed10 (%f, %f, %f, %i, %f)"
129-
x1 (Float_u.to_float (Float32_u.to_float x2)) (Float_u.to_float x3)
130-
(Int64_u.to_int x4) (Float_u.to_float x5)
131-
| Ext_mixed11 (x1, x2, x3, x4, x5, x6) ->
132-
sprintf "Ext_mixed11 (%f, %i, %f, %f, %i, %i)"
133-
x1 (Int32_u.to_int x2) (Float_u.to_float (Float32_u.to_float x3))
134-
(Float_u.to_float x4) (Int64_u.to_int x5) (Nativeint_u.to_int x6)
135-
| _ -> "<ext>"
136-
13786
let print t = print_endline (" " ^ to_string t)
138-
let print_ext t = print_endline (" " ^ ext_to_string t)
13987

14088
(**********************)
14189
(* Test: construction *)
14290

14391
let toplevel = Mixed1 #7.0
144-
let toplevel_ext = Ext_mixed1 #8.0
14592

14693
let run f =
14794
print_endline "Test (construction)";
14895
let lit = Mixed2 (3.0, #4.5) in
14996
let half_lit = Mixed3 (6.0, f, #5.0) in
15097
print toplevel;
151-
print_ext toplevel_ext;
15298
print lit;
15399
print half_lit;
154100
;;
@@ -179,17 +125,6 @@ let construct_and_destruct uf uf' f f' i i32 i64 i_n f32 =
179125
let Mixed9 (f, uf, f32) = Mixed9 (f, uf, f32) in
180126
let Mixed10 (f, f32, uf, i64, uf') = Mixed10 (f, f32, uf, i64, uf') in
181127
let Mixed11 (f, i32, f32, uf, i64, i_n) = Mixed11 (f, i32, f32, uf, i64, i_n) in
182-
let Ext_mixed1 uf = Ext_mixed1 uf in
183-
let Ext_mixed2 (f, uf) = Ext_mixed2 (f, uf) in
184-
let Ext_mixed3 (f, uf, uf') = Ext_mixed3 (f, uf, uf') in
185-
let Ext_mixed4 (f, uf, i32) = Ext_mixed4 (f, uf, i32) in
186-
let Ext_mixed5 (f, uf, i, i32, i_n, i64) = Ext_mixed5 (f, uf, i, i32, i_n, i64) in
187-
let Ext_mixed6 (f, i32, uf) = Ext_mixed6 (f, i32, uf) in
188-
let Ext_mixed7 (f, i64, uf, i_n) = Ext_mixed7 (f, i64, uf, i_n) in
189-
let Ext_mixed8 (f, i32, uf, i64, uf') = Ext_mixed8 (f, i32, uf, i64, uf') in
190-
let Ext_mixed9 (f, uf, f32) = Ext_mixed9 (f, uf, f32) in
191-
let Ext_mixed10 (f, f32, uf, i64, uf') = Ext_mixed10 (f, f32, uf, i64, uf') in
192-
let Ext_mixed11 (f, i32, f32, uf, i64, i_n) = Ext_mixed11 (f, i32, f32, uf, i64, i_n) in
193128
let Uniform2 (f, f') = Uniform2 (f, f') in
194129
sum uf uf' f f' i i32 i64 i_n f32
195130
[@@ocaml.warning "-partial-match"]
@@ -220,12 +155,12 @@ let () =
220155
(* Test: recursive groups *)
221156

222157
let rec f r =
223-
match r, t_rec1, t_rec2, t_ext_rec1, t_ext_rec2 with
158+
match r, t_rec1, t_rec2, t_rec3, t_rec4 with
224159
| Mixed1 a,
225160
Mixed1 x,
226161
Mixed2 (y1, y2),
227-
Ext_mixed1 z,
228-
Ext_mixed2 (w1, w2) ->
162+
Mixed1 z,
163+
Mixed2 (w1, w2) ->
229164
Float_u.to_float x +.
230165
y1 +. Float_u.to_float y2 +.
231166
Float_u.to_float z +.
@@ -234,21 +169,21 @@ let rec f r =
234169

235170
and t_rec1 = Mixed1 #4.0
236171
and t_rec2 = Mixed2 (5.0, #4.0)
237-
and t_ext_rec1 = Ext_mixed1 #5.0
238-
and t_ext_rec2 = Ext_mixed2 (6.0, #7.0)
172+
and t_rec3 = Mixed1 #5.0
173+
and t_rec4 = Mixed2 (6.0, #7.0)
239174

240175
let _ =
241176
Printf.printf "Test (mixed constructors in recursive groups):\n";
242177
print t_rec1;
243178
print t_rec2;
244-
print_ext t_ext_rec2;
245-
print_ext t_ext_rec2;
179+
print t_rec3;
180+
print t_rec4;
246181
let result = f t_rec1 in
247182
print_float " result (31.00)" result;
248183
print t_rec1;
249184
print t_rec2;
250-
print_ext t_ext_rec2;
251-
print_ext t_ext_rec2;
185+
print t_rec3;
186+
print t_rec4;
252187
;;
253188

254189
(**************************)

ocaml/testsuite/tests/mixed-blocks/constructor_args.reference

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
Test (construction)
22
Mixed1 7.000000
3-
Ext_mixed1 8.000000
43
Mixed2 (3.000000, 4.500000)
54
Mixed3 (6.000000, 17.000000, 5.000000)
65
Test (construct and destruct): 150.900000 = 150.900000 (PASS)
76
Test (mixed constructors in recursive groups):
87
Mixed1 4.000000
98
Mixed2 (5.000000, 4.000000)
10-
Ext_mixed2 (6.000000, 7.000000)
11-
Ext_mixed2 (6.000000, 7.000000)
9+
Mixed1 5.000000
10+
Mixed2 (6.000000, 7.000000)
1211
result (31.00): 31.00
1312
Mixed1 4.000000
1413
Mixed2 (5.000000, 4.000000)
15-
Ext_mixed2 (6.000000, 7.000000)
16-
Ext_mixed2 (6.000000, 7.000000)
14+
Mixed1 5.000000
15+
Mixed2 (6.000000, 7.000000)
1716
Test (pattern matching).
1817
Contents of fields:
1918
4.000

ocaml/testsuite/tests/typing-layouts-bits32/basics_beta.ml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,18 @@ type t11_1 = ..
7171
type t11_1 += A of t_bits32;;
7272
[%%expect{|
7373
type t11_1 = ..
74-
type t11_1 += A of t_bits32
74+
Line 3, characters 14-27:
75+
3 | type t11_1 += A of t_bits32;;
76+
^^^^^^^^^^^^^
77+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
7578
|}]
7679

7780
type t11_1 += B of int32#;;
7881
[%%expect{|
79-
type t11_1 += B of int32#
82+
Line 1, characters 14-25:
83+
1 | type t11_1 += B of int32#;;
84+
^^^^^^^^^^^
85+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
8086
|}]
8187

8288
type ('a : bits32) t11_2 = ..
@@ -88,7 +94,10 @@ type 'a t11_2 += B of 'a;;
8894
[%%expect{|
8995
type ('a : bits32) t11_2 = ..
9096
type 'a t11_2 += A of int
91-
type 'a t11_2 += B of 'a
97+
Line 5, characters 17-24:
98+
5 | type 'a t11_2 += B of 'a;;
99+
^^^^^^^
100+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
92101
|}]
93102

94103
(* not allowed: value in flat suffix *)

ocaml/testsuite/tests/typing-layouts-bits64/basics_beta.ml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,26 @@ Error: Expected all flat constructor arguments after non-value argument,
6868
(*****************************************************)
6969
(* Test 11: Allow bits64 in some extensible variants *)
7070

71+
(* CR layouts v5.9: Actually allow mixed extensible variant blocks. *)
72+
7173
(* See [basics_alpha.ml] and [basics_beta.ml] for now *)
7274
type t11_1 = ..
7375

7476
type t11_1 += A of t_bits64;;
7577
[%%expect{|
7678
type t11_1 = ..
77-
type t11_1 += A of t_bits64
79+
Line 3, characters 14-27:
80+
3 | type t11_1 += A of t_bits64;;
81+
^^^^^^^^^^^^^
82+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
7883
|}]
7984

8085
type t11_1 += B of int64#;;
8186
[%%expect{|
82-
type t11_1 += B of int64#
87+
Line 1, characters 14-25:
88+
1 | type t11_1 += B of int64#;;
89+
^^^^^^^^^^^
90+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
8391
|}]
8492

8593
type ('a : bits64) t11_2 = ..
@@ -91,7 +99,10 @@ type 'a t11_2 += B of 'a;;
9199
[%%expect{|
92100
type ('a : bits64) t11_2 = ..
93101
type 'a t11_2 += A of int
94-
type 'a t11_2 += B of 'a
102+
Line 5, characters 17-24:
103+
5 | type 'a t11_2 += B of 'a;;
104+
^^^^^^^
105+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
95106
|}]
96107

97108
(* not allowed: value in flat suffix *)

ocaml/testsuite/tests/typing-layouts-float32/basics.ml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,17 +582,15 @@ type t11_1 = ..
582582
Line 3, characters 14-28:
583583
3 | type t11_1 += A of t_float32;;
584584
^^^^^^^^^^^^^^
585-
Error: The enabled layouts extension does not allow for mixed constructors.
586-
You must enable -extension layouts_beta to use this feature.
585+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
587586
|}]
588587

589588
type t11_1 += B of float32#;;
590589
[%%expect{|
591590
Line 1, characters 14-27:
592591
1 | type t11_1 += B of float32#;;
593592
^^^^^^^^^^^^^
594-
Error: The enabled layouts extension does not allow for mixed constructors.
595-
You must enable -extension layouts_beta to use this feature.
593+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
596594
|}]
597595

598596
type ('a : float32) t11_2 = ..
@@ -607,8 +605,7 @@ type 'a t11_2 += A of int
607605
Line 5, characters 17-24:
608606
5 | type 'a t11_2 += B of 'a;;
609607
^^^^^^^
610-
Error: The enabled layouts extension does not allow for mixed constructors.
611-
You must enable -extension layouts_beta to use this feature.
608+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
612609
|}]
613610

614611
(***************************************)

ocaml/testsuite/tests/typing-layouts-float32/basics_beta.ml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,12 +560,18 @@ type t11_1 = ..
560560
type t11_1 += A of t_float32;;
561561
[%%expect{|
562562
type t11_1 = ..
563-
type t11_1 += A of t_float32
563+
Line 3, characters 14-28:
564+
3 | type t11_1 += A of t_float32;;
565+
^^^^^^^^^^^^^^
566+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
564567
|}]
565568

566569
type t11_1 += B of float32#;;
567570
[%%expect{|
568-
type t11_1 += B of float32#
571+
Line 1, characters 14-27:
572+
1 | type t11_1 += B of float32#;;
573+
^^^^^^^^^^^^^
574+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
569575
|}]
570576

571577
type ('a : float32) t11_2 = ..
@@ -577,7 +583,10 @@ type 'a t11_2 += B of 'a;;
577583
[%%expect{|
578584
type ('a : float32) t11_2 = ..
579585
type 'a t11_2 += A of int
580-
type 'a t11_2 += B of 'a
586+
Line 5, characters 17-24:
587+
5 | type 'a t11_2 += B of 'a;;
588+
^^^^^^^
589+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
581590
|}]
582591

583592
type t11_1 += C of t_float32 * string;;

ocaml/testsuite/tests/typing-layouts-float64/basics.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ Error: Don't know how to untag this type. Only int can be untagged.
573573
(******************************************************)
574574
(* Test 11: Allow float64 in some extensible variants *)
575575

576+
(* CR layouts v5.9: Actually allow mixed extensible variant blocks. *)
577+
576578
(* Currently these are only supported in alpha *)
577579

578580
type t11_1 = ..
@@ -583,17 +585,15 @@ type t11_1 = ..
583585
Line 3, characters 14-28:
584586
3 | type t11_1 += A of t_float64;;
585587
^^^^^^^^^^^^^^
586-
Error: The enabled layouts extension does not allow for mixed constructors.
587-
You must enable -extension layouts_beta to use this feature.
588+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
588589
|}]
589590

590591
type t11_1 += B of float#;;
591592
[%%expect{|
592593
Line 1, characters 14-25:
593594
1 | type t11_1 += B of float#;;
594595
^^^^^^^^^^^
595-
Error: The enabled layouts extension does not allow for mixed constructors.
596-
You must enable -extension layouts_beta to use this feature.
596+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
597597
|}]
598598

599599
type ('a : float64) t11_2 = ..
@@ -608,8 +608,7 @@ type 'a t11_2 += A of int
608608
Line 5, characters 17-24:
609609
5 | type 'a t11_2 += B of 'a;;
610610
^^^^^^^
611-
Error: The enabled layouts extension does not allow for mixed constructors.
612-
You must enable -extension layouts_beta to use this feature.
611+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
613612
|}]
614613

615614
(* Some extensible variants aren't supported, though. *)

ocaml/testsuite/tests/typing-layouts-float64/basics_beta.ml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,19 +560,27 @@ Error: Don't know how to untag this type. Only int can be untagged.
560560
(******************************************************)
561561
(* Test 11: Allow float64 in some extensible variants *)
562562

563+
(* CR layouts v5.9: Actually allow mixed extensible variant blocks. *)
564+
563565
(* Currently these are only supported in alpha *)
564566

565567
type t11_1 = ..
566568

567569
type t11_1 += A of t_float64;;
568570
[%%expect{|
569571
type t11_1 = ..
570-
type t11_1 += A of t_float64
572+
Line 3, characters 14-28:
573+
3 | type t11_1 += A of t_float64;;
574+
^^^^^^^^^^^^^^
575+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
571576
|}]
572577

573578
type t11_1 += B of float#;;
574579
[%%expect{|
575-
type t11_1 += B of float#
580+
Line 1, characters 14-25:
581+
1 | type t11_1 += B of float#;;
582+
^^^^^^^^^^^
583+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
576584
|}]
577585

578586
type ('a : float64) t11_2 = ..
@@ -584,7 +592,10 @@ type 'a t11_2 += B of 'a;;
584592
[%%expect{|
585593
type ('a : float64) t11_2 = ..
586594
type 'a t11_2 += A of int
587-
type 'a t11_2 += B of 'a
595+
Line 5, characters 17-24:
596+
5 | type 'a t11_2 += B of 'a;;
597+
^^^^^^^
598+
Error: Extensible types can't have fields of unboxed type. Consider wrapping the unboxed fields in a record.
588599
|}]
589600

590601
(* Some extensible variants aren't supported, though. *)

0 commit comments

Comments
 (0)