Skip to content

[Concurrency] Use overload resolution to stub voucher_needs_adopt. #39195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions include/swift/Runtime/VoucherShims.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@

#if SWIFT_HAS_VOUCHER_HEADER

static inline bool swift_voucher_needs_adopt(voucher_t _Nullable voucher) {
if (__builtin_available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)) {
return voucher_needs_adopt(voucher);
}
return true;
}

#else

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

static inline bool swift_voucher_needs_adopt(voucher_t _Nullable voucher) {
return true;
}

#endif // __has_include(<os/voucher_private.h>)

static inline void swift_voucher_release(voucher_t _Nullable voucher) {
Expand All @@ -88,10 +77,26 @@ static inline voucher_t _Nullable voucher_copy(void) { return nullptr; }
static inline voucher_t _Nullable voucher_adopt(voucher_t _Nullable voucher) {
return nullptr;
}
static inline bool swift_voucher_needs_adopt(voucher_t _Nullable voucher) {
return true;
}
static inline void swift_voucher_release(voucher_t _Nullable voucher) {}
#endif // __APPLE__

// Declare our own voucher_needs_adopt for when we don't get it from the SDK.
// This declaration deliberately takes `void *` instead of `voucher_t`. When the
// SDK provides one that takes `voucher_t`, then C++ overload resolution will
// favor that one. When the SDK does not provide a declaration, then the call
// site will invoke this stub instead.
static inline bool voucher_needs_adopt(void * _Nullable voucher) {
return true;
}

static inline bool swift_voucher_needs_adopt(voucher_t _Nullable voucher) {
#if __APPLE__
if (__builtin_available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *))
return voucher_needs_adopt(voucher);
return true;
#else
return voucher_needs_adopt(voucher);
#endif
}

#endif // SWIFT_CONCURRENCY_VOUCHERSHIMS_H