@@ -185,22 +185,14 @@ void InFlightSubstitution::expandPackExpansionShape(Type origShape,
185
185
ActivePackExpansions.pop_back ();
186
186
}
187
187
188
- Type InFlightSubstitution::substType (SubstitutableType *origType,
189
- unsigned level) {
190
- auto substType = BaselineSubstType (origType);
191
- if (!substType)
192
- return Type ();
188
+ Type InFlightSubstitution::projectLaneFromPackType (Type substType,
189
+ unsigned level) {
190
+ auto outerExpansions = ArrayRef (ActivePackExpansions).drop_back (level);
191
+ auto innerExpansions = ArrayRef (ActivePackExpansions).take_back (level);
193
192
194
193
// FIXME: All the logic around 'level' is probably slightly wrong, and in
195
194
// the unlikely event that it is correct, at the very least warrants a
196
195
// detailed explanation.
197
-
198
- if (ActivePackExpansions.empty ())
199
- return substType->increasePackElementLevel (level);
200
-
201
- auto outerExpansions = ArrayRef (ActivePackExpansions).drop_back (level);
202
- auto innerExpansions = ArrayRef (ActivePackExpansions).take_back (level);
203
-
204
196
unsigned outerLevel = 0 ;
205
197
if (!getOptions ().contains (SubstFlags::PreservePackExpansionLevel)) {
206
198
for (const auto &activeExpansion : outerExpansions) {
@@ -241,17 +233,24 @@ Type InFlightSubstitution::substType(SubstitutableType *origType,
241
233
}
242
234
}
243
235
244
- ProtocolConformanceRef
245
- InFlightSubstitution::lookupConformance (Type dependentType,
246
- ProtocolDecl *proto,
247
- unsigned level) {
248
- auto substConfRef = BaselineLookupConformance (*this , dependentType, proto);
249
- if (!substConfRef ||
250
- ActivePackExpansions.empty () ||
251
- !substConfRef.isPack ())
252
- return substConfRef;
236
+ Type InFlightSubstitution::substType (SubstitutableType *origType,
237
+ unsigned level) {
238
+ auto substType = BaselineSubstType (origType);
239
+ if (!substType)
240
+ return Type ();
241
+
242
+ if (!ActivePackExpansions.empty ())
243
+ substType = projectLaneFromPackType (substType, level);
244
+ else
245
+ substType = substType->increasePackElementLevel (level);
253
246
254
- auto substPackConf = substConfRef.getPack ();
247
+ return substType;
248
+ }
249
+
250
+ ProtocolConformanceRef
251
+ InFlightSubstitution::projectLaneFromPackConformance (
252
+ PackConformance *substPackConf,
253
+ unsigned level) {
255
254
auto substPackPatterns = substPackConf->getPatternConformances ();
256
255
assert (level < ActivePackExpansions.size () && " too deep" );
257
256
auto index = ActivePackExpansions[ActivePackExpansions.size () - level - 1 ]
@@ -262,6 +261,19 @@ InFlightSubstitution::lookupConformance(Type dependentType,
262
261
return substPackPatterns[index];
263
262
}
264
263
264
+ ProtocolConformanceRef
265
+ InFlightSubstitution::lookupConformance (Type dependentType,
266
+ ProtocolDecl *proto,
267
+ unsigned level) {
268
+ auto substConfRef = BaselineLookupConformance (*this , dependentType, proto);
269
+ if (!ActivePackExpansions.empty () && substConfRef.isPack ()) {
270
+ substConfRef = projectLaneFromPackConformance (
271
+ substConfRef.getPack (), level);
272
+ }
273
+
274
+ return substConfRef;
275
+ }
276
+
265
277
namespace {
266
278
267
279
class TypeSubstituter : public TypeTransform <TypeSubstituter> {
0 commit comments