Skip to content

Commit cf05405

Browse files
committed
[CSOptimizer] Let determineBestChoicesInContext return the best disjunction if one is available
If there is one overall best disjunction, let's attempt it first.
1 parent 527de22 commit cf05405

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

lib/Sema/CSOptimizer.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static bool isOverloadedDeclRef(Constraint *disjunction) {
100100

101101
/// Given a set of disjunctions, attempt to determine
102102
/// favored choices in the current context.
103-
static void determineBestChoicesInContext(
103+
static Constraint *determineBestChoicesInContext(
104104
ConstraintSystem &cs, SmallVectorImpl<Constraint *> &disjunctions,
105105
llvm::DenseMap<Constraint *, llvm::TinyPtrVector<Constraint *>>
106106
&favorings) {
@@ -122,7 +122,7 @@ static void determineBestChoicesInContext(
122122

123123
auto argumentList = cs.getArgumentList(applicableFn.get()->getLocator());
124124
if (!argumentList || cs.containsIDEInspectionTarget(argumentList))
125-
return;
125+
return nullptr;
126126

127127
SmallVector<FunctionType::Param, 8> argsWithLabels;
128128
{
@@ -623,6 +623,22 @@ static void determineBestChoicesInContext(
623623
for (auto *choice : favoredChoicesPerDisjunction[entry.first])
624624
favorings[entry.first].push_back(choice);
625625
}
626+
627+
if (bestOverallScore == 0)
628+
return nullptr;
629+
630+
Constraint *bestDisjunction = nullptr;
631+
for (auto *disjunction : disjunctions) {
632+
if (disjunctionScores[disjunction] != bestOverallScore)
633+
continue;
634+
635+
if (!bestDisjunction)
636+
bestDisjunction = disjunction;
637+
else // Multiple disjunctions with the same score.
638+
return nullptr;
639+
}
640+
641+
return bestDisjunction;
626642
}
627643

628644
// Attempt to find a disjunction of bind constraints where all options
@@ -695,7 +711,9 @@ ConstraintSystem::selectDisjunction() {
695711
return std::make_pair(disjunction, llvm::TinyPtrVector<Constraint *>());
696712

697713
llvm::DenseMap<Constraint *, llvm::TinyPtrVector<Constraint *>> favorings;
698-
determineBestChoicesInContext(*this, disjunctions, favorings);
714+
if (auto *bestDisjunction =
715+
determineBestChoicesInContext(*this, disjunctions, favorings))
716+
return std::make_pair(bestDisjunction, favorings[bestDisjunction]);
699717

700718
// Pick the disjunction with the smallest number of favored, then active
701719
// choices.

0 commit comments

Comments
 (0)