Skip to content

local implies yielding #3532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions otherlibs/stdlib_alpha/capsule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module Password : sig
type 'k t : value mod many portable contended

(* Can break the soundness of the API. *)
val unsafe_mk : unit -> 'k t @ local @@ portable
val unsafe_mk : unit -> 'k t @ local unyielding @@ portable
val id : 'k t @ local -> 'k Id.t @@ portable
end

Expand Down Expand Up @@ -131,7 +131,7 @@ end = struct
| already_set_id -> already_set_id)
| set_id -> set_id

let unsafe_mk () : _ @@ local = A.make Id.uninitialized
let unsafe_mk () : _ @@ local unyielding = A.make Id.uninitialized
end

let[@inline] shared t = t
Expand Down Expand Up @@ -405,13 +405,13 @@ module Key : sig

val with_password_shared :
'k t
-> ('k Password.Shared.t @ local -> 'a) @ local
-> ('k Password.Shared.t @ local unyielding -> 'a) @ local
-> 'a
@@ portable

val with_password_shared_local :
'k t
-> ('k Password.Shared.t @ local -> 'a @ local) @ local
-> ('k Password.Shared.t @ local unyielding -> 'a @ local) @ local
-> 'a @ local
@@ portable

Expand Down Expand Up @@ -680,7 +680,7 @@ module Rwlock = struct
let[@inline] with_read_lock :
type k.
k t
-> (k Password.Shared.t @ local -> 'a) @ local
-> (k Password.Shared.t @ local unyielding -> 'a) @ local
-> 'a
@@ portable
= fun t f ->
Expand Down
25 changes: 10 additions & 15 deletions testsuite/tests/typing-jkind-bounds/basics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1157,15 +1157,7 @@ Error: The kind of type "t" is value
type 'a t : value mod global portable contended many aliased unyielding =
{ x : 'a @@ global portable contended many aliased } [@@unboxed]
[%%expect {|
Lines 1-2, characters 0-66:
1 | type 'a t : value mod global portable contended many aliased unyielding =
2 | { x : 'a @@ global portable contended many aliased } [@@unboxed]
Error: The kind of type "t" is value mod global aliased many contended portable
because it instantiates an unannotated type parameter of t,
chosen to have kind value mod global aliased many contended portable.
But the kind of type "t" must be a subkind of
immutable_data mod global aliased
because of the annotation on the declaration of the type t.
type 'a t = { global_ x : 'a @@ many portable aliased contended; } [@@unboxed]
|}]
(* CR layouts v2.8: this could be accepted, if we infer ('a : value mod
unyielding). We do not currently do this, because we finish inference of the
Expand All @@ -1191,7 +1183,7 @@ Error: The kind of type "t" is value
because it instantiates an unannotated type parameter of t,
chosen to have kind value.
But the kind of type "t" must be a subkind of
immutable_data mod global aliased
immutable_data mod global aliased yielding
because of the annotation on the declaration of the type t.
|}]
(* CR layouts v2.8: this should be accepted *)
Expand Down Expand Up @@ -1264,10 +1256,13 @@ type 'a t : value mod global = { x : 'a @@ global }
Line 1, characters 0-51:
1 | type 'a t : value mod global = { x : 'a @@ global }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The kind of type "t" is immutable_data with 'a
Error: The kind of type "t" is immutable_data with 'a @@ unyielding
because it's a boxed record type.
But the kind of type "t" must be a subkind of value mod global
because of the annotation on the declaration of the type t.

The first mode-crosses less than the second along:
locality: mod local ≰ mod global
|}]

