Skip to content

Commit

Permalink
flambda-backend: Jkind Error Messages (#2730)
Browse files Browse the repository at this point in the history
* Fix Jkind.format

* Improve error messages

* Improve more error messages

* Promote failing tests

* Improve formatting

* Format jkind.ml

* Undo because shuffling in tests

* Undo layout->kind rename in tests

* Undo removing legacy layouts in tests

* Move print_out_jkind to oprint

* Fix build issues

* Fix more build issues

* Make tests say kind when appropriate, and print actual layouts instead of legacy

* Update tests to shuffle because

* Promote failing jkinds and allow_illegal_crossing tests

* Create locale type
  • Loading branch information
liam923 authored Jul 15, 2024
1 parent 8e96af6 commit 64167a4
Show file tree
Hide file tree
Showing 57 changed files with 3,288 additions and 3,357 deletions.
2 changes: 1 addition & 1 deletion compilerlibs/Makefile.compilerlibs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ TYPING = \
typing/shape.cmo \
typing/zero_alloc.cmo \
typing/types.cmo \
typing/jkind.cmo \
typing/btype.cmo \
typing/oprint.cmo \
typing/jkind.cmo \
typing/subst.cmo \
typing/predef.cmo \
typing/datarepr.cmo \
Expand Down
1 change: 1 addition & 0 deletions otherlibs/dynlink/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ COMPILERLIBS_SOURCES=\
typing/primitive.ml \
typing/zero_alloc.ml \
typing/types.ml \
typing/oprint.ml \
typing/jkind.ml \
typing/typedtree.ml \
typing/btype.ml \
Expand Down
5 changes: 5 additions & 0 deletions otherlibs/dynlink/dune
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
primitive
zero_alloc
types
oprint
jkind
value_rec_types
btype
Expand Down Expand Up @@ -194,6 +195,7 @@
(copy_files ../../typing/jkind.ml)
(copy_files ../../typing/jkind_intf.ml)
(copy_files ../../typing/jkind_types.ml)
(copy_files ../../typing/oprint.ml)
(copy_files ../../typing/primitive.ml)
(copy_files ../../typing/shape.ml)
(copy_files ../../typing/solver.ml)
Expand Down Expand Up @@ -264,6 +266,7 @@
(copy_files ../../typing/jkind.mli)
(copy_files ../../typing/jkind_intf.mli)
(copy_files ../../typing/jkind_types.mli)
(copy_files ../../typing/oprint.mli)
(copy_files ../../typing/primitive.mli)
(copy_files ../../typing/shape.mli)
(copy_files ../../typing/solver.mli)
Expand Down Expand Up @@ -386,6 +389,7 @@
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Types.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Attr_helper.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Primitive.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Oprint.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Jkind.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Btype.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Subst.cmo
Expand Down Expand Up @@ -470,6 +474,7 @@
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Types.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Attr_helper.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Primitive.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Oprint.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Jkind.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Btype.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Subst.cmx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ File "libc/c2.ml", line 1, characters 12-15:
1 | let x = B.f B.x
^^^
Error: Function arguments and returns must be representable.
The layout of A.t is any, because
the .cmi file for A.t is missing.
But the layout of A.t must be representable, because
we must know concretely how to pass a function argument.
The layout of A.t is any
because the .cmi file for A.t is missing.
But the layout of A.t must be representable
because we must know concretely how to pass a function argument.
No .cmi file found containing A.t.
Hint: Adding "a" to your dependencies might help.
64 changes: 32 additions & 32 deletions testsuite/tests/typing-immediate/immediate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ end;;
Line 2, characters 2-31:
2 | type t = string [@@immediate]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The layout of type string is value, because
it is the primitive value type string.
But the layout of type string must be a sublayout of immediate, because
of the definition of t at line 2, characters 2-31.
Error: The kind of type string is value
because it is the primitive value type string.
But the kind of type string must be a subkind of immediate
because of the definition of t at line 2, characters 2-31.
|}];;
(* CR layouts v2.9: The "of the definition of t ..." part is not great and it
should only refer to definitions that type check. Fixing it will involve
Expand All @@ -160,10 +160,10 @@ end;;
Line 2, characters 2-41:
2 | type t = Foo of int | Bar [@@immediate]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The layout of type t is value, because
it's a boxed variant type.
But the layout of type t must be a sublayout of immediate, because
of the annotation on the declaration of the type t.
Error: The kind of type t is value
because it's a boxed variant type.
But the kind of type t must be a subkind of immediate
because of the annotation on the declaration of the type t.
|}];;

(* Cannot directly declare a non-immediate type as immediate (record) *)
Expand All @@ -174,10 +174,10 @@ end;;
Line 2, characters 2-38:
2 | type t = { foo : int } [@@immediate]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The layout of type t is value, because
it's a boxed record type.
But the layout of type t must be a sublayout of immediate, because
of the annotation on the declaration of the type t.
Error: The kind of type t is value
because it's a boxed record type.
But the kind of type t must be a subkind of immediate
because of the annotation on the declaration of the type t.
|}];;

(* Not guaranteed that t is immediate, so this is an invalid declaration *)
Expand All @@ -189,10 +189,10 @@ end;;
Line 3, characters 2-26:
3 | type s = t [@@immediate]
^^^^^^^^^^^^^^^^^^^^^^^^
Error: The layout of type t is value, because
of the definition of t at line 2, characters 2-8.
But the layout of type t must be a sublayout of immediate, because
of the definition of s at line 3, characters 2-26.
Error: The kind of type t is value
because of the definition of t at line 2, characters 2-8.
But the kind of type t must be a subkind of immediate
because of the definition of s at line 3, characters 2-26.
|}];;

