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

Duplicate imports #2152

Open
lann opened this issue Aug 28, 2024 · 3 comments
Open

Duplicate imports #2152

lann opened this issue Aug 28, 2024 · 3 comments
Labels

Comments

@lann
Copy link

lann commented Aug 28, 2024

Grain produces Wasm modules with duplicate imports. This is permitted by the Wasm core spec, but with caveats:

https://webassembly.github.io/spec/core/syntax/modules.html#imports

It is possible to import the same module/name pair multiple times [...] However, embedders are not required to support such overloading

The Wasm Component Model in particular does not support duplicate imports, which means that WASI preview1 modules compiled with Grain cannot be converted to components with the preview1 adapter.

Example:

$ grain --version
0.6.6
$ cat hello.gr
module Main
print("Hello, World")
$ grain compile hello.gr
$ wasm-tools dump hello.gr.wasm | grep Import
   0x16b | 16 77 61 73 | import [func 0] Import { module: "wasi_snapshot_preview1", name: "fd_write", ty: Func(2) }
   0x18d | 16 77 61 73 | import [func 1] Import { module: "wasi_snapshot_preview1", name: "fd_write", ty: Func(2) }
   0x1af | 16 77 61 73 | import [func 2] Import { module: "wasi_snapshot_preview1", name: "fd_write", ty: Func(2) }
   0x1d1 | 16 77 61 73 | import [func 3] Import { module: "wasi_snapshot_preview1", name: "fd_write", ty: Func(2) }
@spotandjake
Copy link
Member

If you run grain compile <file> --release it will produce a module without multiple imports.

@ospencer
Copy link
Member

To add to what @spotandjake mentioned, we have successfully used the adapter to make components. Let me know if you want some pointers!

We've been aware of this issue but have been slow to fix it because of the available workaround. This is something we can resolve in the next major release.

@lann
Copy link
Author

lann commented Aug 28, 2024

Aha thanks! Feel free to resolve this unless you'd like to keep it for tracking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants