-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[5.5] Inject hop_to_executor
after self
is fully initialized in unrestricted actor inits
#38490
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 7 commits into
swiftlang:release/5.5
from
kavon:5.5-flowsensitive-init-hop
Jul 20, 2021
Merged
[5.5] Inject hop_to_executor
after self
is fully initialized in unrestricted actor inits
#38490
DougGregor
merged 7 commits into
swiftlang:release/5.5
from
kavon:5.5-flowsensitive-init-hop
Jul 20, 2021
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
I ran into this while implementing async actor inits; where I was emitting an actor hop in the middle of an access region, which caused the access set to be unexpectedly empty.
Because `self` can be used unrestricted after it is fully-initialized in an async actor init, we perform a hop_to_executor(self) immediately after `self` is fully-initialized on all paths within the initializer. If we did not, then code could race with the initializer if it, e.g., spawns a task from the initializer and mutates actor state that the initializer then reads. By hopping to the executor, we prevent that task from running until _after_ the initializer completes.
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
ktoso
approved these changes
Jul 20, 2021
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.
@swift-ci please nominate |
DougGregor
approved these changes
Jul 20, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
concurrency
Feature: umbrella label for concurrency language features
🍒 release cherry pick
Flag: Release branch cherry picks
swift 5.5
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.
Rationale: The typechecker permits unfettered use of
self
throughout an actor'sasync
initializer. This patch brings the implementation of such initializers in line with what the typechecker permits, by actually hopping toself
's initializer in order to reserve it. This prevents a possible race with the initializer's body.Risk: Low
Risk Detail: This change is focused on correcting the code generated by the compiler.
Reward: High
Reward Details: Fixes a miscompile that would lead to a concurrency bug.
Original PR: #38215
Issue: rdar://78790683
Code Reviewed By: Konrad Malawski
Testing Details: Regression test is included.