@@ -1108,37 +1108,23 @@ ProtocolConformanceRef swift::substOpaqueTypesWithUnderlyingTypes(
1108
1108
ProtocolConformanceRef ReplaceOpaqueTypesWithUnderlyingTypes::
1109
1109
operator ()(CanType maybeOpaqueType, Type replacementType,
1110
1110
ProtocolDecl *protocol) const {
1111
- auto abstractRef = ProtocolConformanceRef::forAbstract (maybeOpaqueType, protocol);
1112
-
1113
1111
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);
1127
1114
1128
1115
auto *genericEnv = archetype->getGenericEnvironment ();
1129
1116
auto *decl = genericEnv->getOpaqueTypeDecl ();
1130
1117
auto outerSubs = genericEnv->getOuterSubstitutions ();
1131
1118
1132
1119
auto substitutionKind = shouldPerformSubstitution (decl);
1133
- if (substitutionKind == OpaqueSubstitutionKind::DontSubstitute) {
1134
- return abstractRef;
1135
- }
1120
+ if (substitutionKind == OpaqueSubstitutionKind::DontSubstitute)
1121
+ return lookupConformance (replacementType, protocol);
1136
1122
1137
1123
auto subs = decl->getUniqueUnderlyingTypeSubstitutions ();
1138
1124
// If the body of the opaque decl providing decl has not been type checked we
1139
1125
// don't have a underlying substitution.
1140
1126
if (!subs.has_value ())
1141
- return abstractRef ;
1127
+ return lookupConformance (replacementType, protocol) ;
1142
1128
1143
1129
// Apply the underlying type substitutions to the interface type of the
1144
1130
// archetype in question. This will map the inner generic signature of the
@@ -1159,7 +1145,7 @@ operator()(CanType maybeOpaqueType, Type replacementType,
1159
1145
return true ;
1160
1146
return false ;
1161
1147
}))
1162
- return abstractRef ;
1148
+ return lookupConformance (replacementType, protocol) ;
1163
1149
1164
1150
// Then apply the substitutions from the root opaque archetype, to specialize
1165
1151
// for its type arguments. We perform this substitution after checking for
@@ -1168,7 +1154,8 @@ operator()(CanType maybeOpaqueType, Type replacementType,
1168
1154
auto substTy = partialSubstTy.subst (outerSubs);
1169
1155
1170
1156
auto partialSubstRef =
1171
- abstractRef.subst (archetype->getInterfaceType (), *subs);
1157
+ subs->lookupConformance (archetype->getInterfaceType ()->getCanonicalType (),
1158
+ protocol);
1172
1159
auto substRef =
1173
1160
partialSubstRef.subst (partialSubstTy, outerSubs);
1174
1161
@@ -1181,7 +1168,7 @@ operator()(CanType maybeOpaqueType, Type replacementType,
1181
1168
// type back to the caller. This substitution will fail at runtime
1182
1169
// instead.
1183
1170
if (!alreadySeen->insert (seenKey).second ) {
1184
- return abstractRef ;
1171
+ return lookupConformance (replacementType, protocol) ;
1185
1172
}
1186
1173
1187
1174
auto res = ::substOpaqueTypesWithUnderlyingTypesRec (
0 commit comments