|
24 | 24 |
|
25 | 25 | using namespace swift;
|
26 | 26 |
|
27 |
| -void TypeBase::getTypeParameterPacks( |
28 |
| - SmallVectorImpl<Type> &rootParameterPacks) const { |
29 |
| - llvm::SmallDenseSet<CanType, 2> visited; |
| 27 | +namespace { |
| 28 | + |
| 29 | +/// Collects all unique pack type parameters referenced from the pattern type, |
| 30 | +/// skipping those captured by nested pack expansion types. |
| 31 | +struct PackTypeParameterCollector: TypeWalker { |
| 32 | + llvm::SetVector<Type> typeParams; |
30 | 33 |
|
31 |
| - auto recordType = [&](Type t) { |
32 |
| - if (visited.insert(t->getCanonicalType()).second) |
33 |
| - rootParameterPacks.push_back(t); |
34 |
| - }; |
| 34 | + Action walkToTypePre(Type t) override { |
| 35 | + if (t->is<PackExpansionType>()) |
| 36 | + return Action::SkipChildren; |
35 | 37 |
|
36 |
| - Type(const_cast<TypeBase *>(this)).visit([&](Type t) { |
37 | 38 | if (auto *paramTy = t->getAs<GenericTypeParamType>()) {
|
38 |
| - if (paramTy->isParameterPack()) { |
39 |
| - recordType(paramTy); |
40 |
| - } |
| 39 | + if (paramTy->isParameterPack()) |
| 40 | + typeParams.insert(paramTy); |
41 | 41 | } else if (auto *archetypeTy = t->getAs<PackArchetypeType>()) {
|
42 |
| - if (archetypeTy->isRoot()) { |
43 |
| - recordType(t); |
44 |
| - } |
| 42 | + if (archetypeTy->isRoot()) |
| 43 | + typeParams.insert(paramTy); |
45 | 44 | }
|
46 |
| - }); |
| 45 | + |
| 46 | + return Action::Continue; |
| 47 | + } |
| 48 | +}; |
| 49 | + |
| 50 | +} |
| 51 | + |
| 52 | +void TypeBase::getTypeParameterPacks( |
| 53 | + SmallVectorImpl<Type> &rootParameterPacks) { |
| 54 | + PackTypeParameterCollector collector; |
| 55 | + Type(this).walk(collector); |
| 56 | + |
| 57 | + rootParameterPacks.append(collector.typeParams.begin(), |
| 58 | + collector.typeParams.end()); |
47 | 59 | }
|
48 | 60 |
|
49 | 61 | bool GenericTypeParamType::isParameterPack() const {
|
|
0 commit comments