@@ -116,7 +116,7 @@ would correspond to:
116
116
)
117
117
```
118
118
119
- An ` interface ` can contain [ ` use ` ] [ use ] statements, [ type] [ types ] definitions,
119
+ An ` interface ` can contain [ ` use ` ] [ use ] and [ ` nest ` ] [ nest ] statements, [ type] [ types ] definitions,
120
120
and [ function] [ functions ] definitions. For example:
121
121
122
122
``` wit
@@ -136,7 +136,7 @@ interface types {
136
136
}
137
137
```
138
138
139
- More information about [ ` use ` ] [ use ] and [ types] are described below, but this
139
+ More information about [ ` use ` ] [ use ] , [ ` nest ` ] [ nest ] , and [ types] are described below, but this
140
140
is an example of a collection of items within an ` interface ` . All items defined
141
141
in an ` interface ` , including [ ` use ` ] [ use ] items, are considered as exports from
142
142
the interface. This means that types can further be used from the interface by
@@ -660,6 +660,59 @@ world w2 {
660
660
> configure that a ` use ` 'd interface is a particular import or a particular
661
661
> export.
662
662
663
+ ## Nesting WIT interfaces
664
+ [ nest ] : #nesting-wit-interfaces
665
+ Interfaces can also export other interfaces via the ` nest ` keyword.
666
+ With the ` nest ` keyword, one can reference other interfaces in the same package, foreign packages, or simply define anonymous interfaces inline.
667
+
668
+ ``` wit
669
+ package local:example;
670
+
671
+ interface foo {
672
+ ...
673
+ }
674
+
675
+ interface top {
676
+ nest foo
677
+ nest foreign:pkg/bar;
678
+ baz: interface {
679
+ ...
680
+ }
681
+ }
682
+ ```
683
+
684
+ Each of these forms of nesting interfaces are encoded as:
685
+
686
+ ``` wasm
687
+ (component
688
+ (type (;0;)
689
+ (instance
690
+ ... `types from foo`
691
+ )
692
+ )
693
+ (export "local:example/foo" (type 0))
694
+ (type (;1;)
695
+ (instance
696
+ (alias outer 0 0 (type (;0;)))
697
+ (export "local:example/foo" (instance (type 0)))
698
+ (type (;1;)
699
+ (instance
700
+ ... `types from foreign:pkg/bar`
701
+ )
702
+ )
703
+ (export "foreign:pkg/bar" (instance (type 1)))
704
+ (type (;2;)
705
+ (instance
706
+ ... `types from baz`
707
+ )
708
+ )
709
+ (export "baz" (instance (type 2)))
710
+ )
711
+ )
712
+ (export "local:example/top (type 1))
713
+ )
714
+ ```
715
+
663
716
## WIT Functions
664
717
[ functions ] : #wit-functions
665
718
0 commit comments