Skip to content

Commit c21039a

Browse files
committed
Implement getSwiftRuntimeCompatibilityVersionForTarget for recent releases
We were relying on this for `@isolated(any)` mangling suppression, but it actually doesn't generate correct results for recent deployment targets. As a result, we treated e.g. macOS 14.4 as if it were completely unconstrained in terms of runtime availability. I took this data from availability-macros.def; it's unfortunate that we can't just generate the implementation directly from that. Fixes rdar://129861211
1 parent b4a169e commit c21039a

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

lib/Basic/Platform.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,13 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(
470470
return floorFor64(llvm::VersionTuple(5, 5));
471471
return floorFor64(llvm::VersionTuple(5, 6));
472472
} else if (Major == 13) {
473-
return floorFor64(llvm::VersionTuple(5, 7));
473+
if (Minor <= 2)
474+
return floorFor64(llvm::VersionTuple(5, 7));
475+
return floorFor64(llvm::VersionTuple(5, 8));
476+
} else if (Major == 14) {
477+
if (Minor <= 3)
478+
return floorFor64(llvm::VersionTuple(5, 9));
479+
return floorFor64(llvm::VersionTuple(5, 10));
474480
}
475481
} else if (Triple.isiOS()) { // includes tvOS
476482
llvm::VersionTuple OSVersion = Triple.getiOSVersion();
@@ -510,7 +516,13 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(
510516
return floorForArchitecture(llvm::VersionTuple(5, 5));
511517
return floorForArchitecture(llvm::VersionTuple(5, 6));
512518
} else if (Major <= 16) {
513-
return floorForArchitecture(llvm::VersionTuple(5, 7));
519+
if (Minor <= 3)
520+
return floorForArchitecture(llvm::VersionTuple(5, 7));
521+
return floorForArchitecture(llvm::VersionTuple(5, 8));
522+
} else if (Major <= 17) {
523+
if (Minor <= 3)
524+
return floorForArchitecture(llvm::VersionTuple(5, 9));
525+
return floorForArchitecture(llvm::VersionTuple(5, 10));
514526
}
515527
} else if (Triple.isWatchOS()) {
516528
llvm::VersionTuple OSVersion = Triple.getWatchOSVersion();
@@ -541,11 +553,25 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(
541553
return floorFor64bits(llvm::VersionTuple(5, 5));
542554
return floorFor64bits(llvm::VersionTuple(5, 6));
543555
} else if (Major <= 9) {
544-
return floorFor64bits(llvm::VersionTuple(5, 7));
556+
if (Minor <= 3)
557+
return floorFor64bits(llvm::VersionTuple(5, 7));
558+
return floorFor64bits(llvm::VersionTuple(5, 8));
559+
} else if (Major <= 10) {
560+
if (Minor <= 3)
561+
return floorFor64bits(llvm::VersionTuple(5, 9));
562+
return floorFor64bits(llvm::VersionTuple(5, 10));
545563
}
546564
}
547565
else if (Triple.isXROS()) {
548-
return std::nullopt;
566+
llvm::VersionTuple OSVersion = Triple.getOSVersion();
567+
unsigned Major = OSVersion.getMajor();
568+
unsigned Minor = OSVersion.getMinor().value_or(0);
569+
570+
if (Major <= 1) {
571+
if (Minor <= 0)
572+
return llvm::VersionTuple(5, 9);
573+
return llvm::VersionTuple(5, 10);
574+
}
549575
}
550576

551577
return std::nullopt;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-frontend -emit-ir -target %target-cpu-apple-macos99.99 %s | %FileCheck --check-prefix=CHECK --check-prefix=CHECK-PRESENT %s
2+
// RUN: %target-swift-frontend -emit-ir -target %target-cpu-apple-macos14.4 %s | %FileCheck --check-prefix=CHECK --check-prefix=CHECK-SUPPRESSED %s
3+
4+
// REQUIRES: OS=macosx
5+
// UNSUPPORTED: CPU=arm64e
6+
7+
public struct MyStruct {
8+
let fn: @isolated(any) () -> ()
9+
}
10+
11+
// Make sure that we only emit a demangling-based type description
12+
// for @isolated(any) types when deploying to runtimes that support it.
13+
// If we don't, we fall back on using a type metadata accessor, which
14+
// is fine. Since this is for reflective metadata, we could go a step
15+
// further if we decide we really only care about layout equivalence for
16+
// these; if so, we could just suppress the @isolated(any) part of the
17+
// type completely, since it has the the same external layout as an
18+
// ordinary function type.
19+
// rdar://129861211
20+
21+
// CHECK-LABEL: @"$s32reflection_metadata_isolated_any8MyStructVMF" = internal constant
22+
// CHECK-PRESENT-SAME: ptr @"symbolic yyYAc"
23+
// CHECK-SUPPRESSED-SAME: ptr @"get_type_metadata yyYAc.1"

0 commit comments

Comments
 (0)