Skip to content

Commit 3ea3c1d

Browse files
committed
Revert "[ConformanceLookup] Just kidding, the compiler needs to prefer available"
This reverts commit b139770.
1 parent 7b1730b commit 3ea3c1d

File tree

3 files changed

+18
-43
lines changed

3 files changed

+18
-43
lines changed

lib/AST/ConformanceLookupTable.cpp

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,9 @@ void ConformanceLookupTable::ConformanceEntry::markSupersededBy(
7070
SupersededBy = entry;
7171

7272
if (diagnose) {
73-
// If an unavailable Sendable conformance is superseded by a
74-
// retroactive one in the client, we need to record this error
75-
// at the client decl context.
76-
auto *dc = getDeclContext();
77-
if (getProtocol()->isMarkerProtocol() && isFixed() &&
78-
!entry->isFixed()) {
79-
dc = entry->getDeclContext();
80-
}
81-
8273
// Record the problem in the conformance table. We'll
8374
// diagnose these in semantic analysis.
84-
table.AllSupersededDiagnostics[dc].push_back(this);
75+
table.AllSupersededDiagnostics[getDeclContext()].push_back(this);
8576
}
8677
}
8778

@@ -607,22 +598,21 @@ ConformanceLookupTable::Ordering ConformanceLookupTable::compareConformances(
607598
}
608599
}
609600

610-
// If only one of the conformances is unconditionally available on the
611-
// current deployment target, pick that one.
612-
//
613-
// FIXME: Conformance lookup should really depend on source location for
614-
// this to be 100% correct.
615-
// FIXME: When a class and an extension with the same availability declare the
616-
// same conformance, this silently takes the class and drops the extension.
617-
if (lhs->getDeclContext()->isAlwaysAvailableConformanceContext() !=
618-
rhs->getDeclContext()->isAlwaysAvailableConformanceContext()) {
619-
// Diagnose conflicting marker protocol conformances that differ in
620-
// un-availability.
621-
diagnoseSuperseded = lhs->getProtocol()->isMarkerProtocol();
622-
623-
return (lhs->getDeclContext()->isAlwaysAvailableConformanceContext()
624-
? Ordering::Before
625-
: Ordering::After);
601+
// Unavailable Sendable conformances cannot be replaced by available ones.
602+
if (!lhs->getProtocol()->isMarkerProtocol()) {
603+
// If only one of the conformances is unconditionally available on the
604+
// current deployment target, pick that one.
605+
//
606+
// FIXME: Conformance lookup should really depend on source location for
607+
// this to be 100% correct.
608+
// FIXME: When a class and an extension with the same availability declare the
609+
// same conformance, this silently takes the class and drops the extension.
610+
if (lhs->getDeclContext()->isAlwaysAvailableConformanceContext() !=
611+
rhs->getDeclContext()->isAlwaysAvailableConformanceContext()) {
612+
return (lhs->getDeclContext()->isAlwaysAvailableConformanceContext()
613+
? Ordering::Before
614+
: Ordering::After);
615+
}
626616
}
627617

628618
// If one entry is fixed and the other is not, we have our answer.
@@ -1138,17 +1128,9 @@ void ConformanceLookupTable::lookupConformances(
11381128
if (diagnostics) {
11391129
auto knownDiags = AllSupersededDiagnostics.find(dc);
11401130
if (knownDiags != AllSupersededDiagnostics.end()) {
1141-
for (auto *entry : knownDiags->second) {
1131+
for (const auto *entry : knownDiags->second) {
11421132
ConformanceEntry *supersededBy = entry->getSupersededBy();
11431133

1144-
// Diagnose the client conformance as superseded.
1145-
auto *definingModule = nominal->getParentModule();
1146-
if (entry->getDeclContext()->getParentModule() == definingModule &&
1147-
supersededBy->getDeclContext()->getParentModule() != definingModule) {
1148-
supersededBy = entry;
1149-
entry = entry->getSupersededBy();
1150-
}
1151-
11521134
diagnostics->push_back({entry->getProtocol(),
11531135
entry->getDeclaredLoc(),
11541136
entry->getKind(),

test/Concurrency/Inputs/SendableConformances.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ public class NonSendableClass {}
55
extension NonSendableClass: @unchecked Sendable {}
66

77
public struct SendableStruct: Sendable {}
8-
9-
public struct AnotherSendableStruct: Sendable {}

test/Concurrency/redundant_sendable_conformance.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ extension NonSendableClass: @retroactive @unchecked Sendable {}
1313
// expected-warning@-1 {{conformance of 'NonSendableClass' to protocol 'Sendable' was already stated in the type's module 'SendableConformances'}}
1414

1515
typealias CheckNonSendableClass = RequireSendable<NonSendableClass>
16+
// expected-error@-1 {{conformance of 'NonSendableClass' to 'Sendable' is unavailable}}
1617

1718
extension SendableStruct: @retroactive @unchecked Sendable {}
1819
// expected-warning@-1 {{conformance of 'SendableStruct' to protocol 'Sendable' was already stated in the type's module 'SendableConformances'}}
19-
20-
@available(*, unavailable)
21-
extension AnotherSendableStruct: @retroactive @unchecked Sendable {}
22-
// expected-warning@-1 {{conformance of 'AnotherSendableStruct' to protocol 'Sendable' was already stated in the type's module 'SendableConformances'}}
23-
24-
typealias CheckAnotherSendableStruct = RequireSendable<AnotherSendableStruct>

0 commit comments

Comments
 (0)