Skip to content

Commit dbfeb5e

Browse files
committed
[ConstraintLocator] Add a new locator path element - ConformanceRequirement
Records protocol requirement associated with a particular type in the constraint system, also useful to track parent conformance for conditional requirements.
1 parent 949b0c0 commit dbfeb5e

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

include/swift/Sema/ConstraintLocator.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,20 @@ class LocatorPathElt::ArgumentAttribute final : public StoredIntegerElement<1> {
762762
}
763763
};
764764

765+
class LocatorPathElt::ConformanceRequirement final
766+
: public StoredPointerElement<ProtocolDecl> {
767+
public:
768+
ConformanceRequirement(ProtocolDecl *protocol)
769+
: StoredPointerElement(PathElementKind::ConformanceRequirement,
770+
protocol) {}
771+
772+
ProtocolDecl *getRequirement() const { return getStoredPointer(); }
773+
774+
static bool classof(const LocatorPathElt *elt) {
775+
return elt->getKind() == ConstraintLocator::ConformanceRequirement;
776+
}
777+
};
778+
765779
namespace details {
766780
template <typename CustomPathElement>
767781
class PathElement {

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(ArgumentAttribute)
195195
/// The result of a chain of member accesses off an UnresolvedMemberExpr
196196
SIMPLE_LOCATOR_PATH_ELT(UnresolvedMemberChainResult)
197197

198+
/// The conformance requirement associated with a type.
199+
CUSTOM_LOCATOR_PATH_ELT(ConformanceRequirement)
200+
198201
#undef LOCATOR_PATH_ELT
199202
#undef CUSTOM_LOCATOR_PATH_ELT
200203
#undef SIMPLE_LOCATOR_PATH_ELT

lib/Sema/ConstraintLocator.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ unsigned LocatorPathElt::getNewSummaryFlags() const {
6666
case ConstraintLocator::KeyPathComponent:
6767
case ConstraintLocator::ConditionalRequirement:
6868
case ConstraintLocator::TypeParameterRequirement:
69+
case ConstraintLocator::ConformanceRequirement:
6970
case ConstraintLocator::ImplicitlyUnwrappedDisjunctionChoice:
7071
case ConstraintLocator::DynamicLookupResult:
7172
case ConstraintLocator::ContextualType:
@@ -397,6 +398,14 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) const {
397398
break;
398399
}
399400

401+
case ConformanceRequirement: {
402+
auto reqElt = elt.castTo<LocatorPathElt::ConformanceRequirement>();
403+
out << "conformance requirement (";
404+
reqElt.getRequirement()->dumpRef(out);
405+
out << ")";
406+
break;
407+
}
408+
400409
case ImplicitlyUnwrappedDisjunctionChoice:
401410
out << "implicitly unwrapped disjunction choice";
402411
break;

0 commit comments

Comments
 (0)