assemblyscript
assemblyscript copied to clipboard
New import added after transformation class applied breaks compiler
In our custom transformation, we are adding new methods to some specific classes based on some custom decorators. Everything works pretty well. However, it allowed us to find a bug on the compiler.
In the error below you can see the exact assertion that is failing. When you add new imports to some specific source, and try to parse that file again with new lines (some functions and imports), everything works well as long as some route to that import was there previously.
This object has references to files by name. This is not being refreshed when parsing the new source. https://github.com/AssemblyScript/assemblyscript/blob/8047b024488b74deeea5dded7efdf4b24108474d/src/program.ts#L465
If you want to reproduce the error, please try to apply a custom transformation class to some AS project, importing some dependency (some other file) that was not there at the very beginning, and that assertion will fail.
❯ make build
yarn asbuild
yarn run v1.22.19
$ npm run asbuild:debug && npm run asbuild:release
> asbuild:debug
> asc assembly/index.ts --target debug --bindings esm --use abort= --transform @zondax/fvm-as-bindgen
▌ Whoops, the AssemblyScript compiler has crashed during initialize :-(
▌
▌ Here is the stack trace hinting at the problem, perhaps it's useful?
▌
▌ /home/law/work/zondax/fil-erc20-actor-as/node_modules/assemblyscript/std/portable/index.js:200
▌ throw new AssertionError(message);
▌ ^
▌
▌ AssertionError: assertion failed
▌ at null.Q.assert (/home/law/work/zondax/fil-erc20-actor-as/node_modules/assemblyscript/std/portable/index.js:200:11)
▌ at In.initialize (/home/law/work/zondax/fil-erc20-actor-as/node_modules/assemblyscript/src/program.ts:1162:27)
▌ at Module._S (/home/law/work/zondax/fil-erc20-actor-as/node_modules/assemblyscript/src/index-wasm.ts:319:11)
▌ at Module.Me (/home/law/work/zondax/fil-erc20-actor-as/node_modules/assemblyscript/cli/index.js:697:22)
▌ at async file:///home/law/work/zondax/fil-erc20-actor-as/node_modules/assemblyscript/bin/asc.js:33:22
▌
▌ If you see where the error is, feel free to send us a pull request. If not,
▌ please let us know: https://github.com/AssemblyScript/assemblyscript/issues
▌
▌ Thank you!
Keeping this alive!
Do you have an example of the additional parsing done by the transform? I think this would be useful to understand what's happening.
assert failed here btw: https://github.com/AssemblyScript/assemblyscript/blob/8047b024488b74deeea5dded7efdf4b24108474d/src/program.ts#L1162
I guess when you're adding new import filesByName
doesn't update. Btw filesByName
updates only once during initialize program
Conceptionally, however, the parsing stage would be complete once initialization happens. Anything after would have to modify the program directly. Or is the observation unrelated?