Skip to content

Commit 0bfbc53

Browse files
committed
AST: Simplify TypeSubstituter::transformOpaqueTypeArchetypeType()
1 parent cf784f9 commit 0bfbc53

File tree

1 file changed

+9
-29
lines changed

1 file changed

+9
-29
lines changed

lib/AST/TypeSubstitution.cpp

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -563,35 +563,15 @@ TypeSubstituter::transformOpaqueTypeArchetypeType(OpaqueTypeArchetypeType *opaqu
563563
if (!IFS.shouldSubstituteOpaqueArchetypes())
564564
return std::nullopt;
565565

566-
// If we have a substitution for this type, use it.
567-
if (auto known = IFS.substType(opaque, level)) {
568-
if (known->getCanonicalType() == opaque->getCanonicalType())
569-
return std::nullopt; // Recursively process the substitutions of the
570-
// opaque type archetype.
571-
return known;
572-
}
573-
574-
if (opaque->isRoot())
575-
return ErrorType::get(opaque);
576-
577-
// For nested archetypes, we can substitute the parent.
578-
Type origParent = opaque->getParent();
579-
assert(origParent && "Not a nested archetype");
580-
581-
// Substitute into the parent type.
582-
Type substParent = doIt(origParent, TypePosition::Invariant);
583-
584-
// If the parent didn't change, we won't change.
585-
if (substParent.getPointer() == origParent.getPointer())
586-
return Type(opaque);
587-
588-
// Get the associated type reference from a child archetype.
589-
AssociatedTypeDecl *assocType = opaque->getInterfaceType()
590-
->castTo<DependentMemberType>()->getAssocType();
591-
592-
return getMemberForBaseType(IFS, origParent, substParent,
593-
assocType, assocType->getName(),
594-
level);
566+
auto known = IFS.substType(opaque, level);
567+
ASSERT(known && "Opaque type replacement shouldn't fail");
568+
569+
// If we return an opaque archetype unchanged, recurse into its substitutions
570+
// as a special case.
571+
if (known->getCanonicalType() == opaque->getCanonicalType())
572+
return std::nullopt; // Recursively process the substitutions of the
573+
// opaque type archetype.
574+
return known;
595575
}
596576

597577
std::optional<Type>

0 commit comments

Comments
 (0)