@@ -378,19 +378,37 @@ llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherConstraints(
378
378
llvm::function_ref<bool (Constraint *)> acceptConstraintFn) {
379
379
llvm::TinyPtrVector<Constraint *> constraints;
380
380
381
+ // Local function to test whether the given type variable is in the current
382
+ // interest set for the solver.
383
+ SmallPtrSet<TypeVariableType *, 4 > interestingTypeVars;
384
+ auto isInterestingTypeVar = [&](TypeVariableType *typeVar) {
385
+ if (interestingTypeVars.empty ()) {
386
+ interestingTypeVars.insert (CS.TypeVariables .begin (),
387
+ CS.TypeVariables .end ());
388
+ }
389
+
390
+ return interestingTypeVars.count (typeVar) > 0 ;
391
+ };
392
+
381
393
// Whether we should consider this constraint at all.
382
- auto &reprNode = (*this )[CS.getRepresentative (typeVar)];
383
- auto equivClass = reprNode.getEquivalenceClass ();
394
+ auto rep = CS.getRepresentative (typeVar);
384
395
auto shouldConsiderConstraint = [&](Constraint *constraint) {
385
396
// For a one-way constraint, only consider it when the type variable
386
- // is on the left -hand side of the the binding. Otherwise, it is not
387
- // relevant .
397
+ // is on the right -hand side of the the binding, and the left-hand side of
398
+ // the binding is one of the type variables currently under consideration .
388
399
if (constraint->getKind () == ConstraintKind::OneWayBind) {
389
400
auto lhsTypeVar =
390
401
constraint->getFirstType ()->castTo <TypeVariableType>();
391
- if (std::find (equivClass.begin (), equivClass.end (), lhsTypeVar)
392
- == equivClass.end ())
402
+ if (!isInterestingTypeVar (lhsTypeVar))
393
403
return false ;
404
+
405
+ SmallVector<TypeVariableType *, 2 > rhsTypeVars;
406
+ constraint->getSecondType ()->getTypeVariables (rhsTypeVars);
407
+ for (auto rhsTypeVar : rhsTypeVars) {
408
+ if (CS.getRepresentative (rhsTypeVar) == rep)
409
+ return true ;
410
+ }
411
+ return false ;
394
412
}
395
413
396
414
return true ;
@@ -421,6 +439,8 @@ llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherConstraints(
421
439
}
422
440
};
423
441
442
+ auto &reprNode = (*this )[CS.getRepresentative (typeVar)];
443
+ auto equivClass = reprNode.getEquivalenceClass ();
424
444
for (auto typeVar : equivClass) {
425
445
auto &node = (*this )[typeVar];
426
446
for (auto constraint : node.getConstraints ()) {
0 commit comments