[Constraint graph] Handle orphaned constraints within connected components

Move the logic for creating connected components of orphaned
constraints into the connected-components algorithm code, rather than
making it a special part of SplitterStep.
This commit is contained in:
Doug Gregor
2019-08-07 15:34:21 -07:00
parent 5a4af23a63
commit ab38be128d
4 changed files with 32 additions and 35 deletions

View File

@@ -540,6 +540,8 @@ namespace {
// Assign each type variable to its appropriate component.
SmallVector<Component, 1> components;
components.reserve(
validComponents.size() + cg.getOrphanedConstraints().size());
llvm::SmallDenseMap<TypeVariableType *, unsigned> componentIdxMap;
for (auto typeVar : typeVars) {
// Find the representative. If we aren't creating a type variable
@@ -577,6 +579,12 @@ namespace {
components[componentIdxMap[rep]].constraints.push_back(&constraint);
}
// Gather orphaned constraints; each gets its own component.
for (auto orphaned : cg.getOrphanedConstraints()) {
components.push_back({ });
components.back().constraints.push_back(orphaned);
}
return components;
}
@@ -635,7 +643,6 @@ ConstraintGraph::computeConnectedComponents(
// Perform connected components via a union-find algorithm on all of the
// constraints adjacent to these type variables.
ConnectedComponents cc(*this, typeVars);
return cc.getComponents();
}