Skip to content

Commit ca8415c

Browse files
authored
flambda-backend: Fix the package hack (#2253)
1 parent 1973c38 commit ca8415c

File tree

17 files changed

+525
-167
lines changed

17 files changed

+525
-167
lines changed

testsuite/tests/typing-layouts-err-msg/value.ml

-25
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,6 @@ Error: Tuple element types must have layout value.
5454
(* Probe *)
5555
(* See [probe.ml] *)
5656

57-
(* Package_hack *)
58-
module type S = sig
59-
type t : immediate
60-
end
61-
62-
module type S2 = sig
63-
val m : (module S with type t = string)
64-
end
65-
[%%expect{|
66-
module type S = sig type t : immediate end
67-
Line 6, characters 10-41:
68-
6 | val m : (module S with type t = string)
69-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70-
Error: In this `with' constraint, the new definition of t
71-
does not match its original definition in the constrained signature:
72-
Type declarations do not match:
73-
type t
74-
is not included in
75-
type t : immediate
76-
The layout of the first is value, because
77-
it's a type declaration in a first-class module.
78-
But the layout of the first must be a sublayout of immediate, because
79-
of the definition of t at line 2, characters 2-20.
80-
|}];;
81-
8257
(* Object *)
8358
let f: ('a : void) -> 'b = fun x -> x # baz
8459
[%%expect{|

testsuite/tests/typing-layouts/erasable_annot.ml

+4-12
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,11 @@ end
170170

171171
[%%expect {|
172172
module type S = sig type t : immediate64 end
173-
Line 6, characters 16-43:
173+
Line 6, characters 2-49:
174174
6 | val f : 'a -> (module S with type t = 'a) -> 'a
175-
^^^^^^^^^^^^^^^^^^^^^^^^^^^
176-
Error: In this `with' constraint, the new definition of t
177-
does not match its original definition in the constrained signature:
178-
Type declarations do not match:
179-
type t
180-
is not included in
181-
type t : immediate64
182-
The layout of the first is value, because
183-
it's a type declaration in a first-class module.
184-
But the layout of the first must be a sublayout of immediate64, because
185-
of the definition of t at line 2, characters 2-23.
175+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
176+
Error: Usage of layout immediate/immediate64 in f can't be erased.
177+
This error is produced due to the use of -only-erasable-extensions.
186178
|}];;
187179

188180
(* Annotations here do nothing and should be accepted *)

testsuite/tests/typing-layouts/modules.ml

+21-37
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,11 @@ Line 6, characters 10-42:
498498
Error: In this `with' constraint, the new definition of t
499499
does not match its original definition in the constrained signature:
500500
Type declarations do not match:
501-
type t
501+
type t = int
502502
is not included in
503503
type t : float64
504-
The layout of the first is value, because
505-
it's a type declaration in a first-class module.
504+
The layout of the first is immediate, because
505+
it is the primitive immediate type int.
506506
But the layout of the first must be a sublayout of float64, because
507507
of the definition of t at line 2, characters 2-18.
508508
|}];;
@@ -516,14 +516,19 @@ module type S6_4f = sig
516516
end;;
517517
[%%expect{|
518518
module type S6_3 = sig type t : value end
519-
Line 6, characters 33-34:
519+
Line 6, characters 10-47:
520520
6 | val m : (module S6_3 with type t = t_float64)
521-
^
522-
Error: Signature package constraint types must have layout value.
523-
The layout of t_float64 is float64, because
521+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
522+
Error: In this `with' constraint, the new definition of t
523+
does not match its original definition in the constrained signature:
524+
Type declarations do not match:
525+
type t = t_float64
526+
is not included in
527+
type t : value
528+
The layout of the first is float64, because
524529
of the definition of t_float64 at line 4, characters 0-24.
525-
But the layout of t_float64 must be a sublayout of value, because
526-
it's a type declaration in a first-class module.
530+
But the layout of the first must be a sublayout of value, because
531+
of the definition of t at line 2, characters 2-16.
527532
|}];;
528533

529534
module type S6_5 = sig
@@ -541,11 +546,11 @@ Line 6, characters 10-44:
541546
Error: In this `with' constraint, the new definition of t
542547
does not match its original definition in the constrained signature:
543548
Type declarations do not match:
544-
type t
549+
type t = string
545550
is not included in
546551
type t : immediate
547552
The layout of the first is value, because
548-
it's a type declaration in a first-class module.
553+
it is the primitive value type string.
549554
But the layout of the first must be a sublayout of immediate, because
550555
of the definition of t at line 2, characters 2-20.
551556
|}];;
@@ -561,34 +566,22 @@ Line 3, characters 10-39:
561566
Error: In this `with' constraint, the new definition of t
562567
does not match its original definition in the constrained signature:
563568
Type declarations do not match:
564-
type t
569+
type t = s
565570
is not included in
566571
type t : immediate
567572
The layout of the first is value, because
568-
it's a type declaration in a first-class module.
573+
of the definition of s at line 2, characters 2-8.
569574
But the layout of the first must be a sublayout of immediate, because
570575
of the definition of t at line 2, characters 2-20.
571576
|}];;
572577

