[ConstraintGraph] Use set to gather constraints for type variables

Since it's possible to find the same constraint through two different
but equivalent type variables, let's use a set to store constraints
instead of a vector to avoid processing the same constraint multiple
times.
This commit is contained in:
Pavel Yaskevich
2018-07-26 20:35:42 -07:00
parent ae6645d808
commit dd798accd8
9 changed files with 15 additions and 22 deletions

View File

@@ -467,9 +467,8 @@ void ConstraintGraph::unbindTypeVariable(TypeVariableType *typeVar, Type fixed){
}
void ConstraintGraph::gatherConstraints(
TypeVariableType *typeVar,
SmallVectorImpl<Constraint *> &constraints,
GatheringKind kind) {
TypeVariableType *typeVar, SmallPtrSetImpl<Constraint *> &constraints,
GatheringKind kind) {
auto &reprNode = (*this)[CS.getRepresentative(typeVar)];
auto equivClass = reprNode.getEquivalenceClass();
llvm::SmallPtrSet<TypeVariableType *, 4> typeVars;
@@ -478,7 +477,7 @@ void ConstraintGraph::gatherConstraints(
continue;
for (auto constraint : (*this)[typeVar].getConstraints())
constraints.push_back(constraint);
constraints.insert(constraint);
auto &node = (*this)[typeVar];
@@ -511,7 +510,7 @@ void ConstraintGraph::gatherConstraints(
continue;
for (auto constraint : (*this)[adjTypeVarEquiv].getConstraints())
constraints.push_back(constraint);
constraints.insert(constraint);
}
}
}