WebAssembly / WebAssembly/wabt
WAT imports cannot be resolved dynamically.
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 8.1k
- Forks
- 827
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 18
Description
I'm using WAT as a first-class language, and have an issue resolving imports: If one module exports a value, and another module imports that value, there is no (clean) way for the host to resolve the import, unless it knows what the files contain in advance.
When using the JavaScript API (though this seems to apply generally), we use parseWat to parse the WAT source to a module, then use the module's toBinary method to compile the module to a buffer. The buffer is then passed to WebAssembly.instantiate (with a hash of imports), to get an instance (which exposes its exports as attributes).
The host must provide the imports to WebAssembly.instantiate, but has no obvious way of knowing what must be provided (the module and field names for each import).
The buffer has a log attribute which contains an import section with a subsection for each import. Parsing the log to extract each pair of module and field names is possible, but obviously pretty clunky. It's inherently unreliable too, as there's no formal grammar for the log, so the parsing is crude and would choke on more complex import strings.
Could we give the buffer (returned by toBinary) an imports attribute (as well as log) that references a hash of import strings (populated as the log is generated), using the module names as keys and the field names as values?
Thanks for considering this, and for all the hard work you do on the project (it's my first post here).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the parseWat and toBinary API flow, then inspect how the buffer's log and import section are produced. The work is complete when the returned buffer exposes an imports attribute containing the module and field names needed by WebAssembly.instantiate, including imports represented by more complex import strings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, javascript, wasm
- Domain
- api, compilers, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100