Skip to content

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

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 20, 2024

Conversation

hborla
Copy link
Member

@hborla hborla commented Jan 20, 2024

When determining whether compiler synthesized initializers should have nonisolated applied, skip property initializers that are subsumed, e.g. by an init accessor or a backing property wrapper initializer, and always consider the subsuming initializer. This fixes an issue where the compiler would apply nonisolated to memberwise and default initializers of types that use property wrappers whose backing property wrapper initializer is global actor isolated, but the wrapped value initializer is not, e.g.

@MainActor
@propertyWrapper struct RequiresMain<Value>  {
  var wrappedValue: Value

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

// `S.init()` should be isolated to `@MainActor` because 
// `RequiresMain.init(wrappedValue:)` is isolated to `@MainActor`
struct S {
  @RequiresMain private var x = 10
}

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.

Resolves rdar://121282537

…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.
@hborla hborla force-pushed the default-init-isolation branch from 04c3d20 to 20829fa Compare January 20, 2024 02:12
@hborla
Copy link
Member Author

hborla commented Jan 20, 2024

@swift-ci please smoke test

@hborla
Copy link
Member Author

hborla commented Jan 20, 2024

@swift-ci please test source compatibility

…erring the

isolation of implicit initializers.
@hborla
Copy link
Member Author

hborla commented Jan 20, 2024

Those source compatibility failures are real. This fails under -strict-concurrency=complete

struct CError: Error, RawRepresentable {
  var rawValue: CInt
}

Probably because I'm calling getAllMembers() which invokes the conformance synthesis earlier. Instead, I can iterate over the stored properties and the init accessor properties, because those are what can participate in the implicit initializers.

…ation for

implicit initializers.

This messes with conformance synthesis for `RawRepresentable` and friends because
it invokes conformance synthesis too early.
@hborla
Copy link
Member Author

hborla commented Jan 20, 2024

@swift-ci please smoke test

@hborla
Copy link
Member Author

hborla commented Jan 20, 2024

@swift-ci please test source compatibility

@hborla hborla merged commit a5f0fe7 into swiftlang:main Jan 20, 2024
@hborla hborla deleted the default-init-isolation branch January 20, 2024 23:14
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