@@ -185,22 +185,14 @@ void InFlightSubstitution::expandPackExpansionShape(Type origShape,
185185 ActivePackExpansions.pop_back ();
186186}
187187
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);
193192
194193 // FIXME: All the logic around 'level' is probably slightly wrong, and in
195194 // the unlikely event that it is correct, at the very least warrants a
196195 // 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-
204196 unsigned outerLevel = 0 ;
205197 if (!getOptions ().contains (SubstFlags::PreservePackExpansionLevel)) {
206198 for (const auto &activeExpansion : outerExpansions) {
@@ -241,17 +233,24 @@ Type InFlightSubstitution::substType(SubstitutableType *origType,
241233 }
242234}
243235
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);
253246
254- auto substPackConf = substConfRef.getPack ();
247+ return substType;
248+ }
249+
250+ ProtocolConformanceRef
251+ InFlightSubstitution::projectLaneFromPackConformance (
252+ PackConformance *substPackConf,
253+ unsigned level) {
255254 auto substPackPatterns = substPackConf->getPatternConformances ();
256255 assert (level < ActivePackExpansions.size () && " too deep" );
257256 auto index = ActivePackExpansions[ActivePackExpansions.size () - level - 1 ]
@@ -262,6 +261,19 @@ InFlightSubstitution::lookupConformance(Type dependentType,
262261 return substPackPatterns[index];
263262}
264263
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+
265277namespace {
266278
267279class TypeSubstituter : public TypeTransform <TypeSubstituter> {
0 commit comments