@@ -142,10 +142,9 @@ interface types {
142
142
143
143
More information about [ ` use ` ] [ use ] and [ types] are described below, but this
144
144
is an example of a collection of items within an ` interface ` . All items defined
145
- in an ` interface ` , including [ ` use ` ] [ use ] items, are considered as exports from
146
- the interface. This means that types can further be used from the interface by
147
- other interfaces. An interface has a single namespace which means that none of
148
- the defined names can collide.
145
+ in an ` interface ` are considered as exports from the interface. This means that
146
+ types can further be used from the interface by other interfaces. An interface
147
+ has a single namespace which means that none of the defined names can collide.
149
148
150
149
A WIT package can contain any number of interfaces listed at the top-level and
151
150
in any order. The WIT validator will ensure that all references between
589
588
### Transitive imports and worlds
590
589
591
590
A ` use ` statement is not implemented by copying type information around but
592
- instead retains that it's a reference to a type defined elsewhere. This
593
- representation is plumbed all the way through to the final component, meaning
594
- that ` use ` d types have an impact on the structure of the final generated
595
- component.
591
+ instead retains that it's a reference to a type that must have already been
592
+ imported or exported.
596
593
597
594
For example this document:
598
595
599
596
``` wit
600
597
package local:demo;
601
598
602
599
interface shared {
603
- record metadata {
600
+ resource metadata {
604
601
// ...
605
602
}
606
603
}
607
604
608
605
world my-world {
606
+ import shared; // required by 'use'
609
607
import host: interface {
610
608
use shared.{metadata};
611
609
@@ -617,52 +615,53 @@ world my-world {
617
615
would generate this component:
618
616
619
617
``` wasm
620
- (component
618
+ (component $C
621
619
(import "local:demo/shared" (instance $shared
622
- (type $metadata (record (; ... ;)))
623
- (export "metadata" (type (eq $metadata)))
620
+ (export "metadata" (type (sub resource)))
624
621
))
625
622
(alias export $shared "metadata" (type $metadata_from_shared))
626
623
(import "host" (instance $host
627
- (export $metadata_in_host "metadata" (type (eq $metadata_from_shared) ))
628
- (export "get" (func (result $metadata_in_host )))
624
+ (alias outer $C $metadata_from_shared (type $metadata ))
625
+ (export "get" (func (result $metadata )))
629
626
))
630
627
)
631
628
```
632
629
633
- Here it can be seen that despite the ` world ` only listing ` host ` as an import
634
- the component additionally imports a ` local:demo/shared ` interface. This is due
635
- to the fact that the ` use shared.{ ... } ` implicitly requires that ` shared ` is
636
- imported into the component as well .
630
+ Thus, the ` metadata ` resource type defined in the ` shared ` interface is
631
+ directly shared (via Component Model ` alias ` definitions) with the ` host `
632
+ interface. If the ` import shared; ` line were deleted, this WIT document would
633
+ fail to validate since there is no ` shared.metadata ` type to ` use ` .
637
634
638
635
Note that the name ` "local:demo/shared" ` here is derived from the name of the
639
636
` interface ` plus the package name ` local:demo ` .
640
637
641
- For ` export ` ed interfaces, any transitively ` use ` d interface is assumed to be an
642
- import unless it's explicitly listed as an export. For example, here ` w1 ` is
643
- equivalent to ` w2 ` :
638
+ For ` export ` ed interfaces, any transitively ` use ` d interfaces can be satisfied
639
+ by * either* imports or exports.
640
+
641
+ For example, the following world ` w ` uses both the imported ` r ` defined by ` a `
642
+ and the exported ` s ` defined by ` b ` :
644
643
``` wit
645
644
interface a {
646
645
resource r;
647
646
}
648
647
interface b {
649
- use a.{r};
650
- foo: func() -> r;
651
- }
652
-
653
- world w1 {
654
- export b;
648
+ resource s;
655
649
}
656
- world w2 {
650
+ world w {
657
651
import a;
658
652
export b;
653
+ export converter: interface {
654
+ use a.{r};
655
+ use b.{s};
656
+ convert: func(in: r) -> s;
657
+ }
659
658
}
660
659
```
661
660
662
- > ** Note** : It's planned in the future to have "power user syntax" to configure
663
- > this on a more fine-grained basis for exports, for example being able to
664
- > configure that a ` use ` 'd interface is a particular import or a particular
665
- > export .
661
+ > ** Note** : It's planned in the future to add additional syntax to support and
662
+ > disambiguate the case where the same interface is both imported and exported.
663
+ > With this addition, ` w ` could contain ` import b ` and ` converter ` could ` use `
664
+ > * both * the imported ` s ` * and * the exported ` s ` .
666
665
667
666
## WIT Functions
668
667
[ functions ] : #wit-functions
@@ -1898,6 +1897,7 @@ package wasi:http;
1898
1897
1899
1898
world proxy {
1900
1899
import wasi:logging/logger;
1900
+ import types;
1901
1901
import handler;
1902
1902
export handler;
1903
1903
}
0 commit comments