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

use rvalue-qual Future::onError(); pass 2

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).onError(...)` instead of `f.onError(...)`. This syntactic change in the callsites forces callers to acknowledge the method's rvalue semantics.

Codemod changes:

* expr.MMM(...) ==> std::move(expr).MMM(...)  // if expr is not already an xvalue
* expr->MMM(...) ==> std::move(*expr).MMM(...)

Note: operator precedence of that last step is safe - no need to parenthesize `expr`. Reason: `->` binds more tightly than unary `*`.

Reviewed By: LeeHowes

Differential Revision: D9445122

fbshipit-source-id: 1202bc2dd2e054b541458aa20829abe4c7f52b33
parent dde15a90
......@@ -1106,9 +1106,10 @@ Future<T> Future<T>::thenError(F&& func) && {
// Allow for applying to future with null executor while this is still
// possible.
auto* e = this->getExecutor();
return onError([func = std::forward<F>(func)](ExceptionType& ex) mutable {
return std::forward<F>(func)(ex);
})
return std::move(*this)
.onError([func = std::forward<F>(func)](ExceptionType& ex) mutable {
return std::forward<F>(func)(ex);
})
.via(e ? e : &InlineExecutor::instance());
}
......@@ -1119,10 +1120,11 @@ Future<T> Future<T>::thenError(F&& func) && {
// Allow for applying to future with null executor while this is still
// possible.
auto* e = this->getExecutor();
return onError([func = std::forward<F>(func)](
folly::exception_wrapper&& ex) mutable {
return std::forward<F>(func)(std::move(ex));
})
return std::move(*this)
.onError([func = std::forward<F>(func)](
folly::exception_wrapper&& ex) mutable {
return std::forward<F>(func)(std::move(ex));
})
.via(e ? e : &InlineExecutor::instance());
}
......
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