Skip to content

Commit 1e21d78

Browse files
authored
give stdexec a consteval __transform_completion_signatures function (#1770)
1 parent 9e862d6 commit 1e21d78

55 files changed

Lines changed: 795 additions & 616 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎include/exec/any_sender_of.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ namespace exec {
12491249
template <auto... _SchedulerQueries>
12501250
class any_scheduler {
12511251
// Add the required set_value_t() completions to the schedule-sender.
1252-
using __schedule_completions = STDEXEC::__concat_completion_signatures<
1252+
using __schedule_completions = STDEXEC::__concat_completion_signatures_t<
12531253
_Completions,
12541254
STDEXEC::completion_signatures<STDEXEC::set_value_t()>
12551255
>;

‎include/exec/completion_signatures.hpp‎

Lines changed: 27 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "../stdexec/__detail/__get_completion_signatures.hpp"
1919
#include "../stdexec/__detail/__meta.hpp"
2020
#include "../stdexec/__detail/__sender_concepts.hpp"
21-
#include "../stdexec/__detail/__tuple.hpp" // IWYU pragma: keep for STDEXEC::__tuple
21+
#include "../stdexec/__detail/__transform_completion_signatures.hpp"
2222

2323
namespace exec {
2424
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -77,173 +77,46 @@ namespace exec {
7777
return {};
7878
}
7979

80-
STDEXEC_PRAGMA_PUSH()
81-
STDEXEC_PRAGMA_IGNORE_EDG(expr_has_no_effect)
82-
STDEXEC_PRAGMA_IGNORE_GNU("-Wunused-value")
83-
8480
///////////////////////////////////////////////////////////////////////////////////////////////////
8581
// concat_completion_signatures
86-
namespace detail {
87-
struct concat_completion_signatures_t {
88-
template <STDEXEC::__valid_completion_signatures... Sigs>
89-
[[nodiscard]]
90-
consteval auto operator()(Sigs...) const noexcept //
91-
-> STDEXEC::__concat_completion_signatures<Sigs...> {
92-
return {};
93-
}
94-
95-
template <class... Errors>
96-
[[nodiscard]]
97-
consteval auto operator()(Errors...) const noexcept {
98-
return (Errors{}, ...); // NB: uses overloaded comma operator on _ERROR_ type to produce an
99-
// error type
100-
}
101-
};
102-
} // namespace detail
103-
104-
inline constexpr detail::concat_completion_signatures_t concat_completion_signatures{};
105-
106-
STDEXEC_PRAGMA_POP()
82+
inline constexpr STDEXEC::__detail::__concat_completion_signatures_fn
83+
concat_completion_signatures{};
10784

10885
//////////////////////////////////////////////////////////////////////////////////////////////////
109-
// invalid_completion_signature
86+
// throw_compile_time_error
11087
template <class... What, class... Values>
11188
[[nodiscard]]
112-
consteval auto invalid_completion_signature(Values... vals) {
113-
return STDEXEC::__invalid_completion_signature<What...>(static_cast<Values&&>(vals)...);
89+
consteval auto throw_compile_time_error(Values... vals) {
90+
return STDEXEC::__throw_compile_time_error<What...>(static_cast<Values&&>(vals)...);
11491
}
11592

116-
struct IN_TRANSFORM_COMPLETION_SIGNATURES;
117-
struct A_TRANSFORM_FUNCTION_RETURNED_A_TYPE_THAT_IS_NOT_A_COMPLETION_SIGNATURES_SPECIALIZATION;
118-
struct COULD_NOT_CALL_THE_TRANSFORM_FUNCTION_WITH_THE_GIVEN_TEMPLATE_ARGUMENTS;
119-
120-
namespace detail {
121-
template <class Fn, class... As>
122-
using meta_call_result_t = decltype(STDEXEC::__declval<Fn>().template operator()<As...>());
123-
124-
template <class Ay, class... As, class Fn>
125-
[[nodiscard]]
126-
consteval auto _transform_expr(const Fn& fn) -> meta_call_result_t<const Fn&, Ay, As...> {
127-
return fn.template operator()<Ay, As...>();
128-
}
129-
130-
template <class Fn>
131-
[[nodiscard]]
132-
consteval auto _transform_expr(const Fn& fn) -> STDEXEC::__call_result_t<const Fn&> {
133-
return fn();
134-
}
135-
136-
template <class Fn, class... As>
137-
using _transform_expr_t = decltype(detail::_transform_expr<As...>(
138-
STDEXEC::__declval<const Fn&>()));
139-
140-
// transform_completion_signatures:
141-
template <class... As, class Fn>
142-
[[nodiscard]]
143-
consteval auto _apply_transform(const Fn& fn) {
144-
if constexpr (STDEXEC::__mvalid<_transform_expr_t, Fn, As...>) {
145-
using _completions_t = _transform_expr_t<Fn, As...>;
146-
if constexpr (STDEXEC::__well_formed_completions<_completions_t>) {
147-
return detail::_transform_expr<As...>(fn);
148-
} else {
149-
(void) detail::_transform_expr<As...>(fn); // potentially throwing
150-
return invalid_completion_signature<
151-
IN_TRANSFORM_COMPLETION_SIGNATURES,
152-
A_TRANSFORM_FUNCTION_RETURNED_A_TYPE_THAT_IS_NOT_A_COMPLETION_SIGNATURES_SPECIALIZATION,
153-
STDEXEC::_WITH_FUNCTION_<Fn>,
154-
STDEXEC::_WITH_ARGUMENTS_<As...>
155-
>();
156-
}
157-
} else {
158-
return invalid_completion_signature<
159-
IN_TRANSFORM_COMPLETION_SIGNATURES,
160-
COULD_NOT_CALL_THE_TRANSFORM_FUNCTION_WITH_THE_GIVEN_TEMPLATE_ARGUMENTS,
161-
STDEXEC::_WITH_FUNCTION_<Fn>,
162-
STDEXEC::_WITH_ARGUMENTS_<As...>
163-
>();
164-
}
165-
}
166-
167-
template <class ValueFn, class ErrorFn, class StoppedFn>
168-
struct _transform_one {
169-
ValueFn value_fn;
170-
ErrorFn error_fn;
171-
StoppedFn stopped_fn;
172-
173-
template <class Tag, class... Ts>
174-
[[nodiscard]]
175-
consteval auto operator()(Tag (*)(Ts...)) const {
176-
if constexpr (Tag{} == STDEXEC::set_value) {
177-
return detail::_apply_transform<Ts...>(value_fn);
178-
} else if constexpr (Tag{} == STDEXEC::set_error) {
179-
return detail::_apply_transform<Ts...>(error_fn);
180-
} else {
181-
return detail::_apply_transform<Ts...>(stopped_fn);
182-
}
183-
}
184-
};
185-
186-
template <class TransformOne>
187-
struct _transform_all_fn {
188-
TransformOne tfx1;
189-
190-
template <class... Sigs>
191-
[[nodiscard]]
192-
consteval auto operator()(Sigs*... sigs) const {
193-
return concat_completion_signatures(tfx1(sigs)...);
194-
}
195-
};
196-
197-
template <class TransformOne>
198-
_transform_all_fn(TransformOne) -> _transform_all_fn<TransformOne>;
199-
} // namespace detail
200-
201-
template <class Tag>
202-
struct keep_completion {
203-
template <class... Ts>
204-
consteval auto operator()() const noexcept -> STDEXEC::completion_signatures<Tag(Ts...)> {
205-
return {};
206-
}
207-
};
93+
//////////////////////////////////////////////////////////////////////////////////////////////////
94+
// transform_completion_signatures
95+
template <class _SetTag>
96+
using keep_completion = STDEXEC::__keep_completion<_SetTag>;
20897

209-
struct ignore_completion {
210-
template <class... Ts>
211-
consteval auto operator()() const noexcept -> STDEXEC::completion_signatures<> {
212-
return {};
213-
}
214-
};
98+
using ignore_completion = STDEXEC::__ignore_completion;
21599

216-
template <class Tag, class Fn>
217-
struct transform_arguments {
218-
template <class... Ts>
219-
consteval auto operator()() const noexcept
220-
-> STDEXEC::completion_signatures<Tag(STDEXEC::__minvoke<Fn, Ts>...)> {
221-
return {};
222-
}
223-
};
100+
template <class _SetTag, class _Fn, class... _AlgoTag>
101+
using transform_arguments = STDEXEC::__transform_arguments<_SetTag, _Fn, _AlgoTag...>;
224102

225-
template <class Tag>
226-
struct decay_arguments : transform_arguments<Tag, STDEXEC::__q1<STDEXEC::__decay_t>> { };
103+
template <class _SetTag, class... _AlgoTag>
104+
using decay_arguments = STDEXEC::__decay_arguments<_SetTag, _AlgoTag...>;
227105

228106
template <
229-
class Completions,
230-
class ValueFn = keep_completion<STDEXEC::set_value_t>,
231-
class ErrorFn = keep_completion<STDEXEC::set_error_t>,
232-
class StoppedFn = keep_completion<STDEXEC::set_stopped_t>,
233-
class ExtraSigs = STDEXEC::completion_signatures<>
107+
class _Completions,
108+
class _ValueFn = keep_completion<STDEXEC::set_value_t>,
109+
class _ErrorFn = keep_completion<STDEXEC::set_error_t>,
110+
class _StoppedFn = keep_completion<STDEXEC::set_stopped_t>,
111+
class _ExtraSigs = STDEXEC::completion_signatures<>
234112
>
235113
consteval auto transform_completion_signatures(
236-
Completions,
237-
ValueFn value_fn = {},
238-
ErrorFn error_fn = {},
239-
StoppedFn stopped_fn = {},
240-
ExtraSigs = {}) {
241-
STDEXEC_COMPLSIGS_LET(completions, Completions{}) {
242-
STDEXEC_COMPLSIGS_LET(extra_sigs, ExtraSigs{}) {
243-
detail::_transform_one<ValueFn, ErrorFn, StoppedFn> tfx1{value_fn, error_fn, stopped_fn};
244-
return concat_completion_signatures(
245-
completions.__apply(detail::_transform_all_fn{tfx1}), extra_sigs);
246-
}
247-
}
114+
_Completions,
115+
_ValueFn __value_fn = {},
116+
_ErrorFn __error_fn = {},
117+
_StoppedFn __stopped_fn = {},
118+
_ExtraSigs = {}) {
119+
return STDEXEC::__transform_completion_signatures(
120+
_Completions{}, __value_fn, __error_fn, __stopped_fn, _ExtraSigs{});
248121
}
249122
} // namespace exec

‎include/exec/finally.hpp‎

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace exec {
2828
using namespace STDEXEC;
2929

3030
template <class _Sigs>
31-
using __result_variant = __for_each_completion_signature<_Sigs, __decayed_tuple, __variant_for>;
31+
using __result_variant = __for_each_completion_signature_t<_Sigs, __decayed_tuple, __variant_for>;
3232

3333
template <class _ResultType, class _ReceiverId>
3434
struct __final_operation_base {
@@ -112,7 +112,7 @@ namespace exec {
112112
using __final_receiver_t =
113113
STDEXEC::__t<__final_receiver<__result_variant<__signatures>, _ReceiverId>>;
114114
using __final_op_t = connect_result_t<_FinalSender, __final_receiver_t>;
115-
class __t;
115+
struct __t;
116116
};
117117

118118
template <class _InitialSenderId, class _FinalSenderId, class _ReceiverId>
@@ -176,28 +176,7 @@ namespace exec {
176176
};
177177

178178
template <class _InitialSenderId, class _FinalSenderId, class _ReceiverId>
179-
class __operation_state<_InitialSenderId, _FinalSenderId, _ReceiverId>::__t : public __base_t {
180-
using __initial_receiver_t =
181-
STDEXEC::__t<__initial_receiver<_InitialSenderId, _FinalSenderId, _ReceiverId>>;
182-
183-
struct __initial_op_t {
184-
explicit __initial_op_t(
185-
_InitialSender&& __sndr,
186-
_FinalSender&& __final,
187-
__initial_receiver_t __rcvr)
188-
: __sndr_{static_cast<_FinalSender&&>(__final)}
189-
, __initial_operation_{STDEXEC::connect(
190-
static_cast<_InitialSender&&>(__sndr),
191-
static_cast<__initial_receiver_t&&>(__rcvr))} {
192-
}
193-
194-
_FinalSender __sndr_;
195-
connect_result_t<_InitialSender, __initial_receiver_t> __initial_operation_;
196-
};
197-
198-
__variant_for<__initial_op_t, __final_op_t> __op_;
199-
200-
public:
179+
struct __operation_state<_InitialSenderId, _FinalSenderId, _ReceiverId>::__t : __base_t {
201180
using __id = __operation_state;
202181

203182
template <class... _Args>
@@ -224,6 +203,27 @@ namespace exec {
224203
STDEXEC_ASSERT(__op_.index() == 0);
225204
STDEXEC::start(__op_.template get<0>().__initial_operation_);
226205
}
206+
207+
private:
208+
using __initial_receiver_t =
209+
STDEXEC::__t<__initial_receiver<_InitialSenderId, _FinalSenderId, _ReceiverId>>;
210+
211+
struct __initial_op_t {
212+
explicit __initial_op_t(
213+
_InitialSender&& __sndr,
214+
_FinalSender&& __final,
215+
__initial_receiver_t __rcvr)
216+
: __sndr_{static_cast<_FinalSender&&>(__final)}
217+
, __initial_operation_{STDEXEC::connect(
218+
static_cast<_InitialSender&&>(__sndr),
219+
static_cast<__initial_receiver_t&&>(__rcvr))} {
220+
}
221+
222+
_FinalSender __sndr_;
223+
connect_result_t<_InitialSender, __initial_receiver_t> __initial_operation_;
224+
};
225+
226+
__variant_for<__initial_op_t, __final_op_t> __op_;
227227
};
228228

229229
template <class _InitialSenderId, class _FinalSenderId>
@@ -276,9 +276,9 @@ namespace exec {
276276

277277
template <__decays_to<__t> _Self, class... _Env>
278278
static consteval auto get_completion_signatures() {
279-
return exec::invalid_completion_signature<
279+
return exec::throw_compile_time_error<
280280
_SENDER_TYPE_IS_NOT_COPYABLE_,
281-
_WITH_SENDER_<_FinalSender>
281+
_WITH_PRETTY_SENDER_<_FinalSender>
282282
>();
283283
}
284284

‎include/exec/fork_join.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace exec {
6060

6161
template <class Completions>
6262
using _variant_t = STDEXEC::__mset_insert<
63-
STDEXEC::__for_each_completion_signature<
63+
STDEXEC::__for_each_completion_signature_t<
6464
Completions,
6565
STDEXEC::__decayed_tuple,
6666
STDEXEC::__mset

‎include/exec/into_tuple.hpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace exec {
3232
template <class _Sender, class _Env>
3333
using __too_many_completions_error = __mexception<
3434
_INVALID_ARGUMENT_TO_INTO_TUPLE_<>,
35-
_WITH_SENDER_<_Sender>,
36-
_WITH_ENVIRONMENT_<_Env>
35+
_WITH_PRETTY_SENDER_<_Sender>,
36+
_WITH_ENVIRONMENT_(_Env)
3737
>;
3838

3939
template <class _Sender, class... _Env>

‎include/exec/just_from.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace exec {
101101

102102
struct _throw_completions {
103103
template <class Fn>
104-
using __f = STDEXEC::__concat_completion_signatures<
104+
using __f = STDEXEC::__concat_completion_signatures_t<
105105
STDEXEC::__call_result_t<Fn, _probe_fn>,
106106
STDEXEC::__eptr_completion
107107
>;

‎include/exec/libdispatch_queue.hpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ namespace exec {
129129
STDEXEC::_WHERE_(STDEXEC::_IN_ALGORITHM_, STDEXEC::bulk_t),
130130
STDEXEC::_TO_FIX_THIS_ERROR_(
131131
ADD_A_CONTINUES_ON_TRANSITION_TO_THE_LIBDISPATCH_SCHEDULER_BEFORE_THE_BULK_ALGORITHM),
132-
STDEXEC::_WITH_SENDER_<Sender>,
133-
STDEXEC::_WITH_ENVIRONMENT_<Env>
132+
STDEXEC::_WITH_PRETTY_SENDER_<Sender>,
133+
STDEXEC::_WITH_ENVIRONMENT_(Env)
134134
>();
135135
}
136136
}

‎include/exec/materialize.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ namespace exec {
9595
using __materialize_error = completion_signatures<set_value_t(set_error_t, _Err)>;
9696

9797
template <class _Self, class... _Env>
98-
using __completions_t = __transform_completion_signatures<
98+
using __completions_t = __transform_completion_signatures_t<
9999
__completion_signatures_of_t<__copy_cvref_t<_Self, _Sender>, _Env...>,
100100
__materialize_value,
101101
__materialize_error,

‎include/exec/repeat_effect_until.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ namespace exec {
175175
completion_signatures<>,
176176
completion_signatures<set_value_t()>
177177
>,
178-
__mexception<_INVALID_ARGUMENT_TO_REPEAT_EFFECT_UNTIL_<>, _WITH_SENDER_<_Sender>>
178+
__mexception<_INVALID_ARGUMENT_TO_REPEAT_EFFECT_UNTIL_<>, _WITH_PRETTY_SENDER_<_Sender>>
179179
>;
180180

181181
template <class...>

‎include/exec/repeat_n.hpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ namespace exec {
113113
}
114114

115115
template <class _Tag, class... _Args>
116-
void __complete(_Tag, _Args &&...__args) noexcept { // Intentionally by value...
116+
void __complete(_Tag, _Args &&...__args) noexcept {
117117
static_assert(sizeof...(_Args) <= 1);
118118
static_assert(sizeof...(_Args) == 0 || std::is_same_v<_Tag, STDEXEC::set_error_t>);
119119
STDEXEC_ASSERT(__pair_.__count_ > 0);
@@ -157,7 +157,7 @@ namespace exec {
157157
__mexception<
158158
_REPEAT_N_EXPECTS_A_SENDER_OF_VOID_,
159159
_WHERE_(_IN_ALGORITHM_, repeat_n_t),
160-
_WITH_SENDER_<_Sender>
160+
_WITH_PRETTY_SENDER_<_Sender>
161161
>
162162
>;
163163

0 commit comments

Comments
 (0)