feat(compiler): Deduplicate foreign imports#2233
Conversation
ospencer
left a comment
There was a problem hiding this comment.
I think that you're getting a stack overflow because the snapshot is massive. As of the new object files PR, we don't do snapshots of wat anymore because they're a lot bigger (and thus impossible to really diff/read). The way to test this is programmatically. An example of a test that looks at wasm exports (and you can do the same for imports) is
grain/compiler/test/suites/modules.re
Line 156 in 4b56c53
753c558 to
ac65ee8
Compare
|
I would lean towards trying to prevent the issue rather than rely on the Binaryen pass. I think you're right that this would be annoying to resolve during codegen, but I don't think this is bad to fix as a part of linking at all, because it's already keeping track of names to rewrite. You could dedupe the imports and just keep the needed name in the resolver. |
9dae5f8 to
2691ae7
Compare
|
I refactored this change to handle things in compcore but I still need to figure out why our smallest program got larger, it seems to be that the wrapper isn't being inlined anymore but I am unsure why. |
|
Both those changes have been made. |
|
Why is this marked as breaking? |
I wasn't sure if we considered this optimization a breaking change or not, I'll mark it as non breaking though. |
|
As a note if we merge this before a fix is made for #2243 we will need to make sure to handle the |
This enables the binaryen pass to de-duplicate imports, if were against using the binaryen pass I think we can also do this manually in
compcoreand just filter through the imports incompile_importsbut we'll have to manually handle re-patching the import identifiers through the program.This makes developing for runtimes such as
wasmtimea little nicer.This also adds the
assertWasmSnapshotwhich let's us testwatsnapshots for optimizations that occur after, as the regular mashtree snapshots won't catch these, we can get away with a simpleprint("test")here because multiple places in the runtime importfd_write.Closes: #2152