-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Introducing an immovable `NowTask` isn't quite enough, since most `folly::coro` plumbing takes tasks by forwarding reference. This means that dangerous patterns like this would still compile: ``` auto t = someNowTask(); // ... co_await std::move(t); ``` To to go from "immovable task" to "task that can only be awaited in the statement that created it", we need to make sure that `folly::coro` plumbing takes `NowTask` only by value. Unfortunately, there are other awaitables in the ecosystem, like `folly::coro::Baton`, which must be taken by reference. So, we have to accommodate both scenarios: - For awaitables not deriving from `MustAwaitImmediately` -- by reference (classic behavior) - `MustAwaitImmediately` awaitables like `NowTask` -- by value In the absence of something like https://wg21.link/p2785, C++ does not support perfect forwarding for prvalues. As far as I can tell, this forces me to branch most of the relevant functions on `is_must_await_immediately_t`, as you see above. While this is ugly, I don't currently see a better way to get a safer task. --- **NOTE:** I didn't fix up `co_withAsyncStack` because as far as I can tell, this is an implementation detail only called from `folly::coro` internals, where none of the callsites have potential for user-facing lifetime issues. I did audit them. The most annoying use-case was `*BarrierTask::await_transform`, but it seems OK too, since every callsite does `co_await co_viaIfAsync()`. Comparatively `await_transform` for `BlockingWaitTask` and `InlineTask*` are barely used. Reviewed By: yfeldblum, ispeters Differential Revision: D67883335 fbshipit-source-id: d1c61a484f58e9ba10ab29ee3eaa2c1ed6ced9fd
- Loading branch information
1 parent
1c55773
commit 9252c06
Showing
8 changed files
with
386 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.