[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.
This commit is contained in:
Pavel Yaskevich
2023-03-03 18:50:19 -08:00
committed by Pavel Yaskevich
parent 1dd6d349d1
commit 17b09a801e
4 changed files with 26 additions and 0 deletions

View File

@@ -643,6 +643,20 @@ public:
}
};
class LocatorPathElt::GenericType : public StoredPointerElement<TypeBase> {
public:
GenericType(Type type)
: StoredPointerElement(PathElementKind::GenericType, type.getPointer()) {
assert(type->getDesugaredType()->is<BoundGenericType>());
}
Type getType() const { return getStoredPointer(); }
static bool classof(const LocatorPathElt *elt) {
return elt->getKind() == PathElementKind::GenericType;
}
};
/// Abstract superclass for any kind of tuple element.
class LocatorPathElt::AnyTupleElement : public StoredIntegerElement<1> {
protected:

View File

@@ -181,6 +181,10 @@ CUSTOM_LOCATOR_PATH_ELT(SynthesizedArgument)
/// path components.
CUSTOM_LOCATOR_PATH_ELT(TupleType)
/// A generic type, which provides context for subsequent generic
/// argument path components.
CUSTOM_LOCATOR_PATH_ELT(GenericType)
/// Tuple elements.
ABSTRACT_LOCATOR_PATH_ELT(AnyTupleElement)
/// A tuple element referenced by position.

View File

@@ -67,6 +67,7 @@ unsigned LocatorPathElt::getNewSummaryFlags() const {
case ConstraintLocator::GenericParameter:
case ConstraintLocator::GenericArgument:
case ConstraintLocator::TupleType:
case ConstraintLocator::GenericType:
case ConstraintLocator::NamedTupleElement:
case ConstraintLocator::TupleElement:
case ConstraintLocator::ProtocolRequirement:
@@ -242,6 +243,12 @@ void LocatorPathElt::dump(raw_ostream &out) const {
break;
}
case ConstraintLocator::GenericType: {
auto genericTyElt = elt.castTo<LocatorPathElt::GenericType>();
out << "generic type '" << genericTyElt.getType()->getString(PO) << "'";
break;
}
case ConstraintLocator::NamedTupleElement: {
auto tupleElt = elt.castTo<LocatorPathElt::NamedTupleElement>();
out << "named tuple element #" << llvm::utostr(tupleElt.getIndex());

View File

@@ -5372,6 +5372,7 @@ void constraints::simplifyLocator(ASTNode &anchor,
continue;
case ConstraintLocator::TupleType:
case ConstraintLocator::GenericType:
path = path.slice(1);
continue;