18
18
#include " swift/AST/PackConformance.h"
19
19
#include " swift/AST/ASTContext.h"
20
20
#include " swift/AST/Decl.h"
21
+ #include " swift/AST/InFlightSubstitution.h"
21
22
#include " swift/AST/Module.h"
22
23
#include " swift/AST/Types.h"
23
24
@@ -162,9 +163,8 @@ PackConformance *PackConformance::getAssociatedConformance(
162
163
163
164
ProtocolConformanceRef PackConformance::subst (SubstitutionMap subMap,
164
165
SubstOptions options) const {
165
- return subst (QuerySubstitutionMap{subMap},
166
- LookUpConformanceInSubstitutionMap (subMap),
167
- options);
166
+ InFlightSubstitutionViaSubMap IFS (subMap, options);
167
+ return subst (IFS);
168
168
}
169
169
170
170
// TODO: Move this elsewhere since it's generally useful
@@ -206,14 +206,9 @@ namespace {
206
206
template <typename ImplClass>
207
207
class PackExpander {
208
208
protected:
209
- TypeSubstitutionFn subs;
210
- LookupConformanceFn conformances;
211
- SubstOptions options;
209
+ InFlightSubstitution &IFS;
212
210
213
- PackExpander (TypeSubstitutionFn subs,
214
- LookupConformanceFn conformances,
215
- SubstOptions options)
216
- : subs(subs), conformances(conformances), options(options) {}
211
+ PackExpander (InFlightSubstitution &IFS) : IFS(IFS) {}
217
212
218
213
ImplClass *asImpl () {
219
214
return static_cast <ImplClass *>(this );
@@ -233,7 +228,7 @@ class PackExpander {
233
228
// the expanded count pack type.
234
229
llvm::SmallDenseMap<Type, PackType *, 2 > expandedPacks;
235
230
for (auto origParamType : rootParameterPacks) {
236
- auto substParamType = origParamType.subst (subs, conformances, options );
231
+ auto substParamType = origParamType.subst (IFS );
237
232
238
233
if (auto expandedParamType = substParamType->template getAs <PackType>()) {
239
234
assert (arePackShapesEqual (expandedParamType, expandedCountType) &&
@@ -262,7 +257,7 @@ class PackExpander {
262
257
}
263
258
264
259
// Compute the substituted type using our parent substitutions.
265
- auto substType = Type (type).subst (subs, conformances, options );
260
+ auto substType = Type (type).subst (IFS );
266
261
267
262
// If the substituted type is a pack, project the jth element.
268
263
if (isRootParameterPack (type)) {
@@ -277,12 +272,13 @@ class PackExpander {
277
272
return packType->getElementType (j);
278
273
}
279
274
280
- return subs (type);
275
+ return IFS. substType (type);
281
276
};
282
277
283
278
auto projectedConformances = [&](CanType origType, Type substType,
284
279
ProtocolDecl *proto) -> ProtocolConformanceRef {
285
- auto substConformance = conformances (origType, substType, proto);
280
+ auto substConformance =
281
+ IFS.lookupConformance (origType, substType, proto);
286
282
287
283
// If the substituted conformance is a pack, project the jth element.
288
284
if (isRootedInParameterPack (origType)) {
@@ -294,7 +290,7 @@ class PackExpander {
294
290
295
291
auto origCountElement = expandedCountType->getElementType (j);
296
292
auto substCountElement = origCountElement.subst (
297
- projectedSubs, projectedConformances, options );
293
+ projectedSubs, projectedConformances, IFS. getOptions () );
298
294
299
295
asImpl ()->add (origCountElement, substCountElement, i);
300
296
}
@@ -304,7 +300,7 @@ class PackExpander {
304
300
// / form a new pack expansion.
305
301
void addUnexpandedExpansion (Type origPatternType, Type substCountType,
306
302
unsigned i) {
307
- auto substPatternType = origPatternType.subst (subs, conformances, options );
303
+ auto substPatternType = origPatternType.subst (IFS );
308
304
auto substExpansion = PackExpansionType::get (substPatternType, substCountType);
309
305
310
306
asImpl ()->add (origPatternType, substExpansion, i);
@@ -313,7 +309,7 @@ class PackExpander {
313
309
// / Scalar elements of the original pack are substituted and added to the
314
310
// / flattened pack.
315
311
void addScalar (Type origElement, unsigned i) {
316
- auto substElement = origElement.subst (subs, conformances, options );
312
+ auto substElement = origElement.subst (IFS );
317
313
318
314
asImpl ()->add (origElement, substElement, i);
319
315
}
@@ -323,7 +319,7 @@ class PackExpander {
323
319
auto origPatternType = origExpansion->getPatternType ();
324
320
auto origCountType = origExpansion->getCountType ();
325
321
326
- auto substCountType = origCountType.subst (subs, conformances, options );
322
+ auto substCountType = origCountType.subst (IFS );
327
323
328
324
// If the substituted count type is a pack, we're expanding the
329
325
// original element.
@@ -358,19 +354,16 @@ class PackConformanceExpander : public PackExpander<PackConformanceExpander> {
358
354
359
355
ArrayRef<ProtocolConformanceRef> origConformances;
360
356
361
- PackConformanceExpander (TypeSubstitutionFn subs,
362
- LookupConformanceFn conformances,
363
- SubstOptions options,
357
+ PackConformanceExpander (InFlightSubstitution &IFS,
364
358
ArrayRef<ProtocolConformanceRef> origConformances)
365
- : PackExpander(subs, conformances, options),
366
- origConformances (origConformances) {}
359
+ : PackExpander(IFS), origConformances(origConformances) {}
367
360
368
361
void add (Type origType, Type substType, unsigned i) {
369
362
substElements.push_back (substType);
370
363
371
364
// FIXME: Pass down projection callbacks
372
365
substConformances.push_back (origConformances[i].subst (
373
- origType, subs, conformances, options ));
366
+ origType, IFS ));
374
367
}
375
368
};
376
369
@@ -379,8 +372,13 @@ class PackConformanceExpander : public PackExpander<PackConformanceExpander> {
379
372
ProtocolConformanceRef PackConformance::subst (TypeSubstitutionFn subs,
380
373
LookupConformanceFn conformances,
381
374
SubstOptions options) const {
382
- PackConformanceExpander expander (subs, conformances, options,
383
- getPatternConformances ());
375
+ InFlightSubstitution IFS (subs, conformances, options);
376
+ return subst (IFS);
377
+ }
378
+
379
+ ProtocolConformanceRef
380
+ PackConformance::subst (InFlightSubstitution &IFS) const {
381
+ PackConformanceExpander expander (IFS, getPatternConformances ());
384
382
expander.expand (ConformingType);
385
383
386
384
auto &ctx = Protocol->getASTContext ();
0 commit comments