Skip to content

Commit 0ae3b30

Browse files
committed
[Constraint graph] Maintain constraint order when splitting components.
Maintain the order of constraints when splitting the system into connected components, to match the behavior prior to the refactoring into a separate connected-components algorithm. (cherry picked from commit 5a4af23)
1 parent 1c5cba4 commit 0ae3b30

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lib/Sema/ConstraintGraph.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ static void depthFirstSearch(
443443
TypeVariableType *typeVar,
444444
llvm::function_ref<bool(TypeVariableType *)> preVisitNode,
445445
llvm::function_ref<bool(Constraint *)> visitConstraint,
446-
llvm::DenseSet<Constraint *> &visitedConstraints) {
446+
llvm::SmallPtrSet<Constraint *, 8> &visitedConstraints) {
447447
// Visit this node. If we've already seen it, bail out.
448448
if (!preVisitNode(typeVar))
449449
return;
@@ -500,10 +500,9 @@ namespace {
500500
mutable llvm::SmallDenseMap<TypeVariableType *, TypeVariableType *>
501501
representatives;
502502

503-
504503
/// The complete set of constraints that were visited while computing
505504
/// connected components.
506-
llvm::DenseSet<Constraint *> visitedConstraints;
505+
llvm::SmallPtrSet<Constraint *, 8> visitedConstraints;
507506

508507
public:
509508
using Component = ConstraintGraph::Component;
@@ -542,7 +541,6 @@ namespace {
542541
// Assign each type variable to its appropriate component.
543542
SmallVector<Component, 1> components;
544543
llvm::SmallDenseMap<TypeVariableType *, unsigned> componentIdxMap;
545-
SmallPtrSet<Constraint *, 4> knownConstraints;
546544
for (auto typeVar : typeVars) {
547545
// Find the representative. If we aren't creating a type variable
548546
// for this component, skip it.
@@ -559,18 +557,24 @@ namespace {
559557
components.push_back({ });
560558
}
561559

562-
// Record this type variable as part of the component.
560+
// Record this type variabgetConstraintsle as part of the component.
563561
unsigned componentIdx = knownComponentIdx->second;
564562
auto &component = components[componentIdx];
565563
component.typeVars.push_back(typeVar);
566564
}
567565

568566
// Assign each constraint to its appropriate component.
569-
for (auto constraint : visitedConstraints) {
570-
auto typeVar = constraint->getTypeVariables().front();
567+
// Note: we use the inactive constraints so that we maintain the
568+
// order of constraints when we re-introduce them.
569+
for (auto &constraint : cs.getConstraints()) {
570+
auto constraintTypeVars = constraint.getTypeVariables();
571+
if (constraintTypeVars.empty())
572+
continue;
573+
574+
auto typeVar = constraintTypeVars.front();
571575
auto rep = findRepresentative(typeVar);
572576
assert(componentIdxMap.count(rep) > 0);
573-
components[componentIdxMap[rep]].constraints.push_back(constraint);
577+
components[componentIdxMap[rep]].constraints.push_back(&constraint);
574578
}
575579

576580
return components;

0 commit comments

Comments
 (0)