(* Can't ascribe to an immediate type signature with a non-immediate type *)
Expand All @@ -213,10 +213,10 @@ Error: Signature mismatch:
type t = string
is not included in
type t : immediate
The layout of the first is value, because
it is the primitive value type string.
But the layout of the first must be a sublayout of immediate, because
of the definition of t at line 1, characters 15-35.
The kind of the first is value
because it is the primitive value type string.
But the kind of the first must be a subkind of immediate
because of the definition of t at line 1, characters 15-35.
|}];;

(* Same as above but with explicit signature *)
Expand All @@ -231,10 +231,10 @@ Error: Signature mismatch:
type t = string
is not included in
type t : immediate
The layout of the first is value, because
it is the primitive value type string.
But the layout of the first must be a sublayout of immediate, because
of the definition of t at line 1, characters 20-40.
The kind of the first is value
because it is the primitive value type string.
But the kind of the first must be a subkind of immediate
because of the definition of t at line 1, characters 20-40.
|}];;

module FM_invalid = F (struct type t = string end);;
Expand All @@ -248,10 +248,10 @@ Error: Modules do not match: sig type t = string end is not included in
type t = string
is not included in
type t : immediate
The layout of the first is value, because
it is the primitive value type string.
But the layout of the first must be a sublayout of immediate, because
of the definition of t at line 1, characters 20-40.
The kind of the first is value
because it is the primitive value type string.
But the kind of the first must be a subkind of immediate
because of the definition of t at line 1, characters 20-40.
|}];;

(* Can't use a non-immediate type even if mutually recursive *)
Expand All @@ -263,10 +263,10 @@ end;;
Line 2, characters 2-26:
2 | type t = s [@@immediate]
^^^^^^^^^^^^^^^^^^^^^^^^
Error: The layout of type s is value, because
it is the primitive value type string.
But the layout of type s must be a sublayout of immediate, because
of the definition of t at line 2, characters 2-26.
Error: The kind of type s is value
because it is the primitive value type string.
But the kind of type s must be a subkind of immediate
because of the definition of t at line 2, characters 2-26.
|}];;


Expand Down
40 changes: 20 additions & 20 deletions testsuite/tests/typing-layouts-arrays/basics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ Line 1, characters 27-28:
^
Error: This expression has type float# array
but an expression was expected of type 'a array
The layout of float# is float64, because
it is the primitive float64 type float#.
But the layout of float# must be a sublayout of value, because
of layout requirements from an imported definition.
The layout of float# is float64
because it is the primitive float64 type float#.
But the layout of float# must be a sublayout of value
because of layout requirements from an imported definition.
|}];;

let f (x : float# array) = Array.length x
Expand All @@ -104,10 +104,10 @@ Line 1, characters 40-41:
^
Error: This expression has type float# array
but an expression was expected of type 'a array
The layout of float# is float64, because
it is the primitive float64 type float#.
But the layout of float# must be a sublayout of value, because
of layout requirements from an imported definition.
The layout of float# is float64
because it is the primitive float64 type float#.
But the layout of float# must be a sublayout of value
because of layout requirements from an imported definition.
|}];;

(*****************************************************************)
Expand Down Expand Up @@ -144,10 +144,10 @@ Line 2, characters 23-30:
2 | let d (x : 'a array) = get x 0
^^^^^^^
Error: A representable layout is required here.
The layout of 'a is any, because
of the definition of d at line 2, characters 6-30.
But the layout of 'a must be representable, because
it's the type of an array element.
The layout of 'a is any
because of the definition of d at line 2, characters 6-30.
But the layout of 'a must be representable
because it's the type of an array element.
|}];;

external get : int32# array -> int -> float = "%floatarray_safe_get"
Expand Down Expand Up @@ -257,10 +257,10 @@ Line 11, characters 79-82:
^^^
Error: This expression has type int64# but an expression was expected of type
('a : bits32)
The layout of int64# is bits64, because
it is the primitive bits64 type int64#.
But the layout of int64# must be a sublayout of bits32, because
of the definition of get_third at lines 4-7, characters 16-23.
The layout of int64# is bits64
because it is the primitive bits64 type int64#.
But the layout of int64# must be a sublayout of bits32
because of the definition of get_third at lines 4-7, characters 16-23.
|}]

module M6_2 = struct
Expand All @@ -282,10 +282,10 @@ Line 9, characters 24-35:
^^^^^^^^^^^
Error: This expression has type ('a : float64)
but an expression was expected of type int32#
The layout of int32# is bits32, because
it is the primitive bits32 type int32#.
But the layout of int32# must be a sublayout of float64, because
of the definition of arr at line 6, characters 12-16.
The layout of int32# is bits32
because it is the primitive bits32 type int32#.
But the layout of int32# must be a sublayout of float64
because of the definition of arr at line 6, characters 12-16.
|}]

(*********************)
Expand Down
8 changes: 4 additions & 4 deletions testsuite/tests/typing-layouts-arrays/exp_and_pat_failing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Line 25, characters 13-29:
^^^^^^^^^^^^^^^^
Error: This expression has type Float_u.t = float#
but an expression was expected of type ('a : value)
The layout of Float_u.t is float64, because
it is the primitive float64 type float#.
But the layout of Float_u.t must be a sublayout of value, because
it's the element type of array comprehension.
The layout of Float_u.t is float64
because it is the primitive float64 type float#.
But the layout of Float_u.t must be a sublayout of value
because it's the element type of array comprehension.
|}];;
Loading

0 comments on commit 64167a4

Please sign in to comment.