diff options
| author | rraed <[email protected]> | 2026-02-18 20:00:40 +0300 |
|---|---|---|
| committer | rraed <[email protected]> | 2026-02-18 21:15:00 +0300 |
| commit | 2f21a98b89007c35af0bcdd5c7deb78fcdba547f (patch) | |
| tree | cf45243c21d1178fdb1cc8596f04315162d87743 /util | |
| parent | d792f42da85a7179a44803afdad3a3bc237ae00a (diff) | |
Attributes for coroutine return types
commit_hash:14705eb46ebc07f5bdb3fd77df6d1cbe23720351
Diffstat (limited to 'util')
| -rw-r--r-- | util/system/compiler.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/util/system/compiler.h b/util/system/compiler.h index b1823737691..f63225c81b7 100644 --- a/util/system/compiler.h +++ b/util/system/compiler.h @@ -813,3 +813,49 @@ Y_FORCE_INLINE void DoNotOptimizeAway(const T&) = delete; #else #define Y_NO_UNIQUE_ADDRESS #endif + +/** + * @def Y_CORO_AWAIT_ELIDABLE + * + * A class attribute which can be applied to a coroutine return type. + * + * Allows the compiler to apply heap allocation elision when the coroutine with such return type + * is immediately awaited or passed as an argument to a Y_CORO_AWAIT_ELIDABLE_ARGUMENT parameter. + * + * See https://clang.llvm.org/docs/AttributeReference.html#coro-await-elidable + */ +#if defined(__clang__) && Y_HAS_CPP_ATTRIBUTE(clang::coro_await_elidable) + #define Y_CORO_AWAIT_ELIDABLE [[clang::coro_await_elidable]] +#else + #define Y_CORO_AWAIT_ELIDABLE +#endif + +/** + * @def Y_CORO_AWAIT_ELIDABLE_ARGUMENT + * + * A function parameter attribute which allows the compiler to apply heap allocation elision for + * a coroutine with Y_CORO_AWAIT_ELIDABLE return type passed as argument to the annotated parameter. + * + * See https://clang.llvm.org/docs/AttributeReference.html#coro-await-elidable-argument + */ +#if defined(__clang__) && Y_HAS_CPP_ATTRIBUTE(clang::coro_await_elidable_argument) + #define Y_CORO_AWAIT_ELIDABLE_ARGUMENT [[clang::coro_await_elidable_argument]] +#else + #define Y_CORO_AWAIT_ELIDABLE_ARGUMENT +#endif + +/** + * @def Y_CORO_ONLY_DESTROY_WHEN_COMPLETE + * + * A class attribute which can be applied to a coroutine return type. + * + * Allows the compiler to skip generation of destructors for intermediate suspension points + * and reduce code size. + * + * See https://clang.llvm.org/docs/AttributeReference.html#coro-only-destroy-when-complete + */ +#if defined(__clang__) && Y_HAS_CPP_ATTRIBUTE(clang::coro_only_destroy_when_complete) + #define Y_CORO_ONLY_DESTROY_WHEN_COMPLETE [[clang::coro_only_destroy_when_complete]] +#else + #define Y_CORO_ONLY_DESTROY_WHEN_COMPLETE +#endif |
