wasm-tools icon indicating copy to clipboard operation
wasm-tools copied to clipboard

Nested interfaces in wit

Open macovedj opened this issue 8 months ago • 3 comments

This PR enables the ability to describe nested interfaces in wit via the nest keyword.

package foo:bar;

interface baz {
  nest other:pkg/qux
}

This would indicate that that the instance associated with baz would export the instance associated with interface qux from package other:pkg.

(component 
  (type instance
    (type instance 
    ... definition of "other:pkg/qux" 
    )
   (export "other:pkg/qux" type 0)
  )
  (export "foo:bar/baz" type 0)
)

As I understand it, most use cases most immediately benefit from nesting interfaces from foreign packages, so I started with that, though we could certainly extend this PR or have follow ups to support any combo of locally defined/inlined/anonymous interfaces being nested.

This issue points out that wit currently is not able to express nested instances that can be expressed in wat/binary, so wit-bindgen can't be used by language toolchains to generate that binary. This syntax can be leveraged so that the unlocked dependency syntax referenced in the linked issue can specify the exports it expects in the imports it's describing.

macovedj avatar Jun 19 '24 18:06 macovedj