Skip to content

Commit 9b4d804

Browse files
committed
Remove unnecessary uses of ArchetypeType::getParent().
The most interesting one of these is `ArchetypeType::getRoot()`, which we reimplement in terms of getting the root generic parameter and then looking up the archetype in the generic environment.
1 parent c8b7181 commit 9b4d804

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

include/swift/AST/Types.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5734,9 +5734,6 @@ class NestedArchetypeType final : public ArchetypeType,
57345734
GenericEnvironment *Environment);
57355735
};
57365736
BEGIN_CAN_TYPE_WRAPPER(NestedArchetypeType, ArchetypeType)
5737-
CanArchetypeType getParent() const {
5738-
return CanArchetypeType(getPointer()->getParent());
5739-
}
57405737
END_CAN_TYPE_WRAPPER(NestedArchetypeType, ArchetypeType)
57415738

57425739
/// An archetype that represents an opaque element of a type sequence in context.
@@ -6615,7 +6612,7 @@ inline bool TypeBase::hasSimpleTypeRepr() const {
66156612
return false;
66166613

66176614
case TypeKind::NestedArchetype:
6618-
return cast<NestedArchetypeType>(this)->getParent()->hasSimpleTypeRepr();
6615+
return cast<NestedArchetypeType>(this)->getRoot()->hasSimpleTypeRepr();
66196616

66206617
case TypeKind::OpaqueTypeArchetype:
66216618
case TypeKind::OpenedArchetype:

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3742,7 +3742,6 @@ namespace {
37423742
void visitNestedArchetypeType(NestedArchetypeType *T, StringRef label) {
37433743
printArchetypeCommon(T, "nested_archetype_type", label);
37443744
printField("name", T->getFullName());
3745-
printField("parent", T->getParent());
37463745
printField("assoc_type", T->getAssocType()->printRef());
37473746
PrintWithColorRAII(OS, ParenthesisColor) << ')';
37483747
}

lib/AST/Type.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,11 +3211,10 @@ ArchetypeType::ArchetypeType(TypeKind Kind,
32113211
}
32123212

32133213
ArchetypeType *ArchetypeType::getRoot() const {
3214-
auto parent = this;
3215-
while (auto nested = dyn_cast<NestedArchetypeType>(parent)) {
3216-
parent = nested->getParent();
3217-
}
3218-
return const_cast<ArchetypeType*>(parent);
3214+
auto gp = InterfaceType->getRootGenericParam();
3215+
assert(gp && "Missing root generic parameter?");
3216+
return getGenericEnvironment()->mapTypeIntoContext(
3217+
Type(gp))->castTo<ArchetypeType>();
32193218
}
32203219

32213220
Type ArchetypeType::getExistentialType() const {

0 commit comments

Comments
 (0)