Skip to content

Commit 8818d39

Browse files
committed
[CSOptimizer] Rank disjunctions based on score only if both sides are supported
1 parent 3996b25 commit 8818d39

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/Sema/CSOptimizer.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,16 +677,16 @@ static Constraint *determineBestChoicesInContext(
677677
getLogger() << ")\n";
678678
}
679679

680+
if (bestOverallScore == 0)
681+
return nullptr;
682+
680683
for (auto &entry : disjunctionScores) {
681684
TinyPtrVector<Constraint *> favoredChoices;
682685
for (auto *choice : favoredChoicesPerDisjunction[entry.first])
683686
favoredChoices.push_back(choice);
684687
favorings[entry.first] = std::make_pair(entry.second, favoredChoices);
685688
}
686689

687-
if (bestOverallScore == 0)
688-
return nullptr;
689-
690690
Constraint *bestDisjunction = nullptr;
691691
for (auto *disjunction : disjunctions) {
692692
if (disjunctionScores[disjunction] != bestOverallScore)
@@ -788,8 +788,13 @@ ConstraintSystem::selectDisjunction() {
788788
auto &[firstScore, firstFavoredChoices] = favorings[first];
789789
auto &[secondScore, secondFavoredChoices] = favorings[second];
790790

791-
if (firstScore > secondScore)
792-
return true;
791+
// Rank based on scores only if both disjunctions are supported.
792+
if (isSupportedDisjunction(first) && isSupportedDisjunction(second)) {
793+
// If both disjunctions have the same score they should be ranked
794+
// based on number of favored/active choices.
795+
if (firstScore != secondScore)
796+
return firstScore > secondScore;
797+
}
793798

794799
unsigned numFirstFavored = firstFavoredChoices.size();
795800
unsigned numSecondFavored = secondFavoredChoices.size();

0 commit comments

Comments
 (0)