@@ -1051,7 +1051,8 @@ world-items ::= gate world-definition
1051
1051
1052
1052
world-definition ::= export-item
1053
1053
| import-item
1054
- | use-item
1054
+ | use-export-item
1055
+ | use-import-item
1055
1056
| typedef-item
1056
1057
| include-item
1057
1058
@@ -1060,6 +1061,9 @@ export-item ::= 'export' id ':' extern-type
1060
1061
import-item ::= 'import' id ':' extern-type
1061
1062
| 'import' use-path ';'
1062
1063
1064
+ use-import-item ::= 'use' 'import' use-item-body
1065
+ use-export-item ::= 'use' 'export' use-item-body
1066
+
1063
1067
extern-type ::= func-type ';' | 'interface' '{' interface-items* '}'
1064
1068
```
1065
1069
@@ -1068,6 +1072,27 @@ from the root of a component and used within functions imported and exported.
1068
1072
The ` interface ` item here additionally defines the grammar for IDs used to refer
1069
1073
to ` interface ` items.
1070
1074
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
+
1071
1096
[ `componenttype` ] : Explainer.md#type-definitions
1072
1097
1073
1098
## Item: ` include `
@@ -1144,7 +1169,9 @@ use my:dependency/the-interface.{more, names as foo}
1144
1169
Specifically the structure of this is:
1145
1170
1146
1171
``` 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 '}' ';'
1148
1175
1149
1176
use-names-list ::= use-names-item
1150
1177
| use-names-item ',' use-names-list?
0 commit comments