Skip to content

Commit 0d65079

Browse files
committed
Tighten up wording in WIT.md about identifiers and names
1 parent 77f7be2 commit 0d65079

File tree

1 file changed

+58
-54
lines changed

1 file changed

+58
-54
lines changed

design/mvp/WIT.md

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ The Wasm Interface Type (WIT) format is an [IDL] to provide tooling for the
1616
A WIT package is a collection of WIT [`interface`s][interfaces] and
1717
[`world`s][worlds] defined in files in the same directory that all use the
1818
file extension `wit`, for example `foo.wit`. Files are encoded as valid utf-8
19-
bytes. Types can be imported between interfaces within a package and
20-
additionally from other packages through IDs.
19+
bytes. Types can be imported between interfaces within a package using
20+
unqualified names and additionally from other packages through namespace-
21+
and-package-qualified names.
2122

2223
This document will go through the purpose of the syntactic constructs of a WIT
2324
document, a pseudo-formal [grammar specification][lexical-structure], and
@@ -223,10 +224,10 @@ interface my-interface {
223224
}
224225
225226
world command {
226-
// generates an import of the ID `local:demo/my-interface`
227+
// generates an import of the name `local:demo/my-interface`
227228
import my-interface;
228229
229-
// generates an import of the ID `wasi:filesystem/types`
230+
// generates an import of the name `wasi:filesystem/types`
230231
import wasi:filesystem/types;
231232
232233
// generates an import of the plain name `foo`
@@ -290,9 +291,12 @@ world union-my-world {
290291
}
291292
```
292293

293-
### De-duplication of IDs
294+
### De-duplication of interfaces
294295

295-
If two worlds shared the same set of import and export IDs, then the union of the two worlds will only contain one copy of this set. For example, the following two worlds `union-my-world-a` and `union-my-world-b` are equivalent:
296+
If two worlds share an imported or exported [interface name], then the union of
297+
the two worlds will only contain one copy of that imported or exported name.
298+
For example, the following two worlds `union-my-world-a` and `union-my-world-b`
299+
are equivalent:
296300

297301
```wit
298302
package local:demo;
@@ -320,9 +324,14 @@ world union-my-world-b {
320324

321325
### Name Conflicts and `with`
322326

323-
When two or more included Worlds have the same name for an import or export that does *not* have an ID, automatic de-duplication cannot be used (because the two same-named imports/exports might have different meanings in the different worlds) and thus the conflict has to be resolved manually using the `with` keyword:
324-
The following example shows how to resolve name conflicts where `union-my-world-a` and `union-my-world-b` are equivalent:
327+
When two or more included Worlds have the same name for an import or export
328+
with a *plain* name, automatic de-duplication cannot be used (because the two
329+
same-named imports/exports might have different meanings in the different
330+
worlds) and thus the conflict has to be resolved manually using the `with`
331+
keyword.
325332

333+
The following example shows how to resolve name conflicts where
334+
`union-my-world-a` and `union-my-world-b` are equivalent:
326335
```wit
327336
package local:demo;
328337
@@ -340,8 +349,8 @@ world union-my-world-b {
340349
}
341350
```
342351

343-
`with` cannot be used to rename IDs, however, so the following world would be invalid:
344-
352+
`with` cannot be used to rename interface names, however, so the following
353+
world would be invalid:
345354
```wit
346355
package local:demo;
347356
@@ -354,7 +363,7 @@ world world-using-a {
354363
}
355364
356365
world invalid-union-world {
357-
include my-using-a with { a as b } // invalid: 'a', which is short for 'local:demo/a', is an ID
366+
include my-using-a with { a as b } // invalid: 'a', which is short for 'local:demo/a', is an interface name
358367
}
359368
360369
```
@@ -462,21 +471,17 @@ interface another-interface {
462471
}
463472
```
464473

465-
When referring to an interface an ID form can additionally be used to refer to
466-
dependencies. For example above it was seen:
467-
474+
When referring to an interface, a fully-qualified [interface name] can be used.
475+
For example, in this WIT document:
468476
```wit
469477
package local:demo;
470478
471479
world my-world {
472480
import wasi:clocks/monotonic-clock;
473481
}
474482
```
475-
476-
Here the interface being referred to is the ID `wasi:clocks/monotonic-clock`.
477-
This is the package identified by `wasi:clocks` and the interface
478-
`monotonic-clock` within that package. This same syntax can be used in `use` as
479-
well:
483+
The `monotonic-clock` interface of the `wasi:clocks` package is being imported.
484+
This same syntax can be used in `use` as well:
480485

481486
```wit
482487
package local:demo;
@@ -549,7 +554,7 @@ use wasi:http/handler as http-handler;
549554
```
550555

551556
Note that these can all be combined to additionally import packages with
552-
multiple versions and renaming as different identifiers.
557+
multiple versions and renaming as different WIT identifiers.
553558

554559
```wit
555560
package local:demo;
@@ -610,7 +615,7 @@ to the fact that the `use shared.{ ... }` implicitly requires that `shared` is
610615
imported into the component as well.
611616

612617
Note that the name `"local:demo/shared"` here is derived from the name of the
613-
`interface` plus the package ID `local:demo`.
618+
`interface` plus the package name `local:demo`.
614619

615620
For `export`ed interfaces, any transitively `use`d interface is assumed to be an
616621
import unless it's explicitly listed as an export. For example, here `w1` is
@@ -744,8 +749,32 @@ defined within each language as well.
744749
## WIT Identifiers
745750
[identifiers]: #wit-identifiers
746751

747-
Identifiers in WIT documents are required to be valid plain or interface
748-
names, as defined by the [component model text format](Explainer.md#import-and-export-definitions).
752+
Identifiers in WIT can be defined with two different forms. The first is the
753+
[kebab-case] [`label`](Explainer.md#import-and-export-names) production in the
754+
Component Model text format.
755+
756+
```wit
757+
foo: func(bar: u32);
758+
759+
red-green-blue: func(r: u32, g: u32, b: u32);
760+
761+
resource XML { ... }
762+
parse-XML-document: func(s: string) -> XML;
763+
```
764+
765+
This form can't lexically represent WIT keywords, so the second form is the
766+
same syntax with the same restrictions as the first, but prefixed with '%':
767+
768+
```wit
769+
%foo: func(%bar: u32);
770+
771+
%red-green-blue: func(%r: u32, %g: u32, %b: u32);
772+
773+
// This form also supports identifiers that would otherwise be keywords.
774+
%variant: func(%enum: s32);
775+
```
776+
777+
[kebab-case]: https://en.wikipedia.org/wiki/Letter_case#Kebab_case
749778

750779
# Lexical structure
751780
[lexical-structure]: #lexical-structure
@@ -804,7 +833,7 @@ operator ::= '=' | ',' | ':' | ';' | '(' | ')' | '{' | '}' | '<' | '>' | '*' | '
804833

805834
### Keywords
806835

807-
Certain identifiers are reserved for use in `wit` documents and cannot be used
836+
Certain identifiers are reserved for use in WIT documents and cannot be used
808837
bare as an identifier. These are used to help parse the format, and the list of
809838
keywords is still in flux at this time but the current set is:
810839

@@ -850,7 +879,7 @@ wit-file ::= package-decl? (toplevel-use-item | interface-item | world-item)*
850879
## Package declaration
851880
[package declaration]: #package-declaration
852881

853-
WIT files optionally start with a package declaration which defines the ID of
882+
WIT files optionally start with a package declaration which defines the name of
854883
the package.
855884

856885
```ebnf
@@ -874,7 +903,7 @@ use-path ::= id
874903
| ( id ':' )+ id ( '/' id )+ ('@' valid-semver)? 🪺
875904
```
876905

877-
Here `use-path` is the ID used to refer to interfaces. The bare form `id`
906+
Here `use-path` is an [interface name]. The bare form `id`
878907
refers to interfaces defined within the current package, and the full form
879908
refers to interfaces in package dependencies.
880909

@@ -885,6 +914,8 @@ As a future extension, WIT, components and component registries may allow
885914
nesting both namespaces and packages, which would then generalize the syntax of
886915
`use-path` as suggested by the 🪺 suffixed rule.
887916

917+
[Interface Name]: Explainer.md#import-and-export-definitions
918+
888919
## Item: `world`
889920

890921
Worlds define a [componenttype](https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#type-definitions) as a collection of imports and exports.
@@ -1292,33 +1323,6 @@ where `%[method]file.read` is the desugared name of a method according to the
12921323
Component Model's definition of [`name`](Explainer.md).
12931324

12941325

1295-
## Identifiers
1296-
1297-
Identifiers in `wit` can be defined with two different forms. The first is a
1298-
[kebab-case] [`label`](Explainer.md#import-and-export-names) production in the
1299-
Component Model text format.
1300-
1301-
```wit
1302-
foo: func(bar: u32);
1303-
1304-
red-green-blue: func(r: u32, g: u32, b: u32);
1305-
```
1306-
1307-
This form can't name identifiers which have the same name as wit keywords, so
1308-
the second form is the same syntax with the same restrictions as the first, but
1309-
prefixed with '%':
1310-
1311-
```wit
1312-
%foo: func(%bar: u32);
1313-
1314-
%red-green-blue: func(%r: u32, %g: u32, %b: u32);
1315-
1316-
// This form also supports identifiers that would otherwise be keywords.
1317-
%variant: func(%enum: s32);
1318-
```
1319-
1320-
[kebab-case]: https://en.wikipedia.org/wiki/Letter_case#Kebab_case
1321-
13221326
## Name resolution
13231327

13241328
A `wit` document is resolved after parsing to ensure that all names resolve
@@ -1437,7 +1441,7 @@ This example illustrates the basic structure of interfaces:
14371441
* Each top-level WIT definition (in this example: `types` and `namespace`)
14381442
turns into a type export of the same kebab-name.
14391443
* Each WIT interface is mapped to a component-type that exports an
1440-
instance with a fully-qualified interface name (in this example:
1444+
instance with a fully-qualified [interface name] (in this example:
14411445
`local:demo/types` and `local:demo/namespace`). Note that this nested
14421446
scheme allows a single component to both define and implement a WIT interface
14431447
without name conflict.

0 commit comments

Comments
 (0)