[Constraint solver] Tie together all of the type variables in a key path.

This is a workaround for rdar://problem/54322807 that should limit the
expansion in the number of constraint scopes visited.
This commit is contained in:
Doug Gregor
2019-08-20 11:11:07 -07:00
parent bebc27fb06
commit 562ed4d999
6 changed files with 78 additions and 27 deletions

View File

@@ -5672,11 +5672,13 @@ ConstraintSystem::simplifyOpenedExistentialOfConstraint(
}
ConstraintSystem::SolutionKind
ConstraintSystem::simplifyKeyPathConstraint(Type keyPathTy,
Type rootTy,
Type valueTy,
TypeMatchOptions flags,
ConstraintLocatorBuilder locator) {
ConstraintSystem::simplifyKeyPathConstraint(
Type keyPathTy,
Type rootTy,
Type valueTy,
ArrayRef<TypeVariableType *> componentTypeVars,
TypeMatchOptions flags,
ConstraintLocatorBuilder locator) {
auto subflags = getDefaultDecompositionOptions(flags);
// The constraint ought to have been anchored on a KeyPathExpr.
auto keyPath = cast<KeyPathExpr>(locator.getBaseLocator()->getAnchor());
@@ -5898,7 +5900,8 @@ done:
} else {
addUnsolvedConstraint(Constraint::create(*this, ConstraintKind::KeyPath,
keyPathTy, rootTy, valueTy,
locator.getBaseLocator()));
locator.getBaseLocator(),
componentTypeVars));
}
return SolutionKind::Solved;
}
@@ -7413,18 +7416,22 @@ ConstraintSystem::addKeyPathApplicationConstraint(Type keypath,
}
void
ConstraintSystem::addKeyPathConstraint(Type keypath,
Type root, Type value,
ConstraintLocatorBuilder locator,
bool isFavored) {
ConstraintSystem::addKeyPathConstraint(
Type keypath,
Type root, Type value,
ArrayRef<TypeVariableType *> componentTypeVars,
ConstraintLocatorBuilder locator,
bool isFavored) {
switch (simplifyKeyPathConstraint(keypath, root, value,
componentTypeVars,
TMF_GenerateConstraints,
locator)) {
case SolutionKind::Error:
if (shouldAddNewFailingConstraint()) {
auto c = Constraint::create(*this, ConstraintKind::KeyPath,
keypath, root, value,
getConstraintLocator(locator));
getConstraintLocator(locator),
componentTypeVars);
if (isFavored) c->setFavored();
addNewFailingConstraint(c);
}
@@ -7605,7 +7612,7 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
case ConstraintKind::KeyPath:
return simplifyKeyPathConstraint(
constraint.getFirstType(), constraint.getSecondType(),
constraint.getThirdType(),
constraint.getThirdType(), constraint.getTypeVariables(),
None, constraint.getLocator());
case ConstraintKind::KeyPathApplication: