Skip to content
Open
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
14 changes: 4 additions & 10 deletions include/exec/detail/repeat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,10 @@ namespace experimental::execution::__repeat
// themselves afterward.) If the state is for a walk, __body_op_ is a placeholder.
constexpr auto __connect_body() noexcept(__nothrow_connect) -> __body_op_t &
{
if constexpr (__facade::__walking_receiver<_Receiver>)
{
return __body_op_.emplace();
}
else
{
return __body_op_.__emplace_from(STDEXEC::connect,
__child_t(__child_),
__body_rcvr_t{this});
}
return __facade::__emplace_state_op<_Receiver>(__body_op_,
STDEXEC::connect,
__child_t(__child_),
__body_rcvr_t{this});
}

// Destroys the operations, before the operation completes
Expand Down
12 changes: 5 additions & 7 deletions include/stdexec/__detail/__associate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,12 @@ namespace STDEXEC
: __rcvr_(static_cast<_Receiver&&>(__rcvr))
, __assoc_(STDEXEC::__allocator_aware_forward(std::move(__parts.first), __rcvr_))
{
if constexpr (!__facade::__walking_receiver<_Receiver>)
if (__assoc_)
{
if (__assoc_)
{
__op_.__emplace_from(STDEXEC::connect,
std::move(*__parts.second),
__wrapped_rcvr_t{this});
}
__facade::__emplace_state_op<_Receiver>(__op_,
STDEXEC::connect,
std::move(*__parts.second),
__wrapped_rcvr_t{this});
}
}

Expand Down
13 changes: 7 additions & 6 deletions include/stdexec/__detail/__continues_on.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,19 @@ namespace STDEXEC

STDEXEC_IMMOVABLE(__state);

_Receiver __rcvr_;
__env2_t const __env2_;
__storage_t __storage_{};
connect_result_t<__sched_sndr_t, __sched_rcvr_t> __op_;
_Receiver __rcvr_;
__env2_t const __env2_;
__storage_t __storage_{};
__facade::__state_op_t<_Receiver, connect_result_t, __sched_sndr_t, __sched_rcvr_t> __op_;

private:
template <class _Child>
constexpr explicit __state(__scheduler_t __sch, _Child const & __child, _Receiver&& __rcvr)
: __rcvr_(static_cast<_Receiver&&>(__rcvr))
, __env2_(__trnsfr::__mk_env2(__child, STDEXEC::get_env(__rcvr_)))
, __op_(STDEXEC::connect(STDEXEC::schedule(static_cast<__scheduler_t const &>(__sch)),
__sched_rcvr_t{this}))
, __op_(__facade::__make_state_op<_Receiver>(STDEXEC::connect,
STDEXEC::schedule(__sch),
__sched_rcvr_t{this}))
{}
};

Expand Down
10 changes: 7 additions & 3 deletions include/stdexec/__detail/__counting_scopes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,18 @@ namespace STDEXEC
using __sched_sender_t = __call_result_t<schedule_t, __scheduler_of_t<env_of_t<_Rcvr>>>;
using __sched_rcvr_t =
__facade::__receiver_t<__join_algo, __sched_op, __join_state, _Sender, _Rcvr>;
using __op_t = connect_result_t<__sched_sender_t, __sched_rcvr_t>;
// (A walk's state holds a placeholder for the operation: see __facade::__state_op_t.)
using __op_t =
__facade::__state_op_t<_Rcvr, connect_result_t, __sched_sender_t, __sched_rcvr_t>;

explicit __join_state(__base_scope* __scope, _Rcvr __rcvr)
noexcept(__nothrow_connectable<__sched_sender_t, __sched_rcvr_t>)
: __join_state_base(__scope, &__join_state::__notify)
, __rcvr_(std::move(__rcvr))
, __op_(STDEXEC::connect(schedule(get_start_scheduler(STDEXEC::get_env(__rcvr_))),
__sched_rcvr_t{this}))
, __op_(__facade::__make_state_op<_Rcvr>(STDEXEC::connect,
schedule(
get_start_scheduler(STDEXEC::get_env(__rcvr_))),
__sched_rcvr_t{this}))
{}

