Skip to content

Should type imports be restricted to defined types and resources #769

Open

Description

@alexcrichton

It turns out that wasmparser as a slew of minor issues related to handling type imports of instance, component, and function types. For example:

(component 
    (type $f (func))
    (import "f" (type (eq $f)))
)

One example is that wasmparser rejects, likely erroneously, this currently:

(component
  (type $f (func))
  (export "f" (type $f))
  (import "g" (type (eq $f)))
)

Another example is tests added in bytecodealliance/wasm-tools#2833 as well.

Overall I'm not aware of an actual use case of this. Resources make sense, and defined types make sense for bindings generation, but I'm not sure importing other kinds of types has much of a use case beyond "let's fill out the full matrix". I wanted to raise this as a very-not-urgent issue as a result in case others had thoughts on this.

Activity

  1. lukewagner commented on Nov 18, 2026

    @lukewagner
    Member

    FWIW, I think that second example should fail validation since imported types can't refer to type indices introduced by exports.

    But yeah agreed that imported types with eq bounds currently aren't especially useful and it's mostly just in there to keep imports and exports symmetric (e.g., so that WIT interfaces can be equivalently imported and exported). I could imagine a hypothetical data-related applications where the host reflects on a given component's imports+types to know what data types the component expects and an imported eq-bound type was a way of declaring a named data type, but I'm not aware of anyone doing that any time soon.

  2. alexcrichton commented on Nov 19, 2026

    @alexcrichton
    CollaboratorAuthor

    In the second example though the type created by the export isn't actually used by the import, so I think it should be ok? The original rule in wasmparser was intended to handle resources and accidentally runs afoul of this case currently is what I'm thinking.

    Overall I in theory like the idea of fill out the full matrix of support for everything in all the places, but that always comes at a cost of complexity and LLMs sure are having a field day in that respect. Basically it seems like we've got a lot of minor issues here and there about support the full matrix of things and fixing these issues likely has very little benefit in practice. The bugs are also minor enough that no one's really going to run into them, though, so the effect of fixing or disallowing is likely not really going to come up much anyway

  3. lukewagner commented on Nov 19, 2026

    @lukewagner
    Member

    Oops, right, agreed on the second example.

    I also agree with the general point that we shouldn't pointlessly "fill the matrix" for its own sake if it introduces non-trivial complexity/bug-risk. That being said, I think I forgot a more basic use case in my last comment: if I'm performing guest bindgen for a target world:

    world my-component {
      import wasi:clocks/monotonic-clock;
    }

    then if we ruled out eq-bound imports of non-defined/resource-types and roundtrip though a WAT component type, I think we'd lose the type mark = u64 in monotonic-clock and thus in guest bindings. If we want to go that direction, then maybe we just symmetrically delete eq-bound imports and exports of non-resource/defined types (and the WIT syntax for it, and thus the type mark = u64 in wasi:clocks)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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