Do not spill nested coroutine method calls
commit7993679fc5f6c9d4f1e40e7ee47efb9f191f2e75
authorThomas Jiang <thomasjiang@fb.com>
Thu, 1 Mar 2018 05:04:16 +0000 (28 21:04 -0800)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Thu, 1 Mar 2018 05:16:28 +0000 (28 21:16 -0800)
tree341c26d07162d3992b2bea0c99bcb0ab1c31b34a
parentcf3c5eb4aafa02a565d1bf133c5403ceaef9d5a4
Do not spill nested coroutine method calls

Summary:
Nested suspend method calls like

```
coroutine function nested(MyTestClass $class) {
  suspend $class->method(suspend $class->method(0));
}

```

were being incorrectly spilled:

```
function nested(
  \InternalCoroutineContinuation<mixed> $coroutineContinuation_generated,
  int $number,
): \CoroutineResult<mixed> {
...

          state_label_0:
          $__closure->coroutineResultData2 = $class->method;
          $__closure->nextLabel = 1;
          $__coroutineResult = $class->another_method($__closure, 0);
          if ($__coroutineResult->isSuspended()) {
            return \SuspendedCoroutineResult::create();
          }
          $__coroutineData = $__coroutineResult->getResult();
          state_label_1:
          $__closure->coroutineResultData1 = $__coroutineData;
          if ($__exception_generated !== null) {
            throw $__exception_generated;
          }
          $__closure->nextLabel = 2;
          $__coroutineResult = $__closure->coroutineResultData2(
            $__closure,
            $__closure->coroutineResultData1,
          );
...
}
```
in particular, this line failed lowered typechecking
```
$__closure->coroutineResultData2 = $class->method;
```

This diff changes `might_be_spilled` in `coroutine_suspend_rewriter.ml` such that nested calls such as these do not get inappropriately spilled.

Reviewed By: michaeltingley

Differential Revision: D7114276

fbshipit-source-id: 6f96b66520b64895d6cb184e095cbc733277d54b
hphp/hack/src/parser/coroutine/coroutine_suspend_rewriter.ml