__join_state(__join_state&&) = delete;
Expand Down
33 changes: 9 additions & 24 deletions include/stdexec/__detail/__finally.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,16 @@ namespace STDEXEC
&& __nothrow_connectable<__initial_t, __initial_rcvr_t>)
: __rcvr_(static_cast<_Receiver&&>(__rcvr))
, __env2_(__trnsfr::__mk_env2(__facade::__get_child<0>(__sndr), STDEXEC::get_env(__rcvr_)))
, __final_op_(__state::__connect_final(static_cast<_Sender&&>(__sndr), this))
, __final_op_(__facade::__make_state_op<_Receiver>(STDEXEC::connect,
__facade::__get_child<1>(
static_cast<_Sender&&>(__sndr)),
__final_rcvr_t{this}))
{
if constexpr (!__facade::__walking_receiver<_Receiver>)
{
__initial_op_.__emplace_from(STDEXEC::connect,
__facade::__get_child<0>(static_cast<_Sender&&>(__sndr)),
__initial_rcvr_t{this});
}
__facade::__emplace_state_op<_Receiver>(__initial_op_,
STDEXEC::connect,
__facade::__get_child<0>(
static_cast<_Sender&&>(__sndr)),
__initial_rcvr_t{this});
}

STDEXEC_IMMOVABLE(__state);
Expand All @@ -162,23 +164,6 @@ namespace STDEXEC
__storage_t __storage_{};
__final_op_t __final_op_;
__optional<__initial_op_t> __initial_op_{};

private:
// Connects the final sender, unless the state is for a walk: then __final_op_ is a
// placeholder.
static constexpr auto __connect_final(_Sender&& __sndr, __state* __self)
noexcept(__nothrow_connectable<__final_t, __final_rcvr_t>) -> __final_op_t
{
if constexpr (__facade::__walking_receiver<_Receiver>)
{
return {};
}
else
{
return STDEXEC::connect(__facade::__get_child<1>(static_cast<_Sender&&>(__sndr)),
__final_rcvr_t{__self});
}
}
};

// __finally_(initial, final): when the initial sender completes, its results are saved,
Expand Down
7 changes: 3 additions & 4 deletions include/stdexec/__detail/__just.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ namespace STDEXEC
// Not static_cast<decltype(__state.__data_)&&>(__state.__data_): nvcc's cudafe++
// drops the && when it hands the code to the host compiler, which then copies the
// data instead of moving it.
return STDEXEC::__apply(
[&]<class... _Ts>(_Ts&&... __vs) noexcept
{ return __facade::__send(__state.__rcvr_, _SetTag(), static_cast<_Ts&&>(__vs)...); },
static_cast<_State&&>(__state).__data_);
return __facade::__send_tuple(__state.__rcvr_,
_SetTag(),
static_cast<_State&&>(__state).__data_);
}
};
} // namespace __just
Expand Down
11 changes: 5 additions & 6 deletions include/stdexec/__detail/__let.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,11 @@ namespace STDEXEC
, __env2_(__mk_secondary_env_t<__set_tag_t>()(__facade::__get_child<0>(__sndr),
STDEXEC::get_env(__rcvr_)))
{
if constexpr (!__walking())
{
__ops_.__emplace_from(STDEXEC::connect,
__facade::__get_child<0>(static_cast<_Sender&&>(__sndr)),
__child_rcvr_t{this});
}
__facade::__emplace_state_op<_Receiver>(__ops_,
STDEXEC::connect,
__facade::__get_child<0>(
static_cast<_Sender&&>(__sndr)),
__child_rcvr_t{this});
}

STDEXEC_IMMOVABLE(__state);
Expand Down
109 changes: 106 additions & 3 deletions include/stdexec/__detail/__sender_facade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ namespace STDEXEC
////////////////////////////////////////////////////////////////////////////////////////
// 2. Completing. __send is the only way an algorithm completes: it sends a completion to
// the algorithm's receiver, and returns the token that records the completion.
// __start_nested is the only way it starts a child or nested operation. (Call these
// with qualified names, so that argument-dependent lookup does not look in the
// receiver's namespaces.)
// (__send_tuple sends the elements of a tuple.) __start_nested is the only way it starts
// a child or nested operation. (Call these with qualified names, so that
// argument-dependent lookup does not look in the receiver's namespaces.)
STDEXEC_MODULE_EXPORT_AUTHORING
template <class _Receiver, class _Tag, class... _As>
STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device)
Expand All @@ -218,6 +218,29 @@ namespace STDEXEC
return {};
}

// Sends its arguments as the arguments of a completion (for __send_tuple)
struct __send_fn
{
template <class _Receiver, class _Tag, class... _As>
STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device)
constexpr auto operator()(_Receiver &__rcvr, _Tag, _As &&...__as) const noexcept //
-> __effects<_Tag(_As...)>
{
return __facade::__send(__rcvr, _Tag(), static_cast<_As &&>(__as)...);
}
};

