Commit a5ef29a1 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Fix tail call optimization

Summary: The is_same check was unnecessary. The type of the future which .then() is called on, doesn't matter because it's core is not participating in the callback stealing.

Reviewed By: yfeldblum

Differential Revision: D12836654

fbshipit-source-id: 8dcf3f0a4e44e01a1efda9534edafce9a591e9cf
parent 3a7f777a
......@@ -423,7 +423,7 @@ FutureBase<T>::thenImplementation(F&& func, R) {
auto statePromise = state.stealPromise();
auto tf3 =
chainExecutor(statePromise.core_->getExecutor(), *std::move(tf2));
if (std::is_same<T, B>::value && statePromise.getCore().hasCallback()) {
if (statePromise.getCore().hasCallback()) {
tf3.core_->setExecutor(statePromise.core_->getExecutor());
auto callbackAndContext = statePromise.getCore().stealCallback();
tf3.setCallback_(
......
......@@ -1603,14 +1603,14 @@ TEST(Future, makePromiseContract) {
EXPECT_EQ(4, std::move(c.second).get());
}
Future<int> call(int depth) {
return makeFuture(depth == 0 ? 42 : 0);
Future<bool> call(int depth, Executor* executor) {
return makeFuture().then(executor, [=] { return depth == 0; });
}
Future<int> recursion(Executor* executor, int depth) {
return call(depth).then(executor, [=](int result) {
return call(depth, executor).thenValue([=](auto result) {
if (result) {
return folly::makeFuture(result);
return folly::makeFuture(42);
}
return recursion(executor, depth - 1);
......
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