-
Notifications
You must be signed in to change notification settings - Fork 82
/
WIT.md
1688 lines (1288 loc) · 44.1 KB
/
WIT.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# The `wit` format
The Wasm Interface Type (WIT) format is an [IDL] to provide tooling for the
[WebAssembly Component Model][components] in two primary ways:
* WIT is a developer-friendly format to describe the imports and exports to a
component. It is easy to read and write and provides the foundational basis
for producing components from guest languages as well as consuming components
in host languages.
* WIT packages are the basis of sharing types and definitions in an ecosystem of
components. Authors can import types from other WIT packages when generating a
component, publish a WIT package representing a host embedding, or collaborate
on a WIT definition of a shared set of APIs between platforms.
A WIT package is a collection of WIT [`interface`s][interfaces] and
[`world`s][worlds] defined in files in the same directory that all use the
file extension `wit`, for example `foo.wit`. Files are encoded as valid utf-8
bytes. Types can be imported between interfaces within a package and
additionally from other packages through IDs.
This document will go through the purpose of the syntactic constructs of a WIT
document, a pseudo-formal [grammar specification][lexical-structure], and
additionally a specification of the [binary format][binary-format] of a WIT
package suitable for distribution.
[IDL]: https://en.wikipedia.org/wiki/Interface_description_language
[components]: https://github.com/webassembly/component-model
## Package identifiers
All WIT packages are assigned an "ID". IDs look like `foo:bar@1.0.0` and have
three components:
* A namespace, for example `foo` in `foo:bar`. This namespace is intended to
disambiguate between registries, top-level organizations, etc. For example
WASI interfaces use the `wasi` namespace.
* A package name, for example `clocks` in `wasi:clocks`. A package name groups
together a set of interfaces and worlds that would otherwise be named with a
common prefix.
* An optional version, specified as [full semver](https://semver.org/).
Package identifiers are specified at the top of a WIT file via a `package`
declaration:
```wit
package wasi:clocks
```
or
```wit
package wasi:clocks@1.2.0
```
WIT packages can be defined in a collection of files and at least one of them
must specify a `package` identifier. Multiple files can specify a `package` and
they must all agree on what the identifier is.
Package identifiers are used to generate IDs in the component model binary
format for [`interface`s][interfaces] and [`world`s][worlds].
## WIT Interfaces
[interfaces]: #wit-interfaces
The concept of an "interface" is central in WIT as a collection of [functions]
and [types]. An interface can be thought of as an instance in the WebAssembly
Component Model, for example a unit of functionality imported from the host or
implemented by a component for consumption on a host. All functions and types
belong to an interface.
An example of an interface is:
```wit
package local:demo
interface host {
log: func(msg: string)
}
```
represents an interface called `host` which provides one function, `log`, which
takes a single `string` argument. If this were imported into a component then it
would correspond to:
```wasm
(component
(import (interface "local:demo/host") (instance $host
(export "log" (func (param "msg" string)))
))
;; ...
)
```
An `interface` can contain [`use`][use] statements, [type][types] definitions,
and [function][functions] definitions. For example:
```wit
package wasi:filesystem
interface types {
use wasi:clocks.wall-clock.{datetime}
record stat {
ino: u64,
size: u64,
mtime: datetime,
// ...
}
stat-file: func(path: string) -> result<stat>
}
```
More information about [`use`][use] and [types] are described below, but this
is an example of a collection of items within an `interface`. All items defined
in an `interface`, including [`use`][use] items, are considered as exports from
the interface. This means that types can further be used from the interface by
other interfaces. An interface has a single namespace which means that none of
the defined names can collide.
A WIT package can contain any number of interfaces listed at the top-level and
in any order. The WIT validator will ensure that all references between
interfaces are well-formed and acyclic.
## WIT Worlds
[worlds]: #wit-worlds
WIT packages can contain `world` definitions at the top-level in addition to
[`interface`][interfaces] definitions. A world is a complete description of
both imports and exports of a component. A world can be thought of as an
equivalent of a `component` type in the component model. For example this
world:
```wit
package local:demo
world my-world {
import host: interface {
log: func(param: string)
}
export run: func()
}
```
can be thought of as this component type:
```wasm
(type $my-world (component
(import "host" (instance
(export "log" (func (param "param" string)))
))
(export "run" (func))
))
```
Worlds describe a concrete component and are the basis of bindings generation. A
guest language will use a `world` to determine what functions are imported, what
they're named, and what functions are exported, in addition to their names.
Worlds can contain any number of imports and exports, and can be either a
function or an interface.
```wit
package local:demo
world command {
import wasi:filesystem/filesystem
import wasi:random/random
import wasi:clocks/monotonic-clock
// ...
export main: func(args: list<string>)
}
```
More information about the `wasi:random/random` syntax is available below in the
description of [`use`][use].
An imported or exported interface corresponds to an imported or exported
instance in the component model. Functions are equivalent to bare component
functions.
Additionally interfaces can be defined inline with an explicit kebab-name that
avoids the need to have an out-of-line definition.
```wit
package local:demo
interface out-of-line {
the-function: func()
}
world your-world {
import out-of-line
// ... is roughly equivalent to ...
import out-of-line: interface {
the-function: func()
}
}
```
The kebab name of the `import` or `export` is the name of the corresponding item
in the final component.
In the component model imports to a component either use an ID or a
kebab-name, and in WIT this is reflected in the syntax:
```wit
package local:demo
interface my-interface {
// ..
}
world command {
// generates an import of the ID `local:demo/my-interface`
import my-interface
// generates an import of the ID `wasi:filesystem/types`
import wasi:filesystem/types
// generates an import of the kebab-name `foo`
import foo: func()
// generates an import of the kebab-name `bar`
import bar: interface {
// ...
}
}
```
Kebab names cannot overlap and must be unique, even between imports and exports.
IDs, however, can be both imported and exported. The same interface cannot be
explicitly imported or exported twice.
### Union of Worlds with `include`
A World can be created by taking the union of two or more worlds. This operation allows world builders to form larger worlds from smaller worlds.
Below is a simple example of a world that includes two other worlds.
```wit
package local:demo
// definitions of a, b, c, foo, bar, baz are omitted
world my-world-a {
import a
import b
export c
}
world my-world-b {
import foo
import bar
export baz
}
world union-my-world {
include my-world-a
include my-world-b
}
```
The `include` statement is used to include the imports and exports of another World to the current World. It says that the new World should be able to run all components that target the included worlds and more.
The `union-my-world` World defined above is equivalent to the following World:
```wit
world union-my-world {
import a
import b
export c
import foo
import bar
export baz
}
```
The `include` statement also works with [WIT package](#wit-packages-and-use) defined below with the same semantics. For example, the following World `union-my-world-a` is equivalent to `union-my-world-b`:
```wit
package local:demo
interface b { ... }
interface a { ... }
world my-world-a {
import a
import b
import wasi:io/c
export d: interface { ... }
}
world union-my-world-a {
include my-world-a
}
world union-my-world-b {
import a
import b
import wasi:io/c
export d: interface { ... }
}
```
### De-duplication of IDs
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:
```wit
package local:demo
world my-world-a {
import a1
import b1
}
world my-world-b {
import a1
import b1
}
world union-my-world-a {
include my-world-a
include my-world-b
}
world union-my-world-b {
import a1
import b1
}
```
### Name Conflicts and `with`
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:
The following example shows how to resolve name conflicts where `union-my-world-a` and `union-my-world-b` are equivalent:
```wit
package local:demo
world world-one { import a: func() }
world world-two { import a: func() }
world union-my-world-a {
include world-one
include world-two with { a as b }
}
world union-my-world-b {
import a: func()
import b: func()
}
```
`with` cannot be used to rename IDs, however, so the following world would be invalid:
```wit
package local:demo
interface a {
foo: func()
}
world world-using-a {
import a
}
world invalid-union-world {
include my-using-a with { a as b } // invalid: 'a', which is short for 'local:demo/a', is an ID
}
```
### A Note on SubTyping
In the future, when `optional` export is supported, the world author may explicitly mark exports as optional to make a component targeting an included World a subtype of the union World.
For now, we are not following the subtyping rules for the `include` statement. That is, the `include` statement does not imply any subtyping relationship between the included worlds and the union world.
## WIT Packages and `use`
[use]: #wit-packages-and-use
A WIT package represents a unit of distribution that can be published to a
registry, for example, and used by other WIT packages. WIT packages are a flat
list of interfaces and worlds defined in `*.wit` files. The current thinking
for a convention is that projects will have a `wit` folder where all
`wit/*.wit` files within describe a single package.
The purpose of the `use` statement is to enable sharing types between
interfaces, even if they're defined outside of the current package in a
dependency. The `use` statement can be used both within interfaces and worlds
and at the top-level of a WIT file.
#### Interfaces, worlds, and `use`
A `use` statement inside of an `interface` or `world` block can be used to
import types:
```wit
package local:demo
interface types {
enum errno { /* ... */ }
type size = u32
}
interface my-host-functions {
use types.{errno, size}
}
```
The `use` target, `types`, is resolved within the scope of the package to an
interface, in this case defined prior. Afterwards a list of types are provided
as what's going to be imported with the `use` statement. The interface `types`
may textually come either after or before the `use` directive's interface.
Interfaces linked with `use` must be acyclic.
Names imported via `use` can be renamed as they're imported as well:
```wit
package local:demo
interface my-host-functions {
use types.{errno as my-errno}
}
```
This form of `use` is using a single identifier as the target of what's being
imported, in this case `types`. The name `types` is first looked up within the
scope of the current file, but it will additionally consult the package's
namespace as well. This means that the above syntax still works if the
interfaces are defined in sibling files:
```wit
// types.wit
interface types {
enum errno { /* ... */ }
type size = u32
}
// host.wit
package local:demo
interface my-host-functions {
use types.{errno, size}
}
```
Here the `types` interface is not defined in `host.wit` but lookup will find it
as it's defined in the same package, just instead in a different file.
When importing or exporting an [interface][interfaces] in a [world][worlds]
the same syntax is used in `import` and `export` directives:
```wit
// a.wit
package local:demo
world my-world {
import host
export another-interface
}
interface host {
// ...
}
// b.wit
interface another-interface {
// ...
}
```
When referring to an interface an ID form can additionally be used to refer to
dependencies. For example above it was seen:
```wit
package local:demo
world my-world {
import wasi:clocks/monotonic-clock
}
```
Here the interface being referred to is the ID `wasi:clocks/monotonic-clock`.
This is the package identified by `wasi:clocks` and the interface
`monotonic-clock` within that package. This same syntax can be used in `use` as
well:
```wit
package local:demo
interface my-interface {
use wasi:http/types.{request, response}
}
```
#### Top-level `use`
If a package being referred to has a version number, then using the above syntax
so far it can get a bit repetitive to be referred to:
```wit
package local:demo
interface my-interface {
use wasi:http/types@1.0.0.{request, response}
}
world my-world {
import wasi:http/handler@1.0.0
export wasi:http/handler@1.0.0
}
```
To reduce repetition and to possibly help avoid naming conflicts the `use`
statement can additionally be used at the top-level of a file to rename
interfaces within the scope of the file itself. For example the above could be
rewritten as:
```wit
package local:demo
use wasi:http/types@1.0.0
use wasi:http/handler@1.0.0
interface my-interface {
use types.{request, response}
}
world my-world {
import handler
export handler
}
```
The meaning of this and the previous world are the same, and `use` is purely a
developer convenience for providing smaller names if necessary.
The interface referred to by a `use` is the name that is defined in the current
file's scope:
```wit
package local:demo
use wasi:http/types // defines the name `types`
use wasi:http/handler // defines the name `handler`
```
Like with interface-level-`use` the `as` keyword can be used to rename the
inferred name:
```wit
package local:demo
use wasi:http/types as http-types
use wasi:http/handler as http-handler
```
Note that these can all be combined to additionally import packages with
multiple versions and renaming as different identifiers.
```wit
package local:demo
use wasi:http/types@1.0.0 as http-types1
use wasi:http/types@2.0.0 as http-types2
// ...
```
### Transitive imports and worlds
A `use` statement is not implemented by copying type information around but
instead retains that it's a reference to a type defined elsewhere. This
representation is plumbed all the way through to the final component, meaning
that `use`d types have an impact on the structure of the final generated
component.
For example this document:
```wit
package local:demo
interface shared {
record metadata {
// ...
}
}
world my-world {
import host: interface {
use shared.{metadata}
get: func() -> metadata
}
}
```
would generate this component:
```wasm
(component
(import (interface "local:demo/shared") (instance $shared
(type $metadata (record (; ... ;)))
(export "metadata" (type (eq $metadata)))
))
(alias export $shared "metadata" (type $metadata_from_shared))
(import "host" (instance $host
(export $metadata_in_host "metadata" (type (eq $metadata_from_shared)))
(export "get" (func (result $metadata_in_host)))
))
)
```
Here it can be seen that despite the `world` only listing `host` as an import
the component additionally imports a `local:demo/shared` interface. This is due
to the fact that the `use shared.{ ... }` implicitly requires that `shared` is
imported into the component as well.
Note that the name `"local:demo/shared"` here is derived from the name of the
`interface` plus the package ID `local:demo`.
For `export`ed interfaces any transitively `use`d interface is assumed to be an
import unless it's explicitly listed as an export.
> **Note**: It's planned in the future to have "power user syntax" to configure
> this on a more fine-grained basis for exports, for example being able to
> configure that a `use`'d interface is a particular import or a particular
> export.
## WIT Functions
[functions]: #wit-functions
Functions are defined in an [`interface`][interfaces] or are listed as an
`import` or `export` from a [`world`][worlds]. Parameters to a function must all
be named and have unique names:
```wit
package local:demo
interface foo {
a1: func()
a2: func(x: u32)
a3: func(y: u64, z: float32)
}
```
Functions can return at most one unnamed type:
```wit
package local:demo
interface foo {
a1: func() -> u32
a2: func() -> string
}
```
And functions can also return multiple types by naming them:
```wit
package local:demo
interface foo {
a: func() -> (a: u32, b: float32)
}
```
Note that returning multiple values from a function is not equivalent to
returning a tuple of values from a function. These options are represented
distinctly in the component binary format.
## WIT Types
[types]: #wit-types
Types in WIT files can only be defined in [`interface`s][interfaces] at this
time. The types supported in WIT is the same set of types supported in the
component model itself:
```wit
package local:demo
interface foo {
// "package of named fields"
record r {
a: u32,
b: string,
}
// values of this type will be one of the specified cases
variant human {
baby,
child(u32), // optional type payload
adult,
}
// similar to `variant`, but no type payloads
enum errno {
too-big,
too-small,
too-fast,
too-slow,
}
// similar to `variant`, but doesn't require naming cases and all variants
// have a type payload -- note that this is not a C union, it still has a
// discriminant
union input {
u64,
string,
}
// a bitflags type
flags permissions {
read,
write,
exec,
}
// type aliases are allowed to primitive types and additionally here are some
// examples of other types
type t1 = u32
type t2 = tuple<u32, u64>
type t3 = string
type t4 = option<u32>
type t5 = result<_, errno> // no "ok" type
type t6 = result<string> // no "err" type
type t7 = result<char, errno> // both types specified
type t8 = result // no "ok" or "err" type
type t9 = list<string>
type t10 = t9
}
```
The `record`, `variant`, `enum`, `union`, and `flags` types must all have names
associated with them. The `list`, `option`, `result`, `tuple`, and primitive
types do not need a name and can be mentioned in any context. This restriction
is in place to assist with code generation in all languages to leverage
language-builtin types where possible while accommodating types that need to be
defined within each language as well.
## WIT Identifiers
[identifiers]: #wit-identifiers
Identifiers in WIT documents are required to be valid component identifiers,
meaning that they're "kebab cased". This currently is restricted to ascii
characters and numbers that are `-` separated.
For more information on this see the [binary format](./Binary.md).
# Lexical structure
[lexical-structure]: #lexical-structure
The `wit` format is a curly-braced-based format where whitespace is optional (but
recommended). A `wit` document is parsed as a unicode string, and when stored in
a file is expected to be encoded as utf-8.
Additionally, wit files must not contain any bidirectional override scalar
values, control codes other than newline, carriage return, and horizontal tab,
or codepoints that Unicode officially deprecates or strongly discourages.
The current structure of tokens are:
```ebnf
token ::= whitespace
| operator
| keyword
| integer
| identifier
```
Whitespace and comments are ignored when parsing structures defined elsewhere
here.
### Whitespace
A `whitespace` token in `wit` is a space, a newline, a carriage return, a
tab character, or a comment:
```ebnf
whitespace ::= ' ' | '\n' | '\r' | '\t' | comment
```
### Comments
A `comment` token in `wit` is either a line comment preceded with `//` which
ends at the next newline (`\n`) character or it's a block comment which starts
with `/*` and ends with `*/`. Note that block comments are allowed to be nested
and their delimiters must be balanced
```ebnf
comment ::= '//' character-that-isnt-a-newline*
| '/*' any-unicode-character* '*/'
```
There is a special type of comment called `documentation comment`. A
`doc-comment` is either a line comment preceded with `///` which ends at the next
newline (`\n`) character or it's a block comment which starts with `/**` and ends
with `*/`. Note that block comments are allowed to be nested and their delimiters
must be balanced
```ebnf
doc-comment ::= '///' character-that-isnt-a-newline*
| '/**' any-unicode-character* '*/'
```
### Operators
There are some common operators in the lexical structure of `wit` used for
various constructs. Note that delimiters such as `{` and `(` must all be
balanced.
```ebnf
operator ::= '=' | ',' | ':' | ';' | '(' | ')' | '{' | '}' | '<' | '>' | '*' | '->' | '/' | '.' | '@'
```
### Keywords
Certain identifiers are reserved for use in `wit` documents and cannot be used
bare as an identifier. These are used to help parse the format, and the list of
keywords is still in flux at this time but the current set is:
```ebnf
keyword ::= 'use'
| 'type'
| 'resource'
| 'func'
| 'record'
| 'enum'
| 'flags'
| 'variant'
| 'union'
| 'static'
| 'interface'
| 'world'
| 'import'
| 'export'
| 'package'
| 'include'
```
### Integers
Integers are currently only used for package versions and are a contiguous
sequence of digits:
```ebnf
integer ::= [0-9]+
```
## Top-level items
A `wit` document is a sequence of items specified at the top level. These items
come one after another and it's recommended to separate them with newlines for
readability but this isn't required.
Concretely, the structure of a `wit` file is:
```ebnf
wit-file ::= package-decl? (toplevel-use-item | interface-item | world-item)*
```
## Package declaration
WIT files optionally start with a package declaration which defines the ID of
the package.
```ebnf
package-decl ::= 'package' id ':' id ('@' valid-semver)?
```
The production `valid-semver` is as defined by
[Semantic Versioning 2.0](https://semver.org/) and optional.
## Item: `toplevel-use`
A `use` statement at the top-level of a file can be used to bring interfaces
into the scope of the current file and/or rename interfaces locally for
convenience:
```ebnf
toplevel-use-item ::= 'use' interface ('as' id)?
interface ::= id
| id ':' id '/' id ('@' valid-semver)?
```
Here `interface` is the ID used to refer to interfaces. The bare form `id`
refers to interfaces defined within the current package, and the full form
refers to interfaces in package dependencies.
The `as` syntax can be optionally used to specify a name that should be assigned
to the interface. Otherwise the name is inferred from `interface`.
## Item: `world`
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.
Concretely, the structure of a world is:
```ebnf
world-item ::= 'world' id '{' world-items* '}'
world-items ::= export-item | import-item | use-item | typedef-item | include-item
export-item ::= 'export' id ':' extern-type
| 'export' interface
import-item ::= 'import' id ':' extern-type
| 'import' interface
extern-type ::= func-type | 'interface' '{' interface-items* '}'
```
Note that worlds can import types and define their own types to be exported
from the root of a component and used within functions imported and exported.
The `interface` item here additionally defines the grammar for IDs used to refer
to `interface` items.
## Item: `include`
A `include` statement enables the union of the current world with another world. The structure of an `include` statement is:
```wit
include wasi:io/my-world-1 with { a as a1, b as b1 }
include my-world-2
```
```ebnf
include-item ::= 'include' use-path
| 'include' use-path 'with' '{' include-names-list '}'
include-names-list ::= include-names-item
| include-names-list ',' include-names-item
include-names-item ::= id 'as' id
```
## Item: `interface`
Interfaces can be defined in a `wit` file. Interfaces have a name and a
sequence of items and functions.
Specifically interfaces have the structure:
> **Note**: The symbol `ε`, also known as Epsilon, denotes an empty string.
```ebnf
interface-item ::= 'interface' id '{' interface-items* '}'
interface-items ::= typedef-item
| use-item
| func-item
typedef-item ::= resource-item
| variant-items
| record-item
| union-items
| flags-items
| enum-items
| type-item
func-item ::= id ':' func-type
func-type ::= 'func' param-list result-list
param-list ::= '(' named-type-list ')'
result-list ::= ϵ
| '->' ty
| '->' '(' named-type-list ')'
named-type-list ::= ϵ
| named-type ( ',' named-type )*
named-type ::= id ':' ty
```
## Item: `use`
A `use` statement enables importing type or resource definitions from other
wit packages or interfaces. The structure of a use statement is:
```wit
use an-interface.{a, list, of, names}
use my:dependency/the-interface.{more, names as foo}
```
Specifically the structure of this is:
```ebnf