Skip to content

Commit 31f32be

Browse files
authored
Merge pull request #13047 from xedin/fix-locators
2 parents f9d2c07 + df0fd6a commit 31f32be

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

lib/Sema/ConstraintLocator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void ConstraintLocator::Profile(llvm::FoldingSetNodeID &id, Expr *anchor,
7777
case OpenedGeneric:
7878
case KeyPathComponent:
7979
case ConditionalRequirement:
80+
case TypeParameterRequirement:
8081
if (unsigned numValues = numNumericValuesInPathElement(elt.getKind())) {
8182
id.AddInteger(elt.getValue());
8283
if (numValues > 1)
@@ -243,6 +244,10 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) {
243244
case ConditionalRequirement:
244245
out << "conditional requirement #" << llvm::utostr(elt.getValue());
245246
break;
247+
248+
case TypeParameterRequirement:
249+
out << "type parameter requirement #" << llvm::utostr(elt.getValue());
250+
break;
246251
}
247252
}
248253

lib/Sema/ConstraintLocator.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class ConstraintLocator : public llvm::FoldingSetNode {
125125
KeyPathComponent,
126126
/// The Nth conditional requirement in the parent locator's conformance.
127127
ConditionalRequirement,
128+
/// A single requirement placed on the type parameters.
129+
TypeParameterRequirement,
128130
};
129131

130132
/// \brief Determine the number of numeric values used for the given path
@@ -164,6 +166,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
164166
case TupleElement:
165167
case KeyPathComponent:
166168
case ConditionalRequirement:
169+
case TypeParameterRequirement:
167170
return 1;
168171

169172
case ApplyArgToParam:
@@ -217,6 +220,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
217220
case Witness:
218221
case KeyPathComponent:
219222
case ConditionalRequirement:
223+
case TypeParameterRequirement:
220224
return 0;
221225

222226
case FunctionArgument:
@@ -353,6 +357,10 @@ class ConstraintLocator : public llvm::FoldingSetNode {
353357
return PathElement(ConditionalRequirement, index);
354358
}
355359

360+
static PathElement getTypeRequirementComponent(unsigned index) {
361+
return PathElement(TypeParameterRequirement, index);
362+
}
363+
356364
/// \brief Retrieve the kind of path element.
357365
PathElementKind getKind() const {
358366
switch (static_cast<StoredKind>(storedKind)) {

lib/Sema/ConstraintSystem.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,10 @@ void ConstraintSystem::openGeneric(
10511051
bindArchetypesFromContext(*this, outerDC, locatorPtr, replacements);
10521052

10531053
// Add the requirements as constraints.
1054-
for (auto req : sig->getRequirements()) {
1054+
auto requirements = sig->getRequirements();
1055+
for (unsigned pos = 0, n = requirements.size(); pos != n; ++pos) {
1056+
const auto &req = requirements[pos];
1057+
10551058
Optional<Requirement> openedReq;
10561059
auto openedFirst = openType(req.getFirstType(), replacements);
10571060

@@ -1078,7 +1081,11 @@ void ConstraintSystem::openGeneric(
10781081
openedReq = Requirement(kind, openedFirst, req.getLayoutConstraint());
10791082
break;
10801083
}
1081-
addConstraint(*openedReq, locatorPtr);
1084+
1085+
addConstraint(
1086+
*openedReq,
1087+
locator.withPathElement(ConstraintLocator::OpenedGeneric)
1088+
.withPathElement(LocatorPathElt::getTypeRequirementComponent(pos)));
10821089
}
10831090
}
10841091

0 commit comments

Comments
 (0)