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;

lib/Sema/CSApply.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6749,7 +6749,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
67496749

67506750
case TypeKind::PrimaryArchetype:
67516751
case TypeKind::OpenedArchetype:
6752-
case TypeKind::NestedArchetype:
67536752
case TypeKind::OpaqueTypeArchetype:
67546753
case TypeKind::SequenceArchetype:
67556754
if (!cast<ArchetypeType>(desugaredFromType)->requiresClass())
@@ -7071,7 +7070,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
70717070
case TypeKind::DynamicSelf:
70727071
case TypeKind::PrimaryArchetype:
70737072
case TypeKind::OpenedArchetype:
7074-
case TypeKind::NestedArchetype:
70757073
case TypeKind::OpaqueTypeArchetype:
70767074
case TypeKind::SequenceArchetype:
70777075
case TypeKind::GenericTypeParam:

lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5884,33 +5884,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
58845884
break;
58855885
}
58865886

5887-
// Same for nested archetypes rooted in opaque types.
5888-
case TypeKind::NestedArchetype: {
5889-
auto nested1 = cast<NestedArchetypeType>(desugar1);
5890-
auto nested2 = cast<NestedArchetypeType>(desugar2);
5891-
5892-
auto rootOpaque1 = dyn_cast<OpaqueTypeArchetypeType>(nested1->getRoot());
5893-
auto rootOpaque2 = dyn_cast<OpaqueTypeArchetypeType>(nested2->getRoot());
5894-
if (rootOpaque1 && rootOpaque2) {
5895-
auto interfaceTy1 = rootOpaque1->getCanonicalInterfaceType(
5896-
nested1->getInterfaceType());
5897-
auto interfaceTy2 = rootOpaque2->getCanonicalInterfaceType(
5898-
nested2->getInterfaceType());
5899-
if (interfaceTy1->isEqual(interfaceTy2)
5900-
&& rootOpaque1->getDecl() == rootOpaque2->getDecl()) {
5901-
conversionsOrFixes.push_back(ConversionRestrictionKind::DeepEquality);
5902-
break;
5903-
}
5904-
}
5905-
5906-
// Before failing, let's give repair a chance to run in diagnostic mode.
5907-
if (shouldAttemptFixes())
5908-
break;
5909-
5910-
// If the archetypes aren't rooted in an opaque type, or are rooted in
5911-
// completely different decls, then there's nothing else we can do.
5912-
return getTypeMatchFailure(locator);
5913-
}
59145887
case TypeKind::Pack: {
59155888
auto tmpPackLoc = locator.withPathElement(LocatorPathElt::PackType(type1));
59165889
auto packLoc = tmpPackLoc.withPathElement(LocatorPathElt::PackType(type2));
@@ -6475,7 +6448,6 @@ ConstraintSystem::simplifyConstructionConstraint(
64756448
case TypeKind::BoundGenericStruct:
64766449
case TypeKind::PrimaryArchetype:
64776450
case TypeKind::OpenedArchetype:
6478-
case TypeKind::NestedArchetype:
64796451
case TypeKind::OpaqueTypeArchetype:
64806452
case TypeKind::SequenceArchetype:
64816453
case TypeKind::DynamicSelf:

lib/Serialization/Deserialization.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5540,17 +5540,6 @@ class TypeDeserializer {
55405540
opaqueDecl, interfaceTypeOrError.get(), subsOrError.get());
55415541
}
55425542

5543-
Expected<Type> deserializeNestedArchetypeType(ArrayRef<uint64_t> scratch,
5544-
StringRef blobData) {
5545-
TypeID rootID, interfaceTyID;
5546-
decls_block::NestedArchetypeTypeLayout::readRecord(scratch,
5547-
rootID, interfaceTyID);
5548-
5549-
auto rootTy = MF.getType(rootID)->castTo<ArchetypeType>();
5550-
auto interfaceTy = MF.getType(interfaceTyID)->castTo<DependentMemberType>();
5551-
return rootTy->getGenericEnvironment()->mapTypeIntoContext(interfaceTy);
5552-
}
5553-
55545543
Expected<Type> deserializeSequenceArchetypeType(ArrayRef<uint64_t> scratch,
55555544
StringRef blobData) {
55565545
GenericSignatureID sigID;
@@ -6122,7 +6111,6 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
61226111
CASE(PrimaryArchetype)
61236112
CASE(OpaqueArchetype)
61246113
CASE(OpenedArchetype)
6125-
CASE(NestedArchetype)
61266114
CASE(SequenceArchetype)
61276115
CASE(GenericTypeParam)
61286116
CASE(ProtocolComposition)

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5656
/// describe what change you made. The content of this comment isn't important;
5757
/// it just ensures a conflict if two people change the module format.
5858
/// Don't worry about adhering to the 80-column limit for this line.
59-
const uint16_t SWIFTMODULE_VERSION_MINOR = 659; // opened archetype interface type
59+
const uint16_t SWIFTMODULE_VERSION_MINOR = 660; // remove nested archetypes
6060

6161
/// A standard hash seed used for all string hashes in a serialized module.
6262
///
@@ -1088,12 +1088,6 @@ namespace decls_block {
10881088
SubstitutionMapIDField // the arguments
10891089
>;
10901090

1091-
using NestedArchetypeTypeLayout = BCRecordLayout<
1092-
NESTED_ARCHETYPE_TYPE,
1093-
TypeIDField, // root archetype
1094-
TypeIDField // interface type relative to root
1095-
>;
1096-
10971091
using SequenceArchetypeTypeLayout = BCRecordLayout<
10981092
SEQUENCE_ARCHETYPE_TYPE,
10991093
GenericSignatureIDField, // generic environment

lib/Serialization/Serialization.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4489,15 +4489,6 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
44894489
declID, interfaceTypeID, substMapID);
44904490
}
44914491

4492-
void visitNestedArchetypeType(const NestedArchetypeType *archetypeTy) {
4493-
using namespace decls_block;
4494-
auto rootTypeID = S.addTypeRef(archetypeTy->getRoot());
4495-
auto interfaceTypeID = S.addTypeRef(archetypeTy->getInterfaceType());
4496-
unsigned abbrCode = S.DeclTypeAbbrCodes[NestedArchetypeTypeLayout::Code];
4497-
NestedArchetypeTypeLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
4498-
rootTypeID, interfaceTypeID);
4499-
}
4500-
45014492
void visitSequenceArchetypeType(const SequenceArchetypeType *archetypeTy) {
45024493
using namespace decls_block;
45034494
auto sig = archetypeTy->getGenericEnvironment()->getGenericSignature();
@@ -4900,7 +4891,6 @@ void Serializer::writeAllDeclsAndTypes() {
49004891
registerDeclTypeAbbr<PrimaryArchetypeTypeLayout>();
49014892
registerDeclTypeAbbr<OpenedArchetypeTypeLayout>();
49024893
registerDeclTypeAbbr<OpaqueArchetypeTypeLayout>();
4903-
registerDeclTypeAbbr<NestedArchetypeTypeLayout>();
49044894
registerDeclTypeAbbr<SequenceArchetypeTypeLayout>();
49054895
registerDeclTypeAbbr<ProtocolCompositionTypeLayout>();
49064896
registerDeclTypeAbbr<ExistentialTypeLayout>();

0 commit comments

Comments
 (0)