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

@@ -1317,6 +1317,15 @@ private:
disabledConstraints.erase(
disabledConstraints.begin() + scope->numDisabledConstraints,
disabledConstraints.end());
for (unsigned constraintIdx :
range(scope->numFavoredConstraints, favoredConstraints.size())) {
if (favoredConstraints[constraintIdx]->isFavored())
favoredConstraints[constraintIdx]->setFavored(false);
}
favoredConstraints.erase(
favoredConstraints.begin() + scope->numFavoredConstraints,
favoredConstraints.end());
}
/// Check whether constraint system is allowed to form solutions
@@ -1336,6 +1345,19 @@ private:
disabledConstraints.push_back(constraint);
}
unsigned getNumFavoredConstraints() const {
return favoredConstraints.size();
}
/// Favor the given constraint; this change will be rolled back
/// when we exit the current solver scope.
void favorConstraint(Constraint *constraint) {
if (!constraint->isFavored()) {
constraint->setFavored();
favoredConstraints.push_back(constraint);
}
}
private:
/// The list of constraints that have been retired along the
/// current path, this list is used in LIFO fashion when constraints
@@ -1358,6 +1380,7 @@ private:
std::tuple<SolverScope *, ConstraintList::iterator, unsigned>, 4> scopes;
SmallVector<Constraint *, 4> disabledConstraints;
SmallVector<Constraint *, 4> favoredConstraints;
};
class CacheExprTypes : public ASTWalker {
@@ -1518,6 +1541,8 @@ public:
unsigned numDisabledConstraints;
unsigned numFavoredConstraints;
/// The previous score.
Score PreviousScore;
@@ -3122,12 +3147,14 @@ private:
bool restoreOnFail,
llvm::function_ref<bool(Constraint *)> pred);
public:
// Given a type variable, attempt to find the disjunction of
// bind overloads associated with it. This may return null in cases where
// the disjunction has either not been created or binds the type variable
// in some manner other than by binding overloads.
Constraint *getUnboundBindOverloadDisjunction(TypeVariableType *tyvar);
private:
/// Given a type variable that might represent an overload set, retrieve
///
/// \returns the set of overload choices to which this type variable
@@ -3160,6 +3187,11 @@ private:
Constraint *selectApplyDisjunction();
/// Look at the set of overload choices to determine if there is a best
/// generic overload to favor.
OverloadChoice *tryOptimizeGenericDisjunction(
ArrayRef<OverloadChoice> choices);
/// Solve the system of constraints generated from provided expression.
///
/// \param expr The expression to generate constraints from.
@@ -3751,7 +3783,7 @@ private:
/// easy to work with disjunction and encapsulates
/// some other important information such as locator.
class DisjunctionChoiceProducer : public BindingProducer<DisjunctionChoice> {
// The disjunciton choices that this producer will iterate through.
// The disjunction choices that this producer will iterate through.
ArrayRef<Constraint *> Choices;
// The ordering of disjunction choices. We index into Choices