bytecodealliance / bytecodealliance/wasm-tools
wasm-compose: Elide imports from a component that are made up of only types
- Dominant language
- Rust
- Stars
- 1.8k
- Forks
- 351
- Avg merge
- 16h 57m
- Merged PRs (30d)
- 38
Description
While trying to implement https://github.com/wasmCloud/wasmCloud/issues/497, we discovered that shared types (defined in an `interface`) bubble up as imports to the top level when composing. For example, given an interface that looks like this:
```
package wasmcloud:messaging@0.1.0
interface types {
record broker-message {
subject: string,
body: option>,
reply-to: option,
}
}
interface handler {
use types.{broker-message}
handle-message: func(msg: broker-message) -> result<_, string>
}
interface consumer {
use types.{broker-message}
request: func(subject: string, body: option>, timeout-ms: u32) -> result
request-multi: func(subject: string, body: option>, timeout-ms: u32, max-results: u32) -> result, string>
publish: func(msg: broker-message) -> result<_, string>
}
```
You can have 2 interfaces that both depend on the shared types. When trying to virtualize (i.e. through virtual platform layering) a component that has a world like this:
```
world messaging {
import consumer
export handler
}
```
You end up with a bunch of dangling imports of the `types` interface. For example, this is the world after composing several of the virtualized interfaces:
```
package root:component
world root {
import wasmcloud:messaging/types@0.1.0
// ^^ This shouldn't be here since it is only types
import wasi:io/streams
import wasi:filesystem/types
import wasi:filesystem/preopens
import wasi:cli/environment
import wasi:cli/exit
import wasi:cli/stdin
import wasi:cli/stdout
import wasi:cli/stderr
import wasi:cli/terminal-input
import wasi:cli/terminal-output
import wasi:cli/terminal-stdin
import wasi:cli/terminal-stdout
import wasi:cli/terminal-stderr
import wasmcloud:bus/lattice
import wasmcloud:bus/host
export wasmcloud:bus/guest
}
```
After talking to @peterhuene, he said that we could check if all components being composed have the same import, and if there are no functions in the interface, we can elide it. We would also need to generate type instantiations that could be passed in to satisfy those types
Contributor guide
Assessment
This issue has not been assessed yet.