Skip to content

Commit c881b34

Browse files
dkalinichenko-jsd-kalinichenkoriaqn
authored
local implies yielding (#3532)
* `local` implies `yielding` * accept tests * `yielding` tests * format * dirty fix test change * small improvement * merge fix * fix printing bounds * accept tests * fix the issue with `instance_prim` * Only vary `yielding` with `[@local_opt]` * fixes * tests * fix lazy * format * keep order * fix mixed mode annots * fixes * fix * rebase + accept --------- Co-authored-by: Diana Kalinichenko <[email protected]> Co-authored-by: Zesen Qian <[email protected]>
1 parent 4d7a6a9 commit c881b34

File tree

17 files changed

+458
-117
lines changed

17 files changed

+458
-117
lines changed

otherlibs/stdlib_alpha/capsule.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ module Password : sig
8686
type 'k t : value mod many portable contended
8787

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

@@ -131,7 +131,7 @@ end = struct
131131
| already_set_id -> already_set_id)
132132
| set_id -> set_id
133133

134-
let unsafe_mk () : _ @@ local = A.make Id.uninitialized
134+
let unsafe_mk () : _ @@ local unyielding = A.make Id.uninitialized
135135
end
136136

137137
let[@inline] shared t = t
@@ -405,13 +405,13 @@ module Key : sig
405405

406406
val with_password_shared :
407407
'k t
408-
-> ('k Password.Shared.t @ local -> 'a) @ local
408+
-> ('k Password.Shared.t @ local unyielding -> 'a) @ local
409409
-> 'a
410410
@@ portable
411411

412412
val with_password_shared_local :
413413
'k t
414-
-> ('k Password.Shared.t @ local -> 'a @ local) @ local
414+
-> ('k Password.Shared.t @ local unyielding -> 'a @ local) @ local
415415
-> 'a @ local
416416
@@ portable
417417

@@ -680,7 +680,7 @@ module Rwlock = struct
680680
let[@inline] with_read_lock :
681681
type k.
682682
k t
683-
-> (k Password.Shared.t @ local -> 'a) @ local
683+
-> (k Password.Shared.t @ local unyielding -> 'a) @ local
684684
-> 'a
685685
@@ portable
686686
= fun t f ->

testsuite/tests/typing-jkind-bounds/basics.ml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,15 +1157,7 @@ Error: The kind of type "t" is value
11571157
type 'a t : value mod global portable contended many aliased unyielding =
11581158
{ x : 'a @@ global portable contended many aliased } [@@unboxed]
11591159
[%%expect {|
1160-
Lines 1-2, characters 0-66:
1161-
1 | type 'a t : value mod global portable contended many aliased unyielding =
1162-
2 | { x : 'a @@ global portable contended many aliased } [@@unboxed]
1163-
Error: The kind of type "t" is value mod global aliased many contended portable
1164-
because it instantiates an unannotated type parameter of t,
1165-
chosen to have kind value mod global aliased many contended portable.
1166-
But the kind of type "t" must be a subkind of
1167-
immutable_data mod global aliased
1168-
because of the annotation on the declaration of the type t.
1160+
type 'a t = { global_ x : 'a @@ many portable aliased contended; } [@@unboxed]
11691161
|}]
11701162
(* CR layouts v2.8: this could be accepted, if we infer ('a : value mod
11711163
unyielding). We do not currently do this, because we finish inference of the
@@ -1191,7 +1183,7 @@ Error: The kind of type "t" is value
11911183
because it instantiates an unannotated type parameter of t,
11921184
chosen to have kind value.
11931185
But the kind of type "t" must be a subkind of
1194-
immutable_data mod global aliased
1186+
immutable_data mod global aliased yielding
11951187
because of the annotation on the declaration of the type t.
11961188
|}]
11971189
(* CR layouts v2.8: this should be accepted *)
@@ -1264,10 +1256,13 @@ type 'a t : value mod global = { x : 'a @@ global }
12641256
Line 1, characters 0-51:
12651257
1 | type 'a t : value mod global = { x : 'a @@ global }
12661258
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1267-
Error: The kind of type "t" is immutable_data with 'a
1259+
Error: The kind of type "t" is immutable_data with 'a @@ unyielding
12681260
because it's a boxed record type.
12691261
But the kind of type "t" must be a subkind of value mod global
12701262
because of the annotation on the declaration of the type t.
1263+
1264+
The first mode-crosses less than the second along:
1265+
locality: mod local ≰ mod global
12711266
|}]
12721267

