Skip to content

Sema: Remove requirement/witness ranking #11244

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions lib/Sema/CSRanking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,57 +155,6 @@ static bool sameOverloadChoice(const OverloadChoice &x,
llvm_unreachable("Unhandled OverloadChoiceKind in switch.");
}

/// Compare two declarations to determine whether one is a witness of the other.
static Comparison compareWitnessAndRequirement(TypeChecker &tc, DeclContext *dc,
ValueDecl *decl1,
ValueDecl *decl2) {
// We only have a witness/requirement pair if exactly one of the declarations
// comes from a protocol.
auto proto1 = dyn_cast<ProtocolDecl>(decl1->getDeclContext());
auto proto2 = dyn_cast<ProtocolDecl>(decl2->getDeclContext());
if ((bool)proto1 == (bool)proto2)
return Comparison::Unordered;

// Figure out the protocol, requirement, and potential witness.
ProtocolDecl *proto;
ValueDecl *req;
ValueDecl *potentialWitness;
if (proto1) {
proto = proto1;
req = decl1;
potentialWitness = decl2;
} else {
proto = proto2;
req = decl2;
potentialWitness = decl1;
}

// Cannot compare type declarations this way.
// FIXME: Use the same type-substitution approach as lookupMemberType.
if (isa<TypeDecl>(req))
return Comparison::Unordered;

if (!potentialWitness->getDeclContext()->isTypeContext())
return Comparison::Unordered;

// Determine whether the type of the witness's context conforms to the
// protocol.
auto owningType
= potentialWitness->getDeclContext()->getDeclaredInterfaceType();
auto conformance = tc.conformsToProtocol(owningType, proto, dc,
ConformanceCheckFlags::InExpression);
if (!conformance || conformance->isAbstract())
return Comparison::Unordered;

// If the witness and the potential witness are not the same, there's no
// ordering here.
if (conformance->getConcrete()->getWitnessDecl(req, &tc) != potentialWitness)
return Comparison::Unordered;

// We have a requirement/witness match.
return proto1? Comparison::Worse : Comparison::Better;
}

namespace {
/// Describes the relationship between the context types for two declarations.
enum class SelfTypeRelationship {
Expand Down Expand Up @@ -504,18 +453,6 @@ static bool isDeclAsSpecializedAs(TypeChecker &tc, DeclContext *dc,
return subscript2->isGeneric();
}

// A witness is always more specialized than the requirement it satisfies.
switch (compareWitnessAndRequirement(tc, dc, decl1, decl2)) {
case Comparison::Unordered:
break;

case Comparison::Better:
return true;

case Comparison::Worse:
return false;
}

// Members of protocol extensions have special overloading rules.
ProtocolDecl *inProtocolExtension1 = outerDC1
->getAsProtocolExtensionContext();
Expand Down