Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repro of non-termination bug #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jordwalke
Copy link
Owner

Summary:
This bug came up because of an old change that we made in generate.ml
It removed the return statement from the footer of the main body, however there are some cases where it is needed.
Specifically when the last line of a module is some kind of loop.

Here's what we would need to do to add it back.

  • | Stop -> flush_all queue []
  • | Stop -> flush_all queue [J.Return_statement None, loc]

However, we can't just add it back right now, because our JS modules and Hack modules are structured differently in separate compilation mode.
In Hack, that would result in two return statements.
In JS, that would result in a return statement outside of a function body.
That return statement could end up being in a loop, or floating in the outermost part of the module.

We should probably create a new Rehp node called "ExitModule".
However, it's not clear when to turn that into a return vs. something else (and
what would we even use for JS module bodies)?

One possibility for module bodies in JS:

module: {

var myFunction = ...;
var myOtherFunction = ...;
break module;  // Convert the final Return_statement to a break module
console.log('this is not reached');

}
module.exports = [myFunction, myOtherFunction];

Because it would work if you are in a loop, or not. For PHP we are always in a
function so we can use Return, but need to work out the problem where we end up
with multiple returns. For PHP we could turn the return into the return of the
module exports.

CC:

Summary:
This bug came up because of an old change that we made in generate.ml
It removed the return statement from the footer of the main body, however there are some cases where it is needed.
Specifically when the last line of a module is some kind of loop.

Here's what we would need to do to add it back.

-    | Stop -> flush_all queue []
+    | Stop -> flush_all queue [J.Return_statement None, loc]

However, we can't just add it back right now, because our JS modules and Hack modules are structured differently in separate compilation mode.
In Hack, that would result in two return statements.
In JS, that would result in a return statement outside of a function body.
That return statement could end up being in a loop, or floating in the outermost part of the module.

We should probably create a new Rehp node called "ExitModule".
However, it's not clear when to turn that into a return vs. something else (and
what would we even use for JS module bodies)?

One possibility for module bodies in JS:

```javascript
module: {

var myFunction = ...;
var myOtherFunction = ...;
break module;  // Convert the final Return_statement to a break module
console.log('this is not reached');

}
module.exports = [myFunction, myOtherFunction];
```

Because it would work if you are in a loop, or not. For PHP we are always in a
function so we can use Return, but need to work out the problem where we end up
with multiple returns. For PHP we could turn the return into the return of the
module exports.

CC:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant