@@ -366,6 +366,31 @@ world union-my-world-b {
366366}
367367```
368368
369+ When a world being included contains plain-named imports or exports that
370+ reference a named interface (using the ` id: use-path ` syntax), the ` with `
371+ keyword renames the plain-name label while preserving the underlying
372+ ` [implements=<I>] ` annotation in the encoding. For example:
373+
374+ ``` wit
375+ package local:demo;
376+
377+ interface store {
378+ get: func(key: string) -> option<string>;
379+ }
380+
381+ world base {
382+ import cache: store;
383+ }
384+
385+ world extended {
386+ include base with { cache as my-cache }
387+ }
388+ ```
389+
390+ In this case, ` extended ` has a single import with the plain name ` my-cache `
391+ that implements ` local:demo/store ` , equivalent to writing
392+ ` import my-cache: store; ` directly.
393+
369394` with ` cannot be used to rename interface names, however, so the following
370395world would be invalid:
371396``` wit
@@ -1381,9 +1406,30 @@ export-item ::= 'export' id ':' extern-type
13811406import-item ::= 'import' id ':' extern-type
13821407 | 'import' use-path ';'
13831408
1384- extern-type ::= func-type ';' | 'interface' '{' interface-items* '}'
1409+ extern-type ::= func-type ';' | 'interface' '{' interface-items* '}' | use-path ';'
1410+ ```
1411+
1412+ The third case of ` extern-type ` allows a named interface to be imported or
1413+ exported with a custom [ plain name] . For example:
1414+
1415+ ``` wit
1416+ world my-world {
1417+ import primary: wasi:keyvalue/store;
1418+ import secondary: wasi:keyvalue/store;
1419+ export my-handler: wasi:http/handler;
1420+ }
13851421```
13861422
1423+ Here, ` primary ` and ` secondary ` are two distinct imports that both have the
1424+ instance type of the ` wasi:keyvalue/store ` interface. The plain name of the
1425+ import is the ` id ` before the colon (e.g., ` primary ` ), not the interface name.
1426+ This contrasts with ` import wasi:keyvalue/store; ` (without the ` id : ` prefix),
1427+ which would create a single import using the full interface name
1428+ ` wasi:keyvalue/store ` . Similarly, the export ` my-handler ` has the instance type
1429+ of ` wasi:http/handler ` but uses the plain name ` my-handler ` instead of the full
1430+ interface name, which is useful when a component wants to export the same
1431+ interface multiple times or simply use a more descriptive name.
1432+
13871433Note that worlds can import types and define their own types to be exported
13881434from the root of a component and used within functions imported and exported.
13891435The ` interface ` item here additionally defines the grammar for IDs used to refer
@@ -2061,6 +2107,52 @@ This duplication is useful in the case of cross-package references or split
20612107packages, allowing a compiled ` world ` definition to be fully self-contained and
20622108able to be used to compile a component without additional type information.
20632109
2110+ When a world imports or exports a named interface with a custom plain name
2111+ (using the ` id: use-path ` syntax), the encoding uses the ` [implements=<I>] `
2112+ annotation defined in [ Explainer.md] ( Explainer.md#import-and-export-definitions ) to indicate which
2113+ interface the instance implements. For example, the following WIT:
2114+
2115+ ``` wit
2116+ package local:demo;
2117+
2118+ interface store {
2119+ get: func(key: string) -> option<string>;
2120+ }
2121+
2122+ world w {
2123+ import one: store;
2124+ import two: store;
2125+ }
2126+ ```
2127+
2128+ is encoded as:
2129+
2130+ ``` wat
2131+ (component
2132+ (type (export "w") (component
2133+ (export "local:demo/w" (component
2134+ (import "[implements=<local:demo/store>]one" (instance
2135+ (export "get" (func (param "key" string) (result (option string))))
2136+ ))
2137+ (import "[implements=<local:demo/store>]two" (instance
2138+ (export "get" (func (param "key" string) (result (option string))))
2139+ ))
2140+ ))
2141+ ))
2142+ (type (export "store") (component
2143+ (export "local:demo/store" (instance
2144+ (export "get" (func (param "key" string) (result (option string))))
2145+ ))
2146+ ))
2147+ )
2148+ ```
2149+
2150+ The ` [implements=<local:demo/store>] ` prefix tells bindings generators and
2151+ toolchains which interface each plain-named instance import implements, while
2152+ the labels ` one ` and ` two ` provide distinct plain names. This is a case of
2153+ the general ` [implements=<interfacename>]label ` pattern described in
2154+ [ Explainer.md] ( Explainer.md#import-and-export-definitions ) .
2155+
20642156Putting this all together, the following WIT definitions:
20652157
20662158``` wit
0 commit comments