[CS] Avoid checking RHS of one-way constraint for reactivation

Previously we would only gather one-way constraints
if they were found through a type variable in their
right hand side. However we would incorrectly check
this against the type variable that we started the
search at. This meant that if the constraint was
found through a fixed binding, we would never
return it, and could therefore fail to re-activate
it, leaving it unsolved.

Fix this issue by simply removing the check for
the RHS, and letting the constraint system handle
it instead.

Resolves rdar://64890308.
This commit is contained in:
Hamish Knight
2020-07-02 13:16:56 -07:00
parent 1992579339
commit 23e797422a
2 changed files with 38 additions and 16 deletions

View File

@@ -442,24 +442,15 @@ llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherConstraints(
llvm::function_ref<bool(Constraint *)> acceptConstraintFn) {
llvm::TinyPtrVector<Constraint *> constraints;
// Whether we should consider this constraint at all.
auto rep = CS.getRepresentative(typeVar);
auto shouldConsiderConstraint = [&](Constraint *constraint) {
// For a one-way constraint, only consider it when the type variable
// is on the right-hand side of the the binding, and the left-hand side of
// the binding is one of the type variables currently under consideration.
// For a one-way constraint, only consider it when the left-hand side of
// the binding is one of the type variables currently under consideration,
// as only such constraints need solving for this component. Note that we
// don't perform any other filtering, as the constraint system should be
// responsible for checking any other conditions.
if (constraint->isOneWayConstraint()) {
auto lhsTypeVar =
constraint->getFirstType()->castTo<TypeVariableType>();
if (!CS.isActiveTypeVariable(lhsTypeVar))
return false;
SmallVector<TypeVariableType *, 2> rhsTypeVars;
constraint->getSecondType()->getTypeVariables(rhsTypeVars);
for (auto rhsTypeVar : rhsTypeVars) {
if (CS.getRepresentative(rhsTypeVar) == rep)
return true;
}
return false;
auto lhsTypeVar = constraint->getFirstType()->castTo<TypeVariableType>();
return CS.isActiveTypeVariable(lhsTypeVar);
}
return true;