[5.6] make initializing expressions for member stored properties nonisolated. #40693
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: There was a mismatch between the isolation assigned to the initializing expressions of a stored property member and the actual implementation by the compiler. For example, this program was permitted by the type-checker
but it has an impossible-to-satisfy set of constraints on the
init
. It's not possible to have theinit
be isolated to both global actors, in order for the init to execute thegenStatus
andgenPID
calls. In fact, theinit
has no isolation at all, and is non-async, so it cannot gain actor isolation in its body at all. So the implementation was ignoring the isolation, despite the typechecker providing it.This patch changes the isolation for those initializer expressions for instance members, saying that the isolation is unspecified in order to match the implementation.
Scope of Issue: Programs could have concurrency bugs because isolation was not correctly gained at runtime, despite the type-checker permitting the program. It's limited specifically to any initializing expressions of a nominal type's property that is isolated to a global actor, most commonly the MainActor. If the type has a designated initializer that is not also isolated to that same global-actor, then the bug is present in their program.
Risk: (Medium) This patch will most commonly introduce a source break for code that calls or accesses something isolated to the MainActor specifically within an initializing expression of a stored property member. Users must move those expressions so they appear in each designated initializer. If those initializers had the correct isolation, then the source break is a very simple refactoring. But if those initializers had the wrong isolation, then their code previously had a runtime bug and a larger refactoring is required.
Pull Request URL: #40652
Reviewed By: Doug Gregor
Automated Testing: regression test is included
Issue: rdar://84225474