@@ -948,23 +948,35 @@ namespace {
948
948
949
949
// / Return true if the witness table requires runtime instantiation to
950
950
// / handle resiliently-added requirements with default implementations.
951
- static bool isResilientConformance (const NormalProtocolConformance *conformance) {
951
+ bool IRGenModule::isResilientConformance (
952
+ const NormalProtocolConformance *conformance) {
952
953
// If the protocol is not resilient, the conformance is not resilient
953
954
// either.
954
955
if (!conformance->getProtocol ()->isResilient ())
955
956
return false ;
956
957
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 ())
961
973
return false ;
962
974
963
975
// We have a resilient conformance.
964
976
return true ;
965
977
}
966
978
967
- static bool isResilientConformance (const RootProtocolConformance *root) {
979
+ bool IRGenModule:: isResilientConformance (const RootProtocolConformance *root) {
968
980
if (auto normal = dyn_cast<NormalProtocolConformance>(root))
969
981
return isResilientConformance (normal);
970
982
// Self-conformances never require this.
@@ -997,6 +1009,7 @@ static bool hasDependentTypeWitness(
997
1009
}
998
1010
999
1011
static bool isDependentConformance (
1012
+ IRGenModule &IGM,
1000
1013
const RootProtocolConformance *rootConformance,
1001
1014
bool considerResilience,
1002
1015
llvm::SmallPtrSet<const NormalProtocolConformance *, 4 > &visited){
@@ -1011,7 +1024,7 @@ static bool isDependentConformance(
1011
1024
return false ;
1012
1025
1013
1026
// If the conformance is resilient, this is always true.
1014
- if (considerResilience && isResilientConformance (conformance))
1027
+ if (considerResilience && IGM. isResilientConformance (conformance))
1015
1028
return true ;
1016
1029
1017
1030
// Check whether any of the conformances are dependent.
@@ -1027,7 +1040,8 @@ static bool isDependentConformance(
1027
1040
auto assocConformance =
1028
1041
conformance->getAssociatedConformance (req.getFirstType (), assocProtocol);
1029
1042
if (assocConformance.isAbstract () ||
1030
- isDependentConformance (assocConformance.getConcrete ()
1043
+ isDependentConformance (IGM,
1044
+ assocConformance.getConcrete ()
1031
1045
->getRootConformance (),
1032
1046
considerResilience,
1033
1047
visited))
@@ -1045,10 +1059,12 @@ static bool isDependentConformance(
1045
1059
1046
1060
// / Is there anything about the given conformance that requires witness
1047
1061
// / 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) {
1050
1065
llvm::SmallPtrSet<const NormalProtocolConformance *, 4 > visited;
1051
- return ::isDependentConformance (conformance, considerResilience, visited);
1066
+ return ::isDependentConformance (*this , conformance, considerResilience,
1067
+ visited);
1052
1068
}
1053
1069
1054
1070
static bool isSynthesizedNonUnique (const RootProtocolConformance *conformance) {
@@ -1286,7 +1302,7 @@ class AccessorConformanceInfo : public ConformanceInfo {
1286
1302
Conformance.getDeclContext())),
1287
1303
SILEntries(SILWT->getEntries ()),
1288
1304
SILConditionalConformances(SILWT->getConditionalConformances ()),
1289
- ResilientConformance(isResilientConformance(&Conformance)),
1305
+ ResilientConformance(IGM. isResilientConformance(&Conformance)),
1290
1306
PI(IGM.getProtocolInfo(SILWT->getConformance ()->getProtocol(),
1291
1307
(ResilientConformance
1292
1308
? ProtocolInfoKind::RequirementSignature
@@ -2086,7 +2102,7 @@ void IRGenerator::ensureRelativeSymbolCollocation(SILWitnessTable &wt) {
2086
2102
2087
2103
// Only resilient conformances use relative pointers for witness methods.
2088
2104
if (wt.isDeclaration () || isAvailableExternally (wt.getLinkage ()) ||
2089
- !isResilientConformance (wt.getConformance ()))
2105
+ !CurrentIGM-> isResilientConformance (wt.getConformance ()))
2090
2106
return ;
2091
2107
2092
2108
for (auto &entry : wt.getEntries ()) {
0 commit comments