Skip to content

Commit 39f5599

Browse files
committed
---
yaml --- r: 315101 b: refs/heads/master-next c: 9ab22cf h: refs/heads/master i: 315099: 50c7387
1 parent 8f85255 commit 39f5599

File tree

2 files changed

+37
-68
lines changed

2 files changed

+37
-68
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3fe9333052029c114ef816ea805c335eb1ee8a99
3-
refs/heads/master-next: bf3a786227b510dfb2b9c2b9e437714c40652acf
3+
refs/heads/master-next: 9ab22cf8aee58c874c87f415c489575d2326dbd7
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/lib/Sema/CSSimplify.cpp

Lines changed: 36 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5533,90 +5533,61 @@ ConstraintSystem::simplifyKeyPathConstraint(Type keyPathTy,
55335533
bool definitelyFunctionType = false;
55345534
bool definitelyKeyPathType = false;
55355535

5536-
auto tryMatchRootAndValueFromKeyPathType =
5537-
[&](BoundGenericType *bgt, bool allowPartial) -> SolutionKind {
5538-
Type boundRoot, boundValue;
5536+
auto tryMatchRootAndValueFromType = [&](Type type,
5537+
bool allowPartial = true) -> bool {
5538+
Type boundRoot = Type(), boundValue = Type();
55395539

5540+
if (auto bgt = type->getAs<BoundGenericType>()) {
55405541
definitelyKeyPathType = true;
55415542

55425543
// We can get root and value from a concrete key path type.
5543-
if (bgt->getDecl() == getASTContext().getKeyPathDecl()
5544-
|| bgt->getDecl() == getASTContext().getWritableKeyPathDecl()
5545-
|| bgt->getDecl() == getASTContext().getReferenceWritableKeyPathDecl()) {
5544+
if (bgt->getDecl() == getASTContext().getKeyPathDecl() ||
5545+
bgt->getDecl() == getASTContext().getWritableKeyPathDecl() ||
5546+
bgt->getDecl() == getASTContext().getReferenceWritableKeyPathDecl()) {
55465547
boundRoot = bgt->getGenericArgs()[0];
55475548
boundValue = bgt->getGenericArgs()[1];
55485549
} else if (bgt->getDecl() == getASTContext().getPartialKeyPathDecl()) {
5549-
if (allowPartial) {
5550-
// We can still get the root from a PartialKeyPath.
5551-
boundRoot = bgt->getGenericArgs()[0];
5552-
boundValue = Type();
5553-
} else {
5554-
return SolutionKind::Error;
5555-
}
5556-
} else {
5557-
// We can't bind anything from this type.
5558-
return SolutionKind::Solved;
5550+
if (!allowPartial)
5551+
return false;
5552+
5553+
// We can still get the root from a PartialKeyPath.
5554+
boundRoot = bgt->getGenericArgs()[0];
55595555
}
5560-
if (matchTypes(boundRoot, rootTy,
5561-
ConstraintKind::Bind, subflags, locator).isFailure())
5562-
return SolutionKind::Error;
5556+
}
55635557

5564-
if (boundValue
5565-
&& matchTypes(boundValue, valueTy,
5566-
ConstraintKind::Bind, subflags, locator).isFailure())
5567-
return SolutionKind::Error;
5568-
5569-
return SolutionKind::Solved;
5570-
};
5558+
if (auto fnTy = type->getAs<FunctionType>()) {
5559+
definitelyFunctionType = true;
55715560

5572-
auto tryMatchRootAndValueFromFunctionType =
5573-
[&](FunctionType *fnTy) -> SolutionKind {
5574-
if (fnTy->getParams().size() != 1)
5575-
return SolutionKind::Error;
5561+
if (fnTy->getParams().size() != 1)
5562+
return false;
55765563

5577-
Type boundRoot = fnTy->getParams()[0].getPlainType();
5578-
Type boundValue = fnTy->getResult();
5564+
boundRoot = fnTy->getParams()[0].getPlainType();
5565+
boundValue = fnTy->getResult();
5566+
}
55795567

5580-
if (matchTypes(boundRoot, rootTy, ConstraintKind::Bind, subflags, locator)
5568+
if (boundRoot &&
5569+
matchTypes(boundRoot, rootTy, ConstraintKind::Bind, subflags, locator)
55815570
.isFailure())
5582-
return SolutionKind::Error;
5571+
return false;
55835572

5584-
if (matchTypes(boundValue, valueTy, ConstraintKind::Bind, subflags, locator)
5573+
if (boundValue &&
5574+
matchTypes(boundValue, valueTy, ConstraintKind::Bind, subflags, locator)
55855575
.isFailure())
5586-
return SolutionKind::Error;
5576+
return false;
55875577

5588-
definitelyFunctionType = true;
5589-
return SolutionKind::Solved;
5578+
return true;
55905579
};
55915580

55925581
// If we're fixed to a bound generic type, trying harvesting context from it.
55935582
// However, we don't want a solution that fixes the expression type to
55945583
// PartialKeyPath; we'd rather that be represented using an upcast conversion.
5595-
auto keyPathBGT = keyPathTy->getAs<BoundGenericType>();
5596-
if (keyPathBGT) {
5597-
if (tryMatchRootAndValueFromKeyPathType(keyPathBGT, /*allowPartial*/false)
5598-
== SolutionKind::Error)
5599-
return SolutionKind::Error;
5600-
}
5601-
// If we're bound to a (Root) -> Value function type, use that for context.
5602-
if (auto fnTy = keyPathTy->getAs<FunctionType>()) {
5603-
if (tryMatchRootAndValueFromFunctionType(fnTy) == SolutionKind::Error)
5604-
return SolutionKind::Error;
5605-
}
5584+
if (!tryMatchRootAndValueFromType(keyPathTy, /*allowPartial=*/false))
5585+
return SolutionKind::Error;
56065586

56075587
// If the expression has contextual type information, try using that too.
56085588
if (auto contextualTy = getContextualType(keyPath)) {
5609-
if (auto contextualBGT = contextualTy->getAs<BoundGenericType>()) {
5610-
if (tryMatchRootAndValueFromKeyPathType(contextualBGT,
5611-
/*allowPartial*/true)
5612-
== SolutionKind::Error)
5613-
return SolutionKind::Error;
5614-
}
5615-
if (auto contextualBGT = contextualTy->getAs<FunctionType>()) {
5616-
if (tryMatchRootAndValueFromFunctionType(contextualBGT) ==
5617-
SolutionKind::Error)
5618-
return SolutionKind::Error;
5619-
}
5589+
if (!tryMatchRootAndValueFromType(contextualTy))
5590+
return SolutionKind::Error;
56205591
}
56215592

56225593
// If we have nothing else, and there's another constraint on our keyPathTy
@@ -5628,11 +5599,9 @@ ConstraintSystem::simplifyKeyPathConstraint(Type keyPathTy,
56285599
continue;
56295600
if (constraint.getFirstType().getPointer() == keyPathTy.getPointer()) {
56305601
auto otherType = constraint.getSecondType();
5631-
if (auto otherFT = otherType->getAs<FunctionType>()) {
5632-
if (tryMatchRootAndValueFromFunctionType(otherFT) ==
5633-
SolutionKind::Error)
5634-
return SolutionKind::Error;
5635-
}
5602+
if (otherType->is<FunctionType>() &&
5603+
!tryMatchRootAndValueFromType(otherType))
5604+
return SolutionKind::Error;
56365605
}
56375606
}
56385607
}
@@ -5756,15 +5725,15 @@ ConstraintSystem::simplifyKeyPathConstraint(Type keyPathTy,
57565725

57575726
// FIXME: Allow the type to be upcast if the type system has a concrete
57585727
// KeyPath type assigned to the expression already.
5759-
if (keyPathBGT) {
5728+
if (auto keyPathBGT = keyPathTy->getAs<BoundGenericType>()) {
57605729
if (keyPathBGT->getDecl() == getASTContext().getKeyPathDecl())
57615730
kpDecl = getASTContext().getKeyPathDecl();
57625731
else if (keyPathBGT->getDecl() ==
57635732
getASTContext().getWritableKeyPathDecl() &&
57645733
capability >= Writable)
57655734
kpDecl = getASTContext().getWritableKeyPathDecl();
57665735
}
5767-
5736+
57685737
auto loc = locator.getBaseLocator();
57695738
if (definitelyFunctionType) {
57705739
Type fnType =

0 commit comments

Comments
 (0)