Skip to content

Commit a9dacaf

Browse files
committed
Perform OS version checkout without __builtin_available.
`__builtin_available` requires linking compiler-rt, which is not easier to do within the backward compatibility libraries. Instead, use an API that's been in the standard library since before Swift 5.0 for the version check.
1 parent 1366d7e commit a9dacaf

File tree

1 file changed

+34
-10
lines changed
  • stdlib/toolchain/Compatibility56/Concurrency

1 file changed

+34
-10
lines changed

stdlib/toolchain/Compatibility56/Concurrency/Actor.cpp

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include "swift/Runtime/Casting.h"
99
#include "Runtime/Threading/ThreadLocal.h"
1010

11+
#include <Availability.h>
12+
#include <TargetConditionals.h>
13+
1114
#include <atomic>
1215
#include <new>
1316

@@ -150,17 +153,38 @@ void swift::restoreTaskVoucher(AsyncTask *task) {
150153
static swift_once_t voucherDisableCheckOnce;
151154
static bool vouchersDisabled;
152155

156+
namespace {
157+
struct _SwiftNSOperatingSystemVersion{
158+
intptr_t majorVersion;
159+
intptr_t minorVersion;
160+
intptr_t patchVersion;
161+
};
162+
}
163+
164+
extern "C"
165+
_SwiftNSOperatingSystemVersion
166+
_swift_stdlib_operatingSystemVersion() __attribute__((const));
167+
153168
static void _initializeVouchersDisabled(void *ctxt) {
154-
if (__builtin_available(macOS 12.1, iOS 15.2, tvOS 15.2, watchOS 8.3, *)) {
155-
// Concurrency library in the OS in new enough that it has voucher support.
156-
vouchersDisabled = false;
157-
} else if (__builtin_available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)) {
158-
// Concurrency library in the OS falls in the range that has no voucher support.
159-
vouchersDisabled = true;
160-
} else {
161-
// Concurrency library is back-deployed on this OS, and has voucher support.
162-
vouchersDisabled = false;
163-
}
169+
auto osVersion = _swift_stdlib_operatingSystemVersion();
170+
#if TARGET_OS_WATCH
171+
vouchersDisabled = (
172+
osVersion.majorVersion == 8 &&
173+
osVersion.minorVersion >= 0 && osVersion.minorVersion < 3
174+
);
175+
#elif TARGET_OS_IPHONE
176+
vouchersDisabled = (
177+
osVersion.majorVersion == 15 &&
178+
osVersion.minorVersion >= 0 && osVersion.minorVersion < 2
179+
);
180+
#elif TARGET_OS_OSX
181+
vouchersDisabled = (
182+
osVersion.majorVersion == 12 &&
183+
osVersion.minorVersion >= 0 && osVersion.minorVersion < 1
184+
);
185+
#else
186+
vouchersDisabled = false;
187+
#endif
164188
}
165189

166190
bool VoucherManager::vouchersAreDisabled() {

0 commit comments

Comments
 (0)