Skip to content

Commit 54a7577

Browse files
authored
Merge pull request #39195 from mikeash/voucher-needs-adopt-overload
[Concurrency] Use overload resolution to stub voucher_needs_adopt.
2 parents df76275 + c216d91 commit 54a7577

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

include/swift/Runtime/VoucherShims.h

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@
4141

4242
#if SWIFT_HAS_VOUCHER_HEADER
4343

44-
static inline bool swift_voucher_needs_adopt(voucher_t _Nullable voucher) {
45-
if (__builtin_available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)) {
46-
return voucher_needs_adopt(voucher);
47-
}
48-
return true;
49-
}
50-
5144
#else
5245

5346
// If the header isn't available, declare the necessary calls here.
@@ -64,10 +57,6 @@ extern "C" voucher_t _Nullable voucher_copy(void);
6457
// Consumes argument, returns retained value.
6558
extern "C" voucher_t _Nullable voucher_adopt(voucher_t _Nullable voucher);
6659

67-
static inline bool swift_voucher_needs_adopt(voucher_t _Nullable voucher) {
68-
return true;
69-
}
70-
7160
#endif // __has_include(<os/voucher_private.h>)
7261

7362
static inline void swift_voucher_release(voucher_t _Nullable voucher) {
@@ -88,10 +77,26 @@ static inline voucher_t _Nullable voucher_copy(void) { return nullptr; }
8877
static inline voucher_t _Nullable voucher_adopt(voucher_t _Nullable voucher) {
8978
return nullptr;
9079
}
91-
static inline bool swift_voucher_needs_adopt(voucher_t _Nullable voucher) {
92-
return true;
93-
}
9480
static inline void swift_voucher_release(voucher_t _Nullable voucher) {}
9581
#endif // __APPLE__
9682

83+
// Declare our own voucher_needs_adopt for when we don't get it from the SDK.
84+
// This declaration deliberately takes `void *` instead of `voucher_t`. When the
85+
// SDK provides one that takes `voucher_t`, then C++ overload resolution will
86+
// favor that one. When the SDK does not provide a declaration, then the call
87+
// site will invoke this stub instead.
88+
static inline bool voucher_needs_adopt(void * _Nullable voucher) {
89+
return true;
90+
}
91+
92+
static inline bool swift_voucher_needs_adopt(voucher_t _Nullable voucher) {
93+
#if __APPLE__
94+
if (__builtin_available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *))
95+
return voucher_needs_adopt(voucher);
96+
return true;
97+
#else
98+
return voucher_needs_adopt(voucher);
9799
#endif
100+
}
101+
102+
#endif // SWIFT_CONCURRENCY_VOUCHERSHIMS_H

0 commit comments

Comments
 (0)