Skip to content

Sema: Change behavior of implied 'Sendable' conformance #74908

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

Conversation

slavapestov
Copy link
Contributor

Today, this gives you a conditional conformance to Sendable in Swift 5 and 6 language mode:

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

Change this so that in Swift 5 mode, the implied conformance is unconditional:

extension G: P where T: P {}
// implied: extension G: Sendable {}

And ban it outright in Swift 6 mode:

extension G: P where T: P {}  // error

Fixes rdar://95695543.
Fixes rdar://122754849.
Fixes #71544.

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 force-pushed the fix-implied-sendable-conformance branch from 0b45de0 to 144b9fa Compare July 2, 2024 21:10
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov merged commit e899ff2 into swiftlang:main Jul 3, 2024
@@ -2415,8 +2415,16 @@ checkIndividualConformance(NormalProtocolConformance *conformance) {
ComplainLoc, diag::unchecked_conformance_not_special, ProtoType);
}

bool allowImpliedConditionalConformance = false;
if (Proto->isSpecificProtocol(KnownProtocolKind::Sendable)) {
if (Context.LangOpts.StrictConcurrencyLevel != StrictConcurrency::Complete)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be checking for Swift 6 instead, so we don't change Swift 5 code that enabled strict checking?

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.

Wrong compiler error regarding conditional conformances that involve Sendable
3 participants