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
15 changes: 9 additions & 6 deletions include/stdexec/__detail/__domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import stdexec;

# include "__completion_behavior.hpp"
# include "__concepts.hpp"
# include "__env.hpp"
# include "__meta.hpp"
# include "__sender_introspection.hpp"
# include "__utility.hpp"
Expand Down Expand Up @@ -238,8 +239,8 @@ namespace STDEXEC
template <class _Env, class... _Queries>
struct __hide_query
{
constexpr explicit __hide_query(_Env &&__env, _Queries...) noexcept
: __env_{static_cast<_Env &&>(__env)}
constexpr explicit __hide_query(_Env __env, _Queries...) noexcept
: __env_(static_cast<_Env &&>(__env))
{}

template <class _Env2 = _Env, __none_of<_Queries...> _Query, class... _As>
Expand All @@ -255,22 +256,24 @@ namespace STDEXEC
_Env __env_;
};

// (The environment is held as __env::__held_t says.)
template <class _Env, class... _Queries>
STDEXEC_HOST_DEVICE_DEDUCTION_GUIDE
__hide_query(_Env &&, _Queries...) -> __hide_query<_Env, _Queries...>;
__hide_query(_Env &&, _Queries...) -> __hide_query<__env::__held_t<_Env>, _Queries...>;

//! @brief A wrapper around an environment that hides the get_start_scheduler
//! and get_domain queries.
template <class _Env>
struct __hide_scheduler : __hide_query<_Env, get_start_scheduler_t, get_domain_t>
{
constexpr explicit __hide_scheduler(_Env &&__env) noexcept
constexpr explicit __hide_scheduler(_Env __env) noexcept
: __hide_query<_Env, get_start_scheduler_t, get_domain_t>{static_cast<_Env &&>(__env), {}, {}}
{}
};

template <class _Env>
STDEXEC_HOST_DEVICE_DEDUCTION_GUIDE __hide_scheduler(_Env &&) -> __hide_scheduler<_Env>;
STDEXEC_HOST_DEVICE_DEDUCTION_GUIDE
__hide_scheduler(_Env &&) -> __hide_scheduler<__env::__held_t<_Env>>;

//////////////////////////////////////////////////////////////////////////////
//! @brief A query type for asking a sender's attributes for the domain on
Expand Down Expand Up @@ -454,7 +457,7 @@ namespace STDEXEC
else if constexpr (__callable<get_start_scheduler_t, _Env const &>)
{
using __sch_t = __call_result_t<get_start_scheduler_t, _Env const &>;
using __env_t = __hide_scheduler<_Env const &>;
using __env_t = __hide_scheduler<__env::__held_t<_Env const &>>;
using __cmpl_sch_t =
__call_result_t<get_completion_scheduler_t<set_value_t>, __sch_t, __env_t>;
return __detail::__scheduler_domain_t<__cmpl_sch_t, __env_t>{};
Expand Down
29 changes: 23 additions & 6 deletions include/stdexec/__detail/__env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ namespace STDEXEC
template <class _Env>
concept __is_fwd_env = __is_instance_of<__decay_t<_Env>, __fwd>;

// The type in which an environment adaptor holds the environment it adapts, given the
// type of the expression it adapts: an environment that is free to copy (trivially
// copy-constructible and trivially destructible) is held by value, as is an rvalue; any
// other lvalue is held by reference.
//
// So the type of an adaptor of an environment that is free to copy does not depend on
// whether the adaptor was given an lvalue or an rvalue. Everything computed from the type
// of an environment (completion signatures, completion domains, and so on, for the
// operation and for the operations nested in it) is computed once for each type, and an
// environment that was reachable both ways had two.
template <class _Env>
using __held_t = __if_c<std::is_trivially_copy_constructible_v<__decay_t<_Env>>
&& std::is_trivially_destructible_v<__decay_t<_Env>>,
__decay_t<_Env>,
_Env>;

struct __fwd_fn
{
template <class _Env>
Expand All @@ -91,11 +107,11 @@ namespace STDEXEC
{
if constexpr (__decays_to<_Env, env<>> || __is_fwd_env<_Env>)
{
return static_cast<_Env>(static_cast<_Env &&>(__env));
return static_cast<__held_t<_Env>>(static_cast<_Env &&>(__env));
}
else
{
return __fwd<_Env>{static_cast<_Env &&>(__env)};
return __fwd<__held_t<_Env>>{static_cast<_Env &&>(__env)};
}
}
};
Expand All @@ -108,7 +124,7 @@ namespace STDEXEC
{
template <class _Env>
STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device)
constexpr auto operator()(_Env &&__env) const noexcept -> _Env
constexpr auto operator()(_Env &&__env) const noexcept -> __held_t<_Env>
{
return static_cast<_Env &&>(__env);
}
Expand All @@ -123,12 +139,13 @@ namespace STDEXEC
}
else if constexpr (__decays_to<_Env2, env<>>)
{
return static_cast<_Env1>(static_cast<_Env1 &&>(__env1));
return static_cast<__held_t<_Env1>>(static_cast<_Env1 &&>(__env1));
}
else
{
return env<_Env1, __fwd_env_t<_Env2>>{static_cast<_Env1 &&>(__env1),
__fwd_fn()(static_cast<_Env2 &&>(__env2))};
using __env1_t = __held_t<_Env1>;
return env<__env1_t, __fwd_env_t<_Env2>>{static_cast<_Env1 &&>(__env1),
__fwd_fn()(static_cast<_Env2 &&>(__env2))};
}
}
};
Expand Down
Loading