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