You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: design/mvp/WIT.md
+58-54Lines changed: 58 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,8 +16,9 @@ The Wasm Interface Type (WIT) format is an [IDL] to provide tooling for the
16
16
A WIT package is a collection of WIT [`interface`s][interfaces] and
17
17
[`world`s][worlds] defined in files in the same directory that all use the
18
18
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.
21
22
22
23
This document will go through the purpose of the syntactic constructs of a WIT
23
24
document, a pseudo-formal [grammar specification][lexical-structure], and
@@ -223,10 +224,10 @@ interface my-interface {
223
224
}
224
225
225
226
world command {
226
-
// generates an import of the ID `local:demo/my-interface`
227
+
// generates an import of the name `local:demo/my-interface`
227
228
import my-interface;
228
229
229
-
// generates an import of the ID `wasi:filesystem/types`
230
+
// generates an import of the name `wasi:filesystem/types`
230
231
import wasi:filesystem/types;
231
232
232
233
// generates an import of the plain name `foo`
@@ -290,9 +291,12 @@ world union-my-world {
290
291
}
291
292
```
292
293
293
-
### De-duplication of IDs
294
+
### De-duplication of interfaces
294
295
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:
296
300
297
301
```wit
298
302
package local:demo;
@@ -320,9 +324,14 @@ world union-my-world-b {
320
324
321
325
### Name Conflicts and `with`
322
326
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.
325
332
333
+
The following example shows how to resolve name conflicts where
334
+
`union-my-world-a` and `union-my-world-b` are equivalent:
326
335
```wit
327
336
package local:demo;
328
337
@@ -340,8 +349,8 @@ world union-my-world-b {
340
349
}
341
350
```
342
351
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:
345
354
```wit
346
355
package local:demo;
347
356
@@ -354,7 +363,7 @@ world world-using-a {
354
363
}
355
364
356
365
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
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
1292
1323
Component Model's definition of [`name`](Explainer.md).
1293
1324
1294
1325
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.
0 commit comments