@@ -959,6 +959,13 @@ namespace {
959959 }
960960
961961 void addAssociatedConformance (const AssociatedConformance &req) {
962+ if (req.getAssociation ()->getASTContext ().LangOpts .hasFeature (Feature::Embedded) &&
963+ !req.getAssociatedRequirement ()->requiresClass ()) {
964+ // If it's not a class protocol, the associated type can never be used to create
965+ // an existential. Therefore this witness entry is never used at runtime
966+ // in embedded swift.
967+ return ;
968+ }
962969 Entries.push_back (WitnessTableEntry::forAssociatedConformance (req));
963970 }
964971
@@ -1748,6 +1755,14 @@ class AccessorConformanceInfo : public ConformanceInfo {
17481755 (void )entry;
17491756 SILEntries = SILEntries.slice (1 );
17501757
1758+ if (IGM.Context .LangOpts .hasFeature (Feature::Embedded) &&
1759+ !requirement.getAssociatedRequirement ()->requiresClass ()) {
1760+ // If it's not a class protocol, the associated type can never be used to create
1761+ // an existential. Therefore this witness entry is never used at runtime
1762+ // in embedded swift.
1763+ return ;
1764+ }
1765+
17511766 auto associate =
17521767 ConformanceInContext.getAssociatedType (
17531768 requirement.getAssociation ())->getCanonicalType ();
@@ -1775,7 +1790,10 @@ class AccessorConformanceInfo : public ConformanceInfo {
17751790 if (IGM.Context .LangOpts .hasFeature (Feature::Embedded)) {
17761791 // In Embedded Swift associated-conformance entries simply point to the witness table
17771792 // of the associated conformance.
1778- llvm::Constant *witnessEntry = IGM.getAddrOfWitnessTable (associatedConformance.getConcrete ());
1793+ ProtocolConformanceRef assocConf =
1794+ SILWT->getConformance ()->getAssociatedConformance (requirement.getAssociation (),
1795+ requirement.getAssociatedRequirement ());
1796+ llvm::Constant *witnessEntry = IGM.getAddrOfWitnessTable (assocConf.getConcrete ());
17791797 auto &schema = IGM.getOptions ().PointerAuth
17801798 .ProtocolAssociatedTypeWitnessTableAccessFunctions ;
17811799 Table.addSignedPointer (witnessEntry, schema, requirement);
@@ -3734,7 +3752,7 @@ llvm::Value *irgen::emitWitnessTableRef(IRGenFunction &IGF,
37343752
37353753 // In Embedded Swift, only class-bound wtables are allowed.
37363754 if (srcType->getASTContext ().LangOpts .hasFeature (Feature::Embedded)) {
3737- assert (proto->requiresClass ());
3755+ ASSERT (proto->requiresClass ());
37383756 }
37393757
37403758 assert (Lowering::TypeConverter::protocolRequiresWitnessTable (proto)
0 commit comments