Skip to content

Commit 9ed53cc

Browse files
authored
migrate get_completion_signatures customizations to member function (NVIDIA#1330)
* migrate `get_completion_signatures` customizations to member function * fix the system scheduler
1 parent c2e37c4 commit 9ed53cc

Some content is hidden

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

49 files changed

+367
-371
lines changed

.clang-format

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ AlwaysBreakAfterReturnType: None
2727
AlwaysBreakBeforeMultilineStrings: true
2828
AlwaysBreakTemplateDeclarations: Yes
2929
AttributeMacros: [
30-
'__EXEC__SYSTEM_CONTEXT__INLINE',
31-
'__EXEC_WEAK_ATTRIBUTE'
30+
'STDEXEC_SYSTEM_CONTEXT_INLINE'
3231
]
3332
BinPackArguments: false
3433
BinPackParameters: false

examples/algorithms/retry.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct _retry_sender {
121121
using _value = stdexec::completion_signatures<stdexec::set_value_t(Ts...)>;
122122

123123
template <class Env>
124-
friend auto tag_invoke(stdexec::get_completion_signatures_t, const _retry_sender&, Env)
124+
auto get_completion_signatures(Env&&) const
125125
-> stdexec::make_completion_signatures<
126126
S&,
127127
Env,

examples/algorithms/then.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ struct _then_sender {
7474
_set_value_t>;
7575

7676
template <class Env>
77-
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this _then_sender&&, Env&&) {
78-
return _completions_t<Env>();
77+
auto get_completion_signatures(Env&&) && -> _completions_t<Env> {
78+
return {};
7979
}
8080

8181
// Connect:

examples/benchmark/static_thread_pool_old.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ namespace exec_old {
489489
}
490490

491491
template <stdexec::__decays_to<bulk_sender> Self, class Env>
492-
friend auto tag_invoke(stdexec::get_completion_signatures_t, Self&&, Env&&)
492+
static auto get_completion_signatures(Self&&, Env&&)
493493
-> completion_signatures<Self, Env> {
494494
return {};
495495
}

include/exec/__detail/__basic_sequence.hpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,11 @@ namespace exec {
6262
return _Self::__tag().get_env(*this);
6363
}
6464

65-
template <
66-
stdexec::same_as<stdexec::get_completion_signatures_t> _Tag,
67-
stdexec::__decays_to<__seqexpr> _Self,
68-
class _Env>
69-
friend auto tag_invoke(_Tag, _Self&& __self, _Env&& __env) //
70-
-> stdexec::__msecond<
71-
stdexec::__if_c<stdexec::same_as<_Tag, stdexec::get_completion_signatures_t>>,
72-
decltype(__self.__tag().get_completion_signatures(
73-
static_cast<_Self&&>(__self),
74-
static_cast<_Env&&>(__env)))> {
65+
template <stdexec::__decays_to<__seqexpr> _Self, class _Env>
66+
static auto get_completion_signatures(_Self&& __self, _Env&& __env) //
67+
-> decltype(__self.__tag().get_completion_signatures(
68+
static_cast<_Self&&>(__self),
69+
static_cast<_Env&&>(__env))) {
7570
return {};
7671
}
7772

include/exec/__detail/__system_context_default_impl.hpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@
1818
#include "__system_context_if.h"
1919
#include "stdexec/execution.hpp"
2020
#include "exec/static_thread_pool.hpp"
21-
#include "__weak_attribute.hpp"
2221

2322
namespace exec::__system_context_default_impl {
2423
using namespace stdexec::tags;
2524

2625
using __pool_scheduler_t = decltype(std::declval<exec::static_thread_pool>().get_scheduler());
2726

2827
/// Receiver that calls the callback when the operation completes.
29-
template <class __Sender>
28+
template <class _Sender>
3029
struct __operation;
3130

32-
template <class __Sender>
31+
template <class _Sender>
3332
struct __recv {
3433
using receiver_concept = stdexec::receiver_t;
3534

@@ -40,7 +39,7 @@ namespace exec::__system_context_default_impl {
4039
void* __data_;
4140

4241
/// The owning operation state, to be destructed when the operation completes.
43-
__operation<__Sender>* __op_;
42+
__operation<_Sender>* __op_;
4443

4544
void set_value() noexcept {
4645
__cb_(__data_, 0, nullptr);
@@ -55,18 +54,18 @@ namespace exec::__system_context_default_impl {
5554
}
5655
};
5756

58-
template <typename __Sender>
57+
template <typename _Sender>
5958
struct __operation {
6059
/// The inner operation state, that results out of connecting the underlying sender with the receiver.
61-
stdexec::connect_result_t<__Sender, __recv<__Sender>> __inner_op_;
60+
stdexec::connect_result_t<_Sender, __recv<_Sender>> __inner_op_;
6261
/// True if the operation is on the heap, false if it is in the preallocated space.
6362
bool __on_heap_;
6463

6564
/// Try to construct the operation in the preallocated memory if it fits, otherwise allocate a new operation.
6665
static __operation* __construct_maybe_alloc(
6766
void* __preallocated,
6867
size_t __psize,
69-
__Sender __sndr,
68+
_Sender __sndr,
7069
__exec_system_context_completion_callback_t __cb,
7170
void* __data) {
7271
if (__preallocated == nullptr || __psize < sizeof(__operation)) {
@@ -87,11 +86,11 @@ namespace exec::__system_context_default_impl {
8786

8887
private:
8988
__operation(
90-
__Sender __sndr,
89+
_Sender __sndr,
9190
__exec_system_context_completion_callback_t __cb,
9291
void* __data,
9392
bool __on_heap)
94-
: __inner_op_(stdexec::connect(std::move(__sndr), __recv<__Sender>{__cb, __data, this}))
93+
: __inner_op_(stdexec::connect(std::move(__sndr), __recv<_Sender>{__cb, __data, this}))
9594
, __on_heap_(__on_heap) {
9695
}
9796
};

include/exec/__detail/__system_context_default_impl_entry.hpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,28 @@
1515
*/
1616
#pragma once
1717

18-
// Assumes __EXEC__SYSTEM_CONTEXT__INLINE is defined
18+
// Assumes STDEXEC_SYSTEM_CONTEXT_INLINE is defined
19+
20+
#if !defined(STDEXEC_SYSTEM_CONTEXT_INLINE)
21+
# error "STDEXEC_SYSTEM_CONTEXT_INLINE must be defined before including this header"
22+
#endif
1923

2024
#include "__system_context_default_impl.hpp"
21-
#include "__weak_attribute.hpp"
2225

2326
STDEXEC_PRAGMA_PUSH()
2427
STDEXEC_PRAGMA_IGNORE_GNU("-Wattributes") // warning: inline function '[...]' declared weak
2528

2629
/// Gets the default system context implementation.
27-
extern "C" __EXEC__SYSTEM_CONTEXT__INLINE __EXEC_WEAK_ATTRIBUTE __exec_system_context_interface*
30+
extern "C" STDEXEC_SYSTEM_CONTEXT_INLINE STDEXEC_ATTRIBUTE((weak))
31+
__exec_system_context_interface*
2832
__get_exec_system_context_impl() {
2933
return exec::__system_context_default_impl::__instance_holder::__singleton()
3034
.__get_current_instance();
3135
}
3236

3337
/// Sets the default system context implementation.
34-
extern "C" __EXEC__SYSTEM_CONTEXT__INLINE __EXEC_WEAK_ATTRIBUTE void
38+
extern "C" STDEXEC_SYSTEM_CONTEXT_INLINE STDEXEC_ATTRIBUTE((weak))
39+
void
3540
__set_exec_system_context_impl(__exec_system_context_interface* __instance) {
3641
return exec::__system_context_default_impl::__instance_holder::__singleton()
3742
.__set_current_instance(__instance);

include/exec/__detail/__system_context_if.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifndef __EXEC__SYSTEM_CONTEXT_IF_H__
18-
#define __EXEC__SYSTEM_CONTEXT_IF_H__
17+
#ifndef STDEXEC_SYSTEM_CONTEXT_IF_H
18+
#define STDEXEC_SYSTEM_CONTEXT_IF_H
1919

2020
#include <stddef.h>
2121
#include <stdint.h>

include/exec/__detail/__weak_attribute.hpp

-24
This file was deleted.

include/exec/async_scope.hpp

+21-18
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ namespace exec {
111111
}
112112

113113
template <__decays_to<__t> _Self, class _Env>
114-
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this _Self&&, _Env&&)
114+
static auto get_completion_signatures(_Self&&, _Env&&)
115115
-> completion_signatures_of_t<__copy_cvref_t<_Self, _Constrained>, __env_t<_Env>> {
116116
return {};
117117
}
@@ -252,7 +252,7 @@ namespace exec {
252252
}
253253

254254
template <__decays_to<__t> _Self, class _Env>
255-
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this _Self&&, _Env&&)
255+
static auto get_completion_signatures(_Self&&, _Env&&)
256256
-> completion_signatures_of_t<__copy_cvref_t<_Self, _Constrained>, __env_t<_Env>> {
257257
return {};
258258
}
@@ -598,7 +598,15 @@ namespace exec {
598598
using _Sender = stdexec::__t<_SenderId>;
599599
using _Env = stdexec::__t<_EnvId>;
600600

601-
struct __t {
601+
class __t {
602+
template <class _Self>
603+
using __completions_t = __future_completions_t<__mfront<_Sender, _Self>, _Env>;
604+
605+
template <class _Receiver>
606+
using __future_op_t =
607+
stdexec::__t<__future_op<_SenderId, _EnvId, stdexec::__id<_Receiver>>>;
608+
609+
public:
602610
using __id = __future;
603611
using sender_concept = stdexec::sender_t;
604612

@@ -619,20 +627,6 @@ namespace exec {
619627
__guard, __future_step::__future, __future_step::__no_future);
620628
}
621629
}
622-
private:
623-
friend struct async_scope;
624-
template <class _Self>
625-
using __completions_t = __future_completions_t<__mfront<_Sender, _Self>, _Env>;
626-
627-
template <class _Receiver>
628-
using __future_op_t =
629-
stdexec::__t<__future_op<_SenderId, _EnvId, stdexec::__id<_Receiver>>>;
630-
631-
explicit __t(std::unique_ptr<__future_state<_Sender, _Env>> __state) noexcept
632-
: __state_(std::move(__state)) {
633-
std::unique_lock __guard{__state_->__mutex_};
634-
__state_->__step_from_to_(__guard, __future_step::__created, __future_step::__future);
635-
}
636630

637631
template <__decays_to<__t> _Self, receiver _Receiver>
638632
requires receiver_of<_Receiver, __completions_t<_Self>>
@@ -642,10 +636,19 @@ namespace exec {
642636
}
643637

644638
template <__decays_to<__t> _Self, class _OtherEnv>
645-
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this _Self&&, _OtherEnv&&) -> __completions_t<_Self> {
639+
static auto get_completion_signatures(_Self&&, _OtherEnv&&) -> __completions_t<_Self> {
646640
return {};
647641
}
648642

643+
private:
644+
friend struct async_scope;
645+
646+
explicit __t(std::unique_ptr<__future_state<_Sender, _Env>> __state) noexcept
647+
: __state_(std::move(__state)) {
648+
std::unique_lock __guard{__state_->__mutex_};
649+
__state_->__step_from_to_(__guard, __future_step::__created, __future_step::__future);
650+
}
651+
649652
std::unique_ptr<__future_state<_Sender, _Env>> __state_;
650653
};
651654
};

include/exec/at_coroutine_exit.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace exec {
9494
}
9595

9696
template <__decays_to<__t> _Self, class _Env>
97-
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this _Self&&, _Env&&) -> __completion_signatures<_Env> {
97+
static auto get_completion_signatures(_Self&&, _Env&&) -> __completion_signatures<_Env> {
9898
return {};
9999
}
100100

include/exec/env.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ namespace exec {
128128
}
129129

130130
template <class _Env>
131-
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this __sender, _Env&&) -> __completions_t<_Env> {
131+
auto get_completion_signatures(_Env&&) -> __completions_t<_Env> {
132132
return {};
133133
}
134134
};

include/exec/finally.hpp

+16-15
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,17 @@ namespace exec {
273273
_InitialSender __initial_sndr_;
274274
_FinalSender __final_sndr_;
275275

276+
public:
277+
using __id = __sender;
278+
using sender_concept = stdexec::sender_t;
279+
280+
template <__decays_to<_InitialSender> _Initial, __decays_to<_FinalSender> _Final>
281+
__t(_Initial&& __initial, _Final&& __final) //
282+
noexcept(__nothrow_decay_copyable<_Initial> && __nothrow_decay_copyable<_Final>)
283+
: __initial_sndr_{static_cast<_Initial&&>(__initial)}
284+
, __final_sndr_{static_cast<_Final&&>(__final)} {
285+
}
286+
276287
template <__decays_to<__t> _Self, class _Rec>
277288
STDEXEC_MEMFN_DECL(auto connect)(this _Self&& __self, _Rec&& __receiver) noexcept -> __op_t<_Self, _Rec> {
278289
return {
@@ -282,23 +293,13 @@ namespace exec {
282293
}
283294

284295
template <__decays_to<__t> _Self, class _Env>
285-
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this _Self&&, _Env&&) noexcept -> __completion_signatures_t<
286-
__copy_cvref_t<_Self, _InitialSender>,
287-
__copy_cvref_t<_Self, _FinalSender>,
288-
_Env> {
296+
static auto
297+
get_completion_signatures(_Self&&, _Env&&) noexcept -> __completion_signatures_t<
298+
__copy_cvref_t<_Self, _InitialSender>,
299+
__copy_cvref_t<_Self, _FinalSender>,
300+
_Env> {
289301
return {};
290302
}
291-
292-
public:
293-
using __id = __sender;
294-
using sender_concept = stdexec::sender_t;
295-
296-
template <__decays_to<_InitialSender> _Initial, __decays_to<_FinalSender> _Final>
297-
__t(_Initial&& __initial, _Final&& __final) //
298-
noexcept(__nothrow_decay_copyable<_Initial> && __nothrow_decay_copyable<_Final>)
299-
: __initial_sndr_{static_cast<_Initial&&>(__initial)}
300-
, __final_sndr_{static_cast<_Final&&>(__final)} {
301-
}
302303
};
303304
};
304305

include/exec/libdispatch_queue.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ namespace exec {
317317
}
318318

319319
template <stdexec::__decays_to<__t> Self, class Env>
320-
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this Self &&, Env &&) -> __completions_t<Self, Env> {
320+
static auto get_completion_signatures(Self &&, Env &&) -> __completions_t<Self, Env> {
321321
return {};
322322
}
323323

0 commit comments

Comments
 (0)