Skip to content

Spec for WIT component syntax#627

Open
fibonacci1729 wants to merge 1 commit intoWebAssembly:mainfrom
fibonacci1729:component-wit
Open

Spec for WIT component syntax#627
fibonacci1729 wants to merge 1 commit intoWebAssembly:mainfrom
fibonacci1729:component-wit

Conversation

@fibonacci1729
Copy link
Copy Markdown
Collaborator

This PR proposes changes to WIT.md to address #598.

First attempt, mostly trying to capture what I distilled from the discussion (and some opinion sprinkled in the rules where ambiguity around wit directories arose while prototyping).

I'm working on a prototype for wasm-tools and wit-bindgen (rust only to start).

Signed-off-by: Brian Hardock <brian.hardock@fermyon.com>
Copy link
Copy Markdown
Member

@lukewagner lukewagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for working on this! I can't wait to start using this in official tooling and docs. Just a few nits and small suggestions:

Comment on lines +23 to +26
Alternatively, a WIT file can contain a single unnamed
[`component`][components-wit] definition, which provides a lightweight way to
define the imports and exports of a component without requiring a `package`
declaration, namespace, package name, or world name.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Alternatively, a WIT file can contain a single unnamed
[`component`][components-wit] definition, which provides a lightweight way to
define the imports and exports of a component without requiring a `package`
declaration, namespace, package name, or world name.
Alternatively, a WIT file can contain a single unnamed
[`component`][components-wit] definition, which provides a lightweight way to
define the imports and exports of a component without requiring a `package`
declaration, namespace, package name, or world name. In such cases, the WIT
file cannot be built into a distributable WIT package but is instead fed directly into
the producer toolchain building a specific component.

defining the imports and exports of a single component and don't intend to
publish the WIT as a reusable package.

A `component` definition is an unnamed world: it has `import` and `export`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A `component` definition is an unnamed world: it has `import` and `export`
A `component` definition is like a `world` definition: it has `import` and `export`

Comment on lines +844 to +846
* A WIT file must contain **either** a `package` declaration (with optional
`world` and `interface` definitions) **or** a single `component` definition,
but **not both**. This invariant is enforced by the parser.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: could there be multiple WIT files (fed into wasm-tools just like today), as long as none of the files contain a package declaration if any of the files contains a component definition?

automatically select the unnamed component when the WIT file contains a
`component` definition, without requiring the user to specify a world name.

### Motivation
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we perhaps reframe this section from "Motivation" to "Guidance for when to use a component vs. world definition"?


package-file ::= (package-decl ';')? (package-items | nested-package-definition)*

component-file ::= (toplevel-use-item | nested-package-definition)* component-item
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we perhaps allow (at most one, enforced by validation, not grammar) component-item anywhere in the file (not just at the end)? This is nice when folks want to write things in a top-down definition order, and generally allowed since WIT definitions are order-independent.

Comment on lines +1500 to +1503
A `component` definition is an unnamed world that can appear as the sole
top-level construct in a WIT file (see [WIT Components][components-wit]). Its
body is identical to a `world` body.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A `component` definition is an unnamed world that can appear as the sole
top-level construct in a WIT file (see [WIT Components][components-wit]). Its
body is identical to a `world` body.
A `component` definition is like a `world` definition without a name (see
[WIT Components][components-wit]). Its body is identical to a `world` body.

body is identical to a `world` body.

```ebnf
component-item ::= 'component' '{' world-items* '}'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
component-item ::= 'component' '{' world-items* '}'
component-item ::= 'component' '{' world-definition* '}'

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants