Skip to content

Commit a4dcbe8

Browse files
committed
Split 'use' inside worlds into 'use import' and 'use export'
1 parent 2a3a6dd commit a4dcbe8

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

design/mvp/WIT.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,8 @@ world-items ::= gate world-definition
10511051
10521052
world-definition ::= export-item
10531053
| import-item
1054-
| use-item
1054+
| use-export-item
1055+
| use-import-item
10551056
| typedef-item
10561057
| include-item
10571058
@@ -1060,6 +1061,9 @@ export-item ::= 'export' id ':' extern-type
10601061
import-item ::= 'import' id ':' extern-type
10611062
| 'import' use-path ';'
10621063
1064+
use-import-item ::= 'use' 'import' use-item-body
1065+
use-export-item ::= 'use' 'export' use-item-body
1066+
10631067
extern-type ::= func-type ';' | 'interface' '{' interface-items* '}'
10641068
```
10651069

@@ -1068,6 +1072,27 @@ from the root of a component and used within functions imported and exported.
10681072
The `interface` item here additionally defines the grammar for IDs used to refer
10691073
to `interface` items.
10701074

1075+
The `use export`/`use import` items work just like `use` inside an `interface`
1076+
except that they exclusively refer to exports/imports, respectively. This
1077+
allows a world to import and export the same interface and be able to
1078+
independently refer to same type in both. For example, the following world
1079+
defines a single function using both an imported and exported version of the
1080+
same interface's resource type:
1081+
1082+
```wit
1083+
interface i {
1084+
resource r;
1085+
}
1086+
1087+
world w {
1088+
import i;
1089+
export i;
1090+
use import i.{r as r1};
1091+
use export i.{r as r2};
1092+
export transform: func(in: r1) -> r2;
1093+
}
1094+
```
1095+
10711096
[`componenttype`]: Explainer.md#type-definitions
10721097

10731098
## Item: `include`
@@ -1144,7 +1169,9 @@ use my:dependency/the-interface.{more, names as foo}
11441169
Specifically the structure of this is:
11451170

11461171
```ebnf
1147-
use-item ::= 'use' use-path '.' '{' use-names-list '}' ';'
1172+
use-item ::= 'use' use-item-body
1173+
1174+
use-item-body ::= use-path '.' '{' use-names-list '}' ';'
11481175
11491176
use-names-list ::= use-names-item
11501177
| use-names-item ',' use-names-list?

0 commit comments

Comments
 (0)