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
reimplement nonisolated initializing exprs for instance properties
It's possible to create an impossible set of constraints for
instance-member stored properties of a type. For example:
@mainactor func getStatus() -> Int { /* ... */ }
@PIDActor func genPID() -> ProcessID { /* ... */ }
class Process {
@mainactor var status: Int = getStatus()
@PIDActor var pid: ProcessID = genPID()
init() {} // Problem: what is the isolation of this init?
}
We cannot satisfy the isolation of the initilizing expressions,
which demand that genStatus and genPID are run with isolation
from a non-async designated initializer, which is not possible.
This patch changes the isolation for those initializer expressions
for instance members, saying that the isolation is unspecified.
fixes rdar://84225474
The first attempt to do this was in
#40652
But, I implemented that as a hard source break, since the isolation
was changed in a way that an error diagnostic would be emitted.
This commit reimplements the change more gently, as a warning for
Swift 5 users.
func useFooInADefer()->String{ // expected-note {{calls to global function 'useFooInADefer()' from outside of its actor context are implicitly asynchronous}}
@MainActorvarx=useFooInADefer() // expected-warning {{expression requiring global actor 'MainActor' cannot appear in default-value expression of property 'x'; this is an error in Swift 6}}
591
+
@MainActorvary={()->Boolin
592
+
varz= statefulThingy // expected-warning {{expression requiring global actor 'MainActor' cannot appear in default-value expression of property 'y'; this is an error in Swift 6}}
593
+
return z
594
+
}()
595
+
}
596
+
597
+
@SomeGlobalActor
598
+
classButter{
599
+
vara=useFooInADefer() // expected-error {{call to main actor-isolated global function 'useFooInADefer()' in a synchronous global actor 'SomeGlobalActor'-isolated context}}
600
+
601
+
nonisolatedletb= statefulThingy // expected-error {{var 'statefulThingy' isolated to global actor 'MainActor' can not be referenced from a non-isolated synchronous context}}
602
+
603
+
varc:Int={
604
+
returngetGlobal7() // expected-warning {{expression requiring global actor 'SomeGlobalActor' cannot appear in default-value expression of property 'c'; this is an error in Swift 6}}
func mainActorFn()->Int{return0} // expected-note 2 {{calls to global function 'mainActorFn()' from outside of its actor context are implicitly asynchronous}}
7
+
8
+
@MainActor
9
+
classC{
10
+
varx:Int=mainActorFn() // expected-error {{call to main actor-isolated global function 'mainActorFn()' in a synchronous nonisolated context}}
11
+
12
+
lazy vary:Int=mainActorFn()
13
+
14
+
staticvarz:Int=mainActorFn()
15
+
}
16
+
17
+
@MainActor
18
+
varx:Int=mainActorFn() // expected-error {{call to main actor-isolated global function 'mainActorFn()' in a synchronous nonisolated context}}
0 commit comments