Skip to content

Commit d35cacd

Browse files
committed
Sema: Remove witness/requirement ranking
This doesn't appear to be necessary when name lookup does the right thing. We don't *want* Sema to consider overload sets containing both a protocol requirement and a witness, because this could lead to exponential behavior.
1 parent bfb252a commit d35cacd

File tree

1 file changed

+0
-63
lines changed

1 file changed

+0
-63
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -155,57 +155,6 @@ static bool sameOverloadChoice(const OverloadChoice &x,
155155
llvm_unreachable("Unhandled OverloadChoiceKind in switch.");
156156
}
157157

158-
/// Compare two declarations to determine whether one is a witness of the other.
159-
static Comparison compareWitnessAndRequirement(TypeChecker &tc, DeclContext *dc,
160-
ValueDecl *decl1,
161-
ValueDecl *decl2) {
162-
// We only have a witness/requirement pair if exactly one of the declarations
163-
// comes from a protocol.
164-
auto proto1 = dyn_cast<ProtocolDecl>(decl1->getDeclContext());
165-
auto proto2 = dyn_cast<ProtocolDecl>(decl2->getDeclContext());
166-
if ((bool)proto1 == (bool)proto2)
167-
return Comparison::Unordered;
168-
169-
// Figure out the protocol, requirement, and potential witness.
170-
ProtocolDecl *proto;
171-
ValueDecl *req;
172-
ValueDecl *potentialWitness;
173-
if (proto1) {
174-
proto = proto1;
175-
req = decl1;
176-
potentialWitness = decl2;
177-
} else {
178-
proto = proto2;
179-
req = decl2;
180-
potentialWitness = decl1;
181-
}
182-
183-
// Cannot compare type declarations this way.
184-
// FIXME: Use the same type-substitution approach as lookupMemberType.
185-
if (isa<TypeDecl>(req))
186-
return Comparison::Unordered;
187-
188-
if (!potentialWitness->getDeclContext()->isTypeContext())
189-
return Comparison::Unordered;
190-
191-
// Determine whether the type of the witness's context conforms to the
192-
// protocol.
193-
auto owningType
194-
= potentialWitness->getDeclContext()->getDeclaredInterfaceType();
195-
auto conformance = tc.conformsToProtocol(owningType, proto, dc,
196-
ConformanceCheckFlags::InExpression);
197-
if (!conformance || conformance->isAbstract())
198-
return Comparison::Unordered;
199-
200-
// If the witness and the potential witness are not the same, there's no
201-
// ordering here.
202-
if (conformance->getConcrete()->getWitnessDecl(req, &tc) != potentialWitness)
203-
return Comparison::Unordered;
204-
205-
// We have a requirement/witness match.
206-
return proto1? Comparison::Worse : Comparison::Better;
207-
}
208-
209158
namespace {
210159
/// Describes the relationship between the context types for two declarations.
211160
enum class SelfTypeRelationship {
@@ -504,18 +453,6 @@ static bool isDeclAsSpecializedAs(TypeChecker &tc, DeclContext *dc,
504453
return subscript2->isGeneric();
505454
}
506455

507-
// A witness is always more specialized than the requirement it satisfies.
508-
switch (compareWitnessAndRequirement(tc, dc, decl1, decl2)) {
509-
case Comparison::Unordered:
510-
break;
511-
512-
case Comparison::Better:
513-
return true;
514-
515-
case Comparison::Worse:
516-
return false;
517-
}
518-
519456
// Members of protocol extensions have special overloading rules.
520457
ProtocolDecl *inProtocolExtension1 = outerDC1
521458
->getAsProtocolExtensionContext();

0 commit comments

Comments
 (0)