Skip to content

Commit 20bb077

Browse files
committed
[Constraint solver] Use tryOptimizeGenericDisjunction() during application.
Use tryOptimizeGenericDisjunction() as part of simplifying apply constraints.
1 parent d2c7c8d commit 20bb077

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4404,7 +4404,6 @@ ConstraintSystem::simplifyEscapableFunctionOfConstraint(
44044404
return SolutionKind::Unsolved;
44054405
};
44064406

4407-
44084407
type2 = getFixedTypeRecursive(type2, flags, /*wantRValue=*/true);
44094408
if (auto fn2 = type2->getAs<FunctionType>()) {
44104409
// Solve forward by binding the other type variable to the escapable
@@ -4903,6 +4902,34 @@ Type ConstraintSystem::simplifyAppliedOverloads(
49034902
break;
49044903
}
49054904

4905+
// Collect the active overload choices.
4906+
SmallVector<OverloadChoice, 4> choices;
4907+
for (auto constraint : disjunction->getNestedConstraints()) {
4908+
if (constraint->isDisabled())
4909+
continue;
4910+
choices.push_back(constraint->getOverloadChoice());
4911+
}
4912+
4913+
// If we can favor one generic result over another, do so.
4914+
if (auto favoredChoice = tryOptimizeGenericDisjunction(choices)) {
4915+
unsigned favoredIndex = favoredChoice - choices.data();
4916+
for (auto constraint : disjunction->getNestedConstraints()) {
4917+
if (constraint->isDisabled())
4918+
continue;
4919+
4920+
if (favoredIndex == 0) {
4921+
if (solverState)
4922+
solverState->favorConstraint(constraint);
4923+
else
4924+
constraint->setFavored();
4925+
4926+
break;
4927+
} else {
4928+
--favoredIndex;
4929+
}
4930+
}
4931+
}
4932+
49064933
// If there was a constraint that we couldn't reason about, don't use the
49074934
// results of any common-type computations.
49084935
if (hasUnhandledConstraints)

0 commit comments

Comments
 (0)