New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes for stored property initializers #40652
Conversation
7dc36a9
to
7b5d466
Compare
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
7b5d466
to
fcd3a88
Compare
@swift-ci please test |
Build failed |
Build failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
Some globals, like static stored properties, are lazily initialized. For situations where we do a direct access to that property, we will first call a function that tries to initialize the var if needed, before returning the address of the global to perform the direct access. In this specific case, we were not on the right actor when invoking that function. fixes rdar://83411416
fcd3a88
to
51f8cd1
Compare
@swift-ci please test and merge |
@swift-ci please test and merge |
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 apple#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.
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 apple#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.
There are two related fixes in this PR: