Skip to content

Commit 6de85ee

Browse files
committed
[ParameterPack] Use the 'getTypeParameterPacks' utility when computing the
reduced shape of a given type that is not directly a pack type or archetype.
1 parent 16b9654 commit 6de85ee

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

lib/AST/ParameterPack.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ struct PackTypeParameterCollector: TypeWalker {
3939
if (paramTy->isParameterPack())
4040
typeParams.insert(paramTy);
4141
} else if (auto *archetypeTy = t->getAs<PackArchetypeType>()) {
42-
if (archetypeTy->isRoot())
43-
typeParams.insert(paramTy);
42+
typeParams.insert(archetypeTy->getRoot());
4443
}
4544

4645
return Action::Continue;
@@ -314,35 +313,20 @@ CanPackType PackType::getReducedShape() {
314313
}
315314

316315
CanType TypeBase::getReducedShape() {
316+
if (auto *packArchetype = getAs<PackArchetypeType>())
317+
return packArchetype->getReducedShape();
318+
317319
if (auto *packType = getAs<PackType>())
318320
return packType->getReducedShape();
319321

320322
if (auto *expansionType = getAs<PackExpansionType>())
321323
return expansionType->getReducedShape();
322324

323-
struct PatternTypeWalker : public TypeWalker {
324-
CanType shapeType;
325-
326-
Action walkToTypePre(Type type) override {
327-
// Don't consider pack references inside nested pack
328-
// expansion types.
329-
if (type->is<PackExpansionType>()) {
330-
return Action::Stop;
331-
}
332-
333-
if (auto *archetype = type->getAs<PackArchetypeType>()) {
334-
shapeType = archetype->getReducedShape();
335-
return Action::Stop;
336-
}
337-
338-
return Action::Continue;
339-
}
340-
} patternTypeWalker;
341-
342-
Type(this).walk(patternTypeWalker);
325+
SmallVector<Type, 2> rootParameterPacks;
326+
getTypeParameterPacks(rootParameterPacks);
343327

344-
if (patternTypeWalker.shapeType)
345-
return patternTypeWalker.shapeType;
328+
if (!rootParameterPacks.empty())
329+
return rootParameterPacks.front()->getReducedShape();
346330

347331
assert(!isTypeVariableOrMember());
348332
assert(!hasTypeParameter());

0 commit comments

Comments
 (0)