Skip to content

Commit 0ab1b16

Browse files
committed
Upstream some binary-compatibility logic
1 parent 588a7db commit 0ab1b16

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

stdlib/public/runtime/Bincompat.cpp

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,20 @@ static enum sdk_test isAppAtLeastFall2023() {
6767
const dyld_build_version_t fall_2023_os_versions = {0xffffffff, 0x007e70901};
6868
return isAppAtLeast(fall_2023_os_versions);
6969
}
70+
71+
static enum sdk_test isAppAtLeastFall2024() {
72+
const dyld_build_version_t fall_2024_os_versions = {0xffffffff, 0x007e80000};
73+
return isAppAtLeast(fall_2024_os_versions);
74+
}
7075
#endif
7176

7277
static _SwiftStdlibVersion binCompatVersionOverride = { 0 };
7378

7479
static _SwiftStdlibVersion const knownVersions[] = {
7580
{ /* 5.6.0 */0x050600 },
7681
{ /* 5.7.0 */0x050700 },
82+
// Note: If you add a new entry here, also add it to versionMap in
83+
// _swift_stdlib_isExecutableLinkedOnOrAfter below.
7784
{ 0 },
7885
};
7986

@@ -111,9 +118,27 @@ extern "C" __swift_bool _swift_stdlib_isExecutableLinkedOnOrAfter(
111118
}
112119

113120
#if BINARY_COMPATIBILITY_APPLE
114-
// Return true for all known versions for now -- we can't map them to OS
115-
// versions at this time.
116-
return isKnownBinCompatVersion(version);
121+
typedef struct {
122+
_SwiftStdlibVersion stdlib;
123+
dyld_build_version_t dyld;
124+
} stdlib_version_map;
125+
126+
const dyld_build_version_t spring_2022_os_versions = {0xffffffff, 0x007e60301};
127+
const dyld_build_version_t fall_2022_os_versions = {0xffffffff, 0x007e60901};
128+
129+
static stdlib_version_map const versionMap[] = {
130+
{ { /* 5.6.0 */0x050600 }, spring_2022_os_versions },
131+
{ { /* 5.7.0 */0x050700 }, fall_2022_os_versions },
132+
// Note: if you add a new entry here, also add it to knownVersions above.
133+
{ { 0 }, { 0, 0 } },
134+
};
135+
136+
for (uint32_t i = 0; versionMap[i].stdlib._value != 0; ++i) {
137+
if (versionMap[i].stdlib._value == version._value) {
138+
return isAppAtLeast(versionMap[i].dyld) == newApp;
139+
}
140+
}
141+
return false;
117142

118143
#else // !BINARY_COMPATIBILITY_APPLE
119144
return isKnownBinCompatVersion(version);
@@ -247,9 +272,11 @@ bool useLegacySwiftValueUnboxingInCasting() {
247272
//
248273
bool useLegacySwiftObjCHashing() {
249274
#if BINARY_COMPATIBILITY_APPLE
250-
return true; // For now, legacy behavior on Apple OSes
251-
#elif SWIFT_TARGET_OS_DARWIN
252-
return true; // For now, use legacy behavior on open-source builds for Apple platforms
275+
switch (isAppAtLeastFall2024()) {
276+
case oldOS: return true; // Legacy behavior on old OS
277+
case oldApp: return true; // Legacy behavior for old apps
278+
case newApp: return false; // New behavior for new apps
279+
}
253280
#else
254281
return false; // Always use the new behavior on non-Apple OSes
255282
#endif
@@ -268,12 +295,13 @@ bool useLegacySwiftObjCHashing() {
268295
// * This allows the method to invoke 'SerialExecutor/checkIsolated'
269296
// * Which is allowed to call 'dispatch_precondition' and handle "on dispatch queue but not on Swift executor" cases
270297
//
271-
// FIXME(concurrency): Once the release is announced, adjust the logic detecting the SDKs
272298
bool swift_bincompat_useLegacyNonCrashingExecutorChecks() {
273299
#if BINARY_COMPATIBILITY_APPLE
274-
return true; // For now, legacy behavior on Apple OSes
275-
#elif SWIFT_TARGET_OS_DARWIN
276-
return true; // For now, use legacy behavior on open-source builds for Apple platforms
300+
switch (isAppAtLeastFall2024()) {
301+
case oldOS: return true; // Legacy behavior on old OS
302+
case oldApp: return true; // Legacy behavior for old apps
303+
case newApp: return false; // New behavior for new apps
304+
}
277305
#else
278306
return false; // Always use the new behavior on non-Apple OSes
279307
#endif

0 commit comments

Comments
 (0)