[ConstraintSolver] Prioritize certain type variables while looking for bindings

Presence of some constraints (Subtype at least) requires a certain
contextual ranking of the type variables associated with them when
it comes to picking bindings, otherwise it might lead to no or
invalid solutions, because only a set of the bindings for the best
type variable is attempted.

Resolves: rdar://problem/22898292
This commit is contained in:
Pavel Yaskevich
2017-09-29 22:33:26 -07:00
parent 7b8175082d
commit 001b09747a
4 changed files with 62 additions and 7 deletions

View File

@@ -1695,13 +1695,14 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
}
// If we have a binding for the right-hand side
// (argument type) don't try to bind it to the left-hand
// side (parameter type) directly, because their
// relationship is contravariant and the actual
// binding can only come from the left-hand side.
// (argument type used in the body) don't try
// to bind it to the left-hand side (parameter type)
// directly, because there could be an implicit
// conversion between them, and actual binding
// can only come from the left-hand side.
addUnsolvedConstraint(
Constraint::create(*this, ConstraintKind::ArgumentConversion, type2,
typeVar1, getConstraintLocator(locator)));
Constraint::create(*this, ConstraintKind::Equal, typeVar1, type2,
getConstraintLocator(locator)));
return SolutionKind::Solved;
}