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
39 changes: 36 additions & 3 deletions include/beman/execution/detail/bulk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import beman.execution.detail.meta.combine;
import beman.execution.detail.meta.unique;
import beman.execution.detail.nested_sender_has_affine;
import beman.execution.detail.product_type;
import beman.execution.detail.remap_attrs;
import beman.execution.detail.sender;
import beman.execution.detail.sender_adaptor_closure;
import beman.execution.detail.sender_for;
Expand All @@ -50,6 +51,7 @@ import beman.execution.detail.set_value;
#include <beman/execution/detail/meta_unique.hpp>
#include <beman/execution/detail/nested_sender_has_affine.hpp>
#include <beman/execution/detail/product_type.hpp>
#include <beman/execution/detail/remap_attrs.hpp>
#include <beman/execution/detail/sender.hpp>
#include <beman/execution/detail/sender_adaptor_closure.hpp>
#include <beman/execution/detail/sender_for.hpp>
Expand Down Expand Up @@ -103,12 +105,36 @@ struct bulk_transform_signatures<IsChunked, F, Shape, ::beman::execution::comple
: ::std::bool_constant<
::beman::execution::detail::bulk_traits<IsChunked, F, Shape, Args...>::is_nothrow_invocable> {};

static constexpr bool may_throw = !(... && is_nothrow<Sigs>::value);

using type = ::beman::execution::detail::meta::unique<::beman::execution::detail::meta::combine<
::beman::execution::completion_signatures<Sigs...>,
::std::conditional_t<
(... && is_nothrow<Sigs>::value),
::beman::execution::completion_signatures<>,
::beman::execution::completion_signatures<::beman::execution::set_error_t(::std::exception_ptr)>>>>;
may_throw,
::beman::execution::completion_signatures<::beman::execution::set_error_t(::std::exception_ptr)>,
::beman::execution::completion_signatures<>>>>;
};

// A value completion becomes set_error if the invocation of the function throws.
template <bool IsChunked, typename F, typename Shape>
struct bulk_invocation_exception {
using source = ::beman::execution::set_value_t;
using output = ::beman::execution::set_error_t;

template <typename, typename Signatures, typename...>
static consteval auto applies() noexcept -> bool {
return ::beman::execution::detail::bulk_transform_signatures<IsChunked, F, Shape, Signatures>::may_throw;
}
};

template <bool IsChunked>
struct bulk_get_attrs {
template <typename Policy, typename Shape, typename F>
auto operator()(const ::beman::execution::detail::product_type<Policy, Shape, F>&,
const auto& child) const noexcept {
return ::beman::execution::detail::remap_attrs<
::beman::execution::detail::bulk_invocation_exception<IsChunked, F, Shape>>(child);
}
};

template <bool IsChunked>
Expand Down Expand Up @@ -176,6 +202,8 @@ struct bulk_algo_t {
}

