@@ -948,23 +948,35 @@ namespace {
948948
949949// / Return true if the witness table requires runtime instantiation to
950950// / handle resiliently-added requirements with default implementations.
951- static bool isResilientConformance (const NormalProtocolConformance *conformance) {
951+ bool IRGenModule::isResilientConformance (
952+ const NormalProtocolConformance *conformance) {
952953 // If the protocol is not resilient, the conformance is not resilient
953954 // either.
954955 if (!conformance->getProtocol ()->isResilient ())
955956 return false ;
956957
957- // If the protocol is in the same module as the conformance, we're
958- // not resilient.
959- if (conformance->getDeclContext ()->getParentModule ()
960- == conformance->getProtocol ()->getParentModule ())
958+ auto *conformanceModule = conformance->getDeclContext ()->getParentModule ();
959+
960+ // If the protocol and the conformance are both in the current module,
961+ // they're not resilient.
962+ if (conformanceModule == getSwiftModule () &&
963+ conformanceModule == conformance->getProtocol ()->getParentModule ())
964+ return false ;
965+
966+ // If the protocol and the conformance are in the same module and the
967+ // conforming type is not generic, they're not resilient.
968+ //
969+ // This is an optimization -- a conformance of a non-generic type cannot
970+ // resiliently become dependent.
971+ if (!conformance->getDeclContext ()->isGenericContext () &&
972+ conformanceModule == conformance->getProtocol ()->getParentModule ())
961973 return false ;
962974
963975 // We have a resilient conformance.
964976 return true ;
965977}
966978
967- static bool isResilientConformance (const RootProtocolConformance *root) {
979+ bool IRGenModule:: isResilientConformance (const RootProtocolConformance *root) {
968980 if (auto normal = dyn_cast<NormalProtocolConformance>(root))
969981 return isResilientConformance (normal);
970982 // Self-conformances never require this.
@@ -997,6 +1009,7 @@ static bool hasDependentTypeWitness(
9971009}
9981010
9991011static bool isDependentConformance (
1012+ IRGenModule &IGM,
10001013 const RootProtocolConformance *rootConformance,
10011014 bool considerResilience,
10021015 llvm::SmallPtrSet<const NormalProtocolConformance *, 4 > &visited){
@@ -1011,7 +1024,7 @@ static bool isDependentConformance(
10111024 return false ;
10121025
10131026 // If the conformance is resilient, this is always true.
1014- if (considerResilience && isResilientConformance (conformance))
1027+ if (considerResilience && IGM. isResilientConformance (conformance))
10151028 return true ;
10161029
10171030 // Check whether any of the conformances are dependent.
@@ -1027,7 +1040,8 @@ static bool isDependentConformance(
10271040 auto assocConformance =
10281041 conformance->getAssociatedConformance (req.getFirstType (), assocProtocol);
10291042 if (assocConformance.isAbstract () ||
1030- isDependentConformance (assocConformance.getConcrete ()
1043+ isDependentConformance (IGM,
1044+ assocConformance.getConcrete ()
10311045 ->getRootConformance (),
10321046 considerResilience,
10331047 visited))
@@ -1045,10 +1059,12 @@ static bool isDependentConformance(
10451059
10461060// / Is there anything about the given conformance that requires witness
10471061// / tables to be dependently-generated?
1048- static bool isDependentConformance (const RootProtocolConformance *conformance,
1049- bool considerResilience) {
1062+ bool IRGenModule::isDependentConformance (
1063+ const RootProtocolConformance *conformance,
1064+ bool considerResilience) {
10501065 llvm::SmallPtrSet<const NormalProtocolConformance *, 4 > visited;
1051- return ::isDependentConformance (conformance, considerResilience, visited);
1066+ return ::isDependentConformance (*this , conformance, considerResilience,
1067+ visited);
10521068}
10531069
10541070static bool isSynthesizedNonUnique (const RootProtocolConformance *conformance) {
@@ -1286,7 +1302,7 @@ class AccessorConformanceInfo : public ConformanceInfo {
12861302 Conformance.getDeclContext())),
12871303 SILEntries(SILWT->getEntries ()),
12881304 SILConditionalConformances(SILWT->getConditionalConformances ()),
1289- ResilientConformance(isResilientConformance(&Conformance)),
1305+ ResilientConformance(IGM. isResilientConformance(&Conformance)),
12901306 PI(IGM.getProtocolInfo(SILWT->getConformance ()->getProtocol(),
12911307 (ResilientConformance
12921308 ? ProtocolInfoKind::RequirementSignature
@@ -2086,7 +2102,7 @@ void IRGenerator::ensureRelativeSymbolCollocation(SILWitnessTable &wt) {
20862102
20872103 // Only resilient conformances use relative pointers for witness methods.
20882104 if (wt.isDeclaration () || isAvailableExternally (wt.getLinkage ()) ||
2089- !isResilientConformance (wt.getConformance ()))
2105+ !CurrentIGM-> isResilientConformance (wt.getConformance ()))
20902106 return ;
20912107
20922108 for (auto &entry : wt.getEntries ()) {
0 commit comments