@@ -116,7 +116,7 @@ would correspond to:
116116)
117117```
118118
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,
120120and [ function] [ functions ] definitions. For example:
121121
122122``` wit
@@ -136,7 +136,7 @@ interface types {
136136}
137137```
138138
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
140140is an example of a collection of items within an ` interface ` . All items defined
141141in an ` interface ` , including [ ` use ` ] [ use ] items, are considered as exports from
142142the interface. This means that types can further be used from the interface by
@@ -660,6 +660,59 @@ world w2 {
660660> configure that a ` use ` 'd interface is a particular import or a particular
661661> export.
662662
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+
663716## WIT Functions
664717[ functions ] : #wit-functions
665718
0 commit comments