Skip to content

proposal: wit-parser: create distinct imported and exported TypeDefs, Functions, and Interfaces in a Resolve #1497

Open
@ydnar

Description

@ydnar

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.

  1. Add an attribute to the Interface, Function, and TypeDef structs to indicate whether it is imported or exported.
  2. The tree of imports and exports in a World would be duplicated (if necessary) and have the relevant import/export attribute.
  3. 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 utils is imported, then it uses the imported fd
  • If utils is exported, and fd is not exported, then it uses an imported fd
  • If utils is exported, and fd is exported, then it will use the exported fd

there'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 do export utils; that'll implicitly insert import fd;. If you have export fd; export utils;, however, then no implicit insertion happens and utils uses the exported fd.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions