Skip to content

[6.0] Change behavior of implied 'Sendable' conformance #74914

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

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Jul 2, 2024

6.0 cherry-pick of #74908

  • Description: If a type conditionally conforms to two protocols that both adopt Sendable retroactively, we would attempt to synthesize two conditional conformances to Sendable with incompatible requirements. Instead, change it so that the implied Sendable conformance is unconditional in -swift-version 5 mode, and ban it outright in -swift-version 6.

  • Origination: This is a long-standing issue with conditional conformances, where the original Sendable carveout never quite worked right.

  • Reviewed by: @DougGregor

  • Risk: Low. We might now diagnose a non-Sendable stored property in more cases, because the Sendable conformance is unconditional, but in -swift-version 5 this was a warning, so this should not be a source break. In -swift-version 6, the new behavior is source breaking because the implied Sendable conformance must be declared explicitly. However, this matches the intent of -swift-version 6.

  • Radar: rdar://95695543, rdar://122754849.

A conditional conformance to a protocol does not usually imply
a conformance to the protocol's inherited protocols, because
we have no way to guess what the conditional requirements
should be.

A carveout was added for 'Sendable', so that protocols could
inherit from 'Sendable' retroactively. However, the 'Sendable'
conformance would become conditional, which causes us to
reject a _second_ conditional conformance to such a protocol:

    struct G<T> {}
    protocol P: Sendable {}
    protocol Q: Sendable {}

    extension G: P where T: P {}
    extension G: Q where T: Q {}

To make this work, tweak the code so that an implied conformance
has the same generic signature as the conforming type, that is,
we force it to be unconditional.

Fixes rdar://122754849
Fixes swiftlang#71544
You can't do this anymore:

    struct G<T> {}
    protocol P: Sendable {}
    extension G: P where T: P {}

Fixes rdar://95695543.
@slavapestov slavapestov requested a review from a team as a code owner July 2, 2024 21:39
…sion instead of -strict-concurrency

Also add some comments to explain what in the world is going on
with the new checks.
@slavapestov slavapestov force-pushed the fix-impliedsendable-conformance-6.0 branch from 4654142 to 31074f3 Compare July 3, 2024 15:27
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov merged commit 2a0a26d into swiftlang:release/6.0 Jul 3, 2024
5 checks passed
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