Skip to content

Commit 251c089

Browse files
committed
Remove some dead code; these operations are now done directly in
transformRec.
1 parent c041d10 commit 251c089

File tree

2 files changed

+0
-187
lines changed

2 files changed

+0
-187
lines changed

include/swift/AST/Types.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,8 +2449,6 @@ class TupleType final : public TypeBase, public llvm::FoldingSetNode,
24492449

24502450
bool containsPackExpansionType() const;
24512451

2452-
Type flattenPackTypes();
2453-
24542452
private:
24552453
TupleType(ArrayRef<TupleTypeElt> elements, const ASTContext *CanCtx,
24562454
RecursiveTypeProperties properties)
@@ -3520,8 +3518,6 @@ class AnyFunctionType : public TypeBase {
35203518

35213519
static bool containsPackExpansionType(ArrayRef<Param> params);
35223520

3523-
AnyFunctionType *flattenPackTypes();
3524-
35253521
static void printParams(ArrayRef<Param> Params, raw_ostream &OS,
35263522
const PrintOptions &PO = PrintOptions());
35273523
static void printParams(ArrayRef<Param> Params, ASTPrinter &Printer,
@@ -6842,8 +6838,6 @@ class PackType final : public TypeBase, public llvm::FoldingSetNode,
68426838

68436839
bool containsPackExpansionType() const;
68446840

6845-
PackType *flattenPackTypes();
6846-
68476841
CanTypeWrapper<PackType> getReducedShape();
68486842

68496843
public:
@@ -6938,8 +6932,6 @@ class PackExpansionType : public TypeBase, public llvm::FoldingSetNode {
69386932
/// Retrieves the count type of this pack expansion.
69396933
Type getCountType() const { return countType; }
69406934

6941-
PackExpansionType *expand();
6942-
69436935
CanType getReducedShape();
69446936

69456937
public:

lib/AST/ParameterPack.cpp

Lines changed: 0 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -94,60 +94,6 @@ PackType *TypeBase::getPackSubstitutionAsPackType() {
9494
}
9595
}
9696

97-
/// G<{X1, ..., Xn}, {Y1, ..., Yn}>... => {G<X1, Y1>, ..., G<Xn, Yn>}...
98-
PackExpansionType *PackExpansionType::expand() {
99-
auto countType = getCountType();
100-
auto *countPack = countType->getAs<PackType>();
101-
if (countPack == nullptr)
102-
return this;
103-
104-
auto patternType = getPatternType();
105-
if (patternType->is<PackType>())
106-
return this;
107-
108-
unsigned j = 0;
109-
SmallVector<Type, 4> expandedTypes;
110-
for (auto type : countPack->getElementTypes()) {
111-
Type expandedCount;
112-
if (auto *expansion = type->getAs<PackExpansionType>())
113-
expandedCount = expansion->getCountType();
114-
115-
auto expandedPattern = patternType.transformRec(
116-
[&](Type t) -> Optional<Type> {
117-
if (t->is<PackExpansionType>())
118-
return t;
119-
120-
if (auto *nestedPack = t->getAs<PackType>()) {
121-
auto nestedPackElts = nestedPack->getElementTypes();
122-
if (j < nestedPackElts.size()) {
123-
if (expandedCount) {
124-
if (auto *expansion = nestedPackElts[j]->getAs<PackExpansionType>())
125-
return expansion->getPatternType();
126-
} else {
127-
return nestedPackElts[j];
128-
}
129-
}
130-
131-
return ErrorType::get(t->getASTContext());
132-
}
133-
134-
return None;
135-
});
136-
137-
if (expandedCount) {
138-
expandedTypes.push_back(PackExpansionType::get(expandedPattern,
139-
expandedCount));
140-
} else {
141-
expandedTypes.push_back(expandedPattern);
142-
}
143-
144-
++j;
145-
}
146-
147-
auto *packType = PackType::get(getASTContext(), expandedTypes);
148-
return PackExpansionType::get(packType, countType);
149-
}
150-
15197
CanType PackExpansionType::getReducedShape() {
15298
auto reducedShape = countType->getReducedShape();
15399
if (reducedShape == getASTContext().TheEmptyTupleType)
@@ -174,54 +120,6 @@ bool CanTupleType::containsPackExpansionTypeImpl(CanTupleType tuple) {
174120
return false;
175121
}
176122

177-
/// (W, {X, Y}..., Z) => (W, X, Y, Z)
178-
Type TupleType::flattenPackTypes() {
179-
bool anyChanged = false;
180-
SmallVector<TupleTypeElt, 4> elts;
181-
182-
for (unsigned i = 0, e = getNumElements(); i < e; ++i) {
183-
auto elt = getElement(i);
184-
185-
if (auto *expansionType = elt.getType()->getAs<PackExpansionType>()) {
186-
if (auto *packType = expansionType->getPatternType()->getAs<PackType>()) {
187-
if (!anyChanged) {
188-
elts.append(getElements().begin(), getElements().begin() + i);
189-
anyChanged = true;
190-
}
191-
192-
bool first = true;
193-
for (auto packElt : packType->getElementTypes()) {
194-
if (first) {
195-
elts.push_back(TupleTypeElt(packElt, elt.getName()));
196-
first = false;
197-
continue;
198-
}
199-
elts.push_back(TupleTypeElt(packElt));
200-
}
201-
202-
continue;
203-
}
204-
}
205-
206-
if (anyChanged)
207-
elts.push_back(elt);
208-
}
209-
210-
if (!anyChanged)
211-
return this;
212-
213-
// If pack substitution yields a single-element tuple, the tuple
214-
// structure is flattened to produce the element type.
215-
if (elts.size() == 1) {
216-
auto type = elts.front().getType();
217-
if (!type->is<PackExpansionType>() && !type->is<TypeVariableType>()) {
218-
return type;
219-
}
220-
}
221-
222-
return TupleType::get(elts, getASTContext());
223-
}
224-
225123
bool AnyFunctionType::containsPackExpansionType(ArrayRef<Param> params) {
226124
for (auto param : params) {
227125
if (param.getPlainType()->is<PackExpansionType>())
@@ -231,50 +129,6 @@ bool AnyFunctionType::containsPackExpansionType(ArrayRef<Param> params) {
231129
return false;
232130
}
233131

234-
/// (W, {X, Y}..., Z) -> T => (W, X, Y, Z) -> T
235-
AnyFunctionType *AnyFunctionType::flattenPackTypes() {
236-
bool anyChanged = false;
237-
SmallVector<AnyFunctionType::Param, 4> params;
238-
239-
for (unsigned i = 0, e = getParams().size(); i < e; ++i) {
240-
auto param = getParams()[i];
241-
242-
if (auto *expansionType = param.getPlainType()->getAs<PackExpansionType>()) {
243-
if (auto *packType = expansionType->getPatternType()->getAs<PackType>()) {
244-
if (!anyChanged) {
245-
params.append(getParams().begin(), getParams().begin() + i);
246-
anyChanged = true;
247-
}
248-
249-
bool first = true;
250-
for (auto packElt : packType->getElementTypes()) {
251-
if (first) {
252-
params.push_back(param.withType(packElt));
253-
first = false;
254-
continue;
255-
}
256-
params.push_back(param.withType(packElt).getWithoutLabels());
257-
}
258-
259-
continue;
260-
}
261-
}
262-
263-
if (anyChanged)
264-
params.push_back(param);
265-
}
266-
267-
if (!anyChanged)
268-
return this;
269-
270-
if (auto *genericFuncType = getAs<GenericFunctionType>()) {
271-
return GenericFunctionType::get(genericFuncType->getGenericSignature(),
272-
params, getResult(), getExtInfo());
273-
} else {
274-
return FunctionType::get(params, getResult(), getExtInfo());
275-
}
276-
}
277-
278132
bool PackType::containsPackExpansionType() const {
279133
for (auto type : getElementTypes()) {
280134
if (type->is<PackExpansionType>())
@@ -284,39 +138,6 @@ bool PackType::containsPackExpansionType() const {
284138
return false;
285139
}
286140

287-
/// {W, {X, Y}..., Z} => {W, X, Y, Z}
288-
PackType *PackType::flattenPackTypes() {
289-
bool anyChanged = false;
290-
SmallVector<Type, 4> elts;
291-
292-
for (unsigned i = 0, e = getNumElements(); i < e; ++i) {
293-
auto elt = getElementType(i);
294-
295-
if (auto *expansionType = elt->getAs<PackExpansionType>()) {
296-
if (auto *packType = expansionType->getPatternType()->getAs<PackType>()) {
297-
if (!anyChanged) {
298-
elts.append(getElementTypes().begin(), getElementTypes().begin() + i);
299-
anyChanged = true;
300-
}
301-
302-
for (auto packElt : packType->getElementTypes()) {
303-
elts.push_back(packElt);
304-
}
305-
306-
continue;
307-
}
308-
}
309-
310-
if (anyChanged)
311-
elts.push_back(elt);
312-
}
313-
314-
if (!anyChanged)
315-
return this;
316-
317-
return PackType::get(getASTContext(), elts);
318-
}
319-
320141
template <class T>
321142
static CanPackType getReducedShapeOfPack(const ASTContext &ctx,
322143
const T &elementTypes) {

0 commit comments

Comments
 (0)