Skip to content

Commit 452ecca

Browse files
committed
Remove NestedArchetypeType.
Nested archetypes are represented by their base archetype kinds (primary, opened, or opaque type) with an interface type that is a nested type, as represented by a DependentMemberType. This provides a more uniform representation of archetypes throughout the frontend.
1 parent 96fdbe1 commit 452ecca

16 files changed

+5
-205
lines changed

include/swift/AST/TypeNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ ABSTRACT_TYPE(Substitutable, Type)
147147
ALWAYS_CANONICAL_TYPE(PrimaryArchetype, ArchetypeType)
148148
ALWAYS_CANONICAL_TYPE(OpaqueTypeArchetype, ArchetypeType)
149149
ALWAYS_CANONICAL_TYPE(OpenedArchetype, ArchetypeType)
150-
ALWAYS_CANONICAL_TYPE(NestedArchetype, ArchetypeType)
151150
ALWAYS_CANONICAL_TYPE(SequenceArchetype, ArchetypeType)
152151
TYPE_RANGE(Archetype, PrimaryArchetype, SequenceArchetype)
153152
TYPE(GenericTypeParam, SubstitutableType)

include/swift/AST/Types.h

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5698,44 +5698,6 @@ class OpenedArchetypeType final : public ArchetypeType,
56985698
BEGIN_CAN_TYPE_WRAPPER(OpenedArchetypeType, ArchetypeType)
56995699
END_CAN_TYPE_WRAPPER(OpenedArchetypeType, ArchetypeType)
57005700

