-
-
Notifications
You must be signed in to change notification settings - Fork 667
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
Can't get export info in transform without reloading the module #2829
Comments
Hm, could this be a Binaryen bug? |
I think it's more to do with AssemblyScript's usage of binaryen.js. Internally, before the A solution would be for the original |
There isn't an old instance of Binaryen. The |
So, how would I use |
What do you mean? By the way, I still don't think this is an AS problem, but I could be wrong. |
Actually, does anything change if you change |
Nope. That was the first thing I tried. Same result. |
In assemblyscript/cli/index.d.ts: import { Program, Parser, Module } from "../src";
...
export abstract class Transform {
...
afterCompile?(module: Module): void | Promise<void>;
} So the Typescript definition of But then in assemblyscript/cli/index.js: // From here on we are going to use Binaryen.js
binaryenModule = binaryen.wrapModule(
typeof module === "number" || module instanceof Number
? assemblyscript.getBinaryenModuleRef(module)
: module.ref
);
...
{
let error = await applyTransform("afterCompile", binaryenModule);
if (error) return prepareResult(error);
} It's passing the wrapped So the type definition is incorrect. I've got a Binaryen module, not an AssemblyScript module. Looking at this old example I think an older version passed the AssemblyScript module, but no longer. |
Well, I'm not 100% sure about that. It sure seems like it's behaving like my import of Sorry, I'm not super familiar with the internals here. |
If I compile from with VS Code's JavaScript Debug Terminal, I can set breakpoints and step through to the implementation of the binaryen module's functions. It's the minified version, which is annoying, but I can still see a bit of what's going on there. For example, I.getNumExports=function(){return A._BinaryenGetNumExports(g)} Where From there, I can get the data just fine. For example: A.getExportInfo(I.getExportByIndex(0)) output: {kind: 0, name: 'myFunction1', value: 'assembly/index/myFunction1'} So the information is there, it's just only accessible if using That's why I was saying it's behaving as if it's two different instances. |
I remember that similar issues in the past were a result of two different Binaryen packages in the module graph being present. For instance, AS used version A pinned in its package.json, whereas the surrounding package imported version B. Each instance of Binaryen has its own memory, and AS provides a re-export of the exact Binaryen package it uses here Lines 56 to 59 in de174c5
i.e. import binaryen from "assemblyscript/binaryen";
... which should mitigate such issues - that is, unless something broke, say with the switch to Binaryen's Wasm variant. |
Hm, I thought |
It should, yeah. |
I tried all variations of importing binaryen mentioned here, and a few others such as dynamic import. All same results. |
@mattjohnsonpint could you try cloning AssemblyScript and adding I'd like to hear if that works in your project before making a PR. You should be able to use |
Will try tomorrow and get back to you. Thanks! 🙂 |
Yes. It works perfectly. After adding I will send a PR shortly, including the Typescript changes. Thanks. |
Bug description
In a transform's
afterCompile
stage, I should be able to get information about the module's exports. Indeed, the number of exports seems to be correct, and they have addresses. But for some reason I can't quite figure out - their names are blank.However, if I generate binary from the module, then reload it - then I get the information I was looking for. But this seems rather inefficient and unnecessary.
Steps to reproduce
Make a new AssemblyScript project, containing at least one exported function.
Add a
myTransform.js
file:Add the transform in
asconfig.json
, or compile with--transform ./myTransform.js
, as per the docs.Compile, and note that the output is something like the following:
Then, uncomment the line indicated to workaround the bug, and it compile again. This time, the information is presented correctly:
AssemblyScript version
v0.27.25
The text was updated successfully, but these errors were encountered: