[ConformanceLookup] Don't allow skipping inherited unavailable conformances in favor of explicit available ones.#75135
Merged
hborla merged 4 commits intoswiftlang:mainfrom Jul 13, 2024
Conversation
…mances in favor of explicit available ones. The type checker does not support the notion of multiple protocol conformances; there can only be one conformance, and if that conformance is unavailable, you cannot specify your own available conformance. This is important for Sendable checking; if a framework specifies that a type is explicitly not Sendable with an unavailable Sendable conformance, clients cannot ignore Sendable violations involving that type. If a superclass wants to allow subclasses to add a Sendable conformance, it should not declare an unavailable Sendable conformance.
…rom the defining module, and diagnose redundant Sendable conformances. We still allow re-stating inherited unchecked Sendable conformances in subclasses because inherited Sendable conformances are surprising when they opt out of static checking. Otherwise, warning on redundant Sendable conformances nudges programmers toward cleaning up unnecessary retroactive Sendable conformances over time as libraries incrementally add the conformances directly.
b44aac2 to
85b66d1
Compare
ktoso
approved these changes
Jul 12, 2024
Contributor
ktoso
left a comment
There was a problem hiding this comment.
Tricky impl hah, looks okey
hborla
commented
Jul 12, 2024
Sendable conformances for source compatibility. If conformance lookup always prefers the conformance from the defining module, libraries introducing unavailable Sendable conformances can break source in clients that declare retroactive Sendable conformances. Instead, still prefer the available conformance, and always diagnose the client conformance as redundant (as a warning). Then, when the retroactive conformance is removed, the errors will surface, so the programmer has to take explicit action to experience the source break.
cd9f333 to
b139770
Compare
Member
Author
|
@swift-ci please smoke test |
Member
Author
|
@swift-ci please test source compatibility |
Member
Author
|
@swift-ci please smoke test |
Member
Author
|
@swift-ci please test source compatibility |
Member
Author
|
The macOS smoke test is failing due to a driver test failure unrelated to this change. Looks like a revert is being tested at swiftlang/swift-driver#1662 |
Member
Author
|
@swift-ci please smoke test macOS |
This was referenced Feb 22, 2025
slavapestov
added a commit
to slavapestov/swift
that referenced
this pull request
Jun 17, 2025
…smatched availability This logic was introduced in swiftlang#75135. The intent was to prevent an implied conformance from overriding an existing unavailable one, for example in the case of Sendable. Let's relax this check a bit to only diagnose if the mismatch is in the unconditional availability, and not OS version. Fixes rdar://142873265.
slavapestov
added a commit
to slavapestov/swift
that referenced
this pull request
Jun 17, 2025
…smatched availability This logic was introduced in swiftlang#75135. The intent was to prevent an implied conformance from overriding an existing unavailable one, for example in the case of Sendable. Let's relax this check a bit to only diagnose if the mismatch is in the unconditional availability, and not OS version. Fixes rdar://142873265.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The type checker does not support the notion of multiple protocol conformances; there can only be one conformance, and if that conformance is unavailable, you cannot specify your own available conformance. This is important for Sendable checking; if a framework specifies that a type is explicitly not Sendable with an unavailable Sendable conformance, clients cannot ignore Sendable violations involving that type. If a superclass wants to allow subclasses to add a Sendable conformance, it should not declare an unavailable Sendable conformance.
Note that this change still does not warn if the original unavailable conformance is declared with
@_nonSendabledue to the way@_nonSendableexpansion happens during implicitSendablederivation, after no explicit conformance has been found.Resolves: rdar://124423524