Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add when_all test and handling for const reference error types #320

Merged
merged 2 commits into from
Jul 14, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ namespace pika { namespace execution { namespace experimental {

template <template <typename...> class Variant>
using error_types = pika::util::detail::unique_concat_t<
typename pika::execution::experimental::sender_traits<
Senders>::template error_types<Variant>...,
pika::util::detail::transform_t<
typename pika::execution::experimental::sender_traits<
Senders>::template error_types<Variant>,
std::decay>...,
Variant<std::exception_ptr>>;

static constexpr bool sends_done = false;
Expand Down
83 changes: 37 additions & 46 deletions libs/pika/execution/tests/include/algorithm_test_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct error_sender

using completion_signatures =
pika::execution::experimental::completion_signatures<
pika::execution::experimental::set_value_t(),
aurianer marked this conversation as resolved.
Show resolved Hide resolved
pika::execution::experimental::set_value_t(Ts...),
pika::execution::experimental::set_error_t(std::exception_ptr)>;

template <typename R>
Expand Down Expand Up @@ -96,6 +96,42 @@ struct error_sender
}
};

struct const_reference_error_sender
{
template <template <class...> class Tuple,
template <class...> class Variant>
using value_types = Variant<Tuple<>>;

template <template <class...> class Variant>
using error_types = Variant<std::exception_ptr const&>;

static constexpr bool sends_done = false;

using completion_signatures =
pika::execution::experimental::completion_signatures<
pika::execution::experimental::set_error_t(std::exception_ptr&)>;

template <typename R>
struct operation_state
{
std::decay_t<R> r;
friend void tag_invoke(pika::execution::experimental::start_t,
operation_state& os) noexcept
{
auto const e = std::make_exception_ptr(std::runtime_error("error"));
pika::execution::experimental::set_error(std::move(os.r), e);
}
};

template <typename R>
friend operation_state<R> tag_invoke(
pika::execution::experimental::connect_t, const_reference_error_sender,
R&& r)
{
return {std::forward<R>(r)};
}
};

template <typename F>
struct callback_receiver
{
Expand Down Expand Up @@ -187,51 +223,6 @@ struct void_callback_helper
}
};

template <typename T>
struct error_typed_sender
{
template <template <class...> class Tuple,
template <class...> class Variant>
using value_types = Variant<Tuple<T>>;

template <template <class...> class Variant>
using error_types = Variant<std::exception_ptr>;

static constexpr bool sends_done = false;

using completion_signatures =
pika::execution::experimental::completion_signatures<
pika::execution::experimental::set_value_t(T),
pika::execution::experimental::set_error_t(std::exception_ptr)>;

template <typename R>
struct operation_state
{
std::decay_t<R> r;

friend void tag_invoke(pika::execution::experimental::start_t,
operation_state& os) noexcept
{
try
{
throw std::runtime_error("error");
}
catch (...)
{
pika::execution::experimental::set_error(
std::move(os.r), std::current_exception());
}
};
};

template <typename R>
friend auto tag_invoke(
pika::execution::experimental::connect_t, error_typed_sender, R&& r)
{
return operation_state<R>{std::forward<R>(r)};
}
};

void check_exception_ptr(std::exception_ptr eptr)
{
try
Expand Down
16 changes: 13 additions & 3 deletions libs/pika/execution/tests/unit/algorithm_when_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ int main()
// Failure path
{
std::atomic<bool> set_error_called{false};
auto s = ex::when_all(error_typed_sender<double>{});
auto s = ex::when_all(error_sender<double>{});
auto r = error_callback_receiver<decltype(check_exception_ptr)>{
check_exception_ptr, set_error_called};
auto os = ex::connect(std::move(s), std::move(r));
Expand All @@ -210,7 +210,7 @@ int main()

{
std::atomic<bool> set_error_called{false};
auto s = ex::when_all(ex::just(42), error_typed_sender<double>{});
auto s = ex::when_all(ex::just(42), error_sender<double>{});
auto r = error_callback_receiver<decltype(check_exception_ptr)>{
check_exception_ptr, set_error_called};
auto os = ex::connect(std::move(s), std::move(r));
Expand All @@ -220,7 +220,17 @@ int main()

{
std::atomic<bool> set_error_called{false};
auto s = ex::when_all(error_typed_sender<double>{}, ex::just(42));
auto s = ex::when_all(error_sender<double>{}, ex::just(42));
auto r = error_callback_receiver<decltype(check_exception_ptr)>{
check_exception_ptr, set_error_called};
auto os = ex::connect(std::move(s), std::move(r));
ex::start(os);
PIKA_TEST(set_error_called);
}

{
std::atomic<bool> set_error_called{false};
auto s = ex::when_all(const_reference_error_sender{}, ex::just(42));
auto r = error_callback_receiver<decltype(check_exception_ptr)>{
check_exception_ptr, set_error_called};
auto os = ex::connect(std::move(s), std::move(r));
Expand Down
10 changes: 5 additions & 5 deletions libs/pika/execution/tests/unit/algorithm_when_all_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ int main()
// Failure path
{
std::atomic<bool> set_error_called{false};
auto s = ex::when_all_vector(std::vector{error_typed_sender<double>{}});
auto s = ex::when_all_vector(std::vector{error_sender<double>{}});
auto r = error_callback_receiver<decltype(check_exception_ptr)>{
check_exception_ptr, set_error_called};
auto os = ex::connect(std::move(s), std::move(r));
Expand All @@ -264,7 +264,7 @@ int main()
{
std::atomic<bool> set_error_called{false};
std::vector<ex::unique_any_sender<double>> senders;
senders.emplace_back(error_typed_sender<double>{});
senders.emplace_back(error_sender<double>{});
senders.emplace_back(ex::just(42.0));
senders.emplace_back(ex::just(43.0));
senders.emplace_back(ex::just(44.0));
Expand All @@ -279,7 +279,7 @@ int main()
{
std::atomic<bool> set_error_called{false};
std::vector<ex::unique_any_sender<double>> senders;
senders.emplace_back(error_typed_sender<double>{});
senders.emplace_back(error_sender<double>{});
senders.emplace_back(ex::just(42.0));
senders.emplace_back(ex::just(43.0));
senders.emplace_back(ex::just(44.0));
Expand All @@ -294,7 +294,7 @@ int main()
{
std::atomic<bool> set_error_called{false};
std::vector<ex::any_sender<double>> senders;
senders.emplace_back(error_typed_sender<double>{});
senders.emplace_back(error_sender<double>{});
senders.emplace_back(ex::just(42.0));
senders.emplace_back(ex::just(43.0));
senders.emplace_back(ex::just(44.0));
Expand All @@ -309,7 +309,7 @@ int main()
{
std::atomic<bool> set_error_called{false};
std::vector<ex::any_sender<double>> senders;
senders.emplace_back(error_typed_sender<double>{});
senders.emplace_back(error_sender<double>{});
senders.emplace_back(ex::just(42.0));
senders.emplace_back(ex::just(43.0));
senders.emplace_back(ex::just(44.0));
Expand Down