-
Notifications
You must be signed in to change notification settings - Fork 317
Description
We propose to move logic from wit-bindgen into the wit-parser crate that determines whether an interface, type, or function in a Resolve structure is either imported or exported, and label those structures as such.
- Add an attribute to the
Interface,Function, andTypeDefstructs to indicate whether it is imported or exported. - The tree of imports and exports in a
Worldwould be duplicated (if necessary) and have the relevant import/export attribute. - Modify the JSON serialization of
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 the Resolve data structure (and its JSON representation). This means that each bindings generator that depends on the wit-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 type fd defined in a different interface types:
What ends up happening here is a bit subtle and it's generally related to WIT conventions. The CM itself has no ambiguity, the problem arises when WIT is mapped back to the component model. To answer your question the cases are:
- If
utilsis imported, then it uses the importedfd- If
utilsis exported, andfdis not exported, then it uses an importedfd- If
utilsis exported, andfdis exported, then it will use the exportedfdthere's also implicit insertion of interfaces to handle here too, for example
wasm-tools component wit ./my-witwill show the "elaborated" version of a world. For example if you doexport utils;that'll implicitly insertimport fd;. If you haveexport fd; export utils;, however, then no implicit insertion happens andutilsuses the exportedfd.
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.