Skip to content
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

try making co_return strict #165

Draft
wants to merge 1 commit into
base: v24.3.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/seastar/core/coroutine.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public:
promise_type(promise_type&&) = delete;
promise_type(const promise_type&) = delete;

template<typename... U>
void return_value(U&&... value) {
_promise.set_value(std::forward<U>(value)...);
template<typename U>
void return_value(U&& value) {
_promise.set_value(internal::implicit_tag{}, std::forward<U>(value));
}

void return_value(coroutine::exception ce) noexcept {
Expand Down
15 changes: 15 additions & 0 deletions include/seastar/core/future.hh
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ struct get0_return_type {
template<typename T>
using maybe_wrap_ref = std::conditional_t<std::is_reference_v<T>, std::reference_wrapper<std::remove_reference_t<T>>, T>;

// indicate that a single parameter is used and only implicit conversions should be considered
struct implicit_tag {};
template <typename T, typename U>
T id(U &&v) {
return std::forward<U>(v);
}

/// \brief Wrapper for keeping uninitialized values of non default constructible types.
///
/// This is similar to a std::optional<T>, but it doesn't know if it is holding a value or not, so the user is
Expand All @@ -304,6 +311,10 @@ struct uninitialized_wrapper_base<T, false> {

public:
uninitialized_wrapper_base() noexcept = default;
template<typename U>
void uninitialized_set(implicit_tag, U&& v) {
new (&_v.value) maybe_wrap_ref<T>(id<T>(std::forward<U>(v)));
}
template<typename... U>
std::enable_if_t<!std::is_same_v<std::tuple<std::remove_cv_t<U>...>, std::tuple<tuple_type>>, void>
uninitialized_set(U&&... vs) {
Expand All @@ -326,6 +337,10 @@ public:
template <typename T> struct uninitialized_wrapper_base<T, true> : private T {
using tuple_type = future_tuple_type_t<T>;
uninitialized_wrapper_base() noexcept = default;
template<typename U>
void uninitialized_set(implicit_tag, U&& v) {
new (this) T(id<T>(std::forward<U>(v)));
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK placement new won't perform an excessive copy or move from an rvalue of the same type returned by id function.
This will need some performance testing.

template<typename... U>
std::enable_if_t<!std::is_same_v<std::tuple<std::remove_cv_t<U>...>, std::tuple<tuple_type>>, void>
uninitialized_set(U&&... vs) {
Expand Down