bytecodealliance / bytecodealliance/wit-bindgen

Types appearing both in module and in exports

Open
#903 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.5k
Forks
286
Avg merge
6h 32m
Merged PRs (30d)
19

Description

Consider this wit

```wit
package litehouse:plugin;

interface plugin {
variant update {
time(u64),

temperature(float64),
wind-speed(float64),

current(float64),
voltage(u16),
power(u16),
on-off(bool),
}
}

world plugin-host {
use plugin.{update};
import send-update: func(nickname: string, update: update);

export plugin;
}

```

I want to simultaneously expose the interface to the host as well as require the host to expose a function for the guest to use. The generated code however produces two types, `bindings::litehouse::plugin::plugin::Update` and `bindings::exports::litehouse::plugin::plugin::Update`, one presumably stems from the `use` and one from the `export`. These generated types are (to my eyes) identical. Any `Update` coming from the guest has the first, and any `Update` going into the guest has the latter. I would assume we would be able to, in the case of an interface being exported, defer all references of it to its exported types. Is there a technical reason for not doing this? If it is some technical issue, then a From / Into each way would be handy.

I will note it looks like all types from the interface are generated in both `bindings` and `bindings::exports` despite only importing one of them. I would also imagine those would be pruned to just the ones that are explicitly `use`d plus types they reference.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.