[5.10][SE-0411] Promote IsolatedDefaultValues from an experimental feature to an upcoming feature.
#70839
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
nonisolatedinitializer: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=completeand added new unit tests forIsolatedDefaultValues. ThemainPR for enablingIsolatedDefaultValuesunder-strict-concurrency=completealso passed the source compatibility suite.IsolatedDefaultValuesfrom an experimental feature to an upcoming feature. #70257