Skip to content

Commit 5218a0d

Browse files
committed
[ConstraintSystem] Add a locator path element for pack shapes, and use it for
type variables representing pack shapes.
1 parent 9e21404 commit 5218a0d

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

include/swift/Sema/ConstraintLocatorPathElts.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ CUSTOM_LOCATOR_PATH_ELT(PackType)
195195
/// An element of a pack type - the T in <T, U, V, ...>
196196
CUSTOM_LOCATOR_PATH_ELT(PackElement)
197197

198+
/// The shape of a parameter pack.
199+
SIMPLE_LOCATOR_PATH_ELT(PackShape)
200+
198201
/// An unresolved member.
199202
SIMPLE_LOCATOR_PATH_ELT(UnresolvedMember)
200203

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,10 +2498,9 @@ ConstraintSystem::matchPackExpansionTypes(PackExpansionType *expansion1,
24982498
ConstraintKind kind, TypeMatchOptions flags,
24992499
ConstraintLocatorBuilder locator) {
25002500
// The count types of two pack expansion types must have the same shape.
2501-
//
2502-
// FIXME: Locator for diagnostics.
2503-
auto *loc = getConstraintLocator(locator);
2504-
auto *shapeTypeVar = createTypeVariable(loc, TVO_CanBindToPack);
2501+
auto *shapeLoc = getConstraintLocator(
2502+
locator.withPathElement(ConstraintLocator::PackShape));
2503+
auto *shapeTypeVar = createTypeVariable(shapeLoc, TVO_CanBindToPack);
25052504
addConstraint(ConstraintKind::ShapeOf,
25062505
expansion1->getCountType(), shapeTypeVar, locator);
25072506
addConstraint(ConstraintKind::ShapeOf,
@@ -14156,8 +14155,9 @@ void ConstraintSystem::addConstraint(Requirement req,
1415614155
auto type1 = req.getFirstType();
1415714156
auto type2 = req.getSecondType();
1415814157

14159-
// FIXME: Locator for diagnostics
14160-
auto typeVar = createTypeVariable(getConstraintLocator(locator),
14158+
auto *shapeLoc = getConstraintLocator(
14159+
locator.withPathElement(ConstraintLocator::PackShape));
14160+
auto typeVar = createTypeVariable(shapeLoc,
1416114161
TVO_CanBindToPack);
1416214162

1416314163
addConstraint(ConstraintKind::ShapeOf, type1, typeVar, locator);

lib/Sema/ConstraintLocator.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ unsigned LocatorPathElt::getNewSummaryFlags() const {
9797
case ConstraintLocator::SyntacticElement:
9898
case ConstraintLocator::PackType:
9999
case ConstraintLocator::PackElement:
100+
case ConstraintLocator::PackShape:
100101
case ConstraintLocator::PatternBindingElement:
101102
case ConstraintLocator::NamedPatternDecl:
102103
case ConstraintLocator::AnyPatternDecl:
@@ -444,6 +445,11 @@ void LocatorPathElt::dump(raw_ostream &out) const {
444445
break;
445446
}
446447

448+
case ConstraintLocator::PackShape: {
449+
out << "pack shape";
450+
break;
451+
}
452+
447453
case ConstraintLocator::PatternBindingElement: {
448454
auto patternBindingElt =
449455
elt.castTo<LocatorPathElt::PatternBindingElement>();

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5327,6 +5327,7 @@ void constraints::simplifyLocator(ASTNode &anchor,
53275327
break;
53285328

53295329
case ConstraintLocator::PackElement:
5330+
case ConstraintLocator::PackShape:
53305331
break;
53315332

53325333
case ConstraintLocator::PatternBindingElement: {

0 commit comments

Comments
 (0)