Skip to content

Commit

Permalink
Reviewed the tests, with minor revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
goldfirere committed Dec 24, 2024
1 parent c0a9d50 commit f498428
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 73 deletions.
14 changes: 14 additions & 0 deletions testsuite/tests/typing-jkind-bounds/basics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1573,3 +1573,17 @@ type 'a t =
type 'a u
type 'a t = None | Some of ('a * 'a) t u
|}]

(*********************************)
(* Test 13: Bug in class methods *)

This comment has been minimized.

Copy link
@liam923

liam923 Dec 31, 2024

Contributor

I don't see the bug here - is this a test that used to fail?


type t =
| Atom of string
| List of t list

class sexp_of :
object
method array : ('a -> t) -> ('a array -> t)
end

[%%expect]
17 changes: 14 additions & 3 deletions testsuite/tests/typing-jkind-bounds/composite.ml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ Error: This value is "aliased" but expected to be "unique".

(***********************************************************************)
type 'a t : immutable_data with 'a = { head : 'a; tail : 'a t option }
(* CR layouts v2.8: This should work once we get proper subsumption. *)
[%%expect {|
Line 1, characters 0-70:
1 | type 'a t : immutable_data with 'a = { head : 'a; tail : 'a t option }
Expand Down Expand Up @@ -413,6 +414,8 @@ and 'a u = None | Some of 'a t
|}]

let foo (t : _ t @@ contended) = use_uncontended t
(* CR reisenberg: This looks unsound, unless it's inferring a kind
of [immutable_data] for the argument but failing to print this.*)
[%%expect {|
val foo : 'a t @ contended -> unit = <fun>
|}]
Expand Down Expand Up @@ -657,7 +660,7 @@ type 'a t = None | Some of ('a * 'a) t u
|}]

let foo (t : int t @@ contended) = use_uncontended t
(* CR layouts v2.8: fix this *)
(* CR layouts v2.8: this should work when we get tuples working *)
[%%expect {|
Line 1, characters 51-52:
1 | let foo (t : int t @@ contended) = use_uncontended t
Expand Down Expand Up @@ -690,14 +693,22 @@ type 'a t = None | Some of ('a * 'a) t
|}]

let foo (t : _ t @@ contended) = use_uncontended t
(* CR layouts v2.8: fix this *)
[%%expect {|
Line 1, characters 49-50:
1 | let foo (t : _ t @@ contended) = use_uncontended t
^
Error: This value is "contended" but expected to be "uncontended".
|}]

let foo (t : int t @@ contended) = use_uncontended t
(* CR layouts v2.8: this should work when we get tuples working *)
[%%expect {|
Line 1, characters 51-52:
1 | let foo (t : int t @@ contended) = use_uncontended t
^
Error: This value is "contended" but expected to be "uncontended".
|}]

let foo (t : int t @@ aliased) = use_unique t
[%%expect {|
Line 1, characters 44-45:
Expand Down Expand Up @@ -740,7 +751,7 @@ type 'a t = None | Some of 'a t * 'a t
|}]

let foo (t : _ t @@ contended) = use_uncontended t
(* CR layouts v2.8: fix this *)
(* CR reisenberg: This looks unsound *)
[%%expect {|
val foo : 'a t @ contended -> unit = <fun>
|}]
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/typing-jkind-bounds/predef.ml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ type ('a : immutable_data) t = 'a list
|}]

type 'a t : immutable_data with 'a = 'a list
(* CR layouts v2.8: fix this *)
(* CR layouts v2.8: this should work once we get proper subsumption working *)
[%%expect {|
Line 1, characters 0-44:
1 | type 'a t : immutable_data with 'a = 'a list
Expand Down
178 changes: 146 additions & 32 deletions testsuite/tests/typing-jkind-bounds/records.ml
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,12 @@ type t = { x : int; }
val foo : t @ once contended -> unit = <fun>
|}]

let foo (t : t @@ local) = use_global t [@nontial]
let foo (t : t @@ local) = use_global t [@nontail]
[%%expect {|
Line 1, characters 38-39:
1 | let foo (t : t @@ local) = use_global t [@nontial]
1 | let foo (t : t @@ local) = use_global t [@nontail]
^
Error: This value escapes its region.
Hint: This argument cannot be local,
because it is an argument in a tail call.
|}]

