mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user