Skip to content

Commit 5d1c423

Browse files
committed
AST: Simplify TypeSubstituter::transformOpaqueTypeArchetypeType()
1 parent afbe232 commit 5d1c423

File tree

1 file changed

+6
-28
lines changed

1 file changed

+6
-28
lines changed

lib/AST/TypeSubstitution.cpp

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -568,35 +568,13 @@ TypeSubstituter::transformOpaqueTypeArchetypeType(OpaqueTypeArchetypeType *opaqu
568568
if (!IFS.shouldSubstituteOpaqueArchetypes())
569569
return std::nullopt;
570570

571-
// If we have a substitution for this type, use it.
572-
if (auto known = IFS.substType(opaque, level)) {
573-
if (known->getCanonicalType() == opaque->getCanonicalType())
574-
return std::nullopt; // Recursively process the substitutions of the
575-
// opaque type archetype.
576-
return known;
577-
}
578-
579-
if (opaque->isRoot())
580-
return ErrorType::get(opaque);
581-
582-
// For nested archetypes, we can substitute the parent.
583-
Type origParent = opaque->getParent();
584-
assert(origParent && "Not a nested archetype");
585-
586-
// Substitute into the parent type.
587-
Type substParent = doIt(origParent, TypePosition::Invariant);
571+
auto known = IFS.substType(opaque, level);
572+
ASSERT(known && "Opaque type replacement shouldn't fail");
588573

589-
// If the parent didn't change, we won't change.
590-
if (substParent.getPointer() == origParent.getPointer())
591-
return Type(opaque);
592-
593-
// Get the associated type reference from a child archetype.
594-
AssociatedTypeDecl *assocType = opaque->getInterfaceType()
595-
->castTo<DependentMemberType>()->getAssocType();
596-
597-
return getMemberForBaseType(IFS, origParent, substParent,
598-
assocType, assocType->getName(),
599-
level);
574+
if (known->getCanonicalType() == opaque->getCanonicalType())
575+
return std::nullopt; // Recursively process the substitutions of the
576+
// opaque type archetype.
577+
return known;
600578
}
601579

602580
std::optional<Type>

0 commit comments

Comments
 (0)