Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 4 additions & 8 deletions include/exec/sequence/merge_each.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,15 +857,11 @@ namespace experimental::execution
struct __gather_sequences_t
{
template <class _Completions>
using __f = STDEXEC::__gather_completion_signatures_t<
_Completions,
using __f = STDEXEC::__gather_completions_t<
STDEXEC::set_value_t,
// if set_value
__arg_of_t<_Sequence, _Sender, _Env...>::template __f,
// else remove
STDEXEC::__mconst<STDEXEC::__mlist<>>::__f,
// concat to __mlist result
STDEXEC::__mtry<STDEXEC::__mconcat<STDEXEC::__q<STDEXEC::__mlist>>>::__f>;
_Completions,
__arg_of_t<_Sequence, _Sender, _Env...>,
STDEXEC::__mtry<STDEXEC::__mconcat<STDEXEC::__qq<STDEXEC::__mlist>>>>;
};

template <class _Sequence, class _Sender, class... _Env>
Expand Down
2 changes: 1 addition & 1 deletion include/exec/static_thread_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ namespace experimental::execution
struct _static_thread_pool::_opstate : task_base
{
private:
friend struct ::exec::_pool_::_static_thread_pool::scheduler::_sender;
friend class ::exec::_pool_::_static_thread_pool::scheduler::_sender;

explicit _opstate(_static_thread_pool& pool,
remote_queue* queue,
Expand Down
26 changes: 10 additions & 16 deletions include/nvexec/stream/when_all.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,6 @@ namespace nv::execution::_strm
}

private:
template <class Completions>
using sends_values_t = __gather_completion_signatures_t<Completions,
set_value_t,
__mconst<__mbool<true>>::__f,
__mconst<__mbool<false>>::__f,
__mor_t>;

struct attrs
{
template <class... Env>
Expand Down Expand Up @@ -308,13 +301,14 @@ namespace nv::execution::_strm
exit_opstate_t<__copy_cvref_t<_when_all_sender_t, Sender>, receiver<CvReceiver, Index>>;

// tuple<tuple<Vs1...>, tuple<Vs2...>, ...>
using _child_values_t = __if<sends_values_t<_completions_t>,
__minvoke<__qq<__tuple>,
__value_types_of_t<Senders,
_when_all::env_t<_env_t>,
__qq<__decayed_tuple>,
__msingle_or<void>>...>,
__>;
using _child_values_t =
__if_c<STDEXEC::__detail::__count_of<set_value_t, _completions_t> != 0,
__minvoke<__qq<__tuple>,
__value_types_of_t<Senders,
_when_all::env_t<_env_t>,
__qq<__decayed_tuple>,
__msingle_or<void>>...>,
__>;

using _errors_t =
error_types_of_t<when_all_sender, _when_all::env_t<_env_t>, __uniqued_variant>;
Expand Down Expand Up @@ -394,7 +388,7 @@ namespace nv::execution::_strm
switch (state_.load(std::memory_order_relaxed))
{
case _when_all::started:
if constexpr (sends_values_t<_completions_t>::value)
if constexpr (STDEXEC::__detail::__count_of<set_value_t, _completions_t> != 0)
{
// All child operations completed successfully:
STDEXEC::__apply(
Expand Down Expand Up @@ -462,7 +456,7 @@ namespace nv::execution::_strm
template <std::size_t Index, class... Args>
void _set_value(Args&&... args) noexcept
{
if constexpr (sends_values_t<_completions_t>::value)
if constexpr (STDEXEC::__detail::__count_of<set_value_t, _completions_t> != 0)
{
// We only need to bother recording the completion values
// if we're not already in the "error" or "stopped" state.
Expand Down
2 changes: 1 addition & 1 deletion include/stdexec/__detail/__completion_signatures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ namespace STDEXEC
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// __gather_completion_signatures_t
// __gather_completions_t
namespace __detail
{
template <class _WantedTag>
Expand Down
6 changes: 3 additions & 3 deletions include/stdexec/__detail/__config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,21 +855,21 @@ namespace STDEXEC
# define STDEXEC_EXPLICIT_THIS_END(_NAME) \
template <class... _Ts> \
STDEXEC_ATTRIBUTE(always_inline, host, device) \
auto _NAME(_Ts&&... __args) && STDEXEC_AUTO_RETURN \
constexpr auto _NAME(_Ts&&... __args) && STDEXEC_AUTO_RETURN \
( \
STDEXEC_EXPLICIT_THIS_MANGLE(_NAME)(std::move(*this), static_cast<_Ts&&>(__args)...) \
) \
\
template <class... _Ts> \
STDEXEC_ATTRIBUTE(always_inline, host, device) \
auto _NAME(_Ts&&... __args) & STDEXEC_AUTO_RETURN \
constexpr auto _NAME(_Ts&&... __args) & STDEXEC_AUTO_RETURN \
( \
STDEXEC_EXPLICIT_THIS_MANGLE(_NAME)(*this, static_cast<_Ts&&>(__args)...) \
) \
\
template <class... _Ts> \
STDEXEC_ATTRIBUTE(always_inline, host, device) \
auto _NAME(_Ts&&... __args) const & STDEXEC_AUTO_RETURN \
constexpr auto _NAME(_Ts&&... __args) const & STDEXEC_AUTO_RETURN \
( \
STDEXEC_EXPLICIT_THIS_MANGLE(_NAME)(*this, static_cast<_Ts&&>(__args)...) \
)
Expand Down
39 changes: 27 additions & 12 deletions include/stdexec/__detail/__then.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ namespace STDEXEC
// [execution.senders.adaptors.then]
namespace __then
{
using __on_not_callable = __mbind_front_q<__callable_error_t, then_t>;

template <class _Fun, class _CvSender, class... _Env>
using __completions_t = __transform_completion_signatures_t<
__completion_signatures_of_t<_CvSender, _Env...>,
__with_error_invoke_t<__on_not_callable, set_value_t, _Fun, _CvSender, _Env...>,
__mbind_front<__mtry_catch_q<__set_value_from_t, __on_not_callable>, _Fun>::template __f>;

struct __then_impl : __sexpr_defaults
{
static constexpr auto __get_attrs =
Expand All @@ -50,13 +42,36 @@ namespace STDEXEC
return __sync_attrs{__child};
};

template <class _Fun>
static consteval auto __transform_value_completion() noexcept
{
return []<class... _Args>()
{
if constexpr (__nothrow_invocable<_Fun, _Args...>)
{
return completion_signatures<__single_value_sig_t<__invoke_result_t<_Fun, _Args...>>>();
}
else if constexpr (__invocable<_Fun, _Args...>)
{
return completion_signatures<__single_value_sig_t<__invoke_result_t<_Fun, _Args...>>,
set_error_t(std::exception_ptr)>();
}
else
{
return STDEXEC::__throw_compile_time_error(
__callable_error_t<then_t, _Fun, _Args...>());
}
};
}

template <class _Sender, class... _Env>
static consteval auto __get_completion_signatures() //
-> __completions_t<__decay_t<__data_of<_Sender>>, __child_of<_Sender>, _Env...>
static consteval auto __get_completion_signatures()
{
static_assert(__sender_for<_Sender, then_t>);
// TODO: update this to use constant evaluation:
return {};
using __fn_t = __decay_t<__data_of<_Sender>>;
return STDEXEC::__transform_completion_signatures(
STDEXEC::get_completion_signatures<__child_of<_Sender>, _Env...>(),
__transform_value_completion<__fn_t>());
};

struct __complete_fn
Expand Down
96 changes: 5 additions & 91 deletions include/stdexec/__detail/__transform_completion_signatures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,90 +179,6 @@ namespace STDEXEC
_ErrorTransform,
_StoppedSigs>;

//////////////////////////////////////////////////////////////////////////////////////////////////
// __gather_completion_signatures_t
namespace __cmplsigs
{
template <class _WantedTag, bool = true>
struct __gather_sigs_fn;

template <>
struct __gather_sigs_fn<set_value_t>
{
template <class _Sigs,
template <class...> class _Then,
template <class...> class _Else,
template <class...> class _Variant,
class... _More>
using __f = __transform_reduce_completion_signatures_t<
_Sigs,
_Then,
__mbind_front_q<_Else, set_error_t>::template __f,
_Else<set_stopped_t>,
_Variant,
_More...>;
};

template <>
struct __gather_sigs_fn<set_error_t>
{
template <class _Sigs,
template <class...> class _Then,
template <class...> class _Else,
template <class...> class _Variant,
class... _More>
using __f = __transform_reduce_completion_signatures_t<
_Sigs,
__mbind_front_q<_Else, set_value_t>::template __f,
_Then,
_Else<set_stopped_t>,
_Variant,
_More...>;
};

template <>
struct __gather_sigs_fn<set_stopped_t>
{
template <class _Sigs,
template <class...> class _Then,
template <class...> class _Else,
template <class...> class _Variant,
class... _More>
using __f = __transform_reduce_completion_signatures_t<
_Sigs,
__mbind_front_q<_Else, set_value_t>::template __f,
__mbind_front_q<_Else, set_error_t>::template __f,
_Then<>,
_Variant,
_More...>;
};

template <class _WantedTag>
struct __gather_sigs_fn<_WantedTag, false>
{
template <class _Error,
template <class...> class,
template <class...> class,
template <class...> class,
class...>
using __f = _Error;
};
} // namespace __cmplsigs

template <class _Sigs,
class _WantedTag,
template <class...> class _Then,
template <class...> class _Else,
template <class...> class _Variant,
class... _More>
using __gather_completion_signatures_t = //
__cmplsigs::__gather_sigs_fn<_WantedTag, __ok<_Sigs>>::template __f< //
_Sigs,
_Then,
_Else,
_Variant,
_More...>;

//////////////////////////////////////////////////////////////////////////////////////////////////
// begin implementation of __transform_completion_signatures
struct _IN_TRANSFORM_COMPLETION_SIGNATURES_;
Expand Down Expand Up @@ -291,7 +207,7 @@ namespace STDEXEC

template <class _Fn, class... _Args>
using __transform_expr_t =
decltype(__cmplsigs::__transform_expr<_Args...>(__declval<_Fn const &>(), 0));
__decay_t<decltype(__cmplsigs::__transform_expr<_Args...>(__declval<_Fn const &>(), 0))>;

template <class... _Args, class _Fn>
[[nodiscard]]
Expand Down Expand Up @@ -598,12 +514,10 @@ namespace STDEXEC

template <class _Catch, class _Tag, class _Fun, class _Sender, class... _Env>
using __with_error_invoke_t =
__if<__gather_completion_signatures_t<
__completion_signatures_of_t<_Sender, _Env...>,
_Tag,
__mbind_front<__mtry_catch_q<__nothrow_invocable_t, _Catch>, _Fun>::template __f,
__mconst<__mbool<true>>::__f,
__mand>,
__if<__gather_completions_t<_Tag,
__completion_signatures_of_t<_Sender, _Env...>,
__mbind_front<__mtry_catch_q<__nothrow_invocable_t, _Catch>, _Fun>,
__qq<__mand>>,
completion_signatures<>,
__eptr_completion_t>;

Expand Down
48 changes: 35 additions & 13 deletions include/stdexec/__detail/__upon_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "__completion_signatures_of.hpp"
#include "__diagnostics.hpp"
#include "__meta.hpp"
#include "__queries.hpp"
#include "__sender_adaptor_closure.hpp"
#include "__senders.hpp" // IWYU pragma: keep for __well_formed_sender
#include "__transform_completion_signatures.hpp"
Expand All @@ -33,24 +34,45 @@ namespace STDEXEC
// [execution.senders.adaptors.upon_error]
namespace __upon_error
{
using __on_not_callable = __mbind_front_q<__callable_error_t, upon_error_t>;

template <class _Fun, class _CvSender, class... _Env>
using __completion_signatures_t = __transform_completion_signatures_t<
__completion_signatures_of_t<_CvSender, _Env...>,
__with_error_invoke_t<__on_not_callable, set_error_t, _Fun, _CvSender, _Env...>,
__cmplsigs::__default_set_value,
__mbind_front<__mtry_catch_q<__set_value_from_t, __on_not_callable>, _Fun>::template __f>;

struct __upon_error_impl : __sexpr_defaults
{
static constexpr auto __get_attrs =
[]<class _Child>(__ignore, __ignore, _Child const & __child) noexcept
{
return __sync_attrs{__child};
};

template <class _Fun>
static consteval auto __transform_error_completion() noexcept
{
return []<class... _Args>()
{
if constexpr (__nothrow_invocable<_Fun, _Args...>)
{
return completion_signatures<__single_value_sig_t<__invoke_result_t<_Fun, _Args...>>>();
}
else if constexpr (__invocable<_Fun, _Args...>)
{
return completion_signatures<__single_value_sig_t<__invoke_result_t<_Fun, _Args...>>,
set_error_t(std::exception_ptr)>();
}
else
{
return STDEXEC::__throw_compile_time_error(
__callable_error_t<upon_error_t, _Fun, _Args...>());
}
};
}

template <class _Sender, class... _Env>
static consteval auto __get_completion_signatures() //
-> __completion_signatures_t<__decay_t<__data_of<_Sender>>, __child_of<_Sender>, _Env...>
static consteval auto __get_completion_signatures()
{
static_assert(__sender_for<_Sender, upon_error_t>);
// TODO: update this to use constant evaluation:
return {};
using __fn_t = __decay_t<__data_of<_Sender>>;
return STDEXEC::__transform_completion_signatures(
STDEXEC::get_completion_signatures<__child_of<_Sender>, _Env...>(),
{},
__transform_error_completion<__fn_t>());
};

static constexpr auto __complete =
Expand Down
23 changes: 8 additions & 15 deletions include/stdexec/__detail/__upon_stopped.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "__basic_sender.hpp"
#include "__completion_signatures_of.hpp"
#include "__diagnostics.hpp"
#include "__meta.hpp"
#include "__sender_adaptor_closure.hpp"
#include "__senders.hpp" // IWYU pragma: keep for __well_formed_sender
Expand All @@ -33,25 +32,19 @@ namespace STDEXEC
// [execution.senders.adaptors.upon_stopped]
namespace __upon_stopped
{
using __on_not_callable = __mbind_front_q<__callable_error_t, upon_stopped_t>;

template <class _Fun, class _CvSender, class... _Env>
using __completion_signatures_t = __transform_completion_signatures_t<
__completion_signatures_of_t<_CvSender, _Env...>,
__with_error_invoke_t<__on_not_callable, set_stopped_t, _Fun, _CvSender, _Env...>,
__cmplsigs::__default_set_value,
__cmplsigs::__default_set_error,
__set_value_from_t<_Fun>>;

struct __upon_stopped_impl : __sexpr_defaults
{
template <class _Sender, class... _Env>
static consteval auto __get_completion_signatures() //
-> __completion_signatures_t<__decay_t<__data_of<_Sender>>, __child_of<_Sender>, _Env...>
static consteval auto __get_completion_signatures()
{
static_assert(__sender_for<_Sender, upon_stopped_t>);
// TODO: update this to use constant evaluation:
return {};
using __fn_t = __decay_t<__data_of<_Sender>>;
return STDEXEC::__transform_completion_signatures(
STDEXEC::get_completion_signatures<__child_of<_Sender>, _Env...>(),
{},
{},
__always{__set_value_from_t<__fn_t>()},
__eptr_completion_unless_t<__mbool<__nothrow_callable<__fn_t>>>());
};

static constexpr auto __complete =
Expand Down
Loading
Loading