Skip to content

Commit 680daad

Browse files
authored
Merge pull request #1611 from ericniebler/rework-coro-continuation-handle
make `__continuation_handle` inherit from `std::coroutine_handle`
2 parents e5dbe49 + 86ddfc5 commit 680daad

4 files changed

Lines changed: 31 additions & 27 deletions

File tree

include/exec/at_coroutine_exit.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ namespace exec {
119119
inline constexpr __die_on_stop_t __die_on_stop;
120120

121121
template <class _Promise>
122-
concept __has_continuation = requires(_Promise& __promise, __continuation_handle<> __c) {
123-
{ __promise.continuation() } -> convertible_to<__continuation_handle<>>;
122+
concept __has_continuation = requires(_Promise& __promise, __coroutine_handle<> __c) {
123+
{ __promise.continuation() } -> convertible_to<__coroutine_handle<>>;
124124
{ __promise.set_continuation(__c) };
125125
};
126126

include/exec/on_coro_disposition.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "../stdexec/execution.hpp"
2222
#include "../stdexec/coroutine.hpp"
2323
#include "task.hpp"
24-
#include "inline_scheduler.hpp"
24+
#include "inline_scheduler.hpp" // IWYU pragma: keep
2525
#include "any_sender_of.hpp"
2626

2727
#include <exception>

include/stdexec/__detail/__with_awaitable_senders.hpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,24 @@
1919

2020
#include "__as_awaitable.hpp"
2121
#include "__concepts.hpp"
22+
#include "../coroutine.hpp" // IWYU pragma: keep for __coro::coroutine_handle
2223

2324
#include <exception>
2425

2526
namespace stdexec {
2627
#if !STDEXEC_STD_NO_COROUTINES()
2728
namespace __was {
2829
template <class _Promise = void>
29-
class __continuation_handle;
30+
class __coroutine_handle;
3031

3132
template <>
32-
class __continuation_handle<void> {
33+
class __coroutine_handle<void> : __coro::coroutine_handle<> {
3334
public:
34-
__continuation_handle() = default;
35+
__coroutine_handle() = default;
3536

3637
template <class _Promise>
37-
__continuation_handle(__coro::coroutine_handle<_Promise> __coro) noexcept
38-
: __coro_(__coro) {
38+
__coroutine_handle(__coro::coroutine_handle<_Promise> __coro) noexcept
39+
: __coro::coroutine_handle<>(__coro) {
3940
if constexpr (requires(_Promise& __promise) { __promise.unhandled_stopped(); }) {
4041
__stopped_callback_ = [](void* __address) noexcept -> __coro::coroutine_handle<> {
4142
// This causes the rest of the coroutine (the part after the co_await
@@ -53,43 +54,46 @@ namespace stdexec {
5354

5455
[[nodiscard]]
5556
auto handle() const noexcept -> __coro::coroutine_handle<> {
56-
return __coro_;
57+
return *this;
5758
}
5859

5960
[[nodiscard]]
6061
auto unhandled_stopped() const noexcept -> __coro::coroutine_handle<> {
61-
return __stopped_callback_(__coro_.address());
62+
return __stopped_callback_(address());
6263
}
6364

6465
private:
6566
using __stopped_callback_t = __coro::coroutine_handle<> (*)(void*) noexcept;
6667

67-
__coro::coroutine_handle<> __coro_{};
6868
__stopped_callback_t __stopped_callback_ = [](void*) noexcept -> __coro::coroutine_handle<> {
6969
std::terminate();
7070
};
7171
};
7272

7373
template <class _Promise>
74-
class __continuation_handle {
74+
class __coroutine_handle : public __coroutine_handle<> {
7575
public:
76-
__continuation_handle() = default;
76+
__coroutine_handle() = default;
7777

78-
__continuation_handle(__coro::coroutine_handle<_Promise> __coro) noexcept
79-
: __continuation_{__coro} {
78+
__coroutine_handle(__coro::coroutine_handle<_Promise> __coro) noexcept
79+
: __coroutine_handle<>{__coro} {
8080
}
8181

82-
auto handle() const noexcept -> __coro::coroutine_handle<_Promise> {
83-
return __coro::coroutine_handle<_Promise>::from_address(__continuation_.handle().address());
82+
static auto from_promise(_Promise& __promise) noexcept -> __coroutine_handle {
83+
return __coroutine_handle(__coro::coroutine_handle<_Promise>::from_promise(__promise));
8484
}
8585

86-
[[nodiscard]]
87-
auto unhandled_stopped() const noexcept -> __coro::coroutine_handle<> {
88-
return __continuation_.unhandled_stopped();
86+
auto promise() const noexcept -> _Promise& {
87+
return __coro::coroutine_handle<_Promise>::from_address(address()).promise();
8988
}
9089

91-
private:
92-
__continuation_handle<> __continuation_{};
90+
auto handle() const noexcept -> __coro::coroutine_handle<_Promise> {
91+
return __coro::coroutine_handle<_Promise>::from_address(address());
92+
}
93+
94+
operator __coro::coroutine_handle<_Promise>() const noexcept {
95+
return handle();
96+
}
9397
};
9498

9599
struct __with_awaitable_senders_base {
@@ -99,12 +103,12 @@ namespace stdexec {
99103
__continuation_ = __hcoro;
100104
}
101105

102-
void set_continuation(__continuation_handle<> __continuation) noexcept {
106+
void set_continuation(__coroutine_handle<> __continuation) noexcept {
103107
__continuation_ = __continuation;
104108
}
105109

106110
[[nodiscard]]
107-
auto continuation() const noexcept -> __continuation_handle<> {
111+
auto continuation() const noexcept -> __coroutine_handle<> {
108112
return __continuation_;
109113
}
110114

@@ -113,7 +117,7 @@ namespace stdexec {
113117
}
114118

115119
private:
116-
__continuation_handle<> __continuation_{};
120+
__coroutine_handle<> __continuation_{};
117121
};
118122

119123
template <class _Promise>
@@ -127,6 +131,6 @@ namespace stdexec {
127131
} // namespace __was
128132

129133
using __was::with_awaitable_senders;
130-
using __was::__continuation_handle;
134+
using __was::__coroutine_handle;
131135
#endif
132136
} // namespace stdexec

test/exec/test_task.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ namespace {
259259

260260
struct test_domain {
261261
template <sender_expr_for<then_t> _Sender>
262-
static constexpr auto transform_sender(_Sender&& __sndr) noexcept {
262+
static constexpr auto transform_sender(_Sender&&) noexcept {
263263
return just("goodbye"s);
264264
}
265265
};

0 commit comments

Comments
 (0)