[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

@@ -5051,15 +5051,17 @@ ConstraintSystem::addKeyPathApplicationRootConstraint(Type root, ConstraintLocat
return;
SmallPtrSet<Constraint *, 4> constraints;
CG.gatherConstraints(typeVar, constraints,
ConstraintGraph::GatheringKind::EquivalenceClass);
CG.gatherConstraints(
typeVar, constraints, ConstraintGraph::GatheringKind::EquivalenceClass,
[&keyPathExpr](Constraint *constraint) -> bool {
return constraint->getKind() == ConstraintKind::KeyPath &&
constraint->getLocator()->getAnchor() == keyPathExpr;
});
for (auto constraint : constraints) {
if (constraint->getKind() == ConstraintKind::KeyPath &&
constraint->getLocator()->getAnchor() == keyPathExpr) {
auto keyPathRootTy = constraint->getSecondType();
addConstraint(ConstraintKind::Subtype, root->getWithoutSpecifierType(), keyPathRootTy, locator);
}
auto keyPathRootTy = constraint->getSecondType();
addConstraint(ConstraintKind::Subtype, root->getWithoutSpecifierType(),
keyPathRootTy, locator);
}
}