let foo (t : t @@ aliased) = use_unique t
Expand All @@ -350,14 +348,12 @@ type t = { mutable x : int; }
val foo : t @ once -> unit = <fun>
|}]

let foo (t : t @@ local) = use_global t [@nontial]
let foo (t : t @@ local) = use_global t [@nontail]
[%%expect {|
Line 1, characters 38-39:
1 | let foo (t : t @@ local) = use_global t [@nontial]
1 | let foo (t : t @@ local) = use_global t [@nontail]
^
Error: This value escapes its region.
Hint: This argument cannot be local,
because it is an argument in a tail call.
|}]

let foo (t : t @@ aliased) = use_unique t
Expand Down Expand Up @@ -386,14 +382,12 @@ type 'a t = { x : 'a; }
val foo : int t @ once contended -> unit = <fun>
|}]

let foo (t : int t @@ local) = use_global t [@nontial]
let foo (t : int t @@ local) = use_global t [@nontail]
[%%expect {|
Line 1, characters 42-43:
1 | let foo (t : int t @@ local) = use_global t [@nontial]
1 | let foo (t : int t @@ local) = use_global t [@nontail]
^
Error: This value escapes its region.
Hint: This argument cannot be local,
because it is an argument in a tail call.
|}]

let foo (t : int t @@ aliased) = use_unique t
Expand Down Expand Up @@ -431,14 +425,12 @@ Line 1, characters 37-38:
Error: This value is "once" but expected to be "many".
|}]

let foo (t : _ t @@ local) = use_global t [@nontial]
let foo (t : _ t @@ local) = use_global t [@nontail]
[%%expect {|
Line 1, characters 40-41:
1 | let foo (t : _ t @@ local) = use_global t [@nontial]
1 | let foo (t : _ t @@ local) = use_global t [@nontail]
^
Error: This value escapes its region.
Hint: This argument cannot be local,
because it is an argument in a tail call.
|}]

let foo (t : _ t @@ aliased) = use_unique t
Expand Down Expand Up @@ -466,14 +458,12 @@ Line 3, characters 15-16:
Error: This value is "once" but expected to be "many".
|}]

let foo (t : ('a : immutable_data) t @@ local) = use_global t [@nontial]
let foo (t : ('a : immutable_data) t @@ local) = use_global t [@nontail]
[%%expect {|
Line 1, characters 60-61:
1 | let foo (t : ('a : immutable_data) t @@ local) = use_global t [@nontial]
1 | let foo (t : ('a : immutable_data) t @@ local) = use_global t [@nontail]
^
Error: This value escapes its region.
Hint: This argument cannot be local,
because it is an argument in a tail call.
|}]

let foo (t : ('a : immutable_data) t @@ aliased) = use_unique t
Expand Down Expand Up @@ -501,14 +491,12 @@ Line 3, characters 15-16:
Error: This value is "once" but expected to be "many".
|}]

let foo (t : _ t @@ local) = use_global t [@nontial]
let foo (t : _ t @@ local) = use_global t [@nontail]
[%%expect {|
Line 1, characters 40-41:
1 | let foo (t : _ t @@ local) = use_global t [@nontial]
1 | let foo (t : _ t @@ local) = use_global t [@nontail]
^
Error: This value escapes its region.
Hint: This argument cannot be local,
because it is an argument in a tail call.
|}]

let foo (t : _ t @@ aliased) = use_unique t
Expand Down Expand Up @@ -739,52 +727,57 @@ Error: This type "'a t" should be an instance of type

(**** Test 5: Module inclusion check ****)

module _ : sig
module M : sig
type t : immutable_data
end = struct
type t = { x : int }
end
[%%expect {|
module M : sig type t : immutable_data end
|}]

module _ : sig
module M : sig
type t : mutable_data
end = struct
type t = { mutable x : int; y : int }
end
[%%expect {|
module M : sig type t : mutable_data end
|}]

module _ : sig
module M : sig
type t : immutable_data
end = struct
type t : mutable_data = { x : int }
end
[%%expect {|
module M : sig type t : immutable_data end
|}]

module _ : sig
module M : sig
type ('a : immutable_data) t : immutable_data
end = struct
type ('a : immutable_data) t = { x : 'a }
end
[%%expect {|
module M : sig type ('a : immutable_data) t : immutable_data end
|}]

module _ : sig
module M : sig
type 'a t : immutable_data with 'a
end = struct
type 'a t = { x : 'a }
end
[%%expect {|
module M : sig type 'a t : immutable_data end
|}]

module _ : sig
module M : sig
type 'a t : immutable_data with 'a
end = struct
type 'a t = { x : 'a; y : int }
end
(* CR layouts v2.8: fix this *)
(* CR layouts v2.8: This should work when we have proper subsumption *)
[%%expect {|
Lines 3-5, characters 6-3:
3 | ......struct
Expand All @@ -805,10 +798,131 @@ Error: Signature mismatch:
because of the definition of t at line 2, characters 2-36.
|}]

module _ : sig
module M : sig
type 'a t : immutable_data with int with 'a
end = struct
type 'a t = { x : 'a; y : int }
end
[%%expect {|
module M : sig type 'a t : immutable_data end
|}]

module M : sig
type t : mutable_data
end = struct
type t = { x : int; y : string }
end

[%%expect{|
module M : sig type t : mutable_data end
|}]

module M : sig
type t : immutable_data
end = struct
type t = { mutable x : int; y : string }
end

[%%expect{|
Lines 3-5, characters 6-3:
3 | ......struct
4 | type t = { mutable x : int; y : string }
5 | end
Error: Signature mismatch:
Modules do not match:
sig type t = { mutable x : int; y : string; } end
is not included in
sig type t : immutable_data end
Type declarations do not match:
type t = { mutable x : int; y : string; }
is not included in
type t : immutable_data
The kind of the first is mutable_data
because of the definition of t at line 4, characters 2-42.
But the kind of the first must be a subkind of immutable_data
because of the definition of t at line 2, characters 2-25.
|}]

module M : sig
type t : immutable_data
end = struct
type t = { x : int ref; y : string }
end

[%%expect{|
Lines 3-5, characters 6-3:
3 | ......struct
4 | type t = { x : int ref; y : string }
5 | end
Error: Signature mismatch:
Modules do not match:
sig type t = { x : int ref; y : string; } end
is not included in
sig type t : immutable_data end
Type declarations do not match:
type t = { x : int ref; y : string; }
is not included in
type t : immutable_data
The kind of the first is immutable_data
because of the definition of t at line 4, characters 2-38.
But the kind of the first must be a subkind of immutable_data
because of the definition of t at line 2, characters 2-25.
|}]

module M : sig
type 'a t : immutable_data
end = struct
type 'a t = { x : 'a; y : string }
end

[%%expect{|
Lines 3-5, characters 6-3:
3 | ......struct
4 | type 'a t = { x : 'a; y : string }
5 | end
Error: Signature mismatch:
Modules do not match:
sig type 'a t = { x : 'a; y : string; } end
is not included in
sig type 'a t : immutable_data end
Type declarations do not match:
type 'a t = { x : 'a; y : string; }
is not included in
type 'a t : immutable_data
The kind of the first is immutable_data
because of the definition of t at line 4, characters 2-36.
But the kind of the first must be a subkind of immutable_data
because of the definition of t at line 2, characters 2-28.
|}]

module M : sig
type 'a t : immutable_data
end = struct
type 'a t = { x : int; y : string }
end

[%%expect{|
module M : sig type 'a t : immutable_data end
|}]

(****************************************)

type ('a : immutable_data) t : immutable_data = { x : 'a list }
[%%expect {|
Line 1, characters 0-63:
1 | type ('a : immutable_data) t : immutable_data = { x : 'a list }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The kind of type "t" is immutable_data
because it's a boxed record type.
But the kind of type "t" must be a subkind of immutable_data
because of the annotation on the declaration of the type t.
|}]

type ('a : immutable_data) t : immutable_data = { x : 'a option }
type ('a : immutable_data) t : immutable_data = { x : 'a }
type ('a : immutable_data) t : immutable_data = 'a list
[%%expect {|
type ('a : immutable_data) t = { x : 'a option; }
type ('a : immutable_data) t = { x : 'a; }
type ('a : immutable_data) t = 'a list
|}]
Loading

0 comments on commit f498428

Please sign in to comment.