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

"show source" is not always respected under lazy compilation #1583

Closed
robhogan opened this issue Dec 15, 2024 · 2 comments
Closed

"show source" is not always respected under lazy compilation #1583

robhogan opened this issue Dec 15, 2024 · 2 comments
Labels
bug Something isn't working fixed-in-sh Fixed in SH but "wontfix" in Hermes

Comments

@robhogan
Copy link
Contributor

robhogan commented Dec 15, 2024

Bug Description

Lazy compilation does not respect "show source", so [function].toString() fails to provide useful output.

This is observable under React Native, typically when loading a bundle in development, where we use lazy compilation for input JS exceeding 64KB. It makes "show source" quite unpredictable. Unknown whether other directives are similarly affected.

The symptoms have been reported before but not narrowed down to a lazy compilation issue:

Hermes git revision (if applicable): current / 579e82b
React Native version: N/A
OS: macOS / iOS
Platform: arm64

Steps To Reproduce with Hermes CLI

// show-source.js
print(
  (function getCode() {
    function someFunction() {
      'show source';
      return 'hi!';
    }
    return someFunction.toString();
  })(),
);

'show source' respected with eager compilation

./bin/hermes show-source.js
function someFunction() {
      'show source';
      return 'hi!';
    }

But fails with lazy compilation

./bin/hermes -lazy show-source.js
function someFunction() { [bytecode] }

The Expected Behavior

Lazy compilation doesn't change observable behaviour - show source should work both ways.

@robhogan robhogan added the bug Something isn't working label Dec 15, 2024
@avp
Copy link
Contributor

avp commented Dec 17, 2024

This is due to a problem in how lazy compilation resolves the function sources table in main Hermes. It always tries to lookup on the root RuntimeModule, which is only valid if the function was declared at the top level (which is why our test lazy-function-toString.js passes).

In reality, we'd have to be able to look up the function source in the parent RuntimeModule. We don't currently store this information, so it'd require more than a trivial change to main Hermes to fix.

This does work in Static Hermes, because we've simplified the lazy compilation mechanism significantly and now all the tables are shared among all the compilation invocations.

@tmikov tmikov added fixed-in-sh Fixed in SH but "wontfix" in Hermes and removed bug Something isn't working labels Dec 17, 2024
@tmikov
Copy link
Contributor

tmikov commented Dec 17, 2024

I am applying the label fixed-in-sh, meaning that this has been fixed in Static Hermes but is "Wontfix" in Hermes. We need this label because technically SH has not been released yet, but at the same time we don't want to keep issues like this open.

@tmikov tmikov closed this as completed Dec 17, 2024
@tmikov tmikov added the bug Something isn't working label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed-in-sh Fixed in SH but "wontfix" in Hermes
Projects
None yet
Development

No branches or pull requests

3 participants