573-
(* CR layouts: S6_6'' should be fixed *)
574578
module type S6_6'' = sig
575579
type s = int
576580
val m : (module S6_5 with type t = int)
577581
end;;
578582
[%%expect{|
579-
Line 3, characters 10-41:
580-
3 | val m : (module S6_5 with type t = int)
581-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
582-
Error: In this `with' constraint, the new definition of t
583-
does not match its original definition in the constrained signature:
584-
Type declarations do not match:
585-
type t
586-
is not included in
587-
type t : immediate
588-
The layout of the first is value, because
589-
it's a type declaration in a first-class module.
590-
But the layout of the first must be a sublayout of immediate, because
591-
of the definition of t at line 2, characters 2-20.
583+
module type S6_6'' =
584+
sig type s = int val m : (module S6_5 with type t = int) end
592585
|}];;
593586

594587
(*****************************************)
@@ -729,17 +722,8 @@ end
729722

730723
let x = (module C : S with type t = 'a)
731724

732-
(* This should be accepted *)
733725
[%%expect{|
734726
module type S = sig type t : any end
735727
module C : S
736-
Line 9, characters 8-39:
737-
9 | let x = (module C : S with type t = 'a)
738-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
739-
Error: This expression has type (module S with type t = C.t)
740-
but an expression was expected of type (module S with type t = 'a)
741-
The layout of C.t is any, because
742-
of the definition of t at line 2, characters 2-14.
743-
But the layout of C.t must be a sublayout of value, because
744-
it's a type declaration in a first-class module.
728+
val x : (module S with type t = C.t) = <module>
745729
|}]

testsuite/tests/typing-layouts/modules_alpha.ml

+20-27
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,11 @@ Line 6, characters 10-41:
415415
Error: In this `with' constraint, the new definition of t
416416
does not match its original definition in the constrained signature:
417417
Type declarations do not match:
418-
type t
418+
type t = int
419419
is not included in
420420
type t : void
421-
The layout of the first is value, because
422-
it's a type declaration in a first-class module.
421+
The layout of the first is immediate, because
422+
it is the primitive immediate type int.
423423
But the layout of the first must be a sublayout of void, because
424424
of the definition of t at line 2, characters 2-15.
425425
|}];;
@@ -433,14 +433,19 @@ module type S6_4 = sig
433433
end;;
434434
[%%expect{|
435435
module type S6_3 = sig type t : value end
436-
Line 6, characters 33-34:
436+
Line 6, characters 10-44:
437437
6 | val m : (module S6_3 with type t = t_void)
438-
^
439-
Error: Signature package constraint types must have layout value.
440-
The layout of t_void is void, because
438+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
439+
Error: In this `with' constraint, the new definition of t
440+
does not match its original definition in the constrained signature:
441+
Type declarations do not match:
442+
type t = t_void
443+
is not included in
444+
type t : value
445+
The layout of the first is void, because
441446
of the definition of t_void at line 5, characters 0-19.
442-
But the layout of t_void must be a sublayout of value, because
443-
it's a type declaration in a first-class module.
447+
But the layout of the first must be a sublayout of value, because
448+
of the definition of t at line 2, characters 2-16.
444449
|}];;
445450

446451
module type S6_5 = sig
@@ -458,11 +463,11 @@ Line 6, characters 10-44:
458463
Error: In this `with' constraint, the new definition of t
459464
does not match its original definition in the constrained signature:
460465
Type declarations do not match:
461-
type t
466+
type t = string
462467
is not included in
463468
type t : immediate
464469
The layout of the first is value, because
465-
it's a type declaration in a first-class module.
470+
it is the primitive value type string.
466471
But the layout of the first must be a sublayout of immediate, because
467472
of the definition of t at line 2, characters 2-20.
468473
|}];;
@@ -478,34 +483,22 @@ Line 3, characters 10-39:
478483
Error: In this `with' constraint, the new definition of t
479484
does not match its original definition in the constrained signature:
480485
Type declarations do not match:
481-
type t
486+
type t = s
482487
is not included in
483488
type t : immediate
484489
The layout of the first is value, because
485-
it's a type declaration in a first-class module.
490+
of the definition of s at line 2, characters 2-8.
486491
But the layout of the first must be a sublayout of immediate, because
487492
of the definition of t at line 2, characters 2-20.
488493
|}];;
489494

490-
(* CR layouts: S6_6'' should be fixed *)
491495
module type S6_6'' = sig
492496
type s = int
493497
val m : (module S6_5 with type t = int)
494498
end;;
495499
[%%expect{|
496-
Line 3, characters 10-41:
497-
3 | val m : (module S6_5 with type t = int)
498-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
499-
Error: In this `with' constraint, the new definition of t
500-
does not match its original definition in the constrained signature:
501-
Type declarations do not match:
502-
type t
503-
is not included in
504-
type t : immediate
505-
The layout of the first is value, because
506-
it's a type declaration in a first-class module.
507-
But the layout of the first must be a sublayout of immediate, because
508-
of the definition of t at line 2, characters 2-20.
500+
module type S6_6'' =
501+
sig type s = int val m : (module S6_5 with type t = int) end
509502
|}];;
510503

511504
(*****************************************)

testsuite/tests/typing-modules-bugs/pr6293_bad.compilers.reference

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ File "pr6293_bad.ml", line 10, characters 18-37:
44
Error: In this `with' constraint, the new definition of t
55
does not match its original definition in the constrained signature:
66
Type declarations do not match:
7-
type t
7+
type t = int
88
is not included in
99
type t = { a : int; b : int; }
1010
The first is abstract, but the second is a record.

0 commit comments

Comments
 (0)