Skip to content

Commit f61d68b

Browse files
committed
Split 'use' inside worlds into 'use import' and 'use export'
1 parent f0487b2 commit f61d68b

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

design/mvp/WIT.md

+28-2
Original file line numberDiff line numberDiff line change
@@ -897,13 +897,16 @@ Concretely, the structure of a world is:
897897
```ebnf
898898
world-item ::= 'world' id '{' world-items* '}'
899899
900-
world-items ::= export-item | import-item | use-item | typedef-item | include-item
900+
world-items ::= export-item | import-item | use-export-item | use-import-item | typedef-item | include-item
901901
902902
export-item ::= 'export' id ':' extern-type
903903
| 'export' use-path ';'
904904
import-item ::= 'import' id ':' extern-type
905905
| 'import' use-path ';'
906906
907+
use-import-item ::= 'use' 'import' use-item-body
908+
use-export-item ::= 'use' 'export' use-item-body
909+
907910
extern-type ::= func-type ';' | 'interface' '{' interface-items* '}'
908911
```
909912

@@ -912,6 +915,27 @@ from the root of a component and used within functions imported and exported.
912915
The `interface` item here additionally defines the grammar for IDs used to refer
913916
to `interface` items.
914917

918+
The `use export`/`use import` items work just like `use` inside an `interface`
919+
except that they exclusively refer to exports/imports, respectively. This
920+
allows a world to import and export the same interface and be able to
921+
independently refer to same type in both. For example, the following world
922+
defines a single function using both an imported and exported version of the
923+
same interface's resource type:
924+
925+
```wit
926+
interface i {
927+
resource r;
928+
}
929+
930+
world w {
931+
import i;
932+
export i;
933+
use import i.{r as r1};
934+
use export i.{r as r2};
935+
export transform: func(in: r1) -> r2;
936+
}
937+
```
938+
915939
## Item: `include`
916940

917941
A `include` statement enables the union of the current world with another world. The structure of an `include` statement is:
@@ -983,7 +1007,9 @@ use my:dependency/the-interface.{more, names as foo}
9831007
Specifically the structure of this is:
9841008

9851009
```ebnf
986-
use-item ::= 'use' use-path '.' '{' use-names-list '}' ';'
1010+
use-item ::= 'use' use-item-body
1011+
1012+
use-item-body ::= use-path '.' '{' use-names-list '}' ';'
9871013
9881014
use-names-list ::= use-names-item
9891015
| use-names-item ',' use-names-list?

0 commit comments

Comments
 (0)