[ConstraintGraph] Add filtering to gatherConstraints per type variable

Most of the use-cases of `gatherConstraints` require filtering
at least based on the constraint kind that caller is interested in,
so instead of returning unrelated results and asking caller to
filter separately, let's add that functionality directly to
`gatherConstraints`.
This commit is contained in:
Pavel Yaskevich
2018-07-26 22:18:05 -07:00
parent dd798accd8
commit 48dd1e837b
7 changed files with 88 additions and 79 deletions

View File

@@ -213,17 +213,16 @@ void ConstraintSystem::setMustBeMaterializableRecursive(Type type)
void ConstraintSystem::addTypeVariableConstraintsToWorkList(
TypeVariableType *typeVar) {
// Gather the constraints affected by a change to this type variable.
SmallPtrSet<Constraint *, 8> constraints;
CG.gatherConstraints(typeVar, constraints,
ConstraintGraph::GatheringKind::AllMentions);
SmallPtrSet<Constraint *, 8> inactiveConstraints;
CG.gatherConstraints(
typeVar, inactiveConstraints, ConstraintGraph::GatheringKind::AllMentions,
[](Constraint *constraint) { return !constraint->isActive(); });
// Add any constraints that aren't already active to the worklist.
for (auto constraint : constraints) {
if (!constraint->isActive()) {
ActiveConstraints.splice(ActiveConstraints.end(),
InactiveConstraints, constraint);
constraint->setActive(true);
}
for (auto constraint : inactiveConstraints) {
ActiveConstraints.splice(ActiveConstraints.end(), InactiveConstraints,
constraint);
constraint->setActive(true);
}
}