struct impls_for : ::beman::execution::detail::default_impls {
static constexpr ::beman::execution::detail::bulk_get_attrs<is_chunked> get_attrs{};

struct complete_impl {
template <typename Index,
typename Policy,
Expand Down Expand Up @@ -255,6 +283,11 @@ struct bulk_t {
::beman::execution::detail::forward_like<Sender>(f));
}

// bulk is lowered to bulk_chunked calling f for each index: it throws when bulk_unchunked would.
struct impls_for : ::beman::execution::detail::default_impls {
static constexpr ::beman::execution::detail::bulk_get_attrs<false> get_attrs{};
};

template <::beman::execution::detail::sender_for<bulk_t> Sender, typename Env>
static auto transform_sender(::beman::execution::set_value_t, Sender&& sndr, const Env&) {
auto data = ::beman::execution::detail::forward_like<Sender>(sndr.template get<1>());
Expand Down
7 changes: 4 additions & 3 deletions include/beman/execution/detail/completion_signatures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import std;
#else
#include <concepts>
#include <cstddef>
#include <type_traits>
#endif
#ifdef BEMAN_HAS_MODULES
Expand Down Expand Up @@ -38,11 +39,11 @@ struct completion_signatures {
using type = Tag;
};
template <typename Tag>
static constexpr bool count_of(Tag) {
return (::std::same_as<typename completion_signatures_tag<Signatures>::type, Tag> + ... + 0);
static constexpr auto count_of(Tag) noexcept -> ::std::size_t {
return (::std::same_as<typename completion_signatures_tag<Signatures>::type, Tag> + ... + 0uz);
}
template <typename Fun>
static constexpr void for_each(Fun&& fun) {
static constexpr auto for_each(Fun&& fun) noexcept -> void {
(fun(static_cast<Signatures*>(nullptr)), ...);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct hide_completion_queries {
return ::beman::execution::detail::fwd_env(child_attrs).query(q, ::std::forward<Args>(args)...);
}

::std::remove_cvref_t<ChildAttrs> child_attrs;
ChildAttrs child_attrs;
};
} // namespace beman::execution::detail

Expand Down
12 changes: 11 additions & 1 deletion include/beman/execution/detail/indeterminate_domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct indeterminate_domain {

} // namespace beman::execution

#ifndef BEMAN_EXECUTION_DETAIL_INDETERMINATE_DOMAIN_CPPM
template <typename... Domains1, typename... Domains2>
struct std::common_type<::beman::execution::indeterminate_domain<Domains1...>,
::beman::execution::indeterminate_domain<Domains2...>> {
Expand All @@ -72,12 +73,21 @@ struct std::common_type<::beman::execution::indeterminate_domain<Domains1...>,

template <typename... Domains, typename D>
struct std::common_type<::beman::execution::indeterminate_domain<Domains...>, D> {
using type = ::beman::execution::detail::meta::unique<::beman::execution::indeterminate_domain<Domains..., D>>;
// ReSharper disable once CppFunctionIsNotImplemented
static auto get_common_domain() noexcept -> D
requires(sizeof...(Domains) == 0uz);

// ReSharper disable once CppFunctionIsNotImplemented
static auto get_common_domain() noexcept
-> ::beman::execution::detail::meta::unique<::beman::execution::indeterminate_domain<Domains..., D>>;

using type = decltype(get_common_domain());
};

template <typename D, typename... Domains>
struct std::common_type<D, ::beman::execution::indeterminate_domain<Domains...>>
: ::std::common_type<::beman::execution::indeterminate_domain<Domains...>, D> {};
#endif

// ----------------------------------------------------------------------------

Expand Down
51 changes: 48 additions & 3 deletions include/beman/execution/detail/into_variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import beman.execution.detail.basic_sender;
import beman.execution.detail.child_type;
import beman.execution.detail.completion_signatures;
import beman.execution.detail.completion_signatures_for;
import beman.execution.detail.completion_signatures_of_t;
import beman.execution.detail.decayed_tuple;
import beman.execution.detail.default_impls;
import beman.execution.detail.dependent_sender;
Expand All @@ -27,10 +28,13 @@ import beman.execution.detail.env_of_t;
import beman.execution.detail.error_types_of_t;
import beman.execution.detail.forward_like;
import beman.execution.detail.fwd_env;
import beman.execution.detail.gather_signatures;
import beman.execution.detail.impls_for;
import beman.execution.detail.make_sender;
import beman.execution.detail.meta.combine;
import beman.execution.detail.meta.unique;
import beman.execution.detail.nested_sender_has_affine;
import beman.execution.detail.remap_attrs;
import beman.execution.detail.sender;
import beman.execution.detail.sender_adaptor_closure;
import beman.execution.detail.sender_in;
Expand All @@ -43,6 +47,7 @@ import beman.execution.detail.variant_or_empty;
#else
#include <beman/execution/detail/child_type.hpp>
#include <beman/execution/detail/completion_signatures_for.hpp>
#include <beman/execution/detail/completion_signatures_of_t.hpp>
#include <beman/execution/detail/decayed_tuple.hpp>
#include <beman/execution/detail/default_impls.hpp>
#include <beman/execution/detail/dependent_sender.hpp>
Expand All @@ -52,10 +57,13 @@ import beman.execution.detail.variant_or_empty;
#include <beman/execution/detail/error_types_of_t.hpp>
#include <beman/execution/detail/forward_like.hpp>
#include <beman/execution/detail/fwd_env.hpp>
#include <beman/execution/detail/gather_signatures.hpp>
#include <beman/execution/detail/impls_for.hpp>
#include <beman/execution/detail/make_sender.hpp>
#include <beman/execution/detail/meta_combine.hpp>
#include <beman/execution/detail/meta_unique.hpp>
#include <beman/execution/detail/nested_sender_has_affine.hpp>
#include <beman/execution/detail/remap_attrs.hpp>
#include <beman/execution/detail/sender.hpp>
#include <beman/execution/detail/sender_adaptor_closure.hpp>
#include <beman/execution/detail/sender_in.hpp>
Expand Down Expand Up @@ -92,7 +100,33 @@ struct into_variant_t : ::beman::execution::sender_adaptor_closure<into_variant_
template <typename... E>
using make_error_types = ::beman::execution::completion_signatures<::beman::execution::set_error_t(E)...>;

private:
template <typename Signatures>
using variant_for = ::beman::execution::detail::gather_signatures<::beman::execution::set_value_t,
Signatures,
::beman::execution::detail::decayed_tuple,
::beman::execution::detail::variant_or_empty>;

struct variant_construction_exception {
using source = ::beman::execution::set_value_t;
using output = ::beman::execution::set_error_t;

template <typename, typename Signatures, typename...>
static consteval auto applies() noexcept -> bool {
using variant_type = variant_for<Signatures>;
bool throwing = false;
Signatures::for_each([&]<typename Tag, typename... Args>(Tag (*)(Args...)) noexcept {
if constexpr (::std::same_as<Tag, source>) {
using tuple_type = ::beman::execution::detail::decayed_tuple<Args...>;
constexpr bool nothrow = requires {
{ variant_type(tuple_type{::std::declval<Args>()...}) } noexcept;
};
throwing |= !nothrow;
}
});
return throwing;
}
};

template <typename, typename...>
struct get_signatures;
template <typename Sender>
Expand All @@ -105,13 +139,20 @@ struct into_variant_t : ::beman::execution::sender_adaptor_closure<into_variant_

static consteval auto get() {
using env_t = ::beman::execution::detail::fwd_env_t<Env>;
using variant_type = ::beman::execution::value_types_of_t<Child, env_t>;
using signatures = ::beman::execution::completion_signatures_of_t<Child, env_t>;
using variant_type = variant_for<signatures>;
using value_types = ::std::conditional_t<
::std::same_as<variant_type, ::beman::execution::detail::empty_variant>,
::beman::execution::completion_signatures<>,
::beman::execution::completion_signatures<::beman::execution::set_value_t(variant_type)>>;

using error_types = ::beman::execution::error_types_of_t<Child, env_t, make_error_types>;
using construction_error =
::std::conditional_t<variant_construction_exception::template applies<Child, signatures>(),
make_error_types<::std::exception_ptr>,
make_error_types<>>;
using error_types = ::beman::execution::detail::meta::unique<::beman::execution::detail::meta::combine<
::beman::execution::error_types_of_t<Child, env_t, make_error_types>,
construction_error>>;
using stopped_types =
::std::conditional_t<::beman::execution::sends_stopped<Child, env_t>,
::beman::execution::completion_signatures<::beman::execution::set_stopped_t()>,
Expand All @@ -129,6 +170,10 @@ struct into_variant_t : ::beman::execution::sender_adaptor_closure<into_variant_
return get_signatures<::std::remove_cvref_t<Sender>, Env...>::get();
}
struct impls_for : ::beman::execution::detail::default_impls {
static constexpr auto get_attrs = [](const auto&, const auto& child) noexcept {
return ::beman::execution::detail::remap_attrs<variant_construction_exception>(child);
};

struct get_state_impl {
template <typename Sender, typename Receiver>
auto operator()(Sender&&, Receiver&&) const noexcept -> ::std::type_identity<
Expand Down
15 changes: 13 additions & 2 deletions include/beman/execution/detail/psched_bulk_sender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import beman.execution.detail.meta.unique;
import beman.execution.detail.operation_state;
import beman.execution.detail.parallel_scheduler_replacement;
import beman.execution.detail.receiver;
import beman.execution.detail.remap_attrs;
import beman.execution.detail.sender;
import beman.execution.detail.start;
import beman.execution.detail.set_error;
Expand All @@ -63,6 +64,7 @@ import beman.execution.detail.value_types_of_t;
#include <beman/execution/detail/operation_state.hpp>
#include <beman/execution/detail/parallel_scheduler_replacement.hpp>
#include <beman/execution/detail/receiver.hpp>
#include <beman/execution/detail/remap_attrs.hpp>
#include <beman/execution/detail/sender.hpp>
#include <beman/execution/detail/set_error.hpp>
#include <beman/execution/detail/set_stopped.hpp>
Expand Down Expand Up @@ -240,7 +242,8 @@ struct psched_bulk_sender {
constexpr auto compl_sigs = ::beman::execution::get_completion_signatures<Child, Env...>();
return ::beman::execution::detail::meta::unique<::beman::execution::detail::meta::combine<
::std::remove_cvref_t<decltype(compl_sigs)>,
::beman::execution::completion_signatures<::beman::execution::set_error_t(::std::exception_ptr)>>>{};
::beman::execution::completion_signatures<::beman::execution::set_error_t(::std::exception_ptr),
::beman::execution::set_stopped_t()>>>{};
}

template <typename Rcvr>
Expand All @@ -253,7 +256,15 @@ struct psched_bulk_sender {
::std::move(fn)};
}

auto get_env() const noexcept { return ::beman::execution::get_env(child); }
// After a value completion of the child the work is handed to the backend, which can also
// complete with an error or, when stop was requested, with stopped.
auto get_env() const noexcept {
return ::beman::execution::detail::remap_attrs<
::beman::execution::detail::
redirect_completion<::beman::execution::set_value_t, ::beman::execution::set_error_t, true>,
::beman::execution::detail::
redirect_completion<::beman::execution::set_value_t, ::beman::execution::set_stopped_t, true>>(child);
}

[[BEMAN_EXECUTION_NO_UNIQUE_ADDRESS]] ::std::bool_constant<IsChunked> _;
::std::shared_ptr<backend_type> backend;
Expand Down
Loading