Skip to content

Commit c441187

Browse files
committed
AST: Break circularity in PackArchetypeType::getReducedShape()
This can't happen yet, but with an upcoming change, we hit an infinite recursion here with PackExpansionType::get() -> getReducedShape() -> mapTypeIntoContext() -> PackExpansionType::get().
1 parent f61d8c5 commit c441187

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6414,7 +6414,7 @@ class PackArchetypeType final
64146414
LayoutConstraint Layout);
64156415

64166416
// Returns the reduced shape type for this pack archetype.
6417-
CanType getReducedShape() const;
6417+
CanType getReducedShape();
64186418

64196419
static bool classof(const TypeBase *T) {
64206420
return T->getKind() == TypeKind::PackArchetype;

lib/AST/Type.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3734,9 +3734,18 @@ PackArchetypeType::get(const ASTContext &Ctx,
37343734
{ShapeType}));
37353735
}
37363736

3737-
CanType PackArchetypeType::getReducedShape() const {
3737+
CanType PackArchetypeType::getReducedShape() {
3738+
// mapTypeIntoContext() also calls getReducedShape() via
3739+
// PackExpansionType::get(), so avoid that by short-circuiting
3740+
// the case where the pack archetype represents its own
3741+
// shape class.
37383742
auto shapeType = getTrailingObjects<PackShape>()->shapeType;
3739-
return getGenericEnvironment()->mapTypeIntoContext(shapeType)->getCanonicalType();
3743+
if (shapeType->isEqual(getInterfaceType()))
3744+
return CanType(this);
3745+
3746+
return getGenericEnvironment()
3747+
->mapTypeIntoContext(shapeType)
3748+
->getCanonicalType();
37403749
}
37413750

37423751
ElementArchetypeType::ElementArchetypeType(

0 commit comments

Comments
 (0)