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

hermes is incompatible with numjs and cwise library #954

Closed
paradite opened this issue Apr 2, 2023 · 3 comments
Closed

hermes is incompatible with numjs and cwise library #954

paradite opened this issue Apr 2, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@paradite
Copy link

paradite commented Apr 2, 2023

Problem

The hermes engine is incompatible with numjs, which uses cwise library for generate cache efficient map/reduce operations.

When using numjs, some functions are dynamically generated by the library based on the dimensions of arguments provided.

For example, for the unpack function here reproduced below:

var doUnpack = cwise({
  args: ['array', 'scalar', 'index'],
  body: function unpackCwise (arr, a, idx) {
    var v = a;
    var i;
    for (i = 0; i < idx.length - 1; ++i) {
      v = v[idx[i]];
    }
    v[idx[idx.length - 1]] = arr;
  }
});

When using jsc, the functions can be generated correctly:
hermes bug normal

However, using hermes, we got an error, presumably because the function has already been compiled to bytecode, and the generated function can't make use of it:

hermes bug

Sample error for search indexing:

ReferenceError: Property '_inline_9_bytecode' doesn't exist, js engine: hermes

Solution

Using jsc can be a walkaround but with hermes going to be default, I hope this issue can be addressed with hermes.

Some ideas:

  • Can hermes provides some ability to opt out / exclude bytecode for certain functions?
  • Is there any way I can modify the numjs and cwise lib to make it compatible with the way hermes work now?

Any help on this issue would be appreciated.

Additional Context

Here's the relevant code for compiling and generating dynamic function in cwise-compiler:

https://github.com/scijs/cwise-compiler/blob/b65933f021302e15c6d4624353bb4b69168cd543/lib/compile.js#L116-L199

@paradite paradite added the enhancement New feature or request label Apr 2, 2023
@tmikov
Copy link
Contributor

tmikov commented Apr 2, 2023

If you add the directive "show source" to a function, Hermes will preserve its source code. For example:

function foo() {
  "show source";
  return 1 + 1;
}
print(foo.toString());

@paradite
Copy link
Author

paradite commented Apr 2, 2023

Thank you for the help @tmikov, let me try it out.

@paradite
Copy link
Author

paradite commented Apr 2, 2023

It seems to work, but now I am running into #612

Update:
I am able to walk around #612 by triggering a hot-reload of the file that contains "show source";.

Feel free to close this issue.

@tmikov tmikov closed this as completed Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants