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
23 changes: 16 additions & 7 deletions include/exec/create.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,23 @@ namespace experimental::execution

struct __algo;

// The part of the state that the context's receiver uses. (It is complete while
// __state's members are computed, which call the function with the context: so the
// receiver's member functions can be instantiated then.)
template <class _Receiver>
struct __state_base
{
_Receiver __rcvr_;
};

template <class _Sender, class _Receiver>
struct __state
struct __state : __state_base<_Receiver>
{
using __data_t = __decay_t<__facade::__data_of_t<_Sender>>;
using __fun_t = decltype(__data_t::__fun_);
using __args_t = decltype(__data_t::__args_);
using __rcvr_t = __facade::__receiver_t<__algo, __callback, __state, _Sender, _Receiver>;
using __data_t = __decay_t<__facade::__data_of_t<_Sender>>;
using __fun_t = decltype(__data_t::__fun_);
using __args_t = decltype(__data_t::__args_);
using __rcvr_t =
__facade::__receiver_t<__algo, __callback, __state_base<_Receiver>, _Sender, _Receiver>;
using __context_t = __context<__rcvr_t, __args_t>;

static consteval auto __walking() noexcept -> bool
Expand Down Expand Up @@ -115,7 +125,6 @@ namespace experimental::execution
}
}

_Receiver __rcvr_;
STDEXEC_IMMOVABLE_NO_UNIQUE_ADDRESS
__context_t __ctx_;
STDEXEC_IMMOVABLE_NO_UNIQUE_ADDRESS
Expand All @@ -126,7 +135,7 @@ namespace experimental::execution
private:
template <class _Data>
constexpr explicit __state(_Data&& __data, _Receiver&& __rcvr)
: __rcvr_(static_cast<_Receiver&&>(__rcvr))
: __state_base<_Receiver>{static_cast<_Receiver&&>(__rcvr)}
, __ctx_{__rcvr_t{this}, static_cast<_Data&&>(__data).__args_}
, __fun_(static_cast<_Data&&>(__data).__fun_)
{}
Expand Down
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
2 changes: 1 addition & 1 deletion include/exec/sequence/iterate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ namespace experimental::execution
}
}

constexpr void __start_next() noexcept final
void __start_next() noexcept final
{
STDEXEC_TRY
{
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 @@ -205,14 +205,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 @@ -129,14 +129,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 @@ -134,14 +134,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 @@ -151,23 +153,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 @@ -230,12 +230,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
65 changes: 49 additions & 16 deletions include/stdexec/__detail/__manual_lifetime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import stdexec;
#else

# include "__concepts.hpp"
# include "__utility.hpp"

# if !STDEXEC_USE_MODULES()
# include <memory>
Expand Down Expand Up @@ -61,68 +62,100 @@ namespace STDEXEC
constexpr auto __construct(_Args&&... __args)
noexcept(STDEXEC::__nothrow_constructible_from<_Ty, _Args...>) -> _Ty&
{
// Use placement new instead of std::construct_at to support aggregate
// initialization with brace elision.
return *std::launder(::new (static_cast<void*>(__buffer_))
_Ty{static_cast<_Args&&>(__args)...});
STDEXEC_IF_CONSTEVAL
{
// Placement new is not usable in constant evaluation before C++26 (P2747), and
// std::construct_at uses parentheses, so brace-initialize via an emplacer.
return *std::construct_at(std::addressof(__value_),
STDEXEC::__emplace_from{
[&]() noexcept(
STDEXEC::__nothrow_constructible_from<_Ty, _Args...>)
{ return _Ty{static_cast<_Args&&>(__args)...}; }});
}
else
{
// Use placement new instead of std::construct_at to support aggregate
// initialization with brace elision.
return *::new (static_cast<void*>(std::addressof(__value_)))
_Ty{static_cast<_Args&&>(__args)...};
}
}

//! Construct the `_Ty` in place from the result of calling `func`. There
//! are no safeties guarding against the case that there's already one
//! there.
template <class _Func, class... _Args>
constexpr auto __construct_from(_Func&& func, _Args&&... __args) -> _Ty&
constexpr auto __construct_from(_Func&& func, _Args&&... __args)
noexcept(STDEXEC::__nothrow_callable<_Func, _Args...>) -> _Ty&
{
// Use placement new instead of std::construct_at in case the function
// returns an immovable type.
return *std::launder(::new (static_cast<void*>(__buffer_))
_Ty{static_cast<_Func&&>(func)(static_cast<_Args&&>(__args)...)});
STDEXEC_IF_CONSTEVAL
{
// std::construct_at would need _Ty to be movable, so convert from an emplacer,
// whose conversion function's result initializes the object directly.
return *std::construct_at(
std::addressof(__value_),
STDEXEC::__emplace_from{
[&]() noexcept(STDEXEC::__nothrow_callable<_Func, _Args...>) -> _Ty
{ return static_cast<_Func&&>(func)(static_cast<_Args&&>(__args)...); }});
}
else
{
// Use placement new instead of std::construct_at in case the function
// returns an immovable type.
return *::new (static_cast<void*>(std::addressof(__value_)))
_Ty{static_cast<_Func&&>(func)(static_cast<_Args&&>(__args)...)};
}
}

//! End the lifetime of the contained `_Ty`.
//! @pre The lifetime has started.
constexpr void __destroy() noexcept
{
std::destroy_at(&__get());
std::destroy_at(std::addressof(__value_));
}

//! Get access to the `_Ty`.
//! @pre The lifetime has started.
constexpr auto __get() & noexcept -> _Ty&
{
return *reinterpret_cast<_Ty*>(__buffer_);
return __value_;
}

//! Get access to the `_Ty`.
//! @pre The lifetime has started.
constexpr auto __get() && noexcept -> _Ty&&
{
return static_cast<_Ty&&>(*reinterpret_cast<_Ty*>(__buffer_));
return static_cast<_Ty&&>(__value_);
}

//! Get access to the `_Ty`.
//! @pre The lifetime has started.
[[nodiscard]]
constexpr auto __get() const & noexcept -> _Ty const &
{
return *reinterpret_cast<_Ty const *>(__buffer_);
return __value_;
}

[[nodiscard]]
constexpr auto __get() const && noexcept -> _Ty const && = delete;

constexpr auto operator->() noexcept -> _Ty*
{
return reinterpret_cast<_Ty*>(__buffer_);
return std::addressof(__value_);
}

constexpr auto operator->() const noexcept -> _Ty const *
{
return reinterpret_cast<_Ty const *>(__buffer_);
return std::addressof(__value_);
}

private:
alignas(_Ty) unsigned char __buffer_[sizeof(_Ty)]{};
// A union, rather than a byte buffer, so that the _Ty's lifetime can be managed
// in constant evaluation.
union
{
_Ty __value_;
};
};

template <class _Reference>
Expand Down
4 changes: 2 additions & 2 deletions include/stdexec/__detail/__optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ namespace STDEXEC

template <class _Fn, class... _Args>
requires __std::same_as<_Tp, __call_result_t<_Fn, _Args...>>
auto __emplace_from(_Fn&& __f, _Args&&... __args) noexcept(__nothrow_callable<_Fn, _Args...>)
-> _Tp&
constexpr auto __emplace_from(_Fn&& __f, _Args&&... __args)
noexcept(__nothrow_callable<_Fn, _Args...>) -> _Tp&
{
reset();
auto __sg = __mk_has_value_guard(__has_value_);
Expand Down
6 changes: 3 additions & 3 deletions include/stdexec/__detail/__parallel_scheduler_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace STDEXEC
}
}

constexpr void set_stopped() noexcept final
void set_stopped() noexcept final
{
if constexpr (_Infallible && unstoppable_token<__stop_token_t>)
{
Expand All @@ -261,7 +261,7 @@ namespace STDEXEC
}

protected:
constexpr void
void
__query_env(__type_index __query_id, __type_index __value, void* __dest) const noexcept final
{
if (__query_id == __mtypeid<get_stop_token_t>)
Expand Down Expand Up @@ -347,7 +347,7 @@ namespace STDEXEC
{
using __receiver_proxy::__receiver_proxy_base::__receiver_proxy_base;

constexpr void set_value() noexcept final
void set_value() noexcept final
{
this->__unregister_stop_callback();
STDEXEC::set_value(std::move(this->__rcvr_));
Expand Down
Loading
Loading