Open ydnar opened 6 months ago
I will take a look at this issue if no one has started looking into it
Thanks @Mossaka!
This is going to touch a lot of places in wasm-tools in some subtle ways, but in the end everything should be pretty straightforward except for the Resolve
bits of "actually copy and duplicate everything". One example of being a bit subtle is encoding/decoding which actually have a fair bit of logic to work around the opposite of this issue, specifically generating a single interface instead of two by accident. This might help simplify big chunks of that.
As usual I'm happy to help out with any questions and such, just ping me!
Exported types referencing imported types should be interesting!
Would it make sense for each Interface, TypeDef, and Function to have a reference to its symmetric other (import vs export) if it exists?
This seems relevant to the discussion here:
@ydnar seems reasonable to me yeah, but I think it largely depends on what bindings generators want. If they don't need it it's probably not worth it, but if any needs it then seems good to add.
@Mossaka yeah that should get cleaned up/removed with this issue, in theory.
I feel this change could potentially also facilitate the solution we postponed as too complicated in https://github.com/bytecodealliance/wasm-tools/pull/1438#issuecomment-1984559922 - here only borrowed and exported resource handles should be considered as a pointer, all else as an s32.
Indeed yeah this change should make that trivial
@Mossaka you've probably realized or encountered this already: but I think this proposal means that every WorldItem would be duplicated at least once for each World in a Resolve.
We propose to move logic from
wit-bindgen
into thewit-parser
crate that determines whether an interface, type, or function in aResolve
structure is either imported or exported, and label those structures as such.Interface
,Function
, andTypeDef
structs to indicate whether it is imported or exported.World
would be duplicated (if necessary) and have the relevant import/export attribute.Resolve
(e.g.wasm-tools component wit -j ...
) to include the import/export attribute.Context
This is a followup from a conversation in Zulip regarding imported and exported types in a
Resolve
.Currently, any types (represented as a
TypeDef
), functions (Function
), and interfaces (Interface
) are represented once in theResolve
data structure (and its JSON representation). This means that each bindings generator that depends on thewit-parser
crate must reimplement the heuristic to determine when to use an imported type versus an exported type.Per @alexcrichton:
For given interface
utils
, and a typefd
defined in a different interfacetypes
:This would simplify the implementation of bindings generators, such as wit-bindgen-go, which could then depend on the import/export resolution in
wit-parser
.