Skip to content

Commit f061df6

Browse files
Only vary yielding with [@local_opt]
1 parent 45479d3 commit f061df6

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

testsuite/tests/typing-modes/yielding.ml

+44
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,50 @@ let _ = with_global_effect (fun k -> let _ = Mk4 k in ())
126126
- : unit = ()
127127
|}]
128128

129+
(* Externals and [yielding]: *)
130+
131+
external ok_yielding : 'a @ local -> unit = "%ignore"
132+
133+
let _ = ok_yielding 4
134+
135+
let _ = ok_yielding (stack_ (Some "local string"))
136+
137+
let _ = with_global_effect (fun k -> ok_yielding k)
138+
139+
[%%expect{|
140+
external ok_yielding : local_ 'a -> unit = "%ignore"
141+
- : unit = ()
142+
- : unit = ()
143+
- : unit = ()
144+
|}]
145+
146+
external requires_unyielding : 'a @ local unyielding -> unit = "%ignore"
147+
148+
let _ = requires_unyielding 4
149+
150+
let _ = requires_unyielding (stack_ (Some "local string"))
151+
152+
let _ = with_global_effect (fun k -> requires_unyielding k)
153+
154+
[%%expect{|
155+
external requires_unyielding : local_ 'a @ unyielding -> unit = "%ignore"
156+
- : unit = ()
157+
- : unit = ()
158+
Line 7, characters 57-58:
159+
7 | let _ = with_global_effect (fun k -> requires_unyielding k)
160+
^
161+
Error: This value is "yielding" but expected to be "unyielding".
162+
|}]
163+
164+
external returns_unyielding : 'a -> 'a @ local unyielding = "%identity"
165+
166+
let _ = requires_unyielding (returns_unyielding "some string")
167+
168+
[%%expect{|
169+
external returns_unyielding : 'a -> local_ 'a @ unyielding = "%identity"
170+
- : unit = ()
171+
|}]
172+
129173
(* [@local_opt] and [yielding]: *)
130174

131175
external id : ('a[@local_opt]) -> ('a[@local_opt]) = "%identity"

typing/ctype.ml

+3-5
Original file line numberDiff line numberDiff line change
@@ -1663,14 +1663,12 @@ let instance_label ~fixed lbl =
16631663
)
16641664

16651665
(* CR dkalinichenko: we must vary yieldingness together with locality to get
1666-
sane behavior around defaults. Remove once we have mode polymorphism. *)
1666+
sane behavior around [@local_opt]. Remove once we have mode polymorphism. *)
16671667
let prim_mode mvar mvar' = function
16681668
| Primitive.Prim_global, _ ->
1669-
Locality.allow_right Locality.global,
1670-
Yielding.allow_right Yielding.unyielding
1669+
Locality.allow_right Locality.global, Yielding.newvar ()
16711670
| Primitive.Prim_local, _ ->
1672-
Locality.allow_right Locality.local,
1673-
Yielding.allow_right Yielding.yielding
1671+
Locality.allow_right Locality.local, Yielding.newvar ()
16741672
| Primitive.Prim_poly, _ ->
16751673
match mvar, mvar' with
16761674
| Some mvar, Some mvar' -> mvar, mvar'

0 commit comments

Comments
 (0)