Commit e4430ff2 authored by Marshall Cline's avatar Marshall Cline Committed by Facebook Github Bot

rvalueification of Future::reduce(...): 1/n

Summary:
This is part of "the great r-valuification of folly::Future":
* This is something we should do for safety in general.
* Several of folly::Future's methods are lvalue-qualified even though they act as though they are rvalue-qualified, that is, they provide a postcondition that says, in effect, callers should act as though the method invalidated its `this` object (regardless of whether that invalidation was actual or logical).
* This violates the C++ principle to "Express ideas directly in code" (see Core Guidelines), and generally makes it more confusing for callers as well as hiding the actual semantics from tools (linters, compilers, etc.).
* This dichotomy and confusion has manifested itself by some failures around D7840699 since lvalue-qualification hides that operation's move-out semantics - leads to some use of future operations that are really not correct, but are not obviously incorrect.
* The goal of rvalueification is to make sure methods that are logically rvalue-qualified are actually rvalue-qualified, which forces callsites to acknowledge that rvalueification, e.g., `std::move(f).reduce(...)` instead of `f.reduce(...)`. This syntactic change in the callsites forces callers to acknowledge the method's rvalue semantics.

Reviewed By: yfeldblum

Differential Revision: D9309840

fbshipit-source-id: 7dbb26dc5e5c7a04720c1fb903e33dfa799e8713
parent 587379a1
......@@ -1835,7 +1835,7 @@ window(Executor* executor, Collection input, F func, size_t n) {
template <class T>
template <class I, class F>
Future<I> Future<T>::reduce(I&& initial, F&& func) {
Future<I> Future<T>::reduce(I&& initial, F&& func) && {
return std::move(*this).then(
[minitial = std::forward<I>(initial),
mfunc = std::forward<F>(func)](T&& vals) mutable {
......
......@@ -1775,7 +1775,13 @@ class Future : private futures::detail::FutureBase<T> {
/// i.e., as if `*this` was moved into RESULT.
/// - `RESULT.valid() == true`
template <class I, class F>
Future<I> reduce(I&& initial, F&& func);
Future<I> reduce(I&& initial, F&& func) &&;
template <class I, class F>
Future<I> reduce(I&& initial, F&& func) & {
return std::move(*this).reduce(
std::forward<I>(initial), std::forward<F>(func));
}
/// Create a Future chain from a sequence of continuations. i.e.
///
......
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