Skip to content

Commit 44c2466

Browse files
committed
Introduce LocalArchetypeType as an abstract superclass to Element + Opened
This will be used in places like SIL's tracking of locally-opened archetypes.
1 parent d50e01f commit 44c2466

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

include/swift/AST/TypeNodes.def

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ ABSTRACT_TYPE(Substitutable, Type)
147147
ABSTRACT_TYPE(Archetype, SubstitutableType)
148148
ALWAYS_CANONICAL_TYPE(PrimaryArchetype, ArchetypeType)
149149
ALWAYS_CANONICAL_TYPE(OpaqueTypeArchetype, ArchetypeType)
150-
ALWAYS_CANONICAL_TYPE(OpenedArchetype, ArchetypeType)
151-
ALWAYS_CANONICAL_TYPE(ElementArchetype, ArchetypeType)
150+
ABSTRACT_TYPE(LocalArchetype, ArchetypeType)
151+
ALWAYS_CANONICAL_TYPE(OpenedArchetype, LocalArchetypeType)
152+
ALWAYS_CANONICAL_TYPE(ElementArchetype, LocalArchetypeType)
153+
TYPE_RANGE(LocalArchetype, OpenedArchetype, ElementArchetype)
152154
ALWAYS_CANONICAL_TYPE(PackArchetype, ArchetypeType)
153155
TYPE_RANGE(Archetype, PrimaryArchetype, PackArchetype)
154156
TYPE(GenericTypeParam, SubstitutableType)

include/swift/AST/Types.h

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5914,8 +5914,29 @@ class ReplaceOpaqueTypesWithUnderlyingTypes {
59145914
bool isWholeModule() const { return inContextAndIsWholeModule.getInt(); }
59155915
};
59165916

5917+
/// An archetype that's only valid in a portion of a local context.
5918+
class LocalArchetypeType : public ArchetypeType {
5919+
protected:
5920+
using ArchetypeType::ArchetypeType;
5921+
5922+
public:
5923+
LocalArchetypeType *getRoot() const {
5924+
return cast<LocalArchetypeType>(ArchetypeType::getRoot());
5925+
}
5926+
5927+
static bool classof(const TypeBase *type) {
5928+
return type->getKind() == TypeKind::OpenedArchetype ||
5929+
type->getKind() == TypeKind::ElementArchetype;
5930+
}
5931+
};
5932+
BEGIN_CAN_TYPE_WRAPPER(LocalArchetypeType, ArchetypeType)
5933+
CanLocalArchetypeType getRoot() const {
5934+
return CanLocalArchetypeType(getPointer()->getRoot());
5935+
}
5936+
END_CAN_TYPE_WRAPPER(LocalArchetypeType, ArchetypeType)
5937+
59175938
/// An archetype that represents the dynamic type of an opened existential.
5918-
class OpenedArchetypeType final : public ArchetypeType,
5939+
class OpenedArchetypeType final : public LocalArchetypeType,
59195940
private ArchetypeTrailingObjects<OpenedArchetypeType>
59205941
{
59215942
friend TrailingObjects;
@@ -6016,11 +6037,11 @@ class OpenedArchetypeType final : public ArchetypeType,
60166037
ArrayRef<ProtocolDecl *> conformsTo, Type superclass,
60176038
LayoutConstraint layout);
60186039
};
6019-
BEGIN_CAN_TYPE_WRAPPER(OpenedArchetypeType, ArchetypeType)
6040+
BEGIN_CAN_TYPE_WRAPPER(OpenedArchetypeType, LocalArchetypeType)
60206041
CanOpenedArchetypeType getRoot() const {
60216042
return CanOpenedArchetypeType(getPointer()->getRoot());
60226043
}
6023-
END_CAN_TYPE_WRAPPER(OpenedArchetypeType, ArchetypeType)
6044+
END_CAN_TYPE_WRAPPER(OpenedArchetypeType, LocalArchetypeType)
60246045

60256046
/// A wrapper around a shape type to use in ArchetypeTrailingObjects
60266047
/// for PackArchetypeType.
@@ -6065,7 +6086,7 @@ BEGIN_CAN_TYPE_WRAPPER(PackArchetypeType, ArchetypeType)
60656086
END_CAN_TYPE_WRAPPER(PackArchetypeType, ArchetypeType)
60666087

60676088
/// An archetype that represents the element type of a pack archetype.
6068-
class ElementArchetypeType final : public ArchetypeType,
6089+
class ElementArchetypeType final : public LocalArchetypeType,
60696090
private ArchetypeTrailingObjects<ElementArchetypeType>
60706091
{
60716092
friend TrailingObjects;
@@ -6104,11 +6125,11 @@ class ElementArchetypeType final : public ArchetypeType,
61046125
ArrayRef<ProtocolDecl *> conformsTo, Type superclass,
61056126
LayoutConstraint layout);
61066127
};
6107-
BEGIN_CAN_TYPE_WRAPPER(ElementArchetypeType, ArchetypeType)
6128+
BEGIN_CAN_TYPE_WRAPPER(ElementArchetypeType, LocalArchetypeType)
61086129
CanElementArchetypeType getRoot() const {
61096130
return CanElementArchetypeType(getPointer()->getRoot());
61106131
}
6111-
END_CAN_TYPE_WRAPPER(ElementArchetypeType, ArchetypeType)
6132+
END_CAN_TYPE_WRAPPER(ElementArchetypeType, LocalArchetypeType)
61126133

61136134
template<typename Type>
61146135
const Type *ArchetypeType::getSubclassTrailingObjects() const {

lib/AST/Type.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3964,11 +3964,12 @@ OpenedArchetypeType::OpenedArchetypeType(
39643964
GenericEnvironment *environment, Type interfaceType,
39653965
ArrayRef<ProtocolDecl *> conformsTo, Type superclass,
39663966
LayoutConstraint layout)
3967-
: ArchetypeType(TypeKind::OpenedArchetype, interfaceType->getASTContext(),
3968-
RecursiveTypeProperties::HasArchetype
3969-
| RecursiveTypeProperties::HasOpenedExistential,
3970-
interfaceType, conformsTo, superclass, layout,
3971-
environment)
3967+
: LocalArchetypeType(TypeKind::OpenedArchetype,
3968+
interfaceType->getASTContext(),
3969+
RecursiveTypeProperties::HasArchetype
3970+
| RecursiveTypeProperties::HasOpenedExistential,
3971+
interfaceType, conformsTo, superclass, layout,
3972+
environment)
39723973
{
39733974
assert(!interfaceType->isParameterPack());
39743975
}
@@ -4022,9 +4023,10 @@ ElementArchetypeType::ElementArchetypeType(
40224023
const ASTContext &Ctx, GenericEnvironment *GenericEnv, Type InterfaceType,
40234024
ArrayRef<ProtocolDecl *> ConformsTo, Type Superclass,
40244025
LayoutConstraint Layout)
4025-
: ArchetypeType(TypeKind::ElementArchetype, Ctx,
4026-
RecursiveTypeProperties::HasArchetype, InterfaceType,
4027-
ConformsTo, Superclass, Layout, GenericEnv) {
4026+
: LocalArchetypeType(TypeKind::ElementArchetype, Ctx,
4027+
RecursiveTypeProperties::HasArchetype,
4028+
InterfaceType,
4029+
ConformsTo, Superclass, Layout, GenericEnv) {
40284030
}
40294031

40304032
CanTypeWrapper<ElementArchetypeType> ElementArchetypeType::getNew(

0 commit comments

Comments
 (0)