Skip to content

Commit

Permalink
migrate get_completion_signatures customizations to member function
Browse files Browse the repository at this point in the history
  • Loading branch information
ericniebler committed May 16, 2024
1 parent c2e37c4 commit cba5008
Show file tree
Hide file tree
Showing 49 changed files with 361 additions and 360 deletions.
3 changes: 1 addition & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros: [
'__EXEC__SYSTEM_CONTEXT__INLINE',
'__EXEC_WEAK_ATTRIBUTE'
'STDEXEC_SYSTEM_CONTEXT_INLINE'
]
BinPackArguments: false
BinPackParameters: false
Expand Down
2 changes: 1 addition & 1 deletion examples/algorithms/retry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct _retry_sender {
using _value = stdexec::completion_signatures<stdexec::set_value_t(Ts...)>;

template <class Env>
friend auto tag_invoke(stdexec::get_completion_signatures_t, const _retry_sender&, Env)
auto get_completion_signatures(Env&&) const
-> stdexec::make_completion_signatures<
S&,
Env,
Expand Down
4 changes: 2 additions & 2 deletions examples/algorithms/then.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ struct _then_sender {
_set_value_t>;

template <class Env>
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this _then_sender&&, Env&&) {
return _completions_t<Env>();
auto get_completion_signatures(Env&&) && -> _completions_t<Env> {
return {};
}

// Connect:
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark/static_thread_pool_old.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ namespace exec_old {
}

template <stdexec::__decays_to<bulk_sender> Self, class Env>
friend auto tag_invoke(stdexec::get_completion_signatures_t, Self&&, Env&&)
static auto get_completion_signatures(Self&&, Env&&)
-> completion_signatures<Self, Env> {
return {};
}
Expand Down
15 changes: 5 additions & 10 deletions include/exec/__detail/__basic_sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,11 @@ namespace exec {
return _Self::__tag().get_env(*this);
}

template <
stdexec::same_as<stdexec::get_completion_signatures_t> _Tag,
stdexec::__decays_to<__seqexpr> _Self,
class _Env>
friend auto tag_invoke(_Tag, _Self&& __self, _Env&& __env) //
-> stdexec::__msecond<
stdexec::__if_c<stdexec::same_as<_Tag, stdexec::get_completion_signatures_t>>,
decltype(__self.__tag().get_completion_signatures(
static_cast<_Self&&>(__self),
static_cast<_Env&&>(__env)))> {
template <stdexec::__decays_to<__seqexpr> _Self, class _Env>
static auto get_completion_signatures(_Self&& __self, _Env&& __env) //
-> decltype(__self.__tag().get_completion_signatures(
static_cast<_Self&&>(__self),
static_cast<_Env&&>(__env))) {
return {};
}

Expand Down
17 changes: 8 additions & 9 deletions include/exec/__detail/__system_context_default_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@
#include "__system_context_if.h"
#include "stdexec/execution.hpp"
#include "exec/static_thread_pool.hpp"
#include "__weak_attribute.hpp"

namespace exec::__system_context_default_impl {
using namespace stdexec::tags;

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

/// Receiver that calls the callback when the operation completes.
template <class __Sender>
template <class _Sender>
struct __operation;

template <class __Sender>
template <class _Sender>
struct __recv {
using receiver_concept = stdexec::receiver_t;

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

/// The owning operation state, to be destructed when the operation completes.
__operation<__Sender>* __op_;
__operation<_Sender>* __op_;

void set_value() noexcept {
__cb_(__data_, 0, nullptr);
Expand All @@ -55,18 +54,18 @@ namespace exec::__system_context_default_impl {
}
};

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

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

private:
__operation(
__Sender __sndr,
_Sender __sndr,
__exec_system_context_completion_callback_t __cb,
void* __data,
bool __on_heap)
: __inner_op_(stdexec::connect(std::move(__sndr), __recv<__Sender>{__cb, __data, this}))
: __inner_op_(stdexec::connect(std::move(__sndr), __recv<_Sender>{__cb, __data, this}))
, __on_heap_(__on_heap) {
}
};
Expand Down
13 changes: 9 additions & 4 deletions include/exec/__detail/__system_context_default_impl_entry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,28 @@
*/
#pragma once

// Assumes __EXEC__SYSTEM_CONTEXT__INLINE is defined
// Assumes STDEXEC_SYSTEM_CONTEXT_INLINE is defined

#if !defined(STDEXEC_SYSTEM_CONTEXT_INLINE)
# error "STDEXEC_SYSTEM_CONTEXT_INLINE must be defined before including this header"
#endif

#include "__system_context_default_impl.hpp"
#include "__weak_attribute.hpp"

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

/// Gets the default system context implementation.
extern "C" __EXEC__SYSTEM_CONTEXT__INLINE __EXEC_WEAK_ATTRIBUTE __exec_system_context_interface*
extern "C" STDEXEC_SYSTEM_CONTEXT_INLINE STDEXEC_ATTRIBUTE((weak))
__exec_system_context_interface*
__get_exec_system_context_impl() {
return exec::__system_context_default_impl::__instance_holder::__singleton()
.__get_current_instance();
}

/// Sets the default system context implementation.
extern "C" __EXEC__SYSTEM_CONTEXT__INLINE __EXEC_WEAK_ATTRIBUTE void
extern "C" STDEXEC_SYSTEM_CONTEXT_INLINE STDEXEC_ATTRIBUTE((weak))
void
__set_exec_system_context_impl(__exec_system_context_interface* __instance) {
return exec::__system_context_default_impl::__instance_holder::__singleton()
.__set_current_instance(__instance);
Expand Down
4 changes: 2 additions & 2 deletions include/exec/__detail/__system_context_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

#ifndef __EXEC__SYSTEM_CONTEXT_IF_H__
#define __EXEC__SYSTEM_CONTEXT_IF_H__
#ifndef STDEXEC_SYSTEM_CONTEXT_IF_H
#define STDEXEC_SYSTEM_CONTEXT_IF_H

#include <stddef.h>
#include <stdint.h>
Expand Down
24 changes: 0 additions & 24 deletions include/exec/__detail/__weak_attribute.hpp

This file was deleted.

39 changes: 21 additions & 18 deletions include/exec/async_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace exec {
}

template <__decays_to<__t> _Self, class _Env>
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this _Self&&, _Env&&)
static auto get_completion_signatures(_Self&&, _Env&&)
-> completion_signatures_of_t<__copy_cvref_t<_Self, _Constrained>, __env_t<_Env>> {
return {};
}
Expand Down Expand Up @@ -252,7 +252,7 @@ namespace exec {
}

template <__decays_to<__t> _Self, class _Env>
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this _Self&&, _Env&&)
static auto get_completion_signatures(_Self&&, _Env&&)
-> completion_signatures_of_t<__copy_cvref_t<_Self, _Constrained>, __env_t<_Env>> {
return {};
}
Expand Down Expand Up @@ -598,7 +598,15 @@ namespace exec {
using _Sender = stdexec::__t<_SenderId>;
using _Env = stdexec::__t<_EnvId>;

struct __t {
class __t {
template <class _Self>
using __completions_t = __future_completions_t<__mfront<_Sender, _Self>, _Env>;

template <class _Receiver>
using __future_op_t =
stdexec::__t<__future_op<_SenderId, _EnvId, stdexec::__id<_Receiver>>>;

public:
using __id = __future;
using sender_concept = stdexec::sender_t;

Expand All @@ -619,20 +627,6 @@ namespace exec {
__guard, __future_step::__future, __future_step::__no_future);
}
}
private:
friend struct async_scope;
template <class _Self>
using __completions_t = __future_completions_t<__mfront<_Sender, _Self>, _Env>;

template <class _Receiver>
using __future_op_t =
stdexec::__t<__future_op<_SenderId, _EnvId, stdexec::__id<_Receiver>>>;

explicit __t(std::unique_ptr<__future_state<_Sender, _Env>> __state) noexcept
: __state_(std::move(__state)) {
std::unique_lock __guard{__state_->__mutex_};
__state_->__step_from_to_(__guard, __future_step::__created, __future_step::__future);
}

template <__decays_to<__t> _Self, receiver _Receiver>
requires receiver_of<_Receiver, __completions_t<_Self>>
Expand All @@ -642,10 +636,19 @@ namespace exec {
}

template <__decays_to<__t> _Self, class _OtherEnv>
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this _Self&&, _OtherEnv&&) -> __completions_t<_Self> {
static auto get_completion_signatures(_Self&&, _OtherEnv&&) -> __completions_t<_Self> {
return {};
}

private:
friend struct async_scope;

explicit __t(std::unique_ptr<__future_state<_Sender, _Env>> __state) noexcept
: __state_(std::move(__state)) {
std::unique_lock __guard{__state_->__mutex_};
__state_->__step_from_to_(__guard, __future_step::__created, __future_step::__future);
}

std::unique_ptr<__future_state<_Sender, _Env>> __state_;
};
};
Expand Down
2 changes: 1 addition & 1 deletion include/exec/at_coroutine_exit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace exec {
}

template <__decays_to<__t> _Self, class _Env>
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this _Self&&, _Env&&) -> __completion_signatures<_Env> {
static auto get_completion_signatures(_Self&&, _Env&&) -> __completion_signatures<_Env> {
return {};
}

Expand Down
2 changes: 1 addition & 1 deletion include/exec/env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ namespace exec {
}

template <class _Env>
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this __sender, _Env&&) -> __completions_t<_Env> {
auto get_completion_signatures(_Env&&) -> __completions_t<_Env> {
return {};
}
};
Expand Down
31 changes: 16 additions & 15 deletions include/exec/finally.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,17 @@ namespace exec {
_InitialSender __initial_sndr_;
_FinalSender __final_sndr_;

public:
using __id = __sender;
using sender_concept = stdexec::sender_t;

template <__decays_to<_InitialSender> _Initial, __decays_to<_FinalSender> _Final>
__t(_Initial&& __initial, _Final&& __final) //
noexcept(__nothrow_decay_copyable<_Initial> && __nothrow_decay_copyable<_Final>)
: __initial_sndr_{static_cast<_Initial&&>(__initial)}
, __final_sndr_{static_cast<_Final&&>(__final)} {
}

template <__decays_to<__t> _Self, class _Rec>
STDEXEC_MEMFN_DECL(auto connect)(this _Self&& __self, _Rec&& __receiver) noexcept -> __op_t<_Self, _Rec> {
return {
Expand All @@ -282,23 +293,13 @@ namespace exec {
}

template <__decays_to<__t> _Self, class _Env>
STDEXEC_MEMFN_DECL(auto get_completion_signatures)(this _Self&&, _Env&&) noexcept -> __completion_signatures_t<
__copy_cvref_t<_Self, _InitialSender>,
__copy_cvref_t<_Self, _FinalSender>,
_Env> {
static auto
get_completion_signatures(_Self&&, _Env&&) noexcept -> __completion_signatures_t<
__copy_cvref_t<_Self, _InitialSender>,
__copy_cvref_t<_Self, _FinalSender>,
_Env> {
return {};
}

public:
using __id = __sender;
using sender_concept = stdexec::sender_t;

template <__decays_to<_InitialSender> _Initial, __decays_to<_FinalSender> _Final>
__t(_Initial&& __initial, _Final&& __final) //
noexcept(__nothrow_decay_copyable<_Initial> && __nothrow_decay_copyable<_Final>)
: __initial_sndr_{static_cast<_Initial&&>(__initial)}
, __final_sndr_{static_cast<_Final&&>(__final)} {
}
};
};

Expand Down
2 changes: 1 addition & 1 deletion include/exec/libdispatch_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ namespace exec {
}

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

Expand Down

0 comments on commit cba5008

Please sign in to comment.