-
Notifications
You must be signed in to change notification settings - Fork 1.6k
co_return to accept same expressions and types as return #2977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,6 +297,9 @@ struct uninitialized_wrapper { | |
|
||
public: | ||
uninitialized_wrapper() noexcept = default; | ||
void uninitialized_set_strict(T v) { | ||
new (&_v.value) auto(std::forward<T>(v)); | ||
} | ||
template<typename... U> | ||
requires (!std::same_as<std::tuple<std::remove_cv_t<U>...>, std::tuple<tuple_type>>) | ||
void | ||
|
@@ -546,6 +549,7 @@ inline void future_state_base::any::check_failure() noexcept { | |
} | ||
|
||
struct ready_future_marker {}; | ||
struct strict_type_ready_future_marker {}; | ||
struct exception_future_marker {}; | ||
struct future_for_get_promise_marker {}; | ||
|
||
|
@@ -601,6 +605,13 @@ struct future_state : public future_state_base, private internal::uninitialized | |
move_it(std::move(x)); | ||
return *this; | ||
} | ||
future_state(strict_type_ready_future_marker, T v) noexcept : future_state_base(state::result) { | ||
try { | ||
this->uninitialized_set_strict(std::forward<T>(v)); | ||
} catch (...) { | ||
new (this) future_state(current_exception_future_marker()); | ||
} | ||
} | ||
template <typename... A> | ||
future_state(ready_future_marker, A&&... a) noexcept : future_state_base(state::result) { | ||
try { | ||
|
@@ -609,6 +620,10 @@ struct future_state : public future_state_base, private internal::uninitialized | |
new (this) future_state(current_exception_future_marker()); | ||
} | ||
} | ||
void set_strict(T v) { | ||
assert(_u.st == state::future); | ||
new (this) future_state(strict_type_ready_future_marker(), std::forward<T>(v)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't change future.hh as a side effect. This is the main header and changes here have to be deliberate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean specifically this private function, or any changes to the file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not saying to make the changes elsewhere, but to move them to their own commit with clear justification. That holds triple if we rename set_value() to emplace_value() and introduce a new set_value(). |
||
template <typename... A> | ||
void set(A&&... a) noexcept { | ||
assert(_u.st == state::future); | ||
|
@@ -852,7 +867,8 @@ public: | |
template <typename T> | ||
class promise_base_with_type : protected internal::promise_base { | ||
protected: | ||
using future_state = seastar::future_state<future_stored_type_t<T>>; | ||
using value_type = future_stored_type_t<T>; | ||
using future_state = seastar::future_state<value_type>; | ||
future_state* get_state() noexcept { | ||
return static_cast<future_state*>(_state); | ||
} | ||
|
@@ -876,6 +892,13 @@ public: | |
} | ||
} | ||
|
||
void set_value_strict(value_type v) noexcept { | ||
if (auto *s = get_state()) { | ||
s->set_strict(std::forward<value_type>(v)); | ||
make_ready<urgent::no>(); | ||
} | ||
} | ||
|
||
template <typename... A> | ||
void set_value(A&&... a) noexcept { | ||
if (auto *s = get_state()) { | ||
|
@@ -911,6 +934,7 @@ private: | |
SEASTAR_MODULE_EXPORT | ||
template <typename T> | ||
class promise : private internal::promise_base_with_type<T> { | ||
using value_type = typename internal::promise_base_with_type<T>::value_type; | ||
using future_state = typename internal::promise_base_with_type<T>::future_state; | ||
future_state _local_state; | ||
|
||
|
@@ -954,6 +978,16 @@ public: | |
/// was attached to the future, it will run. | ||
future<T> get_future() noexcept; | ||
|
||
/// \brief Sets the promises value using exactly declared type | ||
/// | ||
/// Forwards the argument and makes them available to the associated | ||
/// future. May be called either before or after \c get_future(). | ||
/// | ||
/// pr.set_value_strict(42); | ||
void set_value_strict(value_type v) noexcept { | ||
internal::promise_base_with_type<T>::set_value_strict(std::forward<value_type>(v)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is set_value_strict needed? What's the difference compared to set_value(T(...))? If we want set_value_strict, I think an API change is in order:
Unfortunately this is a breaking change and must be done by introducing a new API_LEVEL. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The difference is the same as with Do we need a new API_LEVEL only for functions like this that user call explicitly, or for co_return semantics change as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think we'll need it for co_return too as people likely rely on it. |
||
|
||
/// \brief Sets the promises value | ||
/// | ||
/// Forwards the arguments and makes them available to the associated | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll need to change this to support reference types