-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[6.0] Teach #isolation to respect the flow-sensitive nature of actor initializers #74245
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
Merged
DougGregor
merged 5 commits into
swiftlang:release/6.0
from
DougGregor:flow-sensitive-actor-init-isolation-6.0
Jun 12, 2024
Merged
[6.0] Teach #isolation to respect the flow-sensitive nature of actor initializers #74245
DougGregor
merged 5 commits into
swiftlang:release/6.0
from
DougGregor:flow-sensitive-actor-init-isolation-6.0
Jun 12, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ializers Actor initializers have a flow-sensitive property where they are isolated to the actor being initialized only after the actor instance itself is fully-initialized. However, this behavior was not being reflected in the expansion of `#isolation`, which was always expanding to `self`, even before `self` is fully formed. This led to a source compatibility issue with code that used the async for..in loop within an actor initializer *prior* to the point where the actor was fully initialized, because the type checker is introducing the `#isolation` (SE-0421) but Definite Initialization properly rejects the use of `self` before it is initialized. Address this issue by delaying the expansion of `#isolation` until after the actor is fully initialized. In SILGen, we introduce a new builtin for this case (and *just* this case) called `flowSensitiveSelfIsolation`, which takes in `self` as its argument and produces an `(any Actor)?`. Definite initialization does not treat this as a use of `self`. Rather, it tracks these builtins and replaces them either with `self` (if it is fully-initialized at this point) or `nil` (if it is not fully-initialized at this point), mirroring the flow-sensitive isolation semantics described in SE-0327. Fixes rdar://127080037.
Distributed actors can be treated as actors by accessing the `asLocalActor` property. When lowering `#isolation` in a distributed actor initializer, use a separate builtin `flowSensitiveDistributedSelfIsolation` to capture the conformance to `DistributedActor`, and have Definite Initialization introduce the call to the `asLocalActor` getter when needed.
@swift-ci please test |
Hmph, failures are unrelated to this change. |
@swift-ci please test Windows |
@swift-ci please test macOS |
@swift-ci please test Windows |
hborla
approved these changes
Jun 11, 2024
ktoso
approved these changes
Jun 11, 2024
@swift-ci please test |
@swift-ci please test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation: Perform flow-sensitive lowering of
#isolation
within actor initializers so that it lowers tonil
before the actor is fully-initialized andself
(orself.asLocalActor
in the distributed case) after the actor is fully-initialized.Original PR: #74225
Radar/issue: rdar://127080037
Reviewed by: @ktoso
Risk: Low. Only affects actor initializers that use
#isolation
or the asynchronous for-in loop on new-enough platforms (where the newAsyncIteratorProtocol.next(isolation:)
is present).