Skip to content

Commit 8df65e7

Browse files
committed
Remove unnecessary uses of NestedArchetypeType.
`ArchetypeType` has all of the API we need for these cases, so use that instead to isolate us from `NestedArchetypeType`, which we would like to eliminate soon-ish.
1 parent 3b8e9df commit 8df65e7

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

lib/AST/Type.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3409,7 +3409,7 @@ static bool canSubstituteTypeInto(Type ty, const DeclContext *dc,
34093409
// The referenced type might be a different opaque result type.
34103410

34113411
// First, unwrap any nested associated types to get the root archetype.
3412-
if (auto nestedTy = ty->getAs<NestedArchetypeType>())
3412+
if (auto nestedTy = ty->getAs<ArchetypeType>())
34133413
ty = nestedTy->getRoot();
34143414

34153415
// If the root archetype is an opaque result type, check that its
@@ -4258,8 +4258,9 @@ static Type substType(Type derivedType,
42584258
return Type(type);
42594259

42604260
// For nested archetypes, we can substitute the parent.
4261-
auto nestedArchetype = cast<NestedArchetypeType>(substOrig);
4261+
auto nestedArchetype = cast<ArchetypeType>(substOrig);
42624262
auto parent = nestedArchetype->getParent();
4263+
assert(parent && "Not a nested archetype");
42634264

42644265
// Substitute into the parent type.
42654266
Type substParent = substType(parent, substitutions,
@@ -4270,11 +4271,11 @@ static Type substType(Type derivedType,
42704271
return Type(type);
42714272

42724273
// Get the associated type reference from a child archetype.
4273-
AssociatedTypeDecl *assocType = nestedArchetype->getAssocType();
4274+
AssociatedTypeDecl *assocType = nestedArchetype->getInterfaceType()
4275+
->castTo<DependentMemberType>()->getAssocType();
42744276

42754277
return getMemberForBaseType(lookupConformances, parent, substParent,
4276-
assocType, nestedArchetype->getName(),
4277-
options);
4278+
assocType, assocType->getName(), options);
42784279
});
42794280
}
42804281

lib/IRGen/GenArchetype.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ irgen::emitArchetypeTypeMetadataRef(IRGenFunction &IGF,
7070
}
7171

7272
// If there's no local or opaque metadata, it must be a nested type.
73-
auto nested = cast<NestedArchetypeType>(archetype);
73+
assert(archetype->getParent() && "Not a nested archetype");
7474

75-
CanArchetypeType parent(nested->getParent());
76-
AssociatedType association(nested->getAssocType());
75+
CanArchetypeType parent(archetype->getParent());
76+
AssociatedType association(
77+
archetype->getInterfaceType()->castTo<DependentMemberType>()
78+
->getAssocType());
7779

7880
MetadataResponse response =
7981
emitAssociatedTypeMetadataRef(IGF, parent, association, request);

lib/IRGen/GenReflection.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ getRuntimeVersionThatSupportsDemanglingType(CanType type) {
199199
// Swift 5.1 runtime, so we needed to add a new mangling in 5.2.
200200
if (type->hasOpaqueArchetype()) {
201201
auto hasOpaqueAssocType = type.findIf([](CanType t) -> bool {
202-
if (auto a = dyn_cast<NestedArchetypeType>(t)) {
203-
return isa<OpaqueTypeArchetypeType>(a->getRoot());
202+
if (auto a = dyn_cast<ArchetypeType>(t)) {
203+
return isa<OpaqueTypeArchetypeType>(a->getRoot()) &&
204+
a->getInterfaceType()->is<DependentMemberType>();
204205
}
205206
return false;
206207
});

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,8 +1549,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
15491549
case TypeKind::SequenceArchetype: {
15501550
auto *Archetype = BaseTy->castTo<ArchetypeType>();
15511551
AssociatedTypeDecl *assocType = nullptr;
1552-
if (auto nested = dyn_cast<NestedArchetypeType>(Archetype))
1553-
assocType = nested->getAssocType();
1552+
if (auto depMemTy = Archetype->getInterfaceType()
1553+
->getAs<DependentMemberType>())
1554+
assocType = depMemTy->getAssocType();
15541555
auto L = getFilenameAndLocation(*this, assocType);
15551556
auto *File = getOrCreateFile(L.filename);
15561557
unsigned FwdDeclLine = 0;

0 commit comments

Comments
 (0)