-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[5.10][SE-0411] Promote IsolatedDefaultValues
from an experimental feature to an upcoming feature.
#70839
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
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
… isolation boundaries. (cherry picked from commit 49d6399)
(cherry picked from commit f448684)
…e corresponding stored property. (cherry picked from commit e9750bc)
…nitializers should be nonisolated if all initialized properties are Sendable with nonisolated default values. (cherry picked from commit d6fce01)
…to an upcoming feature. (cherry picked from commit 0e71623)
… isolated default arguments. (cherry picked from commit 5ac839b)
…hecking. (cherry picked from commit e47a66c)
(cherry picked from commit 97ee101)
@swift-ci please test |
decl attributes. (cherry picked from commit 275d783)
…nflicts for 5.10 cherry picks.
ae896ef
to
aaa1c85
Compare
@swift-ci please test |
airspeedswift
approved these changes
Jan 11, 2024
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.
SE-0411: Isolated Default Values closed an important hole in Swift's static data-race safety model which prevents actor-isolated default stored property values from being synchronously evaluated from outside the actor. For example, the following code is currently valid, but it will crash at runtime at the call to
MainActor.assertIsolated()
:This happens because
requiresMainActor()
is used as a default argument to the member-wise initializer ofS
, but default arguments are always evaluated in the caller. In this case, the caller is on the generic executor, so the default argument evaluation crashes. Under-enable-upcoming-feature IsolatedDefaultValues
, this code is still value, but callees that have isolated default arguments will hop to the isolation domain before evaluating the default arguments.-strict-concurrency=complete
. Code can also opt into this feature using-enable-upcoming-feature IsolatedDefaultValues
. More specifically, this change impacts structs and classes whose stored properties are global actor isolated and their initial values must run on that global actor.Medium. This is technically a source breaking change for code that uses isolated stored property initial values in a
nonisolated
initializer:In Swift 5.9, the above code is valid. With this change, it's invalid under
-strict-concurrency=complete
:However, I believe such code is rare in practice, and the common code pattern that currently exhibits data races is like the above example, which remains valid (but safe) under this proposal.
-strict-concurrency=complete
and added new unit tests forIsolatedDefaultValues
. Themain
PR for enablingIsolatedDefaultValues
under-strict-concurrency=complete
also passed the source compatibility suite.IsolatedDefaultValues
from an experimental feature to an upcoming feature. #70257