@@ -272,61 +272,31 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
272
272
273
273
auto path = genericSig->getConformancePath (type, proto);
274
274
275
- ProtocolConformanceRef conformance;
276
- for (const auto &step : path) {
277
- // For the first step, grab the initial conformance.
278
- if (conformance.isInvalid ()) {
279
- if (auto initialConformance = getSignatureConformance (
280
- step.first , step.second )) {
281
- conformance = *initialConformance;
282
- continue ;
275
+ // For the first step, grab the initial conformance.
276
+ auto iter = path.begin ();
277
+ const auto step = *iter++;
278
+
279
+ ProtocolConformanceRef conformance =
280
+ *getSignatureConformance (step.first , step.second );
281
+
282
+ // For each remaining step, project an associated conformance.
283
+ while (iter != path.end ()) {
284
+ // FIXME: Remove this hack. It is unsound, because we may not have diagnosed
285
+ // anything but still end up with an ErrorType in the AST.
286
+ if (conformance.isConcrete ()) {
287
+ auto concrete = conformance.getConcrete ();
288
+ auto normal = concrete->getRootNormalConformance ();
289
+
290
+ if (!normal->hasComputedAssociatedConformances ()) {
291
+ if (proto->getASTContext ().evaluator .hasActiveRequest (
292
+ ResolveTypeWitnessesRequest{normal})) {
293
+ return ProtocolConformanceRef::forInvalid ();
294
+ }
283
295
}
284
-
285
- // We couldn't find the initial conformance, fail.
286
- return ProtocolConformanceRef::forInvalid ();
287
- }
288
-
289
- // If we've hit an abstract conformance, everything from here on out is
290
- // abstract.
291
- // FIXME: This may not always be true, but it holds for now.
292
- if (conformance.isAbstract ()) {
293
- // FIXME: Rip this out once we can get a concrete conformance from
294
- // an archetype.
295
- return swift::lookupConformance (type.subst (*this ), proto);
296
296
}
297
297
298
- // For the second step, we're looking into the requirement signature for
299
- // this protocol.
300
- if (conformance.isPack ()) {
301
- auto pack = conformance.getPack ();
302
- conformance = ProtocolConformanceRef (
303
- pack->getAssociatedConformance (step.first , step.second ));
304
- if (conformance.isInvalid ())
305
- return conformance;
306
-
307
- continue ;
308
- }
309
-
310
- auto concrete = conformance.getConcrete ();
311
- auto normal = concrete->getRootNormalConformance ();
312
-
313
- // If we haven't set the signature conformances yet, force the issue now.
314
- if (!normal->hasComputedAssociatedConformances ()) {
315
- // If we're in the process of checking the type witnesses, fail
316
- // gracefully.
317
- //
318
- // FIXME: This is unsound, because we may not have diagnosed anything but
319
- // still end up with an ErrorType in the AST.
320
- if (proto->getASTContext ().evaluator .hasActiveRequest (
321
- ResolveTypeWitnessesRequest{normal})) {
322
- return ProtocolConformanceRef::forInvalid ();
323
- }
324
- }
325
-
326
- // Get the associated conformance.
327
- conformance = concrete->getAssociatedConformance (step.first , step.second );
328
- if (conformance.isInvalid ())
329
- return conformance;
298
+ const auto step = *iter++;
299
+ conformance = conformance.getAssociatedConformance (step.first , step.second );
330
300
}
331
301
332
302
return conformance;
@@ -473,16 +443,18 @@ Type QueryOverrideSubs::operator()(SubstitutableType *type) const {
473
443
}
474
444
475
445
ProtocolConformanceRef
476
- LookUpConformanceInOverrideSubs::operator ()(CanType type ,
477
- Type substType ,
446
+ LookUpConformanceInOverrideSubs::operator ()(InFlightSubstitution &IFS ,
447
+ Type type ,
478
448
ProtocolDecl *proto) const {
479
449
if (type->getRootGenericParam ()->getDepth () >= info.BaseDepth )
480
- return ProtocolConformanceRef::forAbstract (substType , proto);
450
+ return ProtocolConformanceRef::forAbstract (type. subst (IFS) , proto);
481
451
482
- if (auto conformance = info.BaseSubMap .lookupConformance (type, proto))
452
+ if (auto conformance = info.BaseSubMap .lookupConformance (
453
+ type->getCanonicalType (), proto)) {
483
454
return conformance;
455
+ }
484
456
485
- return lookupConformance (substType , proto);
457
+ return lookupConformance (type. subst (IFS) , proto);
486
458
}
487
459
488
460
SubstitutionMap
@@ -665,8 +637,8 @@ Type OuterSubstitutions::operator()(SubstitutableType *type) const {
665
637
}
666
638
667
639
ProtocolConformanceRef OuterSubstitutions::operator ()(
668
- CanType dependentType ,
669
- Type conformingReplacementType ,
640
+ InFlightSubstitution &IFS ,
641
+ Type dependentType ,
670
642
ProtocolDecl *conformedProtocol) const {
671
643
auto sig = subs.getGenericSignature ();
672
644
if (!sig->isValidTypeParameter (dependentType) ||
@@ -683,10 +655,10 @@ ProtocolConformanceRef OuterSubstitutions::operator()(
683
655
// Once we check for that and handle it properly, the lookupConformance()
684
656
// can become a forAbstract().
685
657
return swift::lookupConformance (
686
- conformingReplacementType , conformedProtocol);
658
+ dependentType. subst (IFS) , conformedProtocol);
687
659
}
688
660
689
661
return LookUpConformanceInSubstitutionMap (subs)(
690
- dependentType, conformingReplacementType , conformedProtocol);
662
+ IFS, dependentType , conformedProtocol);
691
663
}
692
664
0 commit comments