|
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,28 @@ 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 | + return true; |
| 1053 | + } |
| 1054 | + |
| 1055 | + return Lowering::TypeConverter::protocolRequiresWitnessTable(proto); |
| 1056 | +} |
| 1057 | + |
1035 | 1058 | static bool isDependentConformance(
|
1036 | 1059 | IRGenModule &IGM,
|
1037 | 1060 | const RootProtocolConformance *rootConformance,
|
@@ -1064,7 +1087,7 @@ static bool isDependentConformance(
|
1064 | 1087 | continue;
|
1065 | 1088 |
|
1066 | 1089 | auto assocProtocol = req.getProtocolDecl();
|
1067 |
| - if (!Lowering::TypeConverter::protocolRequiresWitnessTable(assocProtocol)) |
| 1090 | + if (!protocolCanHaveDependentConformance(assocProtocol)) |
1068 | 1091 | continue;
|
1069 | 1092 |
|
1070 | 1093 | auto assocConformance =
|
|
0 commit comments