Skip to content

Commit

Permalink
Access receiver by reference in split, split_tuple, and ensure_starte…
Browse files Browse the repository at this point in the history
…d visitors
  • Loading branch information
msimberg committed May 21, 2024
1 parent cb59f46 commit 438a1df
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace pika::ensure_started_detail {
template <typename Receiver>
struct error_visitor
{
PIKA_NO_UNIQUE_ADDRESS std::decay_t<Receiver> receiver;
std::decay_t<Receiver>& receiver;

template <typename Error>
void operator()(Error&& error)
Expand All @@ -58,7 +58,7 @@ namespace pika::ensure_started_detail {
template <typename Receiver>
struct value_visitor
{
PIKA_NO_UNIQUE_ADDRESS std::decay_t<Receiver> receiver;
std::decay_t<Receiver>& receiver;

void operator()(std::monostate) { PIKA_UNREACHABLE; }

Expand Down Expand Up @@ -216,7 +216,7 @@ namespace pika::ensure_started_detail {
template <typename Receiver>
struct stopped_error_value_visitor
{
PIKA_NO_UNIQUE_ADDRESS std::decay_t<Receiver> receiver;
std::decay_t<Receiver>& receiver;

template <typename T,
typename =
Expand All @@ -234,8 +234,7 @@ namespace pika::ensure_started_detail {

void operator()(error_type&& error)
{
pika::detail::visit(
error_visitor<Receiver>{PIKA_MOVE(receiver)}, PIKA_MOVE(error));
pika::detail::visit(error_visitor<Receiver>{receiver}, PIKA_MOVE(error));
}

template <typename T,
Expand All @@ -244,8 +243,7 @@ namespace pika::ensure_started_detail {
std::is_same_v<std::decay_t<T>, value_type>>>
void operator()(T&& t)
{
pika::detail::visit(
value_visitor<Receiver>{PIKA_MOVE(receiver)}, PIKA_FORWARD(T, t));
pika::detail::visit(value_visitor<Receiver>{receiver}, PIKA_FORWARD(T, t));
}
};

Expand Down Expand Up @@ -319,7 +317,7 @@ namespace pika::ensure_started_detail {
// TODO: Should this preserve the scheduler? It does not
// if we call set_* inline.
pika::detail::visit(
stopped_error_value_visitor<Receiver>{PIKA_FORWARD(Receiver, receiver)},
stopped_error_value_visitor<Receiver>{receiver},
PIKA_MOVE(v));
}
else
Expand All @@ -336,7 +334,7 @@ namespace pika::ensure_started_detail {
// directly again.
l.unlock();
pika::detail::visit(
stopped_error_value_visitor<Receiver>{PIKA_FORWARD(Receiver, receiver)},
stopped_error_value_visitor<Receiver>{receiver},
PIKA_MOVE(v));
}
else
Expand All @@ -348,8 +346,7 @@ namespace pika::ensure_started_detail {
continuation.emplace(
[this, receiver = PIKA_FORWARD(Receiver, receiver)]() mutable {
pika::detail::visit(
stopped_error_value_visitor<Receiver>{PIKA_MOVE(receiver)},
PIKA_MOVE(v));
stopped_error_value_visitor<Receiver>{receiver}, PIKA_MOVE(v));
});
}
}
Expand Down
21 changes: 8 additions & 13 deletions libs/pika/execution/include/pika/execution/algorithms/split.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace pika::split_detail {
template <typename Receiver>
struct error_visitor
{
PIKA_NO_UNIQUE_ADDRESS std::decay_t<Receiver> receiver;
std::decay_t<Receiver>& receiver;

template <typename Error>
void operator()(Error const& error)
Expand All @@ -58,7 +58,7 @@ namespace pika::split_detail {
template <typename Receiver>
struct value_visitor
{
PIKA_NO_UNIQUE_ADDRESS std::decay_t<Receiver> receiver;
std::decay_t<Receiver>& receiver;

template <typename Ts>
void operator()(Ts const& ts)
Expand Down Expand Up @@ -227,7 +227,7 @@ namespace pika::split_detail {
template <typename Receiver>
struct stopped_error_value_visitor
{
PIKA_NO_UNIQUE_ADDRESS std::decay_t<Receiver> receiver;
std::decay_t<Receiver>& receiver;

[[noreturn]] void operator()(pika::detail::monostate) const { PIKA_UNREACHABLE; }

Expand All @@ -238,14 +238,12 @@ namespace pika::split_detail {

void operator()(error_type const& error)
{
pika::detail::visit(
error_visitor<Receiver>{PIKA_FORWARD(Receiver, receiver)}, error);
pika::detail::visit(error_visitor<Receiver>{receiver}, error);
}

void operator()(value_type const& ts)
{
pika::detail::visit(
value_visitor<Receiver>{PIKA_FORWARD(Receiver, receiver)}, ts);
pika::detail::visit(value_visitor<Receiver>{receiver}, ts);
}
};

Expand Down Expand Up @@ -316,8 +314,7 @@ namespace pika::split_detail {
// We can trigger the continuation directly.
// TODO: Should this preserve the scheduler? It does not
// if we call set_* inline.
pika::detail::visit(
stopped_error_value_visitor<Receiver>{PIKA_FORWARD(Receiver, receiver)}, v);
pika::detail::visit(stopped_error_value_visitor<Receiver>{receiver}, v);
}
else
{
Expand All @@ -333,9 +330,7 @@ namespace pika::split_detail {
// release the lock early and call the continuation
// directly again.
l.unlock();
pika::detail::visit(
stopped_error_value_visitor<Receiver>{PIKA_FORWARD(Receiver, receiver)},
v);
pika::detail::visit(stopped_error_value_visitor<Receiver>{receiver}, v);
}
else
{
Expand All @@ -349,7 +344,7 @@ namespace pika::split_detail {
continuations.emplace_back(
[this, receiver = PIKA_FORWARD(Receiver, receiver)]() mutable {
pika::detail::visit(
stopped_error_value_visitor<Receiver>{PIKA_MOVE(receiver)}, v);
stopped_error_value_visitor<Receiver>{receiver}, v);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace pika::split_tuple_detail {
template <typename Receiver>
struct error_visitor
{
PIKA_NO_UNIQUE_ADDRESS std::decay_t<Receiver> receiver;
std::decay_t<Receiver>& receiver;

template <typename Error>
void operator()(Error const& error)
Expand Down Expand Up @@ -210,8 +210,7 @@ namespace pika::split_tuple_detail {

void operator()(error_type const& error)
{
pika::detail::visit(
error_visitor<Receiver>{PIKA_FORWARD(Receiver, receiver)}, error);
pika::detail::visit(error_visitor<Receiver>{receiver}, error);
}

void operator()(value_type& t)
Expand Down Expand Up @@ -325,12 +324,11 @@ namespace pika::split_tuple_detail {
// to the vector and the vector is not threadsafe in
// itself. The continuation will be called later
// when set_error/set_stopped/set_value is called.
continuations[Index] = [this,
receiver =
PIKA_FORWARD(Receiver, receiver)]() mutable {
pika::detail::visit(
stopped_error_value_visitor<Index, Receiver>{PIKA_MOVE(receiver)}, v);
};
continuations[Index] =
[this, receiver = PIKA_FORWARD(Receiver, receiver)]() mutable {
pika::detail::visit(
stopped_error_value_visitor<Index, Receiver>{receiver}, v);
};
}
}
}
Expand Down

0 comments on commit 438a1df

Please sign in to comment.