Skip to content

Commit 72d87b5

Browse files
committed
[ConstraintSystem] Add a locator path element for the pattern of a pack expansion.
1 parent 9eccfbd commit 72d87b5

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

include/swift/Sema/ConstraintLocatorPathElts.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ CUSTOM_LOCATOR_PATH_ELT(PackElement)
198198
/// The shape of a parameter pack.
199199
SIMPLE_LOCATOR_PATH_ELT(PackShape)
200200

201+
/// The pattern of a pack expansion.
202+
SIMPLE_LOCATOR_PATH_ELT(PackExpansionPattern)
203+
201204
/// An unresolved member.
202205
SIMPLE_LOCATOR_PATH_ELT(UnresolvedMember)
203206

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,10 +2918,12 @@ namespace {
29182918
CS.setType(binding, type);
29192919
}
29202920

2921-
auto elementResultType = CS.getType(expr->getPatternExpr());
2922-
auto patternTy = CS.createTypeVariable(CS.getConstraintLocator(expr),
2921+
auto *patternLoc =
2922+
CS.getConstraintLocator(expr, ConstraintLocator::PackExpansionPattern);
2923+
auto patternTy = CS.createTypeVariable(patternLoc,
29232924
TVO_CanBindToPack |
29242925
TVO_CanBindToHole);
2926+
auto elementResultType = CS.getType(expr->getPatternExpr());
29252927
CS.addConstraint(ConstraintKind::PackElementOf, elementResultType,
29262928
patternTy, CS.getConstraintLocator(expr));
29272929

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7559,9 +7559,10 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifySubclassOfConstraint(
75597559
for (unsigned i = 0, e = packType->getNumElements(); i < e; ++i) {
75607560
auto eltType = packType->getElementType(i);
75617561
if (auto *packExpansionType = eltType->getAs<PackExpansionType>()) {
7562-
// FIXME: Locator element for pack expansion pattern
7562+
auto patternLoc =
7563+
locator.withPathElement(ConstraintLocator::PackExpansionPattern);
75637564
addConstraint(ConstraintKind::SubclassOf, packExpansionType->getPatternType(),
7564-
classType, locator.withPathElement(LocatorPathElt::PackElement(i)));
7565+
classType, patternLoc);
75657566
} else {
75667567
addConstraint(ConstraintKind::SubclassOf, eltType,
75677568
classType, locator.withPathElement(LocatorPathElt::PackElement(i)));
@@ -7677,11 +7678,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
76777678
for (unsigned i = 0, e = packType->getNumElements(); i < e; ++i) {
76787679
auto eltType = packType->getElementType(i);
76797680
if (auto *packExpansionType = eltType->getAs<PackExpansionType>()) {
7680-
// FIXME: Locator element for pack expansion pattern
7681+
auto patternLoc =
7682+
locator.withPathElement(ConstraintLocator::PackExpansionPattern);
76817683
addConstraint(ConstraintKind::ConformsTo,
76827684
packExpansionType->getPatternType(),
76837685
protocol->getDeclaredInterfaceType(),
7684-
locator.withPathElement(LocatorPathElt::PackElement(i)));
7686+
patternLoc);
76857687
} else {
76867688
addConstraint(ConstraintKind::ConformsTo, eltType,
76877689
protocol->getDeclaredInterfaceType(),

lib/Sema/ConstraintLocator.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ unsigned LocatorPathElt::getNewSummaryFlags() const {
9898
case ConstraintLocator::PackType:
9999
case ConstraintLocator::PackElement:
100100
case ConstraintLocator::PackShape:
101+
case ConstraintLocator::PackExpansionPattern:
101102
case ConstraintLocator::PatternBindingElement:
102103
case ConstraintLocator::NamedPatternDecl:
103104
case ConstraintLocator::AnyPatternDecl:
@@ -450,6 +451,11 @@ void LocatorPathElt::dump(raw_ostream &out) const {
450451
break;
451452
}
452453

454+
case ConstraintLocator::PackExpansionPattern: {
455+
out << "pack expansion pattern";
456+
break;
457+
}
458+
453459
case ConstraintLocator::PatternBindingElement: {
454460
auto patternBindingElt =
455461
elt.castTo<LocatorPathElt::PatternBindingElement>();

lib/Sema/ConstraintSystem.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5330,6 +5330,14 @@ void constraints::simplifyLocator(ASTNode &anchor,
53305330
case ConstraintLocator::PackShape:
53315331
break;
53325332

5333+
case ConstraintLocator::PackExpansionPattern: {
5334+
if (auto *expansion = getAsExpr<PackExpansionExpr>(anchor))
5335+
anchor = expansion->getPatternExpr();
5336+
5337+
path = path.slice(1);
5338+
break;
5339+
}
5340+
53335341
case ConstraintLocator::PatternBindingElement: {
53345342
auto pattern = path[0].castTo<LocatorPathElt::PatternBindingElement>();
53355343
auto *patternBinding = cast<PatternBindingDecl>(anchor.get<Decl *>());

0 commit comments

Comments
 (0)