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
[Actors] Permit non-sendable, escaping closures to be actor-isolated.
Remove the heuristic that escaping closures cannot be actor-isolated.
This is in line with the long term plan for actor isolation, but opens
up some holes in the short term because Sendable closures are not enforced
throughout the Swift ecosystem.
One significant effect of this change is that we will now, statically,
fail to detect many cases where actor isolation can be broken.
Copy file name to clipboardExpand all lines: test/Concurrency/actor_isolation.swift
+13-13Lines changed: 13 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ actor MySuperActor {
22
22
varsuperState:Int=25 // expected-note {{mutation of this property is only permitted within the actor}}
23
23
24
24
25
-
func superMethod(){ // expected-note 2 {{calls to instance method 'superMethod()' from outside of its actor context are implicitly asynchronous}}
25
+
func superMethod(){ // expected-note {{calls to instance method 'superMethod()' from outside of its actor context are implicitly asynchronous}}
26
26
self.superState +=5
27
27
}
28
28
@@ -40,12 +40,12 @@ class Point {
40
40
41
41
actorMyActor:MySuperActor{
42
42
letimmutable:Int=17
43
-
// expected-note@+2 3{{property declared here}}
44
-
// expected-note@+1 8{{mutation of this property is only permitted within the actor}}
43
+
// expected-note@+2 2{{property declared here}}
44
+
// expected-note@+1 6{{mutation of this property is only permitted within the actor}}
45
45
varmutable:Int=71
46
46
47
47
// expected-note@+2 3 {{mutation of this property is only permitted within the actor}}
48
-
// expected-note@+1 5{{property declared here}}
48
+
// expected-note@+1 4{{property declared here}}
49
49
vartext:[String]=[]
50
50
51
51
letpoint:Point=Point()
@@ -60,7 +60,7 @@ actor MyActor: MySuperActor {
60
60
classfunc synchronousClass(){}
61
61
staticfunc synchronousStatic(){}
62
62
63
-
func synchronous()->String{ text.first ??"nothing"} // expected-note 20{{calls to instance method 'synchronous()' from outside of its actor context are implicitly asynchronous}}
63
+
func synchronous()->String{ text.first ??"nothing"} // expected-note 19{{calls to instance method 'synchronous()' from outside of its actor context are implicitly asynchronous}}
64
64
func asynchronous()async->String{
65
65
super.superState +=4
66
66
returnsynchronous()
@@ -241,15 +241,15 @@ extension MyActor {
241
241
_ = otherLocalVar
242
242
}
243
243
244
-
// Escaping closures might run concurrently.
244
+
// Escaping closures are still actor-isolated
245
245
acceptEscapingClosure{
246
-
_ =self.text[0] // expected-error{{actor-isolated property 'text' cannot be referenced from an '@escaping' closure}}
247
-
_ =self.mutable // expected-error{{actor-isolated property 'mutable' cannot be referenced from an '@escaping' closure}}
248
-
self.mutable =0 // expected-error{{actor-isolated property 'mutable' cannot be mutated from an '@escaping' closure}}
249
-
acceptInout(&self.mutable) // expected-error{{actor-isolated property 'mutable' cannot be used 'inout' from an '@escaping' closure}}
246
+
_ =self.text[0]
247
+
_ =self.mutable
248
+
self.mutable =0
249
+
acceptInout(&self.mutable)
250
250
_ =self.immutable
251
-
_ =self.synchronous() // expected-error{{actor-isolated instance method 'synchronous()' cannot be referenced from an '@escaping' closure}}
252
-
_ = localVar // okay, don't complain about escaping
251
+
_ =self.synchronous()
252
+
_ = localVar
253
253
_ = localConstant
254
254
}
255
255
@@ -281,7 +281,7 @@ extension MyActor {
281
281
282
282
// Partial application
283
283
_ = synchronous // expected-error{{actor-isolated instance method 'synchronous()' can not be partially applied}}
284
-
_ = super.superMethod // expected-error{{actor-isolated instance method 'superMethod()' can not be referenced from a non-isolated context}}
284
+
_ = super.superMethod
285
285
acceptClosure(synchronous)
286
286
acceptClosure(self.synchronous)
287
287
acceptClosure(otherActor.synchronous) // expected-error{{actor-isolated instance method 'synchronous()' can only be referenced on 'self'}}
0 commit comments