@@ -947,23 +947,35 @@ namespace {
947
947
948
948
// / Return true if the witness table requires runtime instantiation to
949
949
// / handle resiliently-added requirements with default implementations.
950
- static bool isResilientConformance (const NormalProtocolConformance *conformance) {
950
+ bool IRGenModule::isResilientConformance (
951
+ const NormalProtocolConformance *conformance) {
951
952
// If the protocol is not resilient, the conformance is not resilient
952
953
// either.
953
954
if (!conformance->getProtocol ()->isResilient ())
954
955
return false ;
955
956
956
- // If the protocol is in the same module as the conformance, we're
957
- // not resilient.
958
- if (conformance->getDeclContext ()->getParentModule ()
959
- == conformance->getProtocol ()->getParentModule ())
957
+ auto *conformanceModule = conformance->getDeclContext ()->getParentModule ();
958
+
959
+ // If the protocol and the conformance are both in the current module,
960
+ // they're not resilient.
961
+ if (conformanceModule == getSwiftModule () &&
962
+ conformanceModule == conformance->getProtocol ()->getParentModule ())
963
+ return false ;
964
+
965
+ // If the protocol and the conformance are in the same module and the
966
+ // conforming type is not generic, they're not resilient.
967
+ //
968
+ // This is an optimization -- a conformance of a non-generic type cannot
969
+ // resiliently become dependent.
970
+ if (!conformance->getDeclContext ()->isGenericContext () &&
971
+ conformanceModule == conformance->getProtocol ()->getParentModule ())
960
972
return false ;
961
973
962
974
// We have a resilient conformance.
963
975
return true ;
964
976
}
965
977
966
- static bool isResilientConformance (const RootProtocolConformance *root) {
978
+ bool IRGenModule:: isResilientConformance (const RootProtocolConformance *root) {
967
979
if (auto normal = dyn_cast<NormalProtocolConformance>(root))
968
980
return isResilientConformance (normal);
969
981
// Self-conformances never require this.
@@ -996,6 +1008,7 @@ static bool hasDependentTypeWitness(
996
1008
}
997
1009
998
1010
static bool isDependentConformance (
1011
+ IRGenModule &IGM,
999
1012
const RootProtocolConformance *rootConformance,
1000
1013
bool considerResilience,
1001
1014
llvm::SmallPtrSet<const NormalProtocolConformance *, 4 > &visited){
@@ -1010,7 +1023,7 @@ static bool isDependentConformance(
1010
1023
return false ;
1011
1024
1012
1025
// If the conformance is resilient, this is always true.
1013
- if (considerResilience && isResilientConformance (conformance))
1026
+ if (considerResilience && IGM. isResilientConformance (conformance))
1014
1027
return true ;
1015
1028
1016
1029
// Check whether any of the conformances are dependent.
@@ -1026,7 +1039,8 @@ static bool isDependentConformance(
1026
1039
auto assocConformance =
1027
1040
conformance->getAssociatedConformance (req.getFirstType (), assocProtocol);
1028
1041
if (assocConformance.isAbstract () ||
1029
- isDependentConformance (assocConformance.getConcrete ()
1042
+ isDependentConformance (IGM,
1043
+ assocConformance.getConcrete ()
1030
1044
->getRootConformance (),
1031
1045
considerResilience,
1032
1046
visited))
@@ -1044,10 +1058,12 @@ static bool isDependentConformance(
1044
1058
1045
1059
// / Is there anything about the given conformance that requires witness
1046
1060
// / tables to be dependently-generated?
1047
- static bool isDependentConformance (const RootProtocolConformance *conformance,
1048
- bool considerResilience) {
1061
+ bool IRGenModule::isDependentConformance (
1062
+ const RootProtocolConformance *conformance,
1063
+ bool considerResilience) {
1049
1064
llvm::SmallPtrSet<const NormalProtocolConformance *, 4 > visited;
1050
- return ::isDependentConformance (conformance, considerResilience, visited);
1065
+ return ::isDependentConformance (*this , conformance, considerResilience,
1066
+ visited);
1051
1067
}
1052
1068
1053
1069
static bool isSynthesizedNonUnique (const RootProtocolConformance *conformance) {
@@ -1285,7 +1301,7 @@ class AccessorConformanceInfo : public ConformanceInfo {
1285
1301
Conformance.getDeclContext())),
1286
1302
SILEntries(SILWT->getEntries ()),
1287
1303
SILConditionalConformances(SILWT->getConditionalConformances ()),
1288
- ResilientConformance(isResilientConformance(&Conformance)),
1304
+ ResilientConformance(IGM. isResilientConformance(&Conformance)),
1289
1305
PI(IGM.getProtocolInfo(SILWT->getConformance ()->getProtocol(),
1290
1306
(ResilientConformance
1291
1307
? ProtocolInfoKind::RequirementSignature
0 commit comments