Skip to content

Commit 5c69c82

Browse files
committed
a simpler implementation for stdexec::__tuple
1 parent aab07dd commit 5c69c82

File tree

16 files changed

+507
-311
lines changed

16 files changed

+507
-311
lines changed

include/exec/fork_join.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace exec {
3939
template <class Rcvr, class Tuple>
4040
STDEXEC_ATTRIBUTE(always_inline, host, device)
4141
void operator()(Rcvr& rcvr, const Tuple& tupl) const noexcept {
42-
tupl.apply(_impl_fn{}, tupl, rcvr);
42+
stdexec::__apply(_impl_fn{}, tupl, rcvr);
4343
}
4444
};
4545

@@ -55,7 +55,7 @@ namespace exec {
5555
using _maybe_eptr_completion_t = stdexec::__if_c<
5656
stdexec::__nothrow_decay_copyable_results_t<Completions>::value,
5757
stdexec::__mset_nil,
58-
stdexec::__tuple_for<stdexec::set_error_t, ::std::exception_ptr>
58+
stdexec::__tuple<stdexec::set_error_t, ::std::exception_ptr>
5959
>;
6060

6161
template <class Completions>
@@ -122,7 +122,7 @@ namespace exec {
122122
};
123123

124124
template <class Completions, class Closures, class Domain>
125-
using _when_all_sndr_t = stdexec::__tup::__apply_result_t<
125+
using _when_all_sndr_t = stdexec::__apply_result_t<
126126
_mk_when_all_fn,
127127
Closures,
128128
_cache_sndr_t<_variant_t<Completions>, Domain>
@@ -147,7 +147,7 @@ namespace exec {
147147
: _rcvr_(static_cast<Rcvr&&>(rcvr))
148148
, _fork_opstate_(
149149
stdexec::connect(
150-
closures.apply(
150+
stdexec::__apply(
151151
_mk_when_all_fn{},
152152
static_cast<Closures&&>(closures),
153153
_cache_sndr_t{&_cache_}),
@@ -178,7 +178,7 @@ namespace exec {
178178
}
179179
STDEXEC_CATCH_ALL {
180180
if constexpr (!stdexec::__nothrow_decay_copyable<Args...>) {
181-
using _tuple_t = stdexec::__tuple_for<stdexec::set_error_t, ::std::exception_ptr>;
181+
using _tuple_t = stdexec::__tuple<stdexec::set_error_t, ::std::exception_ptr>;
182182
_cache_._results_
183183
.template emplace<_tuple_t>(stdexec::set_error, ::std::current_exception());
184184
}
@@ -216,7 +216,7 @@ namespace exec {
216216

217217
template <class... Closures>
218218
struct _closure_t {
219-
using _closures_t = stdexec::__tuple_for<Closures...>;
219+
using _closures_t = stdexec::__tuple<Closures...>;
220220

221221
template <class Sndr>
222222
STDEXEC_ATTRIBUTE(host, device)
@@ -250,7 +250,7 @@ namespace exec {
250250
template <class Sndr, class... Closures>
251251
struct fork_join_t::_sndr_t {
252252
using sender_concept = stdexec::sender_t;
253-
using _closures_t = stdexec::__tuple_for<Closures...>;
253+
using _closures_t = stdexec::__tuple<Closures...>;
254254

255255
template <class Self, class... Env>
256256
STDEXEC_ATTRIBUTE(host, device)
@@ -297,7 +297,7 @@ namespace exec {
297297
}
298298

299299
STDEXEC_ATTRIBUTE(no_unique_address) fork_join_t _tag_;
300-
stdexec::__tuple_for<Closures...> _closures_;
300+
stdexec::__tuple<Closures...> _closures_;
301301
Sndr sndr_;
302302
};
303303

include/exec/sequence.hpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ namespace exec {
6666
}
6767
};
6868

69+
template <class _Tuple>
70+
struct __convert_tuple_fn {
71+
template <class... _Ts>
72+
STDEXEC_ATTRIBUTE(host, device, always_inline)
73+
constexpr auto
74+
operator()(_Ts&&... __ts) const STDEXEC_AUTO_RETURN(_Tuple{static_cast<_Ts&&>(__ts)...});
75+
};
76+
6977
template <class Rcvr, class... Sndrs>
7078
struct _opstate;
7179

@@ -76,7 +84,7 @@ namespace exec {
7684
// We will be connecting the first sender in the opstate constructor, so we don't need to
7785
// store it in the opstate. The use of `stdexec::__ignore` causes the first sender to not
7886
// be stored.
79-
using _senders_tuple_t = stdexec::__tuple_for<stdexec::__ignore, Sndrs...>;
87+
using _senders_tuple_t = stdexec::__tuple<stdexec::__ignore, Sndrs...>;
8088

8189
template <size_t Idx>
8290
using _rcvr_t = _seq::_rcvr<Rcvr, stdexec::__id<_opstate>, stdexec::__msize_t<Idx>>;
@@ -91,24 +99,23 @@ namespace exec {
9199

92100
using _ops_variant_t = stdexec::__minvoke<
93101
_mk_child_ops_variant_fn,
94-
stdexec::__tuple_for<Sndr0, Sndrs...>,
102+
stdexec::__tuple<Sndr0, Sndrs...>,
95103
stdexec::__make_indices<sizeof...(Sndrs) + 1>
96104
>;
97105

98106
template <class CvrefSndrs>
99107
STDEXEC_ATTRIBUTE(host, device)
100108
explicit _opstate(Rcvr&& rcvr, CvrefSndrs&& sndrs)
101109
: _rcvr{static_cast<Rcvr&&>(rcvr)}
102-
, _sndrs{_senders_tuple_t::__convert_from(static_cast<CvrefSndrs&&>(sndrs))}
103-
// move all but the first sender into the opstate.
110+
, _sndrs{stdexec::__apply(
111+
__convert_tuple_fn<_senders_tuple_t>{},
112+
static_cast<CvrefSndrs&&>(sndrs))} // move all but the first sender into the opstate.
104113
{
105114
// Below, it looks like we are using `sndrs` after it has been moved from. This is not the
106115
// case. `sndrs` is moved into a tuple type that has `__ignore` for the first element. The
107116
// result is that the first sender in `sndrs` is not moved from, but the rest are.
108117
_ops.template emplace_from_at<0>(
109-
stdexec::connect,
110-
sndrs.template __get<0>(static_cast<CvrefSndrs&&>(sndrs)),
111-
_rcvr_t<0>{this});
118+
stdexec::connect, stdexec::__get<0>(static_cast<CvrefSndrs&&>(sndrs)), _rcvr_t<0>{this});
112119
}
113120

114121
template <class Index, class... Args>
@@ -119,7 +126,7 @@ namespace exec {
119126
if constexpr (Idx == sizeof...(Sndrs) + 1) {
120127
stdexec::set_value(static_cast<Rcvr&&>(_rcvr), static_cast<Args&&>(args)...);
121128
} else {
122-
auto& sndr = _sndrs.template __get<Idx>(_sndrs);
129+
auto& sndr = stdexec::__get<Idx>(_sndrs);
123130
auto& op = _ops.template emplace_from_at<Idx>(
124131
stdexec::connect, std::move(sndr), _rcvr_t<Idx>{this});
125132
stdexec::start(op);
@@ -206,7 +213,7 @@ namespace exec {
206213

207214
STDEXEC_ATTRIBUTE(no_unique_address, maybe_unused) sequence_t _tag;
208215
STDEXEC_ATTRIBUTE(no_unique_address, maybe_unused) stdexec::__ignore _ignore;
209-
stdexec::__tuple_for<Sndrs...> _sndrs;
216+
stdexec::__tuple<Sndrs...> _sndrs;
210217
};
211218

212219
template <class Sndr>

include/exec/start_now.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ namespace exec {
170170
template <class _Sender>
171171
using __nested_t = nest_result_t<_AsyncScope, _Sender>;
172172

173-
stdexec::__tuple_for<
173+
stdexec::__tuple<
174174
stdexec::connect_result_t<__nested_t<stdexec::__cvref_t<_SenderIds>>, __receiver_t>...
175175
>
176176
__op_state_;
@@ -182,7 +182,7 @@ namespace exec {
182182
__scope.nest(static_cast<stdexec::__cvref_t<_SenderIds>&&>(__sndr)),
183183
__receiver_t{this})...} {
184184
// Start all of the child operations
185-
__op_state_.for_each(stdexec::start, __op_state_);
185+
stdexec::__apply(stdexec::__for_each{stdexec::start}, __op_state_);
186186
}
187187

188188
auto request_stop() noexcept -> bool {
@@ -249,7 +249,7 @@ namespace exec {
249249
return __storage_t<stdexec::__root_env, _AsyncScope, _Sender...>{
250250
stdexec::__root_env{}, __scope, static_cast<_Sender&&>(__sndr)...};
251251
}
252-
};
252+
};
253253
} // namespace __start_now_
254254

255255
using __start_now_::start_now_t;

include/exec/when_any.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace exec {
8080
template <class _Receiver>
8181
auto __make_visitor_fn(_Receiver& __rcvr) noexcept {
8282
return [&__rcvr]<class _Tuple>(_Tuple&& __result) noexcept {
83-
__result.apply(
83+
stdexec::__apply(
8484
[&__rcvr]<class... _As>(auto __tag, _As&... __args) noexcept {
8585
__tag(static_cast<_Receiver&&>(__rcvr), static_cast<_As&&>(__args)...);
8686
},
@@ -123,7 +123,7 @@ namespace exec {
123123
__result_.template emplace<__result_t>(_Tag{}, static_cast<_Args&&>(__args)...);
124124
}
125125
STDEXEC_CATCH_ALL {
126-
using __error_t = __tuple_for<set_error_t, std::exception_ptr>;
126+
using __error_t = __tuple<set_error_t, std::exception_ptr>;
127127
__result_.template emplace<__error_t>(set_error_t{}, std::current_exception());
128128
}
129129
}
@@ -195,12 +195,12 @@ namespace exec {
195195

196196
class __t : __op_base_t {
197197
using __opstate_tuple =
198-
__tuple_for<connect_result_t<stdexec::__cvref_t<_CvrefSenderIds>, __receiver_t>...>;
198+
__tuple<connect_result_t<stdexec::__cvref_t<_CvrefSenderIds>, __receiver_t>...>;
199199
public:
200200
template <class _SenderTuple>
201201
__t(_SenderTuple&& __senders, _Receiver&& __rcvr) noexcept(__nothrow_construct)
202202
: __op_base_t{static_cast<_Receiver&&>(__rcvr), sizeof...(_CvrefSenderIds)}
203-
, __ops_{__senders.apply(
203+
, __ops_{stdexec::__apply(
204204
[this]<class... _Senders>(_Senders&&... __sndrs) noexcept(
205205
__nothrow_construct) -> __opstate_tuple {
206206
return __opstate_tuple{
@@ -215,7 +215,7 @@ namespace exec {
215215
if (this->__stop_source_.stop_requested()) {
216216
stdexec::set_stopped(static_cast<_Receiver&&>(this->__rcvr_));
217217
} else {
218-
__ops_.for_each(stdexec::start, __ops_);
218+
stdexec::__apply(stdexec::__for_each{stdexec::start}, __ops_);
219219
}
220220
}
221221

@@ -246,7 +246,7 @@ namespace exec {
246246
public:
247247
using __id = __sender;
248248
using sender_concept = stdexec::sender_t;
249-
using __senders_tuple = __tuple_for<stdexec::__t<_SenderIds>...>;
249+
using __senders_tuple = __tuple<stdexec::__t<_SenderIds>...>;
250250

251251
template <__not_decays_to<__t>... _Senders>
252252
explicit(sizeof...(_Senders) == 1) __t(_Senders&&... __senders)

include/nvexec/stream/when_all.cuh

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ namespace nvexec::_strm {
249249

250250
template <size_t... Is>
251251
static auto connect_children_(operation_t* parent_op, WhenAll&& when_all, __indices<Is...>)
252-
-> __tuple_for<child_op_state_t<SenderIds, Is>...> {
252+
-> __tuple<child_op_state_t<SenderIds, Is>...> {
253253

254-
using __child_ops_t = __tuple_for<child_op_state_t<SenderIds, Is>...>;
255-
return when_all.sndrs_.apply(
254+
using __child_ops_t = __tuple<child_op_state_t<SenderIds, Is>...>;
255+
return stdexec::__apply(
256256
[parent_op]<class... Children>(Children&&... children) -> __child_ops_t {
257257
return __child_ops_t{_strm::exit_op_state(
258258
static_cast<Children&&>(children),
@@ -299,7 +299,7 @@ namespace nvexec::_strm {
299299
}
300300
} else {
301301
// Synchronize the streams of all the child operations
302-
child_states_.for_each(_when_all::_sync_op, child_states_);
302+
stdexec::__apply(stdexec::__for_each{_when_all::_sync_op}, child_states_);
303303
}
304304
}
305305

@@ -309,9 +309,9 @@ namespace nvexec::_strm {
309309
case _when_all::started:
310310
if constexpr (__v<sends_values<Completions>>) {
311311
// All child operations completed successfully:
312-
values_->apply(
312+
stdexec::__apply(
313313
[this]<class... Tuples>(Tuples&&... value_tupls) noexcept -> void {
314-
__tup::__cat_apply(
314+
stdexec::__cat_apply(
315315
__mk_completion_fn(stdexec::set_value, rcvr_),
316316
static_cast<Tuples&&>(value_tupls)...);
317317
},
@@ -336,13 +336,14 @@ namespace nvexec::_strm {
336336
using stream_providers_t = std::array<stream_provider_t, sizeof...(SenderIds)>;
337337

338338
static auto get_stream_providers(WhenAll& when_all, Receiver& rcvr) -> stream_providers_t {
339-
return when_all.sndrs_.apply(
340-
[&rcvr](auto&... sndrs) -> stream_providers_t {
339+
return stdexec::__apply(
340+
[](auto& rcvr, auto&... sndrs) -> stream_providers_t {
341341
return stream_providers_t{stdexec::get_completion_scheduler<set_value_t>(
342342
stdexec::get_env(sndrs), stdexec::get_env(rcvr))
343343
.context_state_...};
344344
},
345-
when_all.sndrs_);
345+
when_all.sndrs_,
346+
rcvr);
346347
}
347348

348349
operation_t(WhenAll&& when_all, Receiver rcvr)
@@ -368,7 +369,7 @@ namespace nvexec::_strm {
368369
// the child operations.
369370
stdexec::set_stopped(static_cast<Receiver&&>(rcvr_));
370371
} else {
371-
child_states_.for_each(stdexec::start, child_states_);
372+
stdexec::__apply(stdexec::__for_each{stdexec::start}, child_states_);
372373
if constexpr (sizeof...(SenderIds) == 0) {
373374
complete();
374375
}
@@ -401,10 +402,10 @@ namespace nvexec::_strm {
401402
// We only need to bother recording the completion values
402403
// if we're not already in the "error" or "stopped" state.
403404
if (state_.load() == _when_all::started) {
404-
cudaStream_t stream = child_states_.template __get<Index>(child_states_).get_stream();
405+
cudaStream_t stream = stdexec::__get<Index>(child_states_).get_stream();
405406
if constexpr (sizeof...(Args)) {
406407
_when_all::copy_kernel<Args&&...><<<1, 1, 0, stream>>>(
407-
&(values_->template __get<Index>(*values_)), static_cast<Args&&>(args)...);
408+
&stdexec::__get<Index>(*values_), static_cast<Args&&>(args)...);
408409
statuses_[Index] = cudaGetLastError();
409410
}
410411

@@ -439,7 +440,7 @@ namespace nvexec::_strm {
439440
using child_values_tuple_t = __if<
440441
sends_values<Completions>,
441442
__minvoke<
442-
__qq<__tuple_for>,
443+
__qq<__tuple>,
443444
__value_types_of_t<
444445
stdexec::__t<SenderIds>,
445446
_when_all::env_t<Env>,
@@ -495,7 +496,7 @@ namespace nvexec::_strm {
495496
}
496497

497498
private:
498-
__tuple_for<stdexec::__t<SenderIds>...> sndrs_;
499+
__tuple<stdexec::__t<SenderIds>...> sndrs_;
499500
};
500501
};
501502

include/stdexec/__detail/__basic_sender.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ namespace stdexec {
308308
requires(sender_to<_Child, __receiver_archetype<__env_t<_Is>>> && ...)
309309
auto operator()(__indices<_Is...>, _Child&&... __child) const
310310
noexcept((__nothrow_connectable<_Child, __receiver_t<_Is>> && ...))
311-
-> __tuple_for<connect_result_t<_Child, __receiver_t<_Is>>...> {
311+
-> __tuple<connect_result_t<_Child, __receiver_t<_Is>>...> {
312312
return __tuple{connect(static_cast<_Child&&>(__child), __receiver_t<_Is>{__op_})...};
313313
}
314314
};
@@ -320,7 +320,7 @@ namespace stdexec {
320320
return __impl{__op_}(__indices_for<_Child...>(), static_cast<_Child&&>(__child)...);
321321
}
322322

323-
auto operator()(__ignore, __ignore) const noexcept -> __tuple_for<> {
323+
auto operator()(__ignore, __ignore) const noexcept -> __tuple<> {
324324
return {};
325325
}
326326
};
@@ -429,7 +429,7 @@ namespace stdexec {
429429
STDEXEC_ATTRIBUTE(always_inline) void start() & noexcept {
430430
using __tag_t = __op_state::__tag_t;
431431
auto&& __rcvr = this->__rcvr();
432-
__inner_ops_.apply(
432+
stdexec::__apply(
433433
[&](auto&... __ops) noexcept {
434434
__sexpr_impl<__tag_t>::start(this->__state(), __rcvr, __ops...);
435435
},

0 commit comments

Comments
 (0)