Skip to content

Commit 209167a

Browse files
committed
Eliminate spurious uses of ArchetypeType::getRoot().
1 parent 588c760 commit 209167a

File tree

11 files changed

+24
-25
lines changed

11 files changed

+24
-25
lines changed

include/swift/SIL/AbstractionPattern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ class AbstractionPattern {
981981
return true;
982982
}
983983
if (auto archetype = dyn_cast<ArchetypeType>(type)) {
984-
return !isa<OpaqueTypeArchetypeType>(archetype->getRoot());
984+
return !isa<OpaqueTypeArchetypeType>(archetype);
985985
}
986986
return false;
987987
}

lib/AST/ProtocolConformance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ ProtocolConformanceRef::subst(Type origType,
115115
// unless we're specifically substituting opaque types.
116116
if (auto origArchetype = origType->getAs<ArchetypeType>()) {
117117
if (!options.contains(SubstFlags::SubstituteOpaqueArchetypes)
118-
&& isa<OpaqueTypeArchetypeType>(origArchetype->getRoot())) {
118+
&& isa<OpaqueTypeArchetypeType>(origArchetype)) {
119119
return *this;
120120
}
121121
}

lib/AST/SubstitutionMap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
326326
// If we have an archetype, map out of the context so we can compute a
327327
// conformance access path.
328328
if (auto archetype = dyn_cast<ArchetypeType>(type)) {
329-
if (!isa<OpaqueTypeArchetypeType>(archetype->getRoot())) {
329+
if (!isa<OpaqueTypeArchetypeType>(archetype)) {
330330
type = archetype->getInterfaceType()->getCanonicalType();
331331
}
332332
}

lib/AST/TypeWalker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ class Traversal : public TypeVisitor<Traversal, bool>
207207
bool visitArchetypeType(ArchetypeType *ty) {
208208
// If the root is an opaque archetype, visit its substitution replacement
209209
// types.
210-
if (auto opaqueRoot = dyn_cast<OpaqueTypeArchetypeType>(ty->getRoot())) {
211-
for (auto arg : opaqueRoot->getSubstitutions().getReplacementTypes()) {
210+
if (auto opaque = dyn_cast<OpaqueTypeArchetypeType>(ty)) {
211+
for (auto arg : opaque->getSubstitutions().getReplacementTypes()) {
212212
if (doIt(arg)) {
213213
return true;
214214
}

lib/IRGen/DebugTypeInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class DebugTypeInfo {
9393
bool isContextArchetype() const {
9494
if (auto archetype =
9595
Type->getWithoutSpecifierType()->getAs<ArchetypeType>()) {
96-
return !isa<OpaqueTypeArchetypeType>(archetype->getRoot());
96+
return !isa<OpaqueTypeArchetypeType>(archetype);
9797
}
9898
return false;
9999
}

lib/IRGen/GenReflection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ getRuntimeVersionThatSupportsDemanglingType(CanType type) {
200200
if (type->hasOpaqueArchetype()) {
201201
auto hasOpaqueAssocType = type.findIf([](CanType t) -> bool {
202202
if (auto a = dyn_cast<ArchetypeType>(t)) {
203-
return isa<OpaqueTypeArchetypeType>(a->getRoot()) &&
203+
return isa<OpaqueTypeArchetypeType>(a) &&
204204
a->getInterfaceType()->is<DependentMemberType>();
205205
}
206206
return false;

lib/IRGen/Outlining.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,10 @@ irgen::getTypeAndGenericSignatureForManglingOutlineFunction(SILType type) {
117117
GenericEnvironment *env = nullptr;
118118
loweredType.findIf([&env](Type t) -> bool {
119119
if (auto arch = t->getAs<ArchetypeType>()) {
120-
auto root = arch->getRoot();
121-
if (!isa<PrimaryArchetypeType>(root) &&
122-
!isa<VariadicSequenceType>(root))
120+
if (!isa<PrimaryArchetypeType>(arch) &&
121+
!isa<VariadicSequenceType>(arch))
123122
return false;
124-
env = root->getGenericEnvironment();
123+
env = arch->getGenericEnvironment();
125124
return true;
126125
}
127126
return false;

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,17 @@ static llvm::cl::opt<bool> AllowCriticalEdges("allow-critical-edges",
8686
/// Returns true if A is an opened existential type or is equal to an
8787
/// archetype from F's generic context.
8888
static bool isArchetypeValidInFunction(ArchetypeType *A, const SILFunction *F) {
89-
auto root = A->getRoot();
90-
if (!isa<PrimaryArchetypeType>(root) && !isa<SequenceArchetypeType>(root))
89+
if (!isa<PrimaryArchetypeType>(A) && !isa<SequenceArchetypeType>(A))
9190
return true;
92-
if (isa<OpenedArchetypeType>(root))
91+
if (isa<OpenedArchetypeType>(A))
9392
return true;
94-
if (isa<OpaqueTypeArchetypeType>(root))
93+
if (isa<OpaqueTypeArchetypeType>(A))
9594
return true;
9695

9796
// Ok, we have a primary archetype, make sure it is in the nested generic
9897
// environment of our caller.
9998
if (auto *genericEnv = F->getGenericEnvironment())
100-
if (root->getGenericEnvironment() == genericEnv)
99+
if (A->getGenericEnvironment() == genericEnv)
101100
return true;
102101

103102
return false;

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,11 +1092,11 @@ shouldBePartiallySpecialized(Type Replacement,
10921092
llvm::SmallSetVector<ArchetypeType *, 2> UsedArchetypes;
10931093
Replacement.visit([&](Type Ty) {
10941094
if (auto Archetype = Ty->getAs<ArchetypeType>()) {
1095-
if (auto Primary = dyn_cast<PrimaryArchetypeType>(Archetype->getRoot())) {
1095+
if (auto Primary = dyn_cast<PrimaryArchetypeType>(Archetype)) {
10961096
UsedArchetypes.insert(Primary);
10971097
}
10981098

1099-
if (auto Seq = dyn_cast<SequenceArchetypeType>(Archetype->getRoot())) {
1099+
if (auto Seq = dyn_cast<SequenceArchetypeType>(Archetype)) {
11001100
UsedArchetypes.insert(Seq);
11011101
}
11021102
}
@@ -1322,11 +1322,11 @@ void FunctionSignaturePartialSpecializer::collectUsedCallerArchetypes(
13221322
// Add used generic parameters/archetypes.
13231323
Replacement.visit([&](Type Ty) {
13241324
if (auto Archetype = Ty->getAs<ArchetypeType>()) {
1325-
if (auto Primary = dyn_cast<PrimaryArchetypeType>(Archetype->getRoot())) {
1325+
if (auto Primary = dyn_cast<PrimaryArchetypeType>(Archetype)) {
13261326
UsedCallerArchetypes.insert(Primary);
13271327
}
13281328

1329-
if (auto Seq = dyn_cast<SequenceArchetypeType>(Archetype->getRoot())) {
1329+
if (auto Seq = dyn_cast<SequenceArchetypeType>(Archetype)) {
13301330
UsedCallerArchetypes.insert(Seq);
13311331
}
13321332
}

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,8 +2849,8 @@ ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
28492849
// Handle opaque archetypes.
28502850
if (auto arch1 = type1->getAs<ArchetypeType>()) {
28512851
auto arch2 = type2->castTo<ArchetypeType>();
2852-
auto opaque1 = cast<OpaqueTypeArchetypeType>(arch1->getRoot());
2853-
auto opaque2 = cast<OpaqueTypeArchetypeType>(arch2->getRoot());
2852+
auto opaque1 = cast<OpaqueTypeArchetypeType>(arch1);
2853+
auto opaque2 = cast<OpaqueTypeArchetypeType>(arch2);
28542854
assert(opaque1->getDecl() == opaque2->getDecl());
28552855
assert(opaque1->getCanonicalInterfaceType(arch1->getInterfaceType())->isEqual(
28562856
opaque2->getCanonicalInterfaceType(arch2->getInterfaceType())));

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,14 +692,15 @@ static Type replaceArchetypesWithTypeVariables(ConstraintSystem &cs,
692692
return found->second;
693693

694694
if (auto archetypeType = dyn_cast<ArchetypeType>(origType)) {
695-
auto root = archetypeType->getRoot();
696695
// We leave opaque types and their nested associated types alone here.
697696
// They're globally available.
698-
if (isa<OpaqueTypeArchetypeType>(root))
697+
if (isa<OpaqueTypeArchetypeType>(archetypeType))
699698
return origType;
699+
700+
auto root = archetypeType->getRoot();
700701
// For other nested types, fail here so the default logic in subst()
701702
// for nested types applies.
702-
else if (root != archetypeType)
703+
if (root != archetypeType)
703704
return Type();
704705

705706
auto locator = cs.getConstraintLocator({});

0 commit comments

Comments
 (0)