// Sends the elements of a tuple (an STDEXEC::__tuple) as the arguments of a completion,
// as __send(__rcvr, _Tag(), __elements...) would
STDEXEC_MODULE_EXPORT_AUTHORING
template <class _Receiver, class _Tag, class _Tuple>
STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device)
constexpr auto __send_tuple(_Receiver &__rcvr, _Tag, _Tuple &&__tupl) noexcept
-> __apply_result_t<__send_fn, _Tuple, _Receiver &, _Tag>
{
return STDEXEC::__apply(__send_fn(), static_cast<_Tuple &&>(__tupl), __rcvr, _Tag());
}

////////////////////////////////////////////////////////////////////////////////////////
// 3. Combinators for control flow whose paths complete differently
STDEXEC_MODULE_EXPORT_AUTHORING
Expand Down Expand Up @@ -730,6 +753,86 @@ namespace STDEXEC
template <class _Rcvr, template <class...> class _Fn, class... _Args>
using __state_op_t = __op_or_walk_op<__walking_receiver<_Rcvr>>::template __f<_Fn, _Args...>;

template <bool _Walking>
struct __state_op_maker
{
template <class _Fn, class... _Args>
STDEXEC_ATTRIBUTE(always_inline, host, device)
static constexpr auto __make(_Fn &&__fn, _Args &&...__args)
noexcept(__nothrow_callable<_Fn, _Args...>) -> __call_result_t<_Fn, _Args...>
{
return static_cast<_Fn &&>(__fn)(static_cast<_Args &&>(__args)...);
}

template <std::size_t... _Idx, class _Storage, class _Fn, class... _Args>
STDEXEC_ATTRIBUTE(always_inline, host, device)
static constexpr auto __emplace(_Storage &__storage, _Fn &&__fn, _Args &&...__args)
noexcept(__nothrow_callable<_Fn, _Args...>) -> decltype(auto)
{
return __storage.template __emplace_from<_Idx...>(static_cast<_Fn &&>(__fn),
static_cast<_Args &&>(__args)...);
}
};

template <>
struct __state_op_maker<true>
{
template <class _Fn, class... _Args>
STDEXEC_ATTRIBUTE(always_inline, host, device)
static constexpr auto __make(_Fn &&, _Args &&...) noexcept -> __walk_op
{
return {};
}

template <std::size_t... _Idx, class _Storage, class _Fn, class... _Args>
STDEXEC_ATTRIBUTE(always_inline, host, device)
static constexpr auto __emplace(_Storage &__storage, _Fn &&, _Args &&...) noexcept
-> decltype(auto)
{
return __storage.template __emplace_from<_Idx...>([]() noexcept { return __walk_op(); });
}
};

// Makes an operation for a member of an algorithm's state whose type is
// __state_op_t<_Rcvr, ...>, as __fn(__args...) does (__fn is usually STDEXEC::connect),
// unless the state is for a walk: then it returns the placeholder without calling __fn,
// so the operation's type is never computed. (The arguments are still written, but a
// walk's state is never constructed, so they are never evaluated.)
//
// , __op_(__facade::__make_state_op<_Receiver>(STDEXEC::connect,
// STDEXEC::schedule(__sch),
// __sched_rcvr_t{this}))
//
// __emplace_state_op does the same for a member that holds the operation in an
// __optional or a __variant (with __emplace_from), and returns a reference to it. To
// emplace a __variant's alternative by its index, give the index after _Rcvr.
STDEXEC_MODULE_EXPORT_AUTHORING
template <class _Rcvr, class _Fn, class... _Args>
STDEXEC_ATTRIBUTE(always_inline, host, device)
constexpr auto __make_state_op(_Fn &&__fn, _Args &&...__args) noexcept(noexcept(
__state_op_maker<__walking_receiver<_Rcvr>>::__make(static_cast<_Fn &&>(__fn),
static_cast<_Args &&>(__args)...)))
-> decltype(auto)
{
return __state_op_maker<__walking_receiver<_Rcvr>>::__make(static_cast<_Fn &&>(__fn),
static_cast<_Args &&>(__args)...);
}

STDEXEC_MODULE_EXPORT_AUTHORING
template <class _Rcvr, std::size_t... _Idx, class _Storage, class _Fn, class... _Args>
STDEXEC_ATTRIBUTE(always_inline, host, device)
constexpr auto __emplace_state_op(_Storage &__storage, _Fn &&__fn, _Args &&...__args)
noexcept(noexcept(__state_op_maker<__walking_receiver<_Rcvr>>::template __emplace<_Idx...>(
__storage,
static_cast<_Fn &&>(__fn),
static_cast<_Args &&>(__args)...))) -> decltype(auto)
{
return __state_op_maker<__walking_receiver<_Rcvr>>::template __emplace<_Idx...>(
__storage,
static_cast<_Fn &&>(__fn),
static_cast<_Args &&>(__args)...);
}

