Skip to content

[5.10][Concurrency] Handle cases where a property initializer is subsumed by another property for IsolatedDefaultValues. #71034

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
merged 3 commits into from
Jan 24, 2024

Conversation

hborla
Copy link
Member

@hborla hborla commented Jan 20, 2024

  • Explanation: SE-0411 applies nonisolated to implicit initializers when the initializer does not require actor isolation because all property types are Sendable with nonisolated initializer expressions. This was done by looking at the properties and initial values from the memberwise initializer. However, property wrappers and init accessors can have an actor isolation that's different from the initializer expression that it subsumes. If the backing property wrapper initializer is global actor isolation but the wrapped value initializer is not, the compiler incorrectly applied nonisolated to implicit initializers, and SILGen later errored because the property wrapper backing initializer was skipped due to mismatching isolation, e.g.
@MainActor
@propertyWrapper struct RequiresMain<Value>  {
  var wrappedValue: Value

  init(wrappedValue: Value) {
    self.wrappedValue = wrappedValue
  }
}

struct S { // error: return from initializer without initializing all stored properties
  @RequiresMain private var x = 10
}

To fix this, skip property initializers that are subsumed, e.g. by an init accessor or a backing property wrapper initializer, and always consider the subsuming initializer to determine whether an implicit initializer can be nonisolated.

This change also lessens the source break of SE-0411 by still emitting member initializers in implicit constructors when the initializer violates actor isolation to preserve the behavior of existing code when concurrency diagnostics are downgraded to warnings in Swift 5 mode.

@hborla hborla requested a review from a team as a code owner January 20, 2024 02:52
@hborla
Copy link
Member Author

hborla commented Jan 20, 2024

@swift-ci please test

…y another

property for IsolatedDefaultValues.

For property wrappers and init accesors, skip property initializers that are
subsumed, e.g. by an init accessor or a backing property wrapper initializer,
and always consider the subsuming initializer to determine whether compiler
synthesized initializers should have `nonisolated` applied.

This change also lessens the source break of SE-0411 by still emitting
member initializers in implicit constructors when the initializer violates
actor isolation to preserve the behavior of existing code when concurrency
diagnostics are downgraded to warnings in Swift 5 mode.

(cherry picked from commit 20829fa)
@hborla hborla force-pushed the 5.10-default-init-isolation branch from 1e35f5b to a641192 Compare January 20, 2024 03:59
@hborla
Copy link
Member Author

hborla commented Jan 20, 2024

@swift-ci please test

…erring the

isolation of implicit initializers.

(cherry picked from commit cc1fd1c)
…ation for

implicit initializers.

This messes with conformance synthesis for `RawRepresentable` and friends because
it invokes conformance synthesis too early.

(cherry picked from commit a11dc3c)
@hborla
Copy link
Member Author

hborla commented Jan 20, 2024

@swift-ci please test

@hborla hborla merged commit 3e816f5 into swiftlang:release/5.10 Jan 24, 2024
@hborla hborla deleted the 5.10-default-init-isolation branch January 24, 2024 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants