@@ -2500,10 +2500,30 @@ static llvm::Value *
2500
2500
emitAssociatedTypeWitnessTableRef (IRGenFunction &IGF,
2501
2501
llvm::Value *parentMetadata,
2502
2502
llvm::Value *wtable,
2503
- WitnessIndex index ,
2503
+ AssociatedConformance conformance ,
2504
2504
llvm::Value *associatedTypeMetadata) {
2505
- llvm::Value *witness = emitInvariantLoadOfOpaqueWitness (IGF, wtable,
2506
- index.forProtocolWitnessTable ());
2505
+ auto sourceProtocol = conformance.getSourceProtocol ();
2506
+ llvm::Value *witness;
2507
+ if (IGF.IGM .isResilient (sourceProtocol, ResilienceExpansion::Maximal)) {
2508
+ // For resilient protocols, use the associated conformance descriptor to
2509
+ // determine the index.
2510
+ auto assocConformanceDescriptor =
2511
+ IGF.IGM .getAddrOfAssociatedConformanceDescriptor (conformance);
2512
+
2513
+ auto index =
2514
+ computeResilientWitnessTableIndex (IGF, sourceProtocol,
2515
+ assocConformanceDescriptor);
2516
+
2517
+ witness = emitInvariantLoadOfOpaqueWitness (IGF, wtable, index);
2518
+ } else {
2519
+ // For non-resilient protocols, the index is a constant.
2520
+ auto &pi = IGF.IGM .getProtocolInfo (sourceProtocol,
2521
+ ProtocolInfoKind::RequirementSignature);
2522
+
2523
+ auto index = pi.getAssociatedConformanceIndex (conformance);
2524
+ witness = emitInvariantLoadOfOpaqueWitness (IGF, wtable,
2525
+ index.forProtocolWitnessTable ());
2526
+ }
2507
2527
2508
2528
// Cast the witness to the appropriate function type.
2509
2529
auto sig = IGF.IGM .getAssociatedTypeWitnessTableAccessFunctionSignature ();
@@ -2663,14 +2683,17 @@ MetadataResponse MetadataPath::followComponent(IRGenFunction &IGF,
2663
2683
2664
2684
if (!source) return MetadataResponse ();
2665
2685
2666
- WitnessIndex index (component.getPrimaryIndex (), /* prefix*/ false );
2667
2686
auto sourceMetadata = IGF.emitTypeMetadataRef (sourceType);
2668
2687
auto associatedMetadata = IGF.emitTypeMetadataRef (sourceKey.Type );
2669
2688
auto sourceWTable = source.getMetadata ();
2670
2689
2690
+ AssociatedConformance associatedConformanceRef (sourceProtocol,
2691
+ association,
2692
+ associatedRequirement);
2671
2693
auto associatedWTable =
2672
2694
emitAssociatedTypeWitnessTableRef (IGF, sourceMetadata, sourceWTable,
2673
- index, associatedMetadata);
2695
+ associatedConformanceRef,
2696
+ associatedMetadata);
2674
2697
2675
2698
setProtocolWitnessTableName (IGF.IGM , associatedWTable, sourceKey.Type ,
2676
2699
associatedRequirement);
@@ -3396,13 +3419,7 @@ Signature IRGenModule::getAssociatedTypeMetadataAccessFunctionSignature() {
3396
3419
return Signature (fnType, attrs, SwiftCC);
3397
3420
}
3398
3421
3399
- // / Compute the index into a witness table for a resilient protocol given
3400
- // / a reference to a descriptor of one of the requirements in that witness
3401
- // / table.
3402
- // /
3403
- // / Given an index into the witness table for a resilient protocol that
3404
- // / was compiuted
3405
- static llvm::Value *computeResilientWitnessTableIndex (
3422
+ llvm::Value *irgen::computeResilientWitnessTableIndex (
3406
3423
IRGenFunction &IGF,
3407
3424
ProtocolDecl *proto,
3408
3425
llvm::Constant *reqtDescriptor) {
0 commit comments