Merge pull request #23088 from DougGregor/solver-disjunction-favoring

[Constraint solver] Generalize disjunction favoring
This commit is contained in:
Doug Gregor
2019-03-05 14:41:56 -08:00
committed by GitHub
7 changed files with 157 additions and 163 deletions

View File

@@ -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.