@@ -94,60 +94,6 @@ PackType *TypeBase::getPackSubstitutionAsPackType() {
94
94
}
95
95
}
96
96
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
-
151
97
CanType PackExpansionType::getReducedShape () {
152
98
auto reducedShape = countType->getReducedShape ();
153
99
if (reducedShape == getASTContext ().TheEmptyTupleType )
@@ -174,54 +120,6 @@ bool CanTupleType::containsPackExpansionTypeImpl(CanTupleType tuple) {
174
120
return false ;
175
121
}
176
122
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
-
225
123
bool AnyFunctionType::containsPackExpansionType (ArrayRef<Param> params) {
226
124
for (auto param : params) {
227
125
if (param.getPlainType ()->is <PackExpansionType>())
@@ -231,50 +129,6 @@ bool AnyFunctionType::containsPackExpansionType(ArrayRef<Param> params) {
231
129
return false ;
232
130
}
233
131
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
-
278
132
bool PackType::containsPackExpansionType () const {
279
133
for (auto type : getElementTypes ()) {
280
134
if (type->is <PackExpansionType>())
@@ -284,39 +138,6 @@ bool PackType::containsPackExpansionType() const {
284
138
return false ;
285
139
}
286
140
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
-
320
141
template <class T >
321
142
static CanPackType getReducedShapeOfPack (const ASTContext &ctx,
322
143
const T &elementTypes) {
0 commit comments