Skip to content

Commit e12fe97

Browse files
committed
[CSSolver] Try to Optimize generic disjunction if there are 2 enabled choices
1 parent ded44b4 commit e12fe97

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,15 +2027,26 @@ static Constraint *tryOptimizeGenericDisjunction(
20272027
TypeChecker &tc,
20282028
DeclContext *dc,
20292029
ArrayRef<Constraint *> constraints) {
2030-
if (constraints.size() != 2 ||
2031-
constraints[0]->getKind() != ConstraintKind::BindOverload ||
2032-
constraints[1]->getKind() != ConstraintKind::BindOverload ||
2033-
constraints[0]->isFavored() ||
2034-
constraints[1]->isFavored())
2030+
llvm::SmallVector<Constraint *, 4> choices;
2031+
for (auto *choice : constraints) {
2032+
if (choices.size() > 2)
2033+
return nullptr;
2034+
2035+
if (!choice->isDisabled())
2036+
choices.push_back(choice);
2037+
}
2038+
2039+
if (choices.size() != 2)
2040+
return nullptr;
2041+
2042+
if (choices[0]->getKind() != ConstraintKind::BindOverload ||
2043+
choices[1]->getKind() != ConstraintKind::BindOverload ||
2044+
choices[0]->isFavored() ||
2045+
choices[1]->isFavored())
20352046
return nullptr;
20362047

2037-
OverloadChoice choiceA = constraints[0]->getOverloadChoice();
2038-
OverloadChoice choiceB = constraints[1]->getOverloadChoice();
2048+
OverloadChoice choiceA = choices[0]->getOverloadChoice();
2049+
OverloadChoice choiceB = choices[1]->getOverloadChoice();
20392050

20402051
if (!choiceA.isDecl() || !choiceB.isDecl())
20412052
return nullptr;
@@ -2072,10 +2083,10 @@ static Constraint *tryOptimizeGenericDisjunction(
20722083

20732084
switch (tc.compareDeclarations(dc, declA, declB)) {
20742085
case Comparison::Better:
2075-
return constraints[0];
2086+
return choices[0];
20762087

20772088
case Comparison::Worse:
2078-
return constraints[1];
2089+
return choices[1];
20792090

20802091
case Comparison::Unordered:
20812092
return nullptr;

0 commit comments

Comments
 (0)