12731268
(*****************************)
@@ -1443,7 +1438,7 @@ Line 1, characters 41-51:
14431438
^^^^^^^^^^
14441439
Error: This expression has type "< >" but an expression was expected of type
14451440
"('a : value mod aliased)"
1446-
The kind of < > is value mod global many unyielding
1441+
The kind of < > is value mod global many
14471442
because it's the type of an object.
14481443
But the kind of < > must be a subkind of value mod aliased
14491444
because of the annotation on the wildcard _ at line 1, characters 19-36.
@@ -1456,7 +1451,7 @@ Line 1, characters 42-52:
14561451
^^^^^^^^^^
14571452
Error: This expression has type "< >" but an expression was expected of type
14581453
"('a : value mod portable)"
1459-
The kind of < > is value mod global many unyielding
1454+
The kind of < > is value mod global many
14601455
because it's the type of an object.
14611456
But the kind of < > must be a subkind of value mod portable
14621457
because of the annotation on the wildcard _ at line 1, characters 19-37.
@@ -1469,7 +1464,7 @@ Line 1, characters 43-53:
14691464
^^^^^^^^^^
14701465
Error: This expression has type "< >" but an expression was expected of type
14711466
"('a : value mod contended)"
1472-
The kind of < > is value mod global many unyielding
1467+
The kind of < > is value mod global many
14731468
because it's the type of an object.
14741469
But the kind of < > must be a subkind of value mod contended
14751470
because of the annotation on the wildcard _ at line 1, characters 19-38.
@@ -1482,7 +1477,7 @@ Line 1, characters 43-53:
14821477
^^^^^^^^^^
14831478
Error: This expression has type "< >" but an expression was expected of type
14841479
"('a : value mod external_)"
1485-
The kind of < > is value mod global many unyielding
1480+
The kind of < > is value mod global many
14861481
because it's the type of an object.
14871482
But the kind of < > must be a subkind of value mod external_
14881483
because of the annotation on the wildcard _ at line 1, characters 19-38.

testsuite/tests/typing-jkind-bounds/subsumption/modalities.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ end = struct
124124
type 'a t : immediate with 'a @@ aliased many contended global portable
125125
end
126126
[%%expect {|
127-
module M :
128-
sig type 'a t : value mod global aliased many contended portable end
127+
module M : sig type 'a t : immutable_data mod global aliased yielding end
129128
|}]
130129

131130
module M : sig

testsuite/tests/typing-layouts-products/basics_alpha.ml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,9 @@ Line 3, characters 0-39:
6767
3 | type t3 : any mod non_null = #(t1 * t2);;
6868
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6969
Error: The kind of type "#(t1 * t2)" is
70-
any_non_null mod global aliased many contended portable unyielding
71-
external_
70+
any_non_null mod global aliased many contended portable external_
7271
with t1 with t2
73-
& any_non_null mod global aliased many contended portable unyielding
74-
external_
72+
& any_non_null mod global aliased many contended portable external_
7573
with t1 with t2
7674
because it is an unboxed tuple.
7775
But the kind of type "#(t1 * t2)" must be a subkind of any_non_null
@@ -88,11 +86,9 @@ Line 3, characters 0-45:
8886
3 | type t3 : any & any mod non_null = #(t1 * t2);;
8987
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9088
Error: The kind of type "#(t1 * t2)" is
91-
any_non_null mod global aliased many contended portable unyielding
92-
external_
89+
any_non_null mod global aliased many contended portable external_
9390
with t1 with t2
94-
& any_non_null mod global aliased many contended portable unyielding
95-
external_
91+
& any_non_null mod global aliased many contended portable external_
9692
with t1 with t2
9793
because it is an unboxed tuple.
9894
But the kind of type "#(t1 * t2)" must be a subkind of
@@ -110,11 +106,9 @@ Line 3, characters 0-62:
110106
3 | type t3 : (any mod non_null) & (any mod non_null) = #(t1 * t2);;
111107
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
112108
Error: The kind of type "#(t1 * t2)" is
113-
any_non_null mod global aliased many contended portable unyielding
114-
external_
109+
any_non_null mod global aliased many contended portable external_
115110
with t1 with t2
116-
& any_non_null mod global aliased many contended portable unyielding
117-
external_
111+
& any_non_null mod global aliased many contended portable external_
118112
with t1 with t2
119113
because it is an unboxed tuple.
120114
But the kind of type "#(t1 * t2)" must be a subkind of

testsuite/tests/typing-layouts/allow_any.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ module B = struct
313313
let a t = t.a
314314
end
315315
[%%expect{|
316-
module A : sig type t : mutable_data mod global external_ end
316+
module A : sig type t : mutable_data mod global external_ yielding end
317317
module B :
318318
sig
319319
type t : value mod contended portable = { a : A.t; }

testsuite/tests/typing-layouts/hash_types.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ type r = { i : int ; mutable s : string }
217217
type u = r# = #{ i : int ; s : string @@ global many aliased unyielding }
218218
[%%expect{|
219219
type r = { i : int; mutable s : string; }
220-
type u = r# = #{ i : int; global_ s : string @@ many unyielding aliased; }
220+
type u = r# = #{ i : int; global_ s : string @@ many aliased; }
221221
|}]
222222

223223
(*******************)

testsuite/tests/typing-modes/lazy.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ Line 2, characters 18-19:
2828
Error: The value "x" is local, so cannot be used inside a lazy expression.
2929
|}]
3030

31+
(* For simplicity, we also require them to be [unyielding]. *)
32+
let foo (x @ yielding) =
33+
lazy (let _ = x in ())
34+
[%%expect{|
35+
Line 2, characters 18-19:
36+
2 | lazy (let _ = x in ())
37+
^
38+
Error: The value "x" is yielding, so cannot be used inside a lazy expression that may not yield.
39+
|}]
40+
3141
(* lazy expression is constructed as global *)
3242
let foo () =
3343
lazy ("hello")

0 commit comments

Comments
 (0)