mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #23088 from DougGregor/solver-disjunction-favoring
[Constraint solver] Generalize disjunction favoring
This commit is contained in:
@@ -4538,7 +4538,6 @@ ConstraintSystem::simplifyEscapableFunctionOfConstraint(
|
||||
return SolutionKind::Unsolved;
|
||||
};
|
||||
|
||||
|
||||
type2 = getFixedTypeRecursive(type2, flags, /*wantRValue=*/true);
|
||||
if (auto fn2 = type2->getAs<FunctionType>()) {
|
||||
// Solve forward by binding the other type variable to the escapable
|
||||
@@ -5037,6 +5036,33 @@ retry_after_fail:
|
||||
break;
|
||||
}
|
||||
|
||||
// Collect the active overload choices.
|
||||
SmallVector<OverloadChoice, 4> choices;
|
||||
for (auto constraint : disjunction->getNestedConstraints()) {
|
||||
if (constraint->isDisabled())
|
||||
continue;
|
||||
choices.push_back(constraint->getOverloadChoice());
|
||||
}
|
||||
|
||||
// If we can favor one generic result over another, do so.
|
||||
if (auto favoredChoice = tryOptimizeGenericDisjunction(choices)) {
|
||||
unsigned favoredIndex = favoredChoice - choices.data();
|
||||
for (auto constraint : disjunction->getNestedConstraints()) {
|
||||
if (constraint->isDisabled())
|
||||
continue;
|
||||
|
||||
if (favoredIndex == 0) {
|
||||
if (solverState)
|
||||
solverState->favorConstraint(constraint);
|
||||
else
|
||||
constraint->setFavored();
|
||||
|
||||
break;
|
||||
} else {
|
||||
--favoredIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there was a constraint that we couldn't reason about, don't use the
|
||||
// results of any common-type computations.
|
||||
|
||||
Reference in New Issue
Block a user