@@ -1257,16 +1257,16 @@ emitConditionalConformancesBuffer(IRGenFunction &IGF,
1257
1257
}
1258
1258
1259
1259
static llvm::Value *emitWitnessTableAccessorCall (
1260
- IRGenFunction &IGF, const ProtocolConformance *conformance,
1260
+ IRGenFunction &IGF, CanType conformingType,
1261
+ const ProtocolConformance *conformance,
1261
1262
llvm::Value **srcMetadataCache) {
1262
1263
auto conformanceDescriptor =
1263
1264
IGF.IGM .getAddrOfProtocolConformanceDescriptor (
1264
1265
conformance->getRootConformance ());
1265
1266
1266
1267
// Emit the source metadata if we haven't yet.
1267
1268
if (!*srcMetadataCache) {
1268
- *srcMetadataCache = IGF.emitAbstractTypeMetadataRef (
1269
- conformance->getType ()->getCanonicalType ());
1269
+ *srcMetadataCache = IGF.emitAbstractTypeMetadataRef (conformingType);
1270
1270
}
1271
1271
1272
1272
auto conditionalTables =
@@ -1290,8 +1290,8 @@ static llvm::Value *emitWitnessTableAccessorCall(
1290
1290
// / given type.
1291
1291
static llvm::Function *
1292
1292
getWitnessTableLazyAccessFunction (IRGenModule &IGM,
1293
+ CanType conformingType,
1293
1294
const ProtocolConformance *conformance) {
1294
- auto conformingType = conformance->getType ()->getCanonicalType ();
1295
1295
assert (!conformingType->hasArchetype ());
1296
1296
1297
1297
auto rootConformance = conformance->getRootNormalConformance ();
@@ -1315,7 +1315,7 @@ getWitnessTableLazyAccessFunction(IRGenModule &IGM,
1315
1315
[&](IRGenFunction &IGF, Explosion ¶ms) {
1316
1316
llvm::Value *conformingMetadataCache = nullptr ;
1317
1317
return MetadataResponse::forComplete (emitWitnessTableAccessorCall (
1318
- IGF, conformance, &conformingMetadataCache));
1318
+ IGF, conformingType, conformance, &conformingMetadataCache));
1319
1319
});
1320
1320
1321
1321
return accessor;
@@ -1414,16 +1414,23 @@ class AccessorConformanceInfo : public ConformanceInfo {
1414
1414
1415
1415
llvm::Value *getTable (IRGenFunction &IGF,
1416
1416
llvm::Value **typeMetadataCache) const override {
1417
+ auto conformingType = Conformance->getType ()->getCanonicalType ();
1418
+
1419
+ if (isa<NormalProtocolConformance>(Conformance)) {
1420
+ conformingType = conformingType->getReducedType (
1421
+ Conformance->getGenericSignature ());
1422
+ }
1423
+
1417
1424
// If we're looking up a dependent type, we can't cache the result.
1418
- if (Conformance-> getType () ->hasArchetype () ||
1419
- Conformance-> getType () ->hasDynamicSelfType ()) {
1420
- return emitWitnessTableAccessorCall (IGF, Conformance,
1425
+ if (conformingType ->hasArchetype () ||
1426
+ conformingType ->hasDynamicSelfType ()) {
1427
+ return emitWitnessTableAccessorCall (IGF, conformingType, Conformance,
1421
1428
typeMetadataCache);
1422
1429
}
1423
1430
1424
1431
// Otherwise, call a lazy-cache function.
1425
1432
auto accessor =
1426
- getWitnessTableLazyAccessFunction (IGF.IGM , Conformance);
1433
+ getWitnessTableLazyAccessFunction (IGF.IGM , conformingType, Conformance);
1427
1434
llvm::CallInst *call =
1428
1435
IGF.Builder .CreateCall (accessor->getFunctionType (), accessor, {});
1429
1436
call->setCallingConv (IGF.IGM .DefaultCC );
0 commit comments