Skip to content

Consider WIT extension to avoid superfluous names when defining custom component imports/exports #598

@lukewagner

Description

@lukewagner

(This isn't pressing, but I thought it would be good to have an open issue to capture this use case which was previously buried in #313 since I saw it come up again recently.)

WIT provides good support for defining worlds that are meant to be reused by many component authors by including both a namespace (to keep separate organizations from clashing) and a package name (to group related functionality that is published as an atomic unit with a version) as part of all interface and world names. However, if I'm just defining my own custom component which includes one or more custom imports or exports (not defined elsewhere), then WIT forces me to invent a namespace, package and world name that don't ultimately appear in the compiled component and are thus entirely superfluous. While this feels harmless, I've noticed it weakens tutorial and introductory material by forcing the author to make up some ignorable names and then explain that they don't matter.

For example, in:

package my:test;
world component {
  import wasi:http/client;
  export frob: func(in: string) -> string;
}

the namespace my, package name test and world name component won't show up in the .wasm of a component compiled to target my:test/component, so ideally none of them would be forced to appear in the WIT.

One possible solution is to allow worlds to be unnamed, in which case a package statement is not required or even allowed to be present:

world {
  import wasi:http/client;
  export frob: func(in: string) -> string;
}

Then this WIT could be fed into wit-bindgen or another build tool, which would know to use this unnamed world (instead of requiring the target world name to be explicitly specified).

As a purely-syntactic tweak to the above, we could address the other big, repeated bit of feedback that I've gotten which is: "What's a world? Why don't you just call it a component? That's what I was expecting and then you won't have to explain what a world is.". Now, I think component is confusing when talking about a packaged, published contracts between N hosts and M components -- in these scenarios "world" seems better than "component" IMO. But when we're talking about these non-published one-component worlds, instead of saying "worlds can be unnamed, in which case special rules apply", we could write:

component {
  import wasi:http/client;
  export frob: func(in: string) -> string;
}

and the rule is: "your WIT can contain a component definition xor a package definition", not both, which lines up with what you're actually trying to do (build a component vs. build a WIT package). I'm biased of course, but that WIT looks pretty nice and ideal for providing a gentle introduction to WIT.

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