@@ -272,61 +272,31 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
272272
273273 auto path = genericSig->getConformancePath (type, proto);
274274
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+ }
283295 }
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);
296296 }
297297
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 );
330300 }
331301
332302 return conformance;
@@ -473,16 +443,18 @@ Type QueryOverrideSubs::operator()(SubstitutableType *type) const {
473443}
474444
475445ProtocolConformanceRef
476- LookUpConformanceInOverrideSubs::operator ()(CanType type ,
477- Type substType ,
446+ LookUpConformanceInOverrideSubs::operator ()(InFlightSubstitution &IFS ,
447+ Type type ,
478448 ProtocolDecl *proto) const {
479449 if (type->getRootGenericParam ()->getDepth () >= info.BaseDepth )
480- return ProtocolConformanceRef::forAbstract (substType , proto);
450+ return ProtocolConformanceRef::forAbstract (type. subst (IFS) , proto);
481451
482- if (auto conformance = info.BaseSubMap .lookupConformance (type, proto))
452+ if (auto conformance = info.BaseSubMap .lookupConformance (
453+ type->getCanonicalType (), proto)) {
483454 return conformance;
455+ }
484456
485- return lookupConformance (substType , proto);
457+ return lookupConformance (type. subst (IFS) , proto);
486458}
487459
488460SubstitutionMap
@@ -665,8 +637,8 @@ Type OuterSubstitutions::operator()(SubstitutableType *type) const {
665637}
666638
667639ProtocolConformanceRef OuterSubstitutions::operator ()(
668- CanType dependentType ,
669- Type conformingReplacementType ,
640+ InFlightSubstitution &IFS ,
641+ Type dependentType ,
670642 ProtocolDecl *conformedProtocol) const {
671643 auto sig = subs.getGenericSignature ();
672644 if (!sig->isValidTypeParameter (dependentType) ||
@@ -683,10 +655,10 @@ ProtocolConformanceRef OuterSubstitutions::operator()(
683655 // Once we check for that and handle it properly, the lookupConformance()
684656 // can become a forAbstract().
685657 return swift::lookupConformance (
686- conformingReplacementType , conformedProtocol);
658+ dependentType. subst (IFS) , conformedProtocol);
687659 }
688660
689661 return LookUpConformanceInSubstitutionMap (subs)(
690- dependentType, conformingReplacementType , conformedProtocol);
662+ IFS, dependentType , conformedProtocol);
691663}
692664
0 commit comments