@@ -244,7 +244,7 @@ static void findFavoredChoicesBasedOnArity(
244
244
245
245
// / Given a set of disjunctions, attempt to determine
246
246
// / favored choices in the current context.
247
- static Constraint * determineBestChoicesInContext (
247
+ static void determineBestChoicesInContext (
248
248
ConstraintSystem &cs, SmallVectorImpl<Constraint *> &disjunctions,
249
249
llvm::DenseMap<Constraint *,
250
250
std::pair<double , llvm::TinyPtrVector<Constraint *>>>
@@ -267,14 +267,14 @@ static Constraint *determineBestChoicesInContext(
267
267
268
268
auto argumentList = cs.getArgumentList (applicableFn.get ()->getLocator ());
269
269
if (!argumentList)
270
- return nullptr ;
270
+ return ;
271
271
272
272
for (const auto &argument : *argumentList) {
273
273
if (auto *expr = argument.getExpr ()) {
274
274
// Directly `<#...#>` or has one inside.
275
275
if (isa<CodeCompletionExpr>(expr) ||
276
276
cs.containsIDEInspectionTarget (expr))
277
- return nullptr ;
277
+ return ;
278
278
}
279
279
}
280
280
@@ -924,27 +924,14 @@ static Constraint *determineBestChoicesInContext(
924
924
}
925
925
926
926
if (bestOverallScore == 0 )
927
- return nullptr ;
927
+ return ;
928
928
929
929
for (auto &entry : disjunctionScores) {
930
930
TinyPtrVector<Constraint *> favoredChoices;
931
931
for (auto *choice : favoredChoicesPerDisjunction[entry.first ])
932
932
favoredChoices.push_back (choice);
933
933
favorings[entry.first ] = std::make_pair (entry.second , favoredChoices);
934
934
}
935
-
936
- Constraint *bestDisjunction = nullptr ;
937
- for (auto *disjunction : disjunctions) {
938
- if (disjunctionScores[disjunction] != bestOverallScore)
939
- continue ;
940
-
941
- if (!bestDisjunction)
942
- bestDisjunction = disjunction;
943
- else // Multiple disjunctions with the same score.
944
- return nullptr ;
945
- }
946
-
947
- return bestDisjunction;
948
935
}
949
936
950
937
// Attempt to find a disjunction of bind constraints where all options
@@ -1019,9 +1006,7 @@ ConstraintSystem::selectDisjunction() {
1019
1006
llvm::DenseMap<Constraint *,
1020
1007
std::pair</* bestScore=*/ double , llvm::TinyPtrVector<Constraint *>>>
1021
1008
favorings;
1022
- if (auto *bestDisjunction =
1023
- determineBestChoicesInContext (*this , disjunctions, favorings))
1024
- return std::make_pair (bestDisjunction, favorings[bestDisjunction].second );
1009
+ determineBestChoicesInContext (*this , disjunctions, favorings);
1025
1010
1026
1011
// Pick the disjunction with the smallest number of favored, then active
1027
1012
// choices.
@@ -1034,16 +1019,23 @@ ConstraintSystem::selectDisjunction() {
1034
1019
auto &[firstScore, firstFavoredChoices] = favorings[first];
1035
1020
auto &[secondScore, secondFavoredChoices] = favorings[second];
1036
1021
1022
+ bool isFirstSupported = isSupportedDisjunction (first);
1023
+ bool isSecondSupported = isSupportedDisjunction (second);
1024
+
1037
1025
// Rank based on scores only if both disjunctions are supported.
1038
- if (isSupportedDisjunction (first) && isSupportedDisjunction (second) ) {
1026
+ if (isFirstSupported && isSecondSupported ) {
1039
1027
// If both disjunctions have the same score they should be ranked
1040
1028
// based on number of favored/active choices.
1041
1029
if (firstScore != secondScore)
1042
1030
return firstScore > secondScore;
1043
1031
}
1044
1032
1045
- unsigned numFirstFavored = firstFavoredChoices.size ();
1046
- unsigned numSecondFavored = secondFavoredChoices.size ();
1033
+ unsigned numFirstFavored = isFirstSupported
1034
+ ? firstFavoredChoices.size ()
1035
+ : first->countFavoredNestedConstraints ();
1036
+ unsigned numSecondFavored =
1037
+ isSecondSupported ? secondFavoredChoices.size ()
1038
+ : second->countFavoredNestedConstraints ();
1047
1039
1048
1040
if (numFirstFavored == numSecondFavored) {
1049
1041
if (firstActive != secondActive)
0 commit comments