@@ -443,7 +443,7 @@ static void depthFirstSearch(
443
443
TypeVariableType *typeVar,
444
444
llvm::function_ref<bool (TypeVariableType *)> preVisitNode,
445
445
llvm::function_ref<bool(Constraint *)> visitConstraint,
446
- llvm::DenseSet <Constraint *> &visitedConstraints) {
446
+ llvm::SmallPtrSet <Constraint *, 8 > &visitedConstraints) {
447
447
// Visit this node. If we've already seen it, bail out.
448
448
if (!preVisitNode (typeVar))
449
449
return ;
@@ -500,10 +500,9 @@ namespace {
500
500
mutable llvm::SmallDenseMap<TypeVariableType *, TypeVariableType *>
501
501
representatives;
502
502
503
-
504
503
// / The complete set of constraints that were visited while computing
505
504
// / connected components.
506
- llvm::DenseSet <Constraint *> visitedConstraints;
505
+ llvm::SmallPtrSet <Constraint *, 8 > visitedConstraints;
507
506
508
507
public:
509
508
using Component = ConstraintGraph::Component;
@@ -542,7 +541,6 @@ namespace {
542
541
// Assign each type variable to its appropriate component.
543
542
SmallVector<Component, 1 > components;
544
543
llvm::SmallDenseMap<TypeVariableType *, unsigned > componentIdxMap;
545
- SmallPtrSet<Constraint *, 4 > knownConstraints;
546
544
for (auto typeVar : typeVars) {
547
545
// Find the representative. If we aren't creating a type variable
548
546
// for this component, skip it.
@@ -559,18 +557,24 @@ namespace {
559
557
components.push_back ({ });
560
558
}
561
559
562
- // Record this type variable as part of the component.
560
+ // Record this type variabgetConstraintsle as part of the component.
563
561
unsigned componentIdx = knownComponentIdx->second ;
564
562
auto &component = components[componentIdx];
565
563
component.typeVars .push_back (typeVar);
566
564
}
567
565
568
566
// 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 ();
571
575
auto rep = findRepresentative (typeVar);
572
576
assert (componentIdxMap.count (rep) > 0 );
573
- components[componentIdxMap[rep]].constraints .push_back (constraint);
577
+ components[componentIdxMap[rep]].constraints .push_back (& constraint);
574
578
}
575
579
576
580
return components;
0 commit comments