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
2 changes: 1 addition & 1 deletion include/nvexec/stream/then.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ namespace nv::execution::_strm
{
return exec::transform_completion_signatures(
STDEXEC::get_completion_signatures<__copy_cvref_t<Self, Sender>, Env...>(),
STDEXEC::__transform_upon_completion<Fun, then_t>(),
STDEXEC::__upon::__transform_completion<Fun, then_t>(),
{},
{},
_cuda_error_completion_t());
Expand Down
2 changes: 1 addition & 1 deletion include/nvexec/stream/upon_error.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ namespace nv::execution::_strm
return exec::transform_completion_signatures(
STDEXEC::get_completion_signatures<__copy_cvref_t<Self, Sender>, Env...>(),
{},
STDEXEC::__transform_upon_completion<Fun, upon_error_t>(),
STDEXEC::__upon::__transform_completion<Fun, upon_error_t>(),
{},
_cuda_error_completion_t());
}
Expand Down
2 changes: 1 addition & 1 deletion include/nvexec/stream/upon_stopped.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace nv::execution::_strm
STDEXEC::get_completion_signatures<__copy_cvref_t<Self, Sender>, Env...>(),
{},
{},
STDEXEC::__transform_upon_completion<Fun, STDEXEC::upon_stopped_t>(),
STDEXEC::__upon::__transform_completion<Fun, STDEXEC::upon_stopped_t>(),
_cuda_error_completion_t());
}

Expand Down
31 changes: 6 additions & 25 deletions include/stdexec/__detail/__then.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import stdexec;
# include "__execution_fwd.hpp"

# include "__basic_sender.hpp"
# include "__completion_signatures_of.hpp"
# include "__diagnostics.hpp"
# include "__meta.hpp"
# include "__queries.hpp"
# include "__sender_adaptor_closure.hpp"
# include "__sender_introspection.hpp"
# include "__senders.hpp"
# include "__transform_completion_signatures.hpp"
# include "__upon.hpp"

# include "__prologue.hpp"

Expand All @@ -43,7 +43,7 @@ namespace STDEXEC
// [exec.then]
namespace __then
{
struct __then_impl : __sexpr_defaults
struct __impl : __sexpr_defaults
{
static constexpr auto __get_attrs =
[]<class _Child>(__ignore, __ignore, _Child const & __child) noexcept
Expand All @@ -58,29 +58,10 @@ namespace STDEXEC
using __fn_t = __decay_t<__data_of<_Sender>>;
return STDEXEC::__transform_completion_signatures(
STDEXEC::get_completion_signatures<__child_of<_Sender>, _Env...>(),
__transform_upon_completion<__fn_t, then_t>());
__upon::__transform_completion<__fn_t, then_t>());
}

struct __complete_fn
{
template <class _Tag, class _State, class... _Args>
STDEXEC_ATTRIBUTE(host, device)
constexpr void operator()(__ignore, _State& __state, _Tag, _Args&&... __args) const noexcept
{
if constexpr (__same_as<_Tag, set_value_t>)
{
STDEXEC::__set_value_from(static_cast<_State&&>(__state).__rcvr_,
static_cast<_State&&>(__state).__data_,
static_cast<_Args&&>(__args)...);
}
else
{
_Tag()(static_cast<_State&&>(__state).__rcvr_, static_cast<_Args&&>(__args)...);
}
}
};

static constexpr auto __complete = __complete_fn{};
static constexpr auto __complete = __upon::__complete<set_value_t>;
};
} // namespace __then

Expand Down Expand Up @@ -225,7 +206,7 @@ namespace STDEXEC
};

template <>
struct __sexpr_impl<then_t> : __then::__then_impl
struct __sexpr_impl<then_t> : __then::__impl
{};

template <class _Fun, class _Sender>
Expand Down
23 changes: 0 additions & 23 deletions include/stdexec/__detail/__transform_completion_signatures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,29 +408,6 @@ namespace STDEXEC
}
};

STDEXEC_MODULE_EXPORT_AUTHORING
template <class _Fun, class AlgoTag>
struct __transform_upon_completion
{
template <class... _Args>
constexpr auto operator()() const
{
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<AlgoTag, _Fun, _Args...>());
}
}
};

//! @brief Transforms completion signatures using provided transformation
//! functions.
//!
Expand Down
94 changes: 94 additions & 0 deletions include/stdexec/__detail/__upon.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (c) 2021-2024 NVIDIA Corporation
*
* Licensed under the Apache License Version 2.0 with LLVM Exceptions
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://llvm.org/LICENSE.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include "__config.hpp"

#if STDEXEC_USE_MODULES() && !defined(STDEXEC_IN_MODULE_PURVIEW)

import stdexec;

#else

# include "__execution_fwd.hpp"

# include "../functional.hpp"
# include "__completion_signatures.hpp"
# include "__concepts.hpp"
# include "__diagnostics.hpp"
# include "__meta.hpp"
# include "__partition_completion_signatures.hpp"
# include "__receivers.hpp"

# if !STDEXEC_USE_MODULES()
# include <exception>
# endif

# include "__prologue.hpp"

