diff --git a/include/nvexec/multi_gpu_context.cuh b/include/nvexec/multi_gpu_context.cuh index 07b053e88..d6f410809 100644 --- a/include/nvexec/multi_gpu_context.cuh +++ b/include/nvexec/multi_gpu_context.cuh @@ -43,8 +43,7 @@ namespace nv::execution return ctx_.hub_ == other.ctx_.hub_ && ctx_.priority_ == other.ctx_.priority_; } - [[nodiscard]] - STDEXEC_ATTRIBUTE(host, device) auto schedule() const noexcept + STDEXEC_ATTRIBUTE(nodiscard, host, device) auto schedule() const noexcept { return sender{num_devices_, ctx_}; } diff --git a/include/stdexec/__detail/__config.hpp b/include/stdexec/__detail/__config.hpp index 4e24bde43..4f9216768 100644 --- a/include/stdexec/__detail/__config.hpp +++ b/include/stdexec/__detail/__config.hpp @@ -355,7 +355,24 @@ namespace STDEXEC::__std // STDEXEC_ATTRIBUTE(attr1, attr2, ...) // void foo() { ... } #define STDEXEC_ATTRIBUTE_I(_ATTR) STDEXEC_PP_SWITCH(STDEXEC_ATTRIBUTE, _ATTR) -#define STDEXEC_ATTRIBUTE(...) STDEXEC_PP_FOR_EACH(STDEXEC_ATTRIBUTE_I, __VA_ARGS__) + +// Dispatch on the number of attributes. Specifying more than 4 attributes +// expands to an undeclared identifier whose name explains the problem. +#define STDEXEC_ATTRIBUTE(...) \ + STDEXEC_PP_CAT(STDEXEC_ATTRIBUTE_N_, STDEXEC_ATTRIBUTE_COUNT(__VA_ARGS__))(__VA_ARGS__) +#define STDEXEC_ATTRIBUTE_COUNT(...) \ + STDEXEC_ATTRIBUTE_PICK(__VA_ARGS__ __VA_OPT__(, ) many, 4, 3, 2, 1, 0) +#define STDEXEC_ATTRIBUTE_PICK(_1, _2, _3, _4, _5, _N, ...) _N +#define STDEXEC_ATTRIBUTE_N_0() +#define STDEXEC_ATTRIBUTE_N_1(_A1) STDEXEC_ATTRIBUTE_I(_A1) +#define STDEXEC_ATTRIBUTE_N_2(_A1, _A2) STDEXEC_ATTRIBUTE_I(_A1) STDEXEC_ATTRIBUTE_I(_A2) +#define STDEXEC_ATTRIBUTE_N_3(_A1, _A2, _A3) \ + STDEXEC_ATTRIBUTE_I(_A1) STDEXEC_ATTRIBUTE_I(_A2) STDEXEC_ATTRIBUTE_I(_A3) +#define STDEXEC_ATTRIBUTE_N_4(_A1, _A2, _A3, _A4) \ + STDEXEC_ATTRIBUTE_I(_A1) STDEXEC_ATTRIBUTE_I(_A2) STDEXEC_ATTRIBUTE_I(_A3) \ + STDEXEC_ATTRIBUTE_I(_A4) +#define STDEXEC_ATTRIBUTE_N_many(...) \ + STDEXEC_ATTRIBUTE_error_too_many_attributes_the_limit_is_4 #define STDEXEC_ATTRIBUTE_SWITCH_no_unique_address STDEXEC_PP_CASE(NO_UNIQUE_ADDRESS) #define STDEXEC_ATTRIBUTE_SWITCH_always_inline STDEXEC_PP_CASE(ALWAYS_INLINE) diff --git a/include/stdexec/__detail/__on.hpp b/include/stdexec/__detail/__on.hpp index 854829758..865c1bec4 100644 --- a/include/stdexec/__detail/__on.hpp +++ b/include/stdexec/__detail/__on.hpp @@ -196,9 +196,8 @@ namespace STDEXEC STDEXEC_TERMINATE(); } - [[nodiscard]] - STDEXEC_ATTRIBUTE(always_inline, host, device) constexpr auto get_env() const noexcept - -> env_of_t<_Child> + STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) + constexpr auto get_env() const noexcept -> env_of_t<_Child> { return STDEXEC::get_env(__child_); } @@ -240,10 +239,8 @@ namespace STDEXEC template requires __completion_query<_Query> && __can_return_v<_Sender, _Env> && __queryable_with>, _Query, _Env const &> - [[nodiscard]] - STDEXEC_ATTRIBUTE(host, device) constexpr auto query(_Query, - _Env const & __env) const noexcept - -> decltype(auto) + STDEXEC_ATTRIBUTE(nodiscard, host, device) + constexpr auto query(_Query, _Env const & __env) const noexcept -> decltype(auto) { auto __lowered = __on::__lower_proxy(__sndr_, __env); return STDEXEC::get_env(__lowered).query(_Query(), __env); @@ -252,9 +249,8 @@ namespace STDEXEC template <__forwarding_query _Query, class... _Args> requires(!__completion_query<_Query>) && __queryable_with>, _Query, _Args...> - [[nodiscard]] - STDEXEC_ATTRIBUTE(always_inline, host, device) constexpr auto query(_Query, - _Args&&... __args) const + STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) + constexpr auto query(_Query, _Args&&... __args) const noexcept(__nothrow_queryable_with>, _Query, _Args...>) -> decltype(auto) { diff --git a/include/stdexec/__detail/__preprocessor.hpp b/include/stdexec/__detail/__preprocessor.hpp index e5fab7f71..60c95602a 100644 --- a/include/stdexec/__detail/__preprocessor.hpp +++ b/include/stdexec/__detail/__preprocessor.hpp @@ -77,38 +77,6 @@ #define STDEXEC_PP_WHEN(_XP, ...) STDEXEC_PP_IF(_XP, STDEXEC_PP_EXPAND, STDEXEC_PP_EAT)(__VA_ARGS__) -//////////////////////////////////////////////////////////////////////////////// -// STDEXEC_PP_FOR_EACH -// Inspired by "Recursive macros with C++20 __VA_OPT__", by David Mazières -// https://www.scs.stanford.edu/~dm/blog/va-opt.html -#define STDEXEC_PP_EXPAND_R3(...) \ - STDEXEC_PP_EXPAND(STDEXEC_PP_EXPAND(STDEXEC_PP_EXPAND(STDEXEC_PP_EXPAND(__VA_ARGS__)))) -#define STDEXEC_PP_EXPAND_R2(...) \ - STDEXEC_PP_EXPAND_R3( \ - STDEXEC_PP_EXPAND_R3(STDEXEC_PP_EXPAND_R3(STDEXEC_PP_EXPAND_R3(__VA_ARGS__)))) -#define STDEXEC_PP_EXPAND_R1(...) \ - STDEXEC_PP_EXPAND_R2( \ - STDEXEC_PP_EXPAND_R2(STDEXEC_PP_EXPAND_R2(STDEXEC_PP_EXPAND_R2(__VA_ARGS__)))) -#define STDEXEC_PP_EXPAND_R(...) \ - STDEXEC_PP_EXPAND_R1( \ - STDEXEC_PP_EXPAND_R1(STDEXEC_PP_EXPAND_R1(STDEXEC_PP_EXPAND_R1(__VA_ARGS__)))) - -#define STDEXEC_PP_FOR_EACH_AGAIN() STDEXEC_PP_FOR_EACH_HELPER -#define STDEXEC_PP_FOR_EACH_HELPER(_MACRO, _A1, ...) \ - _MACRO(_A1) __VA_OPT__(STDEXEC_PP_FOR_EACH_AGAIN STDEXEC_PP_PARENS()(_MACRO, __VA_ARGS__)) /**/ -#define STDEXEC_PP_FOR_EACH(_MACRO, ...) \ - __VA_OPT__(STDEXEC_PP_EXPAND_R(STDEXEC_PP_FOR_EACH_HELPER(_MACRO, __VA_ARGS__))) - -//////////////////////////////////////////////////////////////////////////////// - -#define STDEXEC_PP_BACK_AGAIN() STDEXEC_PP_BACK_I -#define STDEXEC_PP_BACK_I(_A1, ...) \ - STDEXEC_PP_FRONT(__VA_OPT__(, ) _A1, ) \ - __VA_OPT__(STDEXEC_PP_BACK_AGAIN STDEXEC_PP_PARENS()(__VA_ARGS__)) -#define STDEXEC_PP_BACK(...) __VA_OPT__(STDEXEC_PP_EXPAND_R(STDEXEC_PP_BACK_I(__VA_ARGS__))) - -#define STDEXEC_PP_TAIL(_IGN, ...) __VA_ARGS__ - #define STDEXEC_PP_REPEAT_I(_N, _MACRO, ...) STDEXEC_PP_REPEAT_##_N(_MACRO, __VA_ARGS__) #define STDEXEC_PP_REPEAT_0(_MACRO, ...) #define STDEXEC_PP_REPEAT_1(_MACRO, ...) _MACRO(0 __VA_OPT__(, ) __VA_ARGS__) diff --git a/include/stdexec/__detail/__sender_facade.hpp b/include/stdexec/__detail/__sender_facade.hpp index 60014fc10..e5ca7c967 100644 --- a/include/stdexec/__detail/__sender_facade.hpp +++ b/include/stdexec/__detail/__sender_facade.hpp @@ -1000,8 +1000,7 @@ namespace STDEXEC STDEXEC_MODULE_EXPORT_AUTHORING struct __no_env_receiver : __receiver_archetype_base { - [[nodiscard]] - STDEXEC_ATTRIBUTE(host, device) constexpr auto get_env() const noexcept -> env<> + STDEXEC_ATTRIBUTE(nodiscard, host, device) constexpr auto get_env() const noexcept -> env<> { return {}; } diff --git a/include/stdexec/__detail/__variant.hpp b/include/stdexec/__detail/__variant.hpp index 4f8be625b..8f6e0aefe 100644 --- a/include/stdexec/__detail/__variant.hpp +++ b/include/stdexec/__detail/__variant.hpp @@ -306,30 +306,26 @@ namespace STDEXEC return *this; } - [[nodiscard]] - STDEXEC_ATTRIBUTE(host, device, always_inline) // - constexpr auto __data() noexcept -> void * + STDEXEC_ATTRIBUTE(nodiscard, host, device, always_inline) + constexpr auto __data() noexcept -> void * { return std::addressof(__storage_); } - [[nodiscard]] - STDEXEC_ATTRIBUTE(host, device, always_inline) // - constexpr auto __data() const noexcept -> void const * + STDEXEC_ATTRIBUTE(nodiscard, host, device, always_inline) + constexpr auto __data() const noexcept -> void const * { return std::addressof(__storage_); } - [[nodiscard]] - STDEXEC_ATTRIBUTE(host, device, always_inline) // - constexpr auto index() const noexcept -> std::size_t + STDEXEC_ATTRIBUTE(nodiscard, host, device, always_inline) + constexpr auto index() const noexcept -> std::size_t { return __index_; } - [[nodiscard]] - STDEXEC_ATTRIBUTE(host, device, always_inline) // - constexpr auto __is_valueless() const noexcept -> bool + STDEXEC_ATTRIBUTE(nodiscard, host, device, always_inline) + constexpr auto __is_valueless() const noexcept -> bool { return __index_ == __variant_npos; }