|
39 | 39 | #include "swift/AST/PrettyStackTrace.h" |
40 | 40 | #include "swift/AST/SubstitutionMap.h" |
41 | 41 | #include "swift/Basic/Assertions.h" |
| 42 | +#include "swift/Basic/Platform.h" |
42 | 43 | #include "swift/ClangImporter/ClangModule.h" |
43 | 44 | #include "swift/IRGen/Linking.h" |
44 | 45 | #include "swift/SIL/SILDeclRef.h" |
@@ -1032,6 +1033,29 @@ static bool isSynthesizedNonUnique(const RootProtocolConformance *conformance) { |
1032 | 1033 | return false; |
1033 | 1034 | } |
1034 | 1035 |
|
| 1036 | +/// Determine whether a protocol can ever have a dependent conformance. |
| 1037 | +static bool protocolCanHaveDependentConformance(ProtocolDecl *proto) { |
| 1038 | + // Objective-C protocols have never been able to have a dependent conformance. |
| 1039 | + if (proto->isObjC()) |
| 1040 | + return false; |
| 1041 | + |
| 1042 | + // Prior to Swift 6.0, only Objective-C protocols were never able to have |
| 1043 | + // a dependent conformance. This is overly pessimistic when the protocol |
| 1044 | + // is a marker protocol (since they don't have requirements), but we must |
| 1045 | + // retain backward compatibility with binaries built for earlier deployment |
| 1046 | + // targets that concluded that these protocols might involve dependent |
| 1047 | + // conformances. |
| 1048 | + ASTContext &ctx = proto->getASTContext(); |
| 1049 | + if (auto runtimeCompatVersion = getSwiftRuntimeCompatibilityVersionForTarget( |
| 1050 | + ctx.LangOpts.Target)) { |
| 1051 | + if (runtimeCompatVersion < llvm::VersionTuple(6, 0) && |
| 1052 | + proto->isSpecificProtocol(KnownProtocolKind::Sendable)) |
| 1053 | + return true; |
| 1054 | + } |
| 1055 | + |
| 1056 | + return Lowering::TypeConverter::protocolRequiresWitnessTable(proto); |
| 1057 | +} |
| 1058 | + |
1035 | 1059 | static bool isDependentConformance( |
1036 | 1060 | IRGenModule &IGM, |
1037 | 1061 | const RootProtocolConformance *rootConformance, |
@@ -1064,7 +1088,7 @@ static bool isDependentConformance( |
1064 | 1088 | continue; |
1065 | 1089 |
|
1066 | 1090 | auto assocProtocol = req.getProtocolDecl(); |
1067 | | - if (!Lowering::TypeConverter::protocolRequiresWitnessTable(assocProtocol)) |
| 1091 | + if (!protocolCanHaveDependentConformance(assocProtocol)) |
1068 | 1092 | continue; |
1069 | 1093 |
|
1070 | 1094 | auto assocConformance = |
|
0 commit comments