Skip to content

Commit

Permalink
nested interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
macovedj committed Jun 24, 2024
1 parent 9eda882 commit e960dde
Showing 1 changed file with 55 additions and 2 deletions.
57 changes: 55 additions & 2 deletions design/mvp/WIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ would correspond to:
)
```

An `interface` can contain [`use`][use] statements, [type][types] definitions,
An `interface` can contain [`use`][use] and [`nest`][nest] statements, [type][types] definitions,
and [function][functions] definitions. For example:

```wit
Expand All @@ -136,7 +136,7 @@ interface types {
}
```

More information about [`use`][use] and [types] are described below, but this
More information about [`use`][use], [`nest`][nest], and [types] are described below, but this
is an example of a collection of items within an `interface`. All items defined
in an `interface`, including [`use`][use] items, are considered as exports from
the interface. This means that types can further be used from the interface by
Expand Down Expand Up @@ -660,6 +660,59 @@ world w2 {
> configure that a `use`'d interface is a particular import or a particular
> export.
## Nesting WIT interfaces
[nest]: #nesting-wit-interfaces
Interfaces can also export other interfaces via the `nest` keyword.
With the `nest` keyword, one can reference other interfaces in the same package, foreign packages, or simply define anonymous interfaces inline.

```wit
package local:example;
interface foo {
...
}
interface top {
nest foo
nest foreign:pkg/bar;
baz: interface {
...
}
}
```

Each of these forms of nesting interfaces would be encoded as:

```wasm
(component
(type (;0;)
(instance
... `types from foo`
)
)
(export "local:example/foo" (type 0))
(type (;1;)
(instance
(alias outer 0 0 (type (;0;)))
(export "local:example/foo" (instance (type 0)))
(type (;1;)
(instance
... `types from foreign:pkg/bar`
)
)
(export "foreign:pkg/bar" (instance (type 1)))
(type (;2;)
(instance
... `types from baz`
)
)
(export "baz" (instance (type 2)))
)
)
(export "local:example/top (type 1))
)
```

## WIT Functions
[functions]: #wit-functions

Expand Down

0 comments on commit e960dde

Please sign in to comment.