[6.0][ConformanceLookup] Don't allow skipping inherited unavailable conformances in favor of explicit available ones.#75223
Merged
hborla merged 4 commits intoswiftlang:release/6.0from Jul 15, 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. (cherry picked from commit 7356fe8)
…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. (cherry picked from commit 85b66d1)
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. (cherry picked from commit b139770)
conformances. (cherry picked from commit e2ddc6c)
Member
Author
|
@swift-ci please test |
ktoso
approved these changes
Jul 13, 2024
DougGregor
approved these changes
Jul 15, 2024
This was referenced Jul 19, 2024
Merged
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.
Explanation: This change fixes an issue where the compiler did not issue redundant conformance warnings when a client tries to add a retroactive
@unchecked Sendableconformance when the library has already added an unavailableSendableconformance.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.Scope: Only impacts redundant conformances where at least one of the conformances is unavailable.
Issues: rdar://124423524
Original PRs: [ConformanceLookup] Don't allow skipping inherited unavailable conformances in favor of explicit available ones. #75135
Risk: Low; the redundant conformance diagnostics added by this change are downgraded to warnings unconditionally. This allows libraries to stage in unavailable conformances to
Sendablelater on, and clients that have already added a retroactive@unchecked Sendableconformance will receive a warning when they rebuild. Conformance lookup will still choose the available conformance to avoid breaking source compatibility in places where the client code uses the type in a way that requires an available conformance toSendable.Testing: Added new tests. Passed source compatibility on the
mainPR.Reviewers: @ktoso