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