Skip to content

Commit 53e7803

Browse files
committed
AST: Simplify TypeSubstituter::transformOpaqueTypeArchetypeType()
1 parent afbe232 commit 53e7803

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
@@ -568,35 +568,15 @@ 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);
588-
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);
571+
auto known = IFS.substType(opaque, level);
572+
ASSERT(known && "Opaque type replacement shouldn't fail");
573+
574+
// If we return an opaque archetype unchanged, recurse into its substitutions
575+
// as a special case.
576+
if (known->getCanonicalType() == opaque->getCanonicalType())
577+
return std::nullopt; // Recursively process the substitutions of the
578+
// opaque type archetype.
579+
return known;
600580
}
601581

602582
std::optional<Type>

0 commit comments

Comments
 (0)