5701-
/// An archetype that is a nested associated type of another archetype.
5702-
class NestedArchetypeType final : public ArchetypeType,
5703-
private ArchetypeTrailingObjects<NestedArchetypeType>
5704-
{
5705-
friend TrailingObjects;
5706-
friend ArchetypeType;
5707-
5708-
public:
5709-
/// getNew - Create a new nested archetype with the given associated type.
5710-
///
5711-
/// The ConformsTo array will be copied into the ASTContext by this routine.
5712-
static CanTypeWrapper<NestedArchetypeType>
5713-
getNew(const ASTContext &Ctx,
5714-
DependentMemberType *InterfaceType,
5715-
SmallVectorImpl<ProtocolDecl *> &ConformsTo,
5716-
Type Superclass, LayoutConstraint Layout,
5717-
GenericEnvironment *Environment);
5718-
5719-
AssociatedTypeDecl *getAssocType() const;
5720-
5721-
static bool classof(const TypeBase *T) {
5722-
return T->getKind() == TypeKind::NestedArchetype;
5723-
}
5724-
5725-
DependentMemberType *getInterfaceType() const {
5726-
return cast<DependentMemberType>(InterfaceType.getPointer());
5727-
}
5728-
5729-
private:
5730-
NestedArchetypeType(const ASTContext &Ctx,
5731-
Type InterfaceType,
5732-
ArrayRef<ProtocolDecl *> ConformsTo,
5733-
Type Superclass, LayoutConstraint Layout,
5734-
GenericEnvironment *Environment);
5735-
};
5736-
BEGIN_CAN_TYPE_WRAPPER(NestedArchetypeType, ArchetypeType)
5737-
END_CAN_TYPE_WRAPPER(NestedArchetypeType, ArchetypeType)
5738-
57395701
/// An archetype that represents an opaque element of a type sequence in context.
57405702
///
57415703
/// \code
@@ -5782,9 +5744,6 @@ const Type *ArchetypeType::getSubclassTrailingObjects() const {
57825744
if (auto openedTy = dyn_cast<OpenedArchetypeType>(this)) {
57835745
return openedTy->getTrailingObjects<Type>();
57845746
}
5785-
if (auto childTy = dyn_cast<NestedArchetypeType>(this)) {
5786-
return childTy->getTrailingObjects<Type>();
5787-
}
57885747
if (auto childTy = dyn_cast<SequenceArchetypeType>(this)) {
57895748
return childTy->getTrailingObjects<Type>();
57905749
}
@@ -6607,9 +6566,6 @@ inline bool TypeBase::hasSimpleTypeRepr() const {
66076566
case TypeKind::Existential:
66086567
return false;
66096568

6610-
case TypeKind::NestedArchetype:
6611-
return cast<NestedArchetypeType>(this)->getRoot()->hasSimpleTypeRepr();
6612-
66136569
case TypeKind::OpaqueTypeArchetype:
66146570
case TypeKind::OpenedArchetype:
66156571
return false;

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3741,12 +3741,6 @@ namespace {
37413741
OS << "\n";
37423742
PrintWithColorRAII(OS, ParenthesisColor) << ')';
37433743
}
3744-
void visitNestedArchetypeType(NestedArchetypeType *T, StringRef label) {
3745-
printArchetypeCommon(T, "nested_archetype_type", label);
3746-
printField("name", T->getFullName());
3747-
printField("assoc_type", T->getAssocType()->printRef());
3748-
PrintWithColorRAII(OS, ParenthesisColor) << ')';
3749-
}
37503744
void visitOpenedArchetypeType(OpenedArchetypeType *T, StringRef label) {
37513745
printArchetypeCommon(T, "opened_archetype_type", label);
37523746
printRec("opened_existential", T->getOpenedExistentialType());

lib/AST/ASTMangler.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,25 +1324,6 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
13241324
opaqueType, opaqueDecl, opaqueType->getSubstitutions(), sig, forDecl);
13251325
}
13261326

1327-
case TypeKind::NestedArchetype: {
1328-
auto nestedType = cast<NestedArchetypeType>(tybase);
1329-
1330-
// Mangle associated types of opaque archetypes like dependent member
1331-
// types, so that they can be accurately demangled at runtime.
1332-
if (auto opaque =
1333-
dyn_cast<OpaqueTypeArchetypeType>(nestedType->getRoot())) {
1334-
return appendOpaqueTypeArchetype(
1335-
nestedType, opaque->getDecl(), opaque->getSubstitutions(), sig,
1336-
forDecl);
1337-
}
1338-
1339-
// FIXME: Never actually used.
1340-
appendType(nestedType->getParent(), sig, forDecl);
1341-
appendIdentifier(nestedType->getName().str());
1342-
appendOperator("Qa");
1343-
return;
1344-
}
1345-
13461327
case TypeKind::DynamicSelf: {
13471328
auto dynamicSelf = cast<DynamicSelfType>(tybase);
13481329
if (dynamicSelf->getSelfType()->getAnyNominal()) {

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5926,11 +5926,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
59265926
}
59275927
}
59285928

5929-
void visitNestedArchetypeType(NestedArchetypeType *T) {
5930-
visitParentType(T->getParent());
5931-
printArchetypeCommon(T, T->getAssocType());
5932-
}
5933-
59345929
static AbstractTypeParamDecl *getAbstractTypeParamDecl(ArchetypeType *T) {
59355930
if (auto gp = T->getInterfaceType()->getAs<GenericTypeParamType>()) {
59365931
return gp->getDecl();

lib/AST/GenericEnvironment.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,7 @@ GenericEnvironment::getOrCreateArchetypeFromInterfaceType(Type depType) {
335335

336336
Type result;
337337

338-
if (nestedDependentMemberType) {
339-
auto *depMemTy = requirements.anchor->castTo<DependentMemberType>();
340-
result = NestedArchetypeType::getNew(ctx, depMemTy,
341-
requirements.protos, superclass,
342-
requirements.layout, this);
343-
} else if (requirements.anchor->getRootGenericParam()->isTypeSequence()) {
338+
if (requirements.anchor->getRootGenericParam()->isTypeSequence()) {
344339
result = SequenceArchetypeType::get(ctx, this, requirements.anchor,
345340
requirements.protos, superclass,
346341
requirements.layout);

lib/AST/Type.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ bool CanType::isReferenceTypeImpl(CanType type, const GenericSignatureImpl *sig,
184184
// Archetypes and existentials are only class references if class-bounded.
185185
case TypeKind::PrimaryArchetype:
186186
case TypeKind::OpenedArchetype:
187-
case TypeKind::NestedArchetype:
188187
case TypeKind::OpaqueTypeArchetype:
189188
case TypeKind::SequenceArchetype:
190189
return cast<ArchetypeType>(type)->requiresClass();
@@ -3281,20 +3280,6 @@ Type OpenedArchetypeType::getOpenedExistentialType() const {
32813280
return getGenericEnvironment()->getOpenedExistentialType();
32823281
}
32833282

3284-
NestedArchetypeType::NestedArchetypeType(const ASTContext &Ctx,
3285-
Type InterfaceType,
3286-
ArrayRef<ProtocolDecl *> ConformsTo,
3287-
Type Superclass,
3288-
LayoutConstraint Layout,
3289-
GenericEnvironment *Environment)
3290-
: ArchetypeType(TypeKind::NestedArchetype, Ctx,
3291-
Environment->mapTypeIntoContext(
3292-
InterfaceType->getRootGenericParam())
3293-
->getRecursiveProperties(),
3294-
InterfaceType, ConformsTo, Superclass, Layout, Environment)
3295-
{
3296-
}
3297-
32983283
OpaqueTypeArchetypeType::OpaqueTypeArchetypeType(
32993284
GenericEnvironment *environment,
33003285
RecursiveTypeProperties properties,
@@ -3601,28 +3586,6 @@ operator()(CanType maybeOpaqueType, Type replacementType,
36013586
return substRef;
36023587
}
36033588

3604-
CanNestedArchetypeType NestedArchetypeType::getNew(
3605-
const ASTContext &Ctx,
3606-
DependentMemberType *InterfaceType,
3607-
SmallVectorImpl<ProtocolDecl *> &ConformsTo,
3608-
Type Superclass,
3609-
LayoutConstraint Layout,
3610-
GenericEnvironment *Environment) {
3611-
assert(!Superclass || Superclass->getClassOrBoundGenericClass());
3612-
3613-
// Gather the set of protocol declarations to which this archetype conforms.
3614-
ProtocolType::canonicalizeProtocols(ConformsTo);
3615-
3616-
auto arena = AllocationArena::Permanent;
3617-
void *mem = Ctx.Allocate(
3618-
NestedArchetypeType::totalSizeToAlloc<ProtocolDecl *, Type, LayoutConstraint>(
3619-
ConformsTo.size(), Superclass ? 1 : 0, Layout ? 1 : 0),
3620-
alignof(NestedArchetypeType), arena);
3621-
3622-
return CanNestedArchetypeType(::new (mem) NestedArchetypeType(
3623-
Ctx, InterfaceType, ConformsTo, Superclass, Layout, Environment));
3624-
}
3625-
36263589
CanPrimaryArchetypeType
36273590
PrimaryArchetypeType::getNew(const ASTContext &Ctx,
36283591
GenericEnvironment *GenericEnv,
@@ -3719,10 +3682,6 @@ Type ArchetypeType::getNestedTypeByName(Identifier name) {
37193682
return Type();
37203683
}
37213684

3722-
AssociatedTypeDecl *NestedArchetypeType::getAssocType() const {
3723-
return InterfaceType->castTo<DependentMemberType>()->getAssocType();
3724-
}
3725-
37263685
Identifier ArchetypeType::getName() const {
37273686
assert(InterfaceType);
37283687
if (auto depMemTy = InterfaceType->getAs<DependentMemberType>())
@@ -4929,22 +4888,6 @@ case TypeKind::Id:
49294888
opaque->getInterfaceType(),
49304889
newSubMap);
49314890
}
4932-
case TypeKind::NestedArchetype: {
4933-
// Transform the root type of a nested opaque archetype.
4934-
auto nestedType = cast<NestedArchetypeType>(base);
4935-
auto root = dyn_cast<OpaqueTypeArchetypeType>(nestedType->getRoot());
4936-
if (!root)
4937-
return *this;
4938-
4939-
auto substRoot = Type(root).transformRec(fn);
4940-
if (substRoot.getPointer() == root) {
4941-
return *this;
4942-
}
4943-
4944-
// Substitute the new root into the root of the interface type.
4945-
return nestedType->getInterfaceType()->substRootParam(substRoot,
4946-
LookUpConformanceInModule(root->getDecl()->getModuleContext()));
4947-
}
49484891

49494892
case TypeKind::ExistentialMetatype: {
49504893
auto meta = cast<ExistentialMetatypeType>(base);
@@ -5568,7 +5511,6 @@ ReferenceCounting TypeBase::getReferenceCounting() {
55685511

55695512
case TypeKind::PrimaryArchetype:
55705513
case TypeKind::OpenedArchetype:
5571-
case TypeKind::NestedArchetype:
55725514
case TypeKind::OpaqueTypeArchetype:
55735515
case TypeKind::SequenceArchetype: {
55745516
auto archetype = cast<ArchetypeType>(type);

lib/IRGen/Fulfillment.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ static bool isLeafTypeMetadata(CanType type) {
6767
// Type parameters are statically opaque.
6868
case TypeKind::PrimaryArchetype:
6969
case TypeKind::OpenedArchetype:
70-
case TypeKind::NestedArchetype:
7170
case TypeKind::OpaqueTypeArchetype:
7271
case TypeKind::SequenceArchetype:
7372
case TypeKind::GenericTypeParam:

lib/IRGen/GenType.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2158,7 +2158,6 @@ const TypeInfo *TypeConverter::convertType(CanType ty) {
21582158

21592159
case TypeKind::PrimaryArchetype:
21602160
case TypeKind::OpenedArchetype:
2161-
case TypeKind::NestedArchetype:
21622161
case TypeKind::OpaqueTypeArchetype:
21632162
case TypeKind::SequenceArchetype:
21642163
return convertArchetypeType(cast<ArchetypeType>(ty));

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
15451545
case TypeKind::OpaqueTypeArchetype:
15461546
case TypeKind::PrimaryArchetype:
15471547
case TypeKind::OpenedArchetype:
1548-
case TypeKind::NestedArchetype:
15491548
case TypeKind::SequenceArchetype: {
15501549
auto *Archetype = BaseTy->castTo<ArchetypeType>();
15511550
AssociatedTypeDecl *assocType = nullptr;

0 commit comments

Comments
 (0)