@@ -3329,6 +3329,48 @@ lowerKeyPathSubscriptIndexTypes(
3329
3329
}
3330
3330
};
3331
3331
3332
+ // / Map the given protocol conformance out of context, replacing archetypes
3333
+ // / with their corresponding interface types.
3334
+ static ProtocolConformance *mapConformanceOutOfContext (
3335
+ ProtocolConformance *conformance) {
3336
+ if (!conformance->getType ()->hasArchetype ())
3337
+ return conformance;
3338
+
3339
+ ASTContext &ctx = conformance->getProtocol ()->getASTContext ();
3340
+ switch (conformance->getKind ()) {
3341
+ case ProtocolConformanceKind::Normal:
3342
+ case ProtocolConformanceKind::Self:
3343
+ llvm_unreachable (" Normal and self conformances never have archetypes" );
3344
+
3345
+ case ProtocolConformanceKind::Inherited: {
3346
+ auto inherited = cast<InheritedProtocolConformance>(conformance);
3347
+ return ctx.getInheritedConformance (
3348
+ inherited->getType ()->mapTypeOutOfContext (),
3349
+ mapConformanceOutOfContext (inherited->getInheritedConformance ()));
3350
+ }
3351
+
3352
+ case ProtocolConformanceKind::Specialized: {
3353
+ auto specialized = cast<SpecializedProtocolConformance>(conformance);
3354
+ return ctx.getSpecializedConformance (
3355
+ specialized->getType ()->mapTypeOutOfContext (),
3356
+ mapConformanceOutOfContext (specialized->getGenericConformance ()),
3357
+ specialized->getSubstitutionMap ()
3358
+ .mapReplacementTypesOutOfContext ());
3359
+ }
3360
+ }
3361
+ }
3362
+
3363
+ // / Map the given protocol conformance out of context, replacing archetypes
3364
+ // / with their corresponding interface types.
3365
+ static ProtocolConformanceRef mapConformanceOutOfContext (
3366
+ ProtocolConformanceRef conformance) {
3367
+ if (conformance.isAbstract ())
3368
+ return conformance;
3369
+
3370
+ return ProtocolConformanceRef (
3371
+ mapConformanceOutOfContext (conformance.getConcrete ()));
3372
+ }
3373
+
3332
3374
static void
3333
3375
lowerKeyPathSubscriptIndexPatterns (
3334
3376
SmallVectorImpl<KeyPathPatternComponent::Index> &indexPatterns,
@@ -3339,10 +3381,9 @@ lowerKeyPathSubscriptIndexPatterns(
3339
3381
CanType formalTy;
3340
3382
SILType loweredTy;
3341
3383
std::tie (formalTy, loweredTy) = indexTypes[i];
3342
- auto hashable = indexHashables[i];
3384
+ auto hashable = mapConformanceOutOfContext ( indexHashables[i]) ;
3343
3385
assert (hashable.isAbstract () ||
3344
- hashable.getConcrete ()->getType ()->mapTypeOutOfContext ()
3345
- ->isEqual (formalTy));
3386
+ hashable.getConcrete ()->getType ()->isEqual (formalTy));
3346
3387
3347
3388
indexPatterns.push_back ({baseOperand++, formalTy, loweredTy, hashable});
3348
3389
}
0 commit comments