// The type of the operations that a state holds, as _Lazy::__t (a class that names it, so
// that it is not instantiated unless used), or _Walk if the state is for a walk.
template <bool _Walking>
Expand Down
20 changes: 12 additions & 8 deletions include/stdexec/__detail/__sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,24 @@ namespace STDEXEC
, __env2s_(__later_t::__mk_env2s(__sndr, STDEXEC::get_env(__rcvr_)))
, __sndrs_(__later_t::__take_senders(static_cast<_Sender &&>(__sndr)))
{
if constexpr (__nbr != 0 && !__walking())
if constexpr (__nbr != 0)
{
if constexpr (__attaches<0>())
{
__ops_.__emplace_from(__attach_t<0>(),
*this,
__facade::__get_child<0>(static_cast<_Sender &&>(__sndr)),
__receiver_t<0>{this});
__facade::__emplace_state_op<_Receiver>(__ops_,
__attach_t<0>(),
*this,
__facade::__get_child<0>(
static_cast<_Sender &&>(__sndr)),
__receiver_t<0>{this});
}
else
{
__ops_.__emplace_from(STDEXEC::connect,
__facade::__get_child<0>(static_cast<_Sender &&>(__sndr)),
__receiver_t<0>{this});
__facade::__emplace_state_op<_Receiver>(__ops_,
STDEXEC::connect,
__facade::__get_child<0>(
static_cast<_Sender &&>(__sndr)),
__receiver_t<0>{this});
}
}
}
Expand Down
34 changes: 18 additions & 16 deletions include/stdexec/__detail/__starts_on.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,38 +101,40 @@ namespace STDEXEC
constexpr explicit __state(_Sender&& __sndr, _Receiver&& __rcvr) noexcept(__nothrow_v)
: __rcvr_(static_cast<_Receiver&&>(__rcvr))
, __env2_(STDEXEC::__mk_sch_env(__facade::__get_data(__sndr), STDEXEC::get_env(__rcvr_)))
, __sched_op_(STDEXEC::connect(STDEXEC::schedule(static_cast<__scheduler_t const &>(
__facade::__get_data(__sndr))),
__sched_rcvr_t{this}))
, __sched_op_(__facade::__make_state_op<_Receiver>(
STDEXEC::connect,
STDEXEC::schedule(static_cast<__scheduler_t const &>(__facade::__get_data(__sndr))),
__sched_rcvr_t{this}))
, __child_op_(__attach_child(__facade::__get_child<0>(static_cast<_Sender&&>(__sndr))))
{}

STDEXEC_IMMOVABLE(__state);

_Receiver __rcvr_;
__env2_t const __env2_;
connect_result_t<__sched_sndr_t, __sched_rcvr_t> __sched_op_;
__child_op_t __child_op_;
_Receiver __rcvr_;
__env2_t const __env2_;
__facade::__state_op_t<_Receiver, connect_result_t, __sched_sndr_t, __sched_rcvr_t>
__sched_op_;
__child_op_t __child_op_;

private:
// Connects the child, or attaches it (see __facade::__attaches_child), unless the state
// is for a walk: then __child_op_ is a placeholder.
// Connects the child, or attaches it (see __facade::__attaches_child)
STDEXEC_ATTRIBUTE(always_inline)
constexpr auto __attach_child(__child_t&& __child) noexcept(__nothrow_v) -> __child_op_t
{
if constexpr (__facade::__walking_receiver<_Receiver>)
{
return {};
}
else if constexpr (__facade::__attaches_child<__algo, _Sender, 0>)
if constexpr (__facade::__attaches_child<__algo, _Sender, 0>)
{
using __attach_t =
__facade::__attach_child_t<__algo, _Sender, 0, __child_rcvr_t, _Subscribing...>;
return __attach_t()(*this, static_cast<__child_t&&>(__child), __child_rcvr_t{this});
return __facade::__make_state_op<_Receiver>(__attach_t(),
*this,
static_cast<__child_t&&>(__child),
__child_rcvr_t{this});
}
else
{
return STDEXEC::connect(static_cast<__child_t&&>(__child), __child_rcvr_t{this});
return __facade::__make_state_op<_Receiver>(STDEXEC::connect,
static_cast<__child_t&&>(__child),
__child_rcvr_t{this});
}
}
};
Expand Down
Loading
Loading