Skip to content

Commit 62305d0

Browse files
committed
[ConstraintSystem] Use isDeclSubstitutable instead of compareDeclarations
to order generic operator overload choices.
1 parent c62d898 commit 62305d0

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,8 +2197,7 @@ void ConstraintSystem::partitionDisjunction(
21972197
auto *declA = dyn_cast<ValueDecl>(Choices[lhs]->getOverloadChoice().getDecl());
21982198
auto *declB = dyn_cast<ValueDecl>(Choices[rhs]->getOverloadChoice().getDecl());
21992199

2200-
auto result = TypeChecker::compareDeclarations(DC, declA, declB);
2201-
return result == Comparison::Better;
2200+
return TypeChecker::isDeclSubstitutable(declA, declB);
22022201
});
22032202

22042203
everythingElse.append(genericOverloads.begin(), genericOverloads.end());

lib/Sema/CSStep.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ bool IsDeclSubstitutableRequest::evaluate(Evaluator &evaluator,
574574
return substTypeA->isEqual(substTypeB);
575575
}
576576

577-
static bool isDeclSubstitutable(ValueDecl *declA, ValueDecl *declB) {
577+
bool TypeChecker::isDeclSubstitutable(ValueDecl *declA, ValueDecl *declB) {
578578
return evaluateOrDefault(declA->getASTContext().evaluator,
579579
IsDeclSubstitutableRequest{ declA, declB },
580580
false);
@@ -616,10 +616,8 @@ bool DisjunctionStep::shouldSkip(const DisjunctionChoice &choice) const {
616616
auto *declA = LastSolvedChoice->first->getOverloadChoice().getDecl();
617617
auto *declB = static_cast<Constraint *>(choice)->getOverloadChoice().getDecl();
618618

619-
if (TypeChecker::compareDeclarations(CS.DC, declA, declB) == Comparison::Better) {
620-
if (isDeclSubstitutable(declA, /*by=*/declB))
621-
return skip("subtype");
622-
}
619+
if (TypeChecker::isDeclSubstitutable(declA, declB))
620+
return skip("subtype");
623621
}
624622

625623
// If the solver already found a solution with a choice that did not

lib/Sema/TypeChecker.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,11 @@ isUnsupportedMemberTypeAccess(Type type, TypeDecl *typeDecl);
903903
Comparison compareDeclarations(DeclContext *dc, ValueDecl *decl1,
904904
ValueDecl *decl2);
905905

906+
/// Checks whether the first decl is a refinement of the second
907+
/// decl, meaning that the second decl can always be used in place
908+
/// of the first one and the expression will still type check.
909+
bool isDeclSubstitutable(ValueDecl *declA, ValueDecl *declB);
910+
906911
/// Build a type-checked reference to the given value.
907912
Expr *buildCheckedRefExpr(VarDecl *D, DeclContext *UseDC, DeclNameLoc nameLoc,
908913
bool Implicit);

0 commit comments

Comments
 (0)