// NOLINTNEXTLINE(bugprone-std-namespace-modification, modernize-concat-nested-namespaces)
namespace STDEXEC
{
//////////////////////////////////////////////////////////////////////////////
// Helpers for [exec.then]
namespace __upon
{
template <class _SetTag>
static constexpr auto __complete =
[]<class _Tag, class _State, class... _Args>(__ignore,
_State& __state,
_Tag,
_Args&&... __args) noexcept -> void
{
if constexpr (__same_as<_Tag, _SetTag>)
{
STDEXEC::__set_value_from(static_cast<_State&&>(__state).__rcvr_,
static_cast<_State&&>(__state).__data_,
static_cast<_Args&&>(__args)...);
}
else
{
_Tag()(static_cast<_State&&>(__state).__rcvr_, static_cast<_Args&&>(__args)...);
}
};

STDEXEC_MODULE_EXPORT_AUTHORING
template <class _Fun, class AlgoTag>
struct __transform_completion
{
template <class... _Args>
constexpr auto operator()() const
{
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<AlgoTag, _Fun, _Args...>());
}
}
};
} // namespace __upon
} // namespace STDEXEC

# include "__epilogue.hpp"
#endif // !STDEXEC_USE_MODULES() || defined(STDEXEC_IN_MODULE_PURVIEW)
30 changes: 7 additions & 23 deletions include/stdexec/__detail/__upon_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import stdexec;
# include "__execution_fwd.hpp"

# include "__basic_sender.hpp"
# 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 "__sender_introspection.hpp"
# include "__senders.hpp"
# include "__transform_completion_signatures.hpp"
# include "__upon.hpp"

# include "__prologue.hpp"

Expand All @@ -43,7 +43,7 @@ namespace STDEXEC
// [exec.then]
namespace __upon_error
{
struct __upon_error_impl : __sexpr_defaults
struct __impl : __sexpr_defaults
{
static constexpr auto __get_attrs =
[]<class _Child>(__ignore, __ignore, _Child const & __child) noexcept
Expand All @@ -59,26 +59,10 @@ namespace STDEXEC
return STDEXEC::__transform_completion_signatures(
STDEXEC::get_completion_signatures<__child_of<_Sender>, _Env...>(),
{},
__transform_upon_completion<__fn_t, upon_error_t>());
__upon::__transform_completion<__fn_t, upon_error_t>());
}

static constexpr auto __complete =
[]<class _Tag, class _State, class... _Args>(__ignore,
_State& __state,
_Tag,
_Args&&... __args) noexcept -> void
{
if constexpr (__same_as<_Tag, set_error_t>)
{
STDEXEC::__set_value_from(static_cast<_State&&>(__state).__rcvr_,
static_cast<_State&&>(__state).__data_,
static_cast<_Args&&>(__args)...);
}
else
{
_Tag()(static_cast<_State&&>(__state).__rcvr_, static_cast<_Args&&>(__args)...);
}
};
static constexpr auto __complete = __upon::__complete<set_error_t>;
};
} // namespace __upon_error

Expand Down Expand Up @@ -225,7 +209,7 @@ namespace STDEXEC
};

template <>
struct __sexpr_impl<upon_error_t> : __upon_error::__upon_error_impl
struct __sexpr_impl<upon_error_t> : __upon_error::__impl
{};

template <class _Fun, class _Sender>
Expand Down
31 changes: 7 additions & 24 deletions include/stdexec/__detail/__upon_stopped.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import stdexec;
# include "__execution_fwd.hpp"

# include "__basic_sender.hpp"
# include "__completion_signatures_of.hpp"
# include "__meta.hpp"
# include "__sender_adaptor_closure.hpp"
# include "__senders.hpp" // IWYU pragma: keep for __well_formed_sender
# include "__sender_introspection.hpp"
# include "__senders.hpp"
# include "__transform_completion_signatures.hpp"
# include "__upon.hpp"

# include "__prologue.hpp"

Expand All @@ -41,7 +41,7 @@ namespace STDEXEC
// [exec.then]
namespace __upon_stopped
{
struct __upon_stopped_impl : __sexpr_defaults
struct __impl : __sexpr_defaults
{
template <class _Sender, class... _Env>
static consteval auto __get_completion_signatures()
Expand All @@ -52,27 +52,10 @@ namespace STDEXEC
STDEXEC::get_completion_signatures<__child_of<_Sender>, _Env...>(),
{},
{},
__always{__set_value_from_t<__fn_t>()},
__eptr_completion_unless_t<__mbool<__nothrow_callable<__fn_t>>>());
__upon::__transform_completion<__fn_t, upon_stopped_t>());
}

static constexpr auto __complete =
[]<class _Tag, class _State, class... _Args>(__ignore,
_State& __state,
_Tag,
_Args&&... __args) noexcept -> void
{
if constexpr (__same_as<_Tag, set_stopped_t>)
{
STDEXEC::__set_value_from(static_cast<_State&&>(__state).__rcvr_,
static_cast<_State&&>(__state).__data_,
static_cast<_Args&&>(__args)...);
}
else
{
_Tag()(static_cast<_State&&>(__state).__rcvr_, static_cast<_Args&&>(__args)...);
}
};
static constexpr auto __complete = __upon::__complete<set_stopped_t>;
};
} // namespace __upon_stopped

Expand Down Expand Up @@ -215,7 +198,7 @@ namespace STDEXEC
};

template <>
struct __sexpr_impl<upon_stopped_t> : __upon_stopped::__upon_stopped_impl
struct __sexpr_impl<upon_stopped_t> : __upon_stopped::__impl
{};

template <class _Fun, class _Sender>
Expand Down
Loading