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

Global scoped try/catch emits compilation error #537

Closed
Ferossgp opened this issue Jun 17, 2021 · 6 comments
Closed

Global scoped try/catch emits compilation error #537

Ferossgp opened this issue Jun 17, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@Ferossgp
Copy link

I've been trying to compile an app bundle generated by Closure Compiler.

Compiling the bundle with the Hermes compiler:

hermesc -O -emit-binary -out ./test.hbc /test.js

emits the following error:

index.js:1:1: error: Too deeply nested try/catch

Hermes versions tested with:

LLVM (http://llvm.org/):
  LLVH version 8.0.0svn
  Optimized build

Hermes JavaScript compiler.
  Hermes release version: 0.7.2
  HBC bytecode version: 76

  Features:
    Debugger
    Zip file input
---------------------------------
LLVM (http://llvm.org/):
  LLVH version 8.0.0svn
  Optimized build

Hermes JavaScript compiler.
  Hermes release version: 0.8.0
  HBC bytecode version: 83

  Features:
    Debugger
    Zip file input

By inspecting the JS code I found that the reason is the presence of a try/catch in the global scope. The try/catch does not have any recursion and deep function traces inside its scope. Removing it solves the error.

Adding this try {} catch (a) {} at the end of file, also causes the error.

Seems like there is something else in the bundle that in combination with a global try/catch causes the error.

In a simple test project, the error is not reproducible. I want to create a repro thus I would like to know some hints for the direction to dig in.

@Ferossgp Ferossgp added the bug Something isn't working label Jun 17, 2021
@avp
Copy link
Contributor

avp commented Jun 17, 2021

You can perhaps try deleting pieces of the code in order to figure out which parts are actually making things fail.

If you build Hermes with debug information (https://github.com/facebook/hermes/blob/master/doc/BuildingAndRunning.md) then you can also attach a debugger and breakpoint on the error message (it's in lib/BCGen/Exceptions.cpp) in order to look at the stacktrace and perhaps help figure out how you can find a useful repro we can take a look at.

@avp avp added the need more info Awating additional info before proceeding label Jun 17, 2021
@Ferossgp
Copy link
Author

@avp Thank you!

There is a gist that throws the same exception https://gist.github.com/Ferossgp/c4107f30bb686f56c5f2893541838eda

I will try to create a reproduction without so many try/catch'es too. Basically what I've found is that this code:

try{} catch(a){}

function recursive(argument) {
  if (argument) {
    recursive(argument--)
  }
}

also decreases the maxRecursionDepth inside the lib/BCGen/Exceptions.cpp, and by removing the try-catch does not execute that part of the code anymore.

@avp avp removed the need more info Awating additional info before proceeding label Jun 18, 2021
@avp
Copy link
Contributor

avp commented Jun 18, 2021

Thanks for the reproduction. We'll take a look and see what has to be done to avoid hitting this case in the wrong circumstances.

@neildhar
Copy link
Contributor

@Ferossgp This should be fixed in 42f8319, are you able to build Hermes from trunk and verify that the issue with your bundle is resolved?

@Ferossgp
Copy link
Author

@neildhar yes, thank you! Can confirm that the build from 42f8319 solved the issue for us.

@neildhar
Copy link
Contributor

Great, thanks for confirming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants