Commit 02177495 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook GitHub Bot

Use coro::* instead of std::experimental::*

Summary: Depending on the version of the std library, coro types may be in std or std::experimental namespace. Use coro namespace instead to make switching library implementation easier.

Reviewed By: yfeldblum

Differential Revision: D26744795

fbshipit-source-id: 8856b901d4d757bf378acb56f236135feb0c5488
parent 6aa5e27b
......@@ -1324,7 +1324,7 @@ bool operator>(const Value& other, const Expected<Value, Error>&) = delete;
// Enable the use of folly::Expected with `co_await`
// Inspired by https://github.com/toby-allsopp/coroutine_monad
#if FOLLY_HAS_COROUTINES
#include <experimental/coroutine>
#include <folly/experimental/coro/Coroutine.h>
namespace folly {
namespace expected_detail {
......@@ -1357,10 +1357,8 @@ struct Promise {
// or:
// auto retobj = p.get_return_object(); // clang
PromiseReturn<Value, Error> get_return_object() noexcept { return *this; }
std::experimental::suspend_never initial_suspend() const noexcept {
return {};
}
std::experimental::suspend_never final_suspend() const noexcept { return {}; }
coro::suspend_never initial_suspend() const noexcept { return {}; }
coro::suspend_never final_suspend() const noexcept { return {}; }
template <typename U = Value>
void return_value(U&& u) {
value_->emplace(static_cast<U&&>(u));
......@@ -1383,7 +1381,7 @@ struct Awaitable {
// Explicitly only allow suspension into a Promise
template <typename U>
void await_suspend(std::experimental::coroutine_handle<Promise<U, Error>> h) {
void await_suspend(coro::coroutine_handle<Promise<U, Error>> h) {
*h.promise().value_ = makeUnexpected(std::move(o_.error()));
// Abort the rest of the coroutine. resume() is not going to be called
h.destroy();
......
......@@ -611,7 +611,7 @@ FOLLY_NAMESPACE_STD_END
// Enable the use of folly::Optional with `co_await`
// Inspired by https://github.com/toby-allsopp/coroutine_monad
#if FOLLY_HAS_COROUTINES
#include <experimental/coroutine>
#include <folly/experimental/coro/Coroutine.h>
namespace folly {
namespace detail {
......@@ -642,10 +642,8 @@ struct OptionalPromise {
// or:
// auto retobj = p.get_return_object(); // clang
OptionalPromiseReturn<Value> get_return_object() noexcept { return *this; }
std::experimental::suspend_never initial_suspend() const noexcept {
return {};
}
std::experimental::suspend_never final_suspend() const noexcept { return {}; }
coro::suspend_never initial_suspend() const noexcept { return {}; }
coro::suspend_never final_suspend() const noexcept { return {}; }
template <typename U = Value>
void return_value(U&& u) {
*value_ = static_cast<U&&>(u);
......@@ -665,8 +663,7 @@ struct OptionalAwaitable {
// Explicitly only allow suspension into an OptionalPromise
template <typename U>
void await_suspend(
std::experimental::coroutine_handle<OptionalPromise<U>> h) const {
void await_suspend(coro::coroutine_handle<OptionalPromise<U>> h) const {
// Abort the rest of the coroutine. resume() is not going to be called
h.destroy();
}
......
......@@ -80,7 +80,7 @@ class Barrier {
}
return std::exchange(continuation_, {});
} else {
return noop_coroutine();
return coro::noop_coroutine();
}
}
......@@ -95,12 +95,12 @@ class Barrier {
auto coro = std::exchange(continuation_, {});
if (asyncFrame_ != nullptr) {
folly::resumeCoroutineWithNewAsyncStackRoot(coro, *asyncFrame_);
return noop_coroutine();
return coro::noop_coroutine();
} else {
return coro;
}
} else {
return noop_coroutine();
return coro::noop_coroutine();
}
}
......
......@@ -103,7 +103,7 @@ struct TrickyAwaitable {
bool await_ready() const { return false; }
bool await_suspend(std::experimental::coroutine_handle<>) {
bool await_suspend(folly::coro::coroutine_handle<>) {
value_ = std::make_unique<int>(42);
return false;
}
......@@ -144,7 +144,7 @@ class SimplePromise {
bool await_ready() { return awaiter_.await_ready(); }
template <typename Promise>
auto await_suspend(std::experimental::coroutine_handle<Promise> h) {
auto await_suspend(folly::coro::coroutine_handle<Promise> h) {
return awaiter_.await_suspend(h);
}
......
......@@ -28,9 +28,9 @@ class Wait {
public:
Wait get_return_object() { return Wait(promise_.get_future()); }
std::experimental::suspend_never initial_suspend() noexcept { return {}; }
folly::coro::suspend_never initial_suspend() noexcept { return {}; }
std::experimental::suspend_never final_suspend() noexcept { return {}; }
folly::coro::suspend_never final_suspend() noexcept { return {}; }
void return_void() { promise_.set_value(); }
......@@ -69,16 +69,15 @@ class InlineTask {
bool await_ready() const { return false; }
std::experimental::coroutine_handle<> await_suspend(
std::experimental::coroutine_handle<> awaiter) {
folly::coro::coroutine_handle<> await_suspend(
folly::coro::coroutine_handle<> awaiter) {
promise_->valuePtr_ = &value_;
promise_->awaiter_ = std::move(awaiter);
return std::experimental::coroutine_handle<promise_type>::from_promise(
*promise_);
return folly::coro::coroutine_handle<promise_type>::from_promise(*promise_);
}
T await_resume() {
std::experimental::coroutine_handle<promise_type>::from_promise(
folly::coro::coroutine_handle<promise_type>::from_promise(
*std::exchange(promise_, nullptr))
.destroy();
T value = std::move(value_);
......@@ -96,14 +95,14 @@ class InlineTask {
void unhandled_exception() { std::terminate(); }
std::experimental::suspend_always initial_suspend() { return {}; }
folly::coro::suspend_always initial_suspend() { return {}; }
class FinalSuspender {
public:
bool await_ready() noexcept { return false; }
auto await_suspend(
std::experimental::coroutine_handle<promise_type> h) noexcept {
folly::coro::coroutine_handle<promise_type> h) noexcept {
return h.promise().awaiter_;
}
......@@ -116,7 +115,7 @@ class InlineTask {
friend class InlineTask;
T* valuePtr_;
std::experimental::coroutine_handle<> awaiter_;
folly::coro::coroutine_handle<> awaiter_;
};
private:
......@@ -161,16 +160,15 @@ class InlineTaskAllocator {
bool await_ready() const { return false; }
std::experimental::coroutine_handle<> await_suspend(
std::experimental::coroutine_handle<> awaiter) {
folly::coro::coroutine_handle<> await_suspend(
folly::coro::coroutine_handle<> awaiter) {
promise_->valuePtr_ = &value_;
promise_->awaiter_ = std::move(awaiter);
return std::experimental::coroutine_handle<promise_type>::from_promise(
*promise_);
return folly::coro::coroutine_handle<promise_type>::from_promise(*promise_);
}
T await_resume() {
std::experimental::coroutine_handle<promise_type>::from_promise(
folly::coro::coroutine_handle<promise_type>::from_promise(
*std::exchange(promise_, nullptr))
.destroy();
T value = std::move(value_);
......@@ -205,14 +203,14 @@ class InlineTaskAllocator {
[[noreturn]] void unhandled_exception() noexcept { std::terminate(); }
std::experimental::suspend_always initial_suspend() noexcept { return {}; }
folly::coro::suspend_always initial_suspend() noexcept { return {}; }
class FinalSuspender {
public:
bool await_ready() noexcept { return false; }
auto await_suspend(
std::experimental::coroutine_handle<promise_type> h) noexcept {
folly::coro::coroutine_handle<promise_type> h) noexcept {
return h.promise().awaiter_;
}
......@@ -225,7 +223,7 @@ class InlineTaskAllocator {
friend class InlineTaskAllocator;
T* valuePtr_;
std::experimental::coroutine_handle<> awaiter_;
folly::coro::coroutine_handle<> awaiter_;
};
private:
......
......@@ -37,9 +37,9 @@ class Wait {
public:
Wait get_return_object() { return Wait(promise_.get_future()); }
std::experimental::suspend_never initial_suspend() noexcept { return {}; }
folly::coro::suspend_never initial_suspend() noexcept { return {}; }
std::experimental::suspend_never final_suspend() noexcept { return {}; }
folly::coro::suspend_never final_suspend() noexcept { return {}; }
void return_void() { promise_.set_value(); }
......@@ -78,16 +78,15 @@ class InlineTask {
bool await_ready() const { return false; }
std::experimental::coroutine_handle<> await_suspend(
std::experimental::coroutine_handle<> awaiter) {
folly::coro::coroutine_handle<> await_suspend(
folly::coro::coroutine_handle<> awaiter) {
promise_->valuePtr_ = &value_;
promise_->awaiter_ = std::move(awaiter);
return std::experimental::coroutine_handle<promise_type>::from_promise(
*promise_);
return folly::coro::coroutine_handle<promise_type>::from_promise(*promise_);
}
T await_resume() {
std::experimental::coroutine_handle<promise_type>::from_promise(
folly::coro::coroutine_handle<promise_type>::from_promise(
*std::exchange(promise_, nullptr))
.destroy();
T value = std::move(value_);
......@@ -105,24 +104,23 @@ class InlineTask {
void unhandled_exception() { std::terminate(); }
std::experimental::suspend_always initial_suspend() { return {}; }
folly::coro::suspend_always initial_suspend() { return {}; }
class FinalSuspender {
public:
explicit FinalSuspender(
std::experimental::coroutine_handle<> awaiter) noexcept
explicit FinalSuspender(folly::coro::coroutine_handle<> awaiter) noexcept
: awaiter_(std::move(awaiter)) {}
bool await_ready() noexcept { return false; }
auto await_suspend(std::experimental::coroutine_handle<>) noexcept {
auto await_suspend(folly::coro::coroutine_handle<>) noexcept {
return awaiter_;
}
void await_resume() noexcept {}
private:
std::experimental::coroutine_handle<> awaiter_;
folly::coro::coroutine_handle<> awaiter_;
};
FinalSuspender final_suspend() noexcept {
......@@ -133,7 +131,7 @@ class InlineTask {
friend class InlineTask;
T* valuePtr_;
std::experimental::coroutine_handle<> awaiter_;
folly::coro::coroutine_handle<> awaiter_;
};
private:
......
......@@ -362,7 +362,7 @@ template <int value>
struct AwaitableInt {
bool await_ready() const { return true; }
bool await_suspend(std::experimental::coroutine_handle<>) {
bool await_suspend(coro::coroutine_handle<>) {
LOG(FATAL) << "Should never be called.";
}
......
......@@ -200,7 +200,7 @@ TEST_F(InlineTaskTest, ExceptionsPropagateFromVoidTask) {
struct MyException : std::exception {};
auto f = []() -> InlineTask<void> {
co_await std::experimental::suspend_never{};
co_await folly::coro::suspend_never{};
throw MyException{};
};
EXPECT_THROW(folly::coro::blockingWait(f()), MyException);
......@@ -210,7 +210,7 @@ TEST_F(InlineTaskTest, ExceptionsPropagateFromValueTask) {
struct MyException : std::exception {};
auto f = []() -> InlineTask<int> {
co_await std::experimental::suspend_never{};
co_await folly::coro::suspend_never{};
throw MyException{};
};
EXPECT_THROW(folly::coro::blockingWait(f()), MyException);
......@@ -220,7 +220,7 @@ TEST_F(InlineTaskTest, ExceptionsPropagateFromRefTask) {
struct MyException : std::exception {};
auto f = []() -> InlineTask<int&> {
co_await std::experimental::suspend_never{};
co_await folly::coro::suspend_never{};
throw MyException{};
};
EXPECT_THROW(folly::coro::blockingWait(f()), MyException);
......
......@@ -16,8 +16,8 @@
#include <folly/Portability.h>
#include <folly/experimental/coro/Coroutine.h>
#include <folly/experimental/coro/Traits.h>
#include <experimental/coroutine>
#include <type_traits>
#if FOLLY_HAS_COROUTINES
......@@ -27,39 +27,38 @@ using namespace folly::coro;
template <typename T>
struct SomeAwaiter1 {
bool await_ready();
void await_suspend(std::experimental::coroutine_handle<>);
void await_suspend(coroutine_handle<>);
T await_resume();
};
template <typename T>
struct SomeAwaiter2 {
bool await_ready();
bool await_suspend(std::experimental::coroutine_handle<>);
bool await_suspend(coroutine_handle<>);
T await_resume();
};
template <typename T>
struct SomeAwaiter3 {
bool await_ready();
std::experimental::coroutine_handle<> await_suspend(
std::experimental::coroutine_handle<>);
coroutine_handle<> await_suspend(coroutine_handle<>);
T await_resume();
};
struct MissingAwaitReady {
void await_suspend(std::experimental::coroutine_handle<>);
void await_suspend(coroutine_handle<>);
int await_resume();
};
struct WrongAwaitReadyReturnType {
void* await_ready();
void await_suspend(std::experimental::coroutine_handle<>);
void await_suspend(coroutine_handle<>);
int await_resume();
};
struct MissingAwaitResume {
bool await_ready();
void await_suspend(std::experimental::coroutine_handle<void>);
void await_suspend(coroutine_handle<void>);
};
struct MemberOperatorCoAwait {
......
......@@ -274,14 +274,14 @@ class BatonAwaitableWaiter : public Baton::Waiter {
void await_resume() {}
void await_suspend(std::experimental::coroutine_handle<> h) {
void await_suspend(coro::coroutine_handle<> h) {
assert(!h_);
h_ = std::move(h);
baton_.setWaiter(*this);
}
private:
std::experimental::coroutine_handle<> h_;
coro::coroutine_handle<> h_;
Baton& baton_;
};
} // namespace detail
......
......@@ -2611,7 +2611,7 @@ class FutureAwaiter {
}
FOLLY_CORO_AWAIT_SUSPEND_NONTRIVIAL_ATTRIBUTES void await_suspend(
std::experimental::coroutine_handle<> h) {
coro::coroutine_handle<> h) {
// FutureAwaiter may get destroyed as soon as the callback is executed.
// Make sure the future object doesn't get destroyed until setCallback_
// returns.
......
......@@ -71,7 +71,7 @@ inline void popAsyncStackFrameCallee(
template <typename Promise>
void resumeCoroutineWithNewAsyncStackRoot(
std::experimental::coroutine_handle<Promise> h) noexcept {
coro::coroutine_handle<Promise> h) noexcept {
resumeCoroutineWithNewAsyncStackRoot(h, h.promise().getAsyncFrame());
}
......
......@@ -172,8 +172,7 @@ AsyncStackFrame& getDetachedRootAsyncStackFrame() noexcept {
#if FOLLY_HAS_COROUTINES
FOLLY_NOINLINE void resumeCoroutineWithNewAsyncStackRoot(
std::experimental::coroutine_handle<> h,
folly::AsyncStackFrame& frame) noexcept {
coro::coroutine_handle<> h, folly::AsyncStackFrame& frame) noexcept {
detail::ScopedAsyncStackRoot root;
root.activateFrame(frame);
h.resume();
......
......@@ -257,7 +257,7 @@ AsyncStackFrame& getDetachedRootAsyncStackFrame() noexcept;
// on the current thread and setting the specified AsyncStackFrame as
// the current async frame.
FOLLY_NOINLINE void resumeCoroutineWithNewAsyncStackRoot(
std::experimental::coroutine_handle<> h, AsyncStackFrame& frame) noexcept;
coro::coroutine_handle<> h, AsyncStackFrame& frame) noexcept;
// Resume the specified coroutine after installing a new AsyncStackRoot
// on the current thread and setting the coroutine's associated
......@@ -265,7 +265,7 @@ FOLLY_NOINLINE void resumeCoroutineWithNewAsyncStackRoot(
// current async frame.
template <typename Promise>
void resumeCoroutineWithNewAsyncStackRoot(
std::experimental::coroutine_handle<Promise> h) noexcept;
coro::coroutine_handle<Promise> h) noexcept;
#endif // FOLLY_HAS_COROUTINES
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment