Skip to content

Commit 5f6839e

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

16 files changed

Lines changed: 488 additions & 288 deletions

include/exec/fork_join.hpp

Lines changed: 3 additions & 3 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

@@ -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_}),

include/exec/sequence.hpp

Lines changed: 13 additions & 6 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

@@ -99,16 +107,15 @@ namespace exec {
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);

include/exec/start_now.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 3 additions & 3 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
},
@@ -200,7 +200,7 @@ namespace exec {
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

include/nvexec/stream/when_all.cuh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ namespace nvexec::_strm {
252252
-> __tuple_for<child_op_state_t<SenderIds, Is>...> {
253253

254254
using __child_ops_t = __tuple_for<child_op_state_t<SenderIds, Is>...>;
255-
return when_all.sndrs_.apply(
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

include/stdexec/__detail/__basic_sender.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
},

include/stdexec/__detail/__config.hpp

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@
112112
# define STDEXEC_INTELLISENSE() 0
113113
#endif
114114

115+
////////////////////////////////////////////////////////////////////////////////////////////////////
116+
#if STDEXEC_MSVC()
117+
# define STDEXEC_PRAGMA(_ARG) __pragma(_ARG)
118+
#else
119+
# define STDEXEC_PRAGMA(_ARG) _Pragma(STDEXEC_STRINGIZE(_ARG))
120+
#endif
121+
115122
////////////////////////////////////////////////////////////////////////////////////////////////////
116123
#if defined(__CUDACC__) || defined(_NVHPC_CUDA)
117124
# define STDEXEC_CUDA_COMPILATION() 1
@@ -133,6 +140,13 @@
133140
# define STDEXEC_HOST_DEVICE_DEDUCTION_GUIDE
134141
#endif
135142

143+
////////////////////////////////////////////////////////////////////////////////////////////////////
144+
#if STDEXEC_NVCC()
145+
# define STDEXEC_EXEC_CHECK_DISABLE STDEXEC_PRAGMA(nv_exec_check_disable)
146+
#else
147+
# define STDEXEC_EXEC_CHECK_DISABLE
148+
#endif
149+
136150
////////////////////////////////////////////////////////////////////////////////////////////////////
137151
#if __cpp_impl_coroutine >= 2019'02 && __cpp_lib_coroutine >= 2019'02
138152
# include <coroutine> // IWYU pragma: keep
@@ -241,32 +255,39 @@ namespace __coro = std::experimental;
241255
#define STDEXEC_ATTR_launch_bounds(...) STDEXEC_PROBE(~, 7)
242256
#define STDEXEC_ATTR___launch_bounds__(...) STDEXEC_PROBE(~, 7)
243257

258+
#if STDEXEC_MSVC() && !STDEXEC_CLANG_CL()
259+
# define STDEXEC_ATTR_WHICH_8(_ATTR) __declspec(_ATTR)
260+
#else
261+
# define STDEXEC_ATTR_WHICH_8(_ATTR) /*nothing*/
262+
#endif
263+
#define STDEXEC_ATTR_empty_bases STDEXEC_PROBE(~, 8)
264+
244265
////////////////////////////////////////////////////////////////////////////////////////////////////
245266
// warning push/pop portability macros
246267
#if STDEXEC_NVCC()
247-
# define STDEXEC_PRAGMA_PUSH() _Pragma("nv_diagnostic push")
248-
# define STDEXEC_PRAGMA_POP() _Pragma("nv_diagnostic pop")
249-
# define STDEXEC_PRAGMA_IGNORE_EDG(...) _Pragma(STDEXEC_STRINGIZE(nv_diag_suppress __VA_ARGS__))
268+
# define STDEXEC_PRAGMA_PUSH() STDEXEC_PRAGMA(nv_diagnostic push)
269+
# define STDEXEC_PRAGMA_POP() STDEXEC_PRAGMA(nv_diagnostic pop)
270+
# define STDEXEC_PRAGMA_IGNORE_EDG(...) STDEXEC_PRAGMA(nv_diag_suppress __VA_ARGS__)
250271
#elif STDEXEC_EDG()
251272
# define STDEXEC_PRAGMA_PUSH() \
252-
_Pragma("diagnostic push") STDEXEC_PRAGMA_IGNORE_EDG(invalid_error_number) \
253-
STDEXEC_PRAGMA_IGNORE_EDG(invalid_error_tag)
254-
# define STDEXEC_PRAGMA_POP() _Pragma("diagnostic pop")
255-
# define STDEXEC_PRAGMA_IGNORE_EDG(...) _Pragma(STDEXEC_STRINGIZE(diag_suppress __VA_ARGS__))
273+
STDEXEC_PRAGMA(diagnostic push) \
274+
STDEXEC_PRAGMA_IGNORE_EDG(invalid_error_number) STDEXEC_PRAGMA_IGNORE_EDG(invalid_error_tag)
275+
# define STDEXEC_PRAGMA_POP() STDEXEC_PRAGMA(diagnostic pop)
276+
# define STDEXEC_PRAGMA_IGNORE_EDG(...) STDEXEC_PRAGMA(diag_suppress __VA_ARGS__)
256277
#elif STDEXEC_CLANG() || STDEXEC_GCC()
257278
# define STDEXEC_PRAGMA_PUSH() \
258-
_Pragma("GCC diagnostic push") STDEXEC_PRAGMA_IGNORE_GNU("-Wpragmas") \
259-
STDEXEC_PRAGMA_IGNORE_GNU("-Wunknown-pragmas") \
260-
STDEXEC_PRAGMA_IGNORE_GNU("-Wunknown-warning-option") \
261-
STDEXEC_PRAGMA_IGNORE_GNU("-Wunknown-attributes") \
262-
STDEXEC_PRAGMA_IGNORE_GNU("-Wattributes")
263-
# define STDEXEC_PRAGMA_POP() _Pragma("GCC diagnostic pop")
264-
# define STDEXEC_PRAGMA_IGNORE_GNU(...) \
265-
_Pragma(STDEXEC_STRINGIZE(GCC diagnostic ignored __VA_ARGS__))
279+
STDEXEC_PRAGMA(GCC diagnostic push) \
280+
STDEXEC_PRAGMA_IGNORE_GNU("-Wpragmas") \
281+
STDEXEC_PRAGMA_IGNORE_GNU("-Wunknown-pragmas") \
282+
STDEXEC_PRAGMA_IGNORE_GNU("-Wunknown-warning-option") \
283+
STDEXEC_PRAGMA_IGNORE_GNU("-Wunknown-attributes") \
284+
STDEXEC_PRAGMA_IGNORE_GNU("-Wattributes")
285+
# define STDEXEC_PRAGMA_POP() STDEXEC_PRAGMA(GCC diagnostic pop)
286+
# define STDEXEC_PRAGMA_IGNORE_GNU(...) STDEXEC_PRAGMA(GCC diagnostic ignored __VA_ARGS__)
266287
#elif STDEXEC_MSVC()
267-
# define STDEXEC_PRAGMA_PUSH() __pragma(warning(push))
268-
# define STDEXEC_PRAGMA_POP() __pragma(warning(pop))
269-
# define STDEXEC_PRAGMA_IGNORE_MSVC(...) __pragma(warning(disable : __VA_ARGS__))
288+
# define STDEXEC_PRAGMA_PUSH() STDEXEC_PRAGMA(warning(push))
289+
# define STDEXEC_PRAGMA_POP() STDEXEC_PRAGMA(warning(pop))
290+
# define STDEXEC_PRAGMA_IGNORE_MSVC(...) STDEXEC_PRAGMA(warning(disable : __VA_ARGS__))
270291
#else
271292
# define STDEXEC_PRAGMA_PUSH()
272293
# define STDEXEC_PRAGMA_POP()

include/stdexec/__detail/__continues_on.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ namespace stdexec {
8787
STDEXEC_ATTRIBUTE(always_inline)
8888
auto __make_visitor_fn(_State* __state) noexcept {
8989
return [__state]<class _Tup>(_Tup& __tupl) noexcept -> void {
90-
__tupl.apply(
90+
stdexec::__apply(
9191
[&]<class... _Args>(auto __tag, _Args&... __args) noexcept -> void {
9292
__tag(std::move(__state->__receiver()), static_cast<_Args&&>(__args)...);
9393
},
@@ -356,11 +356,11 @@ namespace stdexec {
356356
_Args&&... __args) noexcept -> void {
357357
// Write the tag and the args into the operation state so that we can forward the completion
358358
// from within the scheduler's execution context.
359-
if constexpr (__nothrow_callable<__tup::__mktuple_t, _Tag, _Args...>) {
360-
__state.__data_.emplace_from(__tup::__mktuple, __tag, static_cast<_Args&&>(__args)...);
359+
if constexpr (__nothrow_callable<__mktuple_t, _Tag, _Args...>) {
360+
__state.__data_.emplace_from(__mktuple, __tag, static_cast<_Args&&>(__args)...);
361361
} else {
362362
STDEXEC_TRY {
363-
__state.__data_.emplace_from(__tup::__mktuple, __tag, static_cast<_Args&&>(__args)...);
363+
__state.__data_.emplace_from(__mktuple, __tag, static_cast<_Args&&>(__args)...);
364364
}
365365
STDEXEC_CATCH_ALL {
366366
stdexec::set_error(static_cast<_Receiver&&>(__rcvr), std::current_exception());

include/stdexec/__detail/__just.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ namespace stdexec {
4848

4949
static constexpr auto start =
5050
[]<class _State, class _Receiver>(_State& __state, _Receiver& __rcvr) noexcept -> void {
51-
__state.apply(__tag_t(), static_cast<_State&&>(__state), static_cast<_Receiver&&>(__rcvr));
51+
stdexec::__apply(
52+
__tag_t(), static_cast<_State&&>(__state), static_cast<_Receiver&&>(__rcvr));
5253
};
5354

5455
static constexpr auto submit =
5556
[]<class _Sender, class _Receiver>(_Sender&& __sndr, _Receiver __rcvr) noexcept -> void {
5657
static_assert(sender_expr_for<_Sender, _JustTag>);
5758
auto&& __state = get_state(static_cast<_Sender&&>(__sndr), __rcvr);
58-
__state.apply(
59+
stdexec::__apply(
5960
__tag_t(), static_cast<decltype(__state)>(__state), static_cast<_Receiver&&>(__rcvr));
6061
};
6162
};

include/stdexec/__detail/__let.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,9 @@ namespace stdexec {
579579
template <class _State, class _OpState, class... _As>
580580
static void __bind_(_State& __state, _OpState& __op_state, _As&&... __as) {
581581
// Store the passed-in (received) args:
582-
auto& __args = __state.__args_.emplace_from(__tup::__mktuple, static_cast<_As&&>(__as)...);
582+
auto& __args = __state.__args_.emplace_from(__mktuple, static_cast<_As&&>(__as)...);
583583
// Apply the function to the args to get the sender:
584-
auto __sndr2 = __args.apply(std::move(__state.__fun_), __args);
584+
auto __sndr2 = stdexec::__apply(std::move(__state.__fun_), __args);
585585
// Create a receiver based on the state, the computed sender, and the operation state:
586586
auto __rcvr2 = __state.__get_result_receiver(__sndr2, __op_state);
587587
// Connect the sender to the receiver and start it:

0 commit comments

Comments
 (0)