@@ -2781,6 +2781,30 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
2781
2781
return LoweredValInfo ();
2782
2782
}
2783
2783
2784
+ void walkInheritanceHierarchyAndCreateWitnessTableCopies (IRWitnessTable* witnessTable, Type* subType, InheritanceDecl* inheritanceDecl)
2785
+ {
2786
+ auto baseDeclRef = inheritanceDecl->base .type .As <DeclRefType>();
2787
+ if (auto baseInterfaceDeclRef = baseDeclRef->declRef .As <InterfaceDecl>())
2788
+ {
2789
+ for (auto subInheritanceDeclRef : getMembersOfType<InheritanceDecl>(baseInterfaceDeclRef))
2790
+ {
2791
+ auto cpyMangledName = getMangledNameForConformanceWitness (subType, subInheritanceDeclRef.getDecl ()->getSup ().type );
2792
+ if (!witnessTablesDictionary.ContainsKey (cpyMangledName))
2793
+ {
2794
+ auto cpyTable = context->irBuilder ->createWitnessTable ();
2795
+ cpyTable->mangledName = cpyMangledName;
2796
+ context->irBuilder ->createWitnessTableEntry (witnessTable,
2797
+ context->irBuilder ->getDeclRefVal (subInheritanceDeclRef), cpyTable);
2798
+ cpyTable->entries = witnessTable->entries ;
2799
+ witnessTablesDictionary.Add (cpyMangledName, cpyTable);
2800
+ walkInheritanceHierarchyAndCreateWitnessTableCopies (witnessTable, subType, subInheritanceDeclRef.getDecl ());
2801
+ }
2802
+ }
2803
+ }
2804
+ }
2805
+
2806
+ Dictionary<String, IRWitnessTable*> witnessTablesDictionary;
2807
+
2784
2808
LoweredValInfo visitInheritanceDecl (InheritanceDecl* inheritanceDecl)
2785
2809
{
2786
2810
// Construct a type for the parent declaration.
@@ -2817,6 +2841,8 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
2817
2841
// conformance of the type to its super-type.
2818
2842
auto witnessTable = context->irBuilder ->createWitnessTable ();
2819
2843
witnessTable->mangledName = mangledName;
2844
+
2845
+ witnessTablesDictionary.Add (mangledName, witnessTable);
2820
2846
2821
2847
if (parentDecl->ParentDecl )
2822
2848
witnessTable->genericDecl = dynamic_cast <GenericDecl*>(parentDecl->ParentDecl );
@@ -2850,6 +2876,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
2850
2876
}
2851
2877
2852
2878
witnessTable->moveToEnd ();
2879
+ walkInheritanceHierarchyAndCreateWitnessTableCopies (witnessTable, type, inheritanceDecl);
2853
2880
2854
2881
// A direct reference to this inheritance relationship (e.g.,
2855
2882
// as a subtype witness) will take the form of a reference to
0 commit comments