You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Concurrency] Ensure we do implicit-async from @actorIndependent & global-actors contexts
We weren't allowing implicit "async" promotions for cross-actor references
from functions defined within an actor that were @actorIndependent
or part of a global actor. Ensure we do promotion there.
... and because these lead to misleading diagnostics in a lot of places,
don't do implicit "async" promotion if we're not in an async context
already. We still need to improve the diagnostics here.
func synchronous()->String{ text.first ??"nothing"} // expected-note 21{{calls to instance method 'synchronous()' from outside of its actor context are implicitly asynchronous}}
38
+
func synchronous()->String{ text.first ??"nothing"} // expected-note 20{{calls to instance method 'synchronous()' from outside of its actor context are implicitly asynchronous}}
39
39
func asynchronous()async->String{synchronous()}
40
40
}
41
41
@@ -45,7 +45,6 @@ extension MyActor {
45
45
set{}
46
46
}
47
47
48
-
// expected-note@+1 {{add 'async' to function 'actorIndependentFunc(otherActor:)' to make it asynchronous}} {{67-67= async}}
_ =text[0] // expected-error{{actor-isolated property 'text' can not be referenced from an '@actorIndependent' context}}
@@ -65,8 +64,11 @@ extension MyActor {
65
64
_ = otherActor.actorIndependentVar
66
65
otherActor.actorIndependentVar =17
67
66
67
+
// async promotion
68
+
_ =synchronous() // expected-error{{actor-isolated instance method 'synchronous()' can not be referenced from an '@actorIndependent' context}}
69
+
68
70
// Global actors
69
-
syncGlobalActorFunc() /// expected-error{{'async' in a function that does not support concurrency}}
71
+
syncGlobalActorFunc() /// expected-error{{global function 'syncGlobalActorFunc()' isolated to global actor 'SomeGlobalActor' can not be referenced from an '@actorIndependent' context}}
70
72
_ = syncGlobalActorFunc // expected-error{{global function 'syncGlobalActorFunc()' isolated to global actor 'SomeGlobalActor' can not be referenced from an '@actorIndependent' context}}
@SomeGlobalActorfunc syncGlobalActorFunc(){syncGlobalActorFunc()} // expected-note{{calls to global function 'syncGlobalActorFunc()' from outside of its actor context are implicitly asynchronous}}
237
+
@SomeGlobalActorfunc syncGlobalActorFunc(){syncGlobalActorFunc()} // expected-note 2{{calls to global function 'syncGlobalActorFunc()' from outside of its actor context are implicitly asynchronous}}
_ =synchronous() // expected-error{{actor-isolated instance method 'synchronous()' can not be referenced from context of global actor 'SomeGlobalActor'}}
265
+
_ =synchronous() // expected-error{{call is 'async' but is not marked with 'await'}}
266
+
_ =awaitsynchronous()
264
267
_ =text[0] // expected-error{{actor-isolated property 'text' can not be referenced from context of global actor 'SomeGlobalActor'}}
265
268
266
269
// Accesses on 'self' are only okay for immutable and asynchronous, because
267
270
// we are outside of the actor instance.
268
271
_ =self.immutable
269
-
_ =self.synchronous() // expected-error{{actor-isolated instance method 'synchronous()' can not be referenced from context of global actor 'SomeGlobalActor'}}
272
+
_ =self.synchronous() // expected-error{{call is 'async' but is not marked with 'await'}}
273
+
_ =awaitself.synchronous()
274
+
270
275
_ =awaitself.asynchronous()
271
276
_ =self.text[0] // expected-error{{actor-isolated property 'text' can not be referenced from context of global actor 'SomeGlobalActor'}}
272
277
_ =self[0] // expected-error{{actor-isolated subscript 'subscript(_:)' can not be referenced from context of global actor 'SomeGlobalActor'}}
273
278
274
279
// Accesses on 'super' are not okay; we're outside of the actor.
275
280
_ = super.superState // expected-error{{actor-isolated property 'superState' can not be referenced from context of global actor 'SomeGlobalActor'}}
276
-
super.superMethod() // expected-error{{actor-isolated instance method 'superMethod()' can not be referenced from context of global actor 'SomeGlobalActor'}}
281
+
super.superMethod() // expected-error{{call is 'async' but is not marked with 'await'}}
282
+
await super.superMethod()
277
283
await super.superAsyncMethod()
278
284
_ = super[0] // expected-error{{actor-isolated subscript 'subscript(_:)' can not be referenced from context of global actor 'SomeGlobalActor'}}
279
285
@@ -288,16 +294,14 @@ extension MyActor {
288
294
}
289
295
290
296
structGenericStruct<T>{
291
-
@GenericGlobalActor<T>func f(){} // expected-note{{calls to instance method 'f()' from outside of its actor context are implicitly asynchronous}}
297
+
@GenericGlobalActor<T>func f(){} // expected-note 2{{calls to instance method 'f()' from outside of its actor context are implicitly asynchronous}}
292
298
293
299
@GenericGlobalActor<T>func g(){
294
300
f() // okay
295
301
}
296
302
297
-
// expected-note@+2 {{add '@asyncHandler' to function 'h()' to create an implicit asynchronous context}} {{3-3=@asyncHandler }}
298
-
// expected-note@+1 {{add 'async' to function 'h()' to make it asynchronous}} {{39-39= async}}
299
303
@GenericGlobalActor<String>func h(){
300
-
f() // expected-error{{'async' in a function that does not support concurrency}}
304
+
f() // expected-error{{instance method 'f()' isolated to global actor 'GenericGlobalActor<T>' can not be referenced from different global actor 'GenericGlobalActor<String>'}}
301
305
_ = f // expected-error{{instance method 'f()' isolated to global actor 'GenericGlobalActor<T>' can not be referenced from different global actor 'GenericGlobalActor<String>'}}
302
306
}
303
307
}
@@ -472,9 +476,7 @@ class SomeClassInActor {
472
476
473
477
extensionSomeClassInActor.ID{
474
478
func f(_ object:SomeClassInActor){ // expected-note{{add '@MainActor' to make instance method 'f' part of global actor 'MainActor'}}
475
-
// expected-note@-1{{add 'async' to function 'f' to make it asynchronous}}
476
-
// expected-note@-2{{add '@asyncHandler' to function 'f' to create an implicit asynchronous context}}
477
-
object.inActor() // expected-error{{'async' in a function that does not support concurrency}}
479
+
object.inActor() // expected-error{{instance method 'inActor()' isolated to global actor 'MainActor' can not be referenced from this context}}
0 commit comments