@@ -1108,37 +1108,23 @@ ProtocolConformanceRef swift::substOpaqueTypesWithUnderlyingTypes(
11081108ProtocolConformanceRef ReplaceOpaqueTypesWithUnderlyingTypes::
11091109operator ()(CanType maybeOpaqueType, Type replacementType,
11101110 ProtocolDecl *protocol) const {
1111- auto abstractRef = ProtocolConformanceRef::forAbstract (maybeOpaqueType, protocol);
1112-
11131111 auto archetype = dyn_cast<OpaqueTypeArchetypeType>(maybeOpaqueType);
1114- if (!archetype) {
1115- if (maybeOpaqueType->isTypeParameter () ||
1116- maybeOpaqueType->is <ArchetypeType>())
1117- return abstractRef;
1118-
1119- // SIL type lowering may have already substituted away the opaque type, in
1120- // which case we'll end up "substituting" the same type.
1121- if (maybeOpaqueType->isEqual (replacementType)) {
1122- return lookupConformance (replacementType, protocol);
1123- }
1124-
1125- llvm_unreachable (" origType should have been an opaque type or type parameter" );
1126- }
1112+ if (!archetype)
1113+ return lookupConformance (replacementType, protocol);
11271114
11281115 auto *genericEnv = archetype->getGenericEnvironment ();
11291116 auto *decl = genericEnv->getOpaqueTypeDecl ();
11301117 auto outerSubs = genericEnv->getOuterSubstitutions ();
11311118
11321119 auto substitutionKind = shouldPerformSubstitution (decl);
1133- if (substitutionKind == OpaqueSubstitutionKind::DontSubstitute) {
1134- return abstractRef;
1135- }
1120+ if (substitutionKind == OpaqueSubstitutionKind::DontSubstitute)
1121+ return lookupConformance (replacementType, protocol);
11361122
11371123 auto subs = decl->getUniqueUnderlyingTypeSubstitutions ();
11381124 // If the body of the opaque decl providing decl has not been type checked we
11391125 // don't have a underlying substitution.
11401126 if (!subs.has_value ())
1141- return abstractRef ;
1127+ return lookupConformance (replacementType, protocol) ;
11421128
11431129 // Apply the underlying type substitutions to the interface type of the
11441130 // archetype in question. This will map the inner generic signature of the
@@ -1159,7 +1145,7 @@ operator()(CanType maybeOpaqueType, Type replacementType,
11591145 return true ;
11601146 return false ;
11611147 }))
1162- return abstractRef ;
1148+ return lookupConformance (replacementType, protocol) ;
11631149
11641150 // Then apply the substitutions from the root opaque archetype, to specialize
11651151 // for its type arguments. We perform this substitution after checking for
@@ -1168,7 +1154,8 @@ operator()(CanType maybeOpaqueType, Type replacementType,
11681154 auto substTy = partialSubstTy.subst (outerSubs);
11691155
11701156 auto partialSubstRef =
1171- abstractRef.subst (archetype->getInterfaceType (), *subs);
1157+ subs->lookupConformance (archetype->getInterfaceType ()->getCanonicalType (),
1158+ protocol);
11721159 auto substRef =
11731160 partialSubstRef.subst (partialSubstTy, outerSubs);
11741161
@@ -1181,7 +1168,7 @@ operator()(CanType maybeOpaqueType, Type replacementType,
11811168 // type back to the caller. This substitution will fail at runtime
11821169 // instead.
11831170 if (!alreadySeen->insert (seenKey).second ) {
1184- return abstractRef ;
1171+ return lookupConformance (replacementType, protocol) ;
11851172 }
11861173
11871174 auto res = ::substOpaqueTypesWithUnderlyingTypesRec (
0 commit comments