Skip to content

Commit 2db0e60

Browse files
committed
[ConstraintSystem] Add kind to generic requirement locator
Having requirement kind encoded in the locator helps to identify what kind of fix to generate (applicable to same-type, superclass) without retrieving requirement itself.
1 parent 46981fe commit 2db0e60

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

lib/Sema/ConstraintLocator.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,26 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) {
243243
out << "conditional requirement #" << llvm::utostr(elt.getValue());
244244
break;
245245

246-
case TypeParameterRequirement:
247-
out << "type parameter requirement #" << llvm::utostr(elt.getValue());
246+
case TypeParameterRequirement: {
247+
out << "type parameter requirement #" << llvm::utostr(elt.getValue())
248+
<< " (";
249+
switch (static_cast<RequirementKind>(elt.getValue2())) {
250+
case RequirementKind::Conformance:
251+
out << "conformance";
252+
break;
253+
case RequirementKind::Superclass:
254+
out << "superclass";
255+
break;
256+
case RequirementKind::SameType:
257+
out << "same-type";
258+
break;
259+
case RequirementKind::Layout:
260+
out << "layout";
261+
break;
262+
}
263+
out << ")";
248264
break;
265+
}
249266

250267
case ImplicitlyUnwrappedDisjunctionChoice:
251268
out << "implicitly unwrapped disjunction choice";

lib/Sema/ConstraintLocator.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ class ConstraintLocator : public llvm::FoldingSetNode {
174174
case TupleElement:
175175
case KeyPathComponent:
176176
case ConditionalRequirement:
177-
case TypeParameterRequirement:
178177
return 1;
179178

179+
case TypeParameterRequirement:
180180
case ApplyArgToParam:
181181
return 2;
182182
}
@@ -365,8 +365,10 @@ class ConstraintLocator : public llvm::FoldingSetNode {
365365
return PathElement(ConditionalRequirement, index);
366366
}
367367

368-
static PathElement getTypeRequirementComponent(unsigned index) {
369-
return PathElement(TypeParameterRequirement, index);
368+
static PathElement getTypeRequirementComponent(unsigned index,
369+
RequirementKind kind) {
370+
return PathElement(TypeParameterRequirement, index,
371+
static_cast<unsigned>(kind));
370372
}
371373

372374
/// \brief Retrieve the kind of path element.

lib/Sema/ConstraintSystem.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,8 @@ void ConstraintSystem::openGenericRequirements(
11891189
addConstraint(
11901190
*openedReq,
11911191
locator.withPathElement(ConstraintLocator::OpenedGeneric)
1192-
.withPathElement(LocatorPathElt::getTypeRequirementComponent(pos)));
1192+
.withPathElement(
1193+
LocatorPathElt::getTypeRequirementComponent(pos, kind)));
11931194
}
11941195
}
11951196

0 commit comments

Comments
 (0)