Skip to content

Commit 17b09a8

Browse files
committed
[ConstraintSystem] Add a locator element to represent a generic type
This locator is going to be used as a "parent" element for "generic argument" elements.
1 parent 1dd6d34 commit 17b09a8

File tree

4 files changed

+26
-0
lines changed

4 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
@@ -643,6 +643,20 @@ class LocatorPathElt::TupleType : public StoredPointerElement<TypeBase> {
643643
}
644644
};
645645

646+
class LocatorPathElt::GenericType : public StoredPointerElement<TypeBase> {
647+
public:
648+
GenericType(Type type)
649+
: StoredPointerElement(PathElementKind::GenericType, type.getPointer()) {
650+
assert(type->getDesugaredType()->is<BoundGenericType>());
651+
}
652+
653+
Type getType() const { return getStoredPointer(); }
654+
655+
static bool classof(const LocatorPathElt *elt) {
656+
return elt->getKind() == PathElementKind::GenericType;
657+
}
658+
};
659+
646660
/// Abstract superclass for any kind of tuple element.
647661
class LocatorPathElt::AnyTupleElement : public StoredIntegerElement<1> {
648662
protected:

include/swift/Sema/ConstraintLocatorPathElts.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ CUSTOM_LOCATOR_PATH_ELT(SynthesizedArgument)
181181
/// path components.
182182
CUSTOM_LOCATOR_PATH_ELT(TupleType)
183183

184+
/// A generic type, which provides context for subsequent generic
185+
/// argument path components.
186+
CUSTOM_LOCATOR_PATH_ELT(GenericType)
187+
184188
/// Tuple elements.
185189
ABSTRACT_LOCATOR_PATH_ELT(AnyTupleElement)
186190
/// A tuple element referenced by position.

lib/Sema/ConstraintLocator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ unsigned LocatorPathElt::getNewSummaryFlags() const {
6767
case ConstraintLocator::GenericParameter:
6868
case ConstraintLocator::GenericArgument:
6969
case ConstraintLocator::TupleType:
70+
case ConstraintLocator::GenericType:
7071
case ConstraintLocator::NamedTupleElement:
7172
case ConstraintLocator::TupleElement:
7273
case ConstraintLocator::ProtocolRequirement:
@@ -242,6 +243,12 @@ void LocatorPathElt::dump(raw_ostream &out) const {
242243
break;
243244
}
244245

246+
case ConstraintLocator::GenericType: {
247+
auto genericTyElt = elt.castTo<LocatorPathElt::GenericType>();
248+
out << "generic type '" << genericTyElt.getType()->getString(PO) << "'";
249+
break;
250+
}
251+
245252
case ConstraintLocator::NamedTupleElement: {
246253
auto tupleElt = elt.castTo<LocatorPathElt::NamedTupleElement>();
247254
out << "named tuple element #" << llvm::utostr(tupleElt.getIndex());

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5372,6 +5372,7 @@ void constraints::simplifyLocator(ASTNode &anchor,
53725372
continue;
53735373

53745374
case ConstraintLocator::TupleType:
5375+
case ConstraintLocator::GenericType:
53755376
path = path.slice(1);
53765377
continue;
53775378

0 commit comments

Comments
 (0)