(*****************************)
Expand Down Expand Up @@ -1443,7 +1438,7 @@ Line 1, characters 41-51:
^^^^^^^^^^
Error: This expression has type "< >" but an expression was expected of type
"('a : value mod aliased)"
The kind of < > is value mod global many unyielding
The kind of < > is value mod global many
because it's the type of an object.
But the kind of < > must be a subkind of value mod aliased
because of the annotation on the wildcard _ at line 1, characters 19-36.
Expand All @@ -1456,7 +1451,7 @@ Line 1, characters 42-52:
^^^^^^^^^^
Error: This expression has type "< >" but an expression was expected of type
"('a : value mod portable)"
The kind of < > is value mod global many unyielding
The kind of < > is value mod global many
because it's the type of an object.
But the kind of < > must be a subkind of value mod portable
because of the annotation on the wildcard _ at line 1, characters 19-37.
Expand All @@ -1469,7 +1464,7 @@ Line 1, characters 43-53:
^^^^^^^^^^
Error: This expression has type "< >" but an expression was expected of type
"('a : value mod contended)"
The kind of < > is value mod global many unyielding
The kind of < > is value mod global many
because it's the type of an object.
But the kind of < > must be a subkind of value mod contended
because of the annotation on the wildcard _ at line 1, characters 19-38.
Expand All @@ -1482,7 +1477,7 @@ Line 1, characters 43-53:
^^^^^^^^^^
Error: This expression has type "< >" but an expression was expected of type
"('a : value mod external_)"
The kind of < > is value mod global many unyielding
The kind of < > is value mod global many
because it's the type of an object.
But the kind of < > must be a subkind of value mod external_
because of the annotation on the wildcard _ at line 1, characters 19-38.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ end = struct
type 'a t : immediate with 'a @@ aliased many contended global portable
end
[%%expect {|
module M :
sig type 'a t : value mod global aliased many contended portable end
module M : sig type 'a t : immutable_data mod global aliased yielding end
|}]

module M : sig
Expand Down
18 changes: 6 additions & 12 deletions testsuite/tests/typing-layouts-products/basics_alpha.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ Line 3, characters 0-39:
3 | type t3 : any mod non_null = #(t1 * t2);;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The kind of type "#(t1 * t2)" is
any_non_null mod global aliased many contended portable unyielding
external_
any_non_null mod global aliased many contended portable external_
with t1 with t2
& any_non_null mod global aliased many contended portable unyielding
external_
& any_non_null mod global aliased many contended portable external_
with t1 with t2
because it is an unboxed tuple.
But the kind of type "#(t1 * t2)" must be a subkind of any_non_null
Expand All @@ -88,11 +86,9 @@ Line 3, characters 0-45:
3 | type t3 : any & any mod non_null = #(t1 * t2);;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The kind of type "#(t1 * t2)" is
any_non_null mod global aliased many contended portable unyielding
external_
any_non_null mod global aliased many contended portable external_
with t1 with t2
& any_non_null mod global aliased many contended portable unyielding
external_
& any_non_null mod global aliased many contended portable external_
with t1 with t2
because it is an unboxed tuple.
But the kind of type "#(t1 * t2)" must be a subkind of
Expand All @@ -110,11 +106,9 @@ Line 3, characters 0-62:
3 | type t3 : (any mod non_null) & (any mod non_null) = #(t1 * t2);;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The kind of type "#(t1 * t2)" is
any_non_null mod global aliased many contended portable unyielding
external_
any_non_null mod global aliased many contended portable external_
with t1 with t2
& any_non_null mod global aliased many contended portable unyielding
external_
& any_non_null mod global aliased many contended portable external_
with t1 with t2
because it is an unboxed tuple.
But the kind of type "#(t1 * t2)" must be a subkind of
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/typing-layouts/allow_any.ml
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ module B = struct
let a t = t.a
end
[%%expect{|
module A : sig type t : mutable_data mod global external_ end
module A : sig type t : mutable_data mod global external_ yielding end
module B :
sig
type t : value mod contended portable = { a : A.t; }
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/typing-layouts/hash_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ type r = { i : int ; mutable s : string }
type u = r# = #{ i : int ; s : string @@ global many aliased unyielding }
[%%expect{|
type r = { i : int; mutable s : string; }
type u = r# = #{ i : int; global_ s : string @@ many unyielding aliased; }
type u = r# = #{ i : int; global_ s : string @@ many aliased; }
|}]

(*******************)
Expand Down
10 changes: 10 additions & 0 deletions testsuite/tests/typing-modes/lazy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ Line 2, characters 18-19:
Error: The value "x" is local, so cannot be used inside a lazy expression.
|}]

(* For simplicity, we also require them to be [unyielding]. *)
let foo (x @ yielding) =
lazy (let _ = x in ())
[%%expect{|
Line 2, characters 18-19:
2 | lazy (let _ = x in ())
^
Error: The value "x" is yielding, so cannot be used inside a lazy expression that may not yield.
|}]

(* lazy expression is constructed as global *)
let foo () =
lazy ("hello")
Expand Down
Loading