component-model icon indicating copy to clipboard operation
component-model copied to clipboard

Allow exporting types directly worlds without interface

Open jcbhmr opened this issue 1 year ago • 1 comments

Components are also able to directly export types, so it is just a temporary WIT limitation that you're not able to define and export the math-class enum directly in the world. We should probably fix that to avoid this question.

In the meantime, you can also write:

world w {
  export types: interface {
    enum math-class { ... }
  }
}

Originally posted by @lukewagner in https://github.com/WebAssembly/component-model/issues/295#issuecomment-1904839659

The ideal is to somehow have the math-class enum on the root world instead of nested inside a redundant interface name. Unsure if you still want to pursue this.

jcbhmr avatar Dec 05 '24 07:12 jcbhmr

I think this is still a good idea. The general goal here is to achieve full co-expressivity between WIT and component-model types and indeed today in component-model WAT, you can define a type:

(type $w (component
  (type $math-class (enum ...))
  (export "math-class" (type (eq $math-class)))
))

so it makes sense for us to provide a WIT "rendering" of this raw WAT type. My best guess is that it would look like:

world w {
  export math-class: enum { ... }
}

symmetric to how named and unnamed interfaces work. It's mostly just a matter of prioritization and getting someone (with enough WIT tooling experience) to work on an implementation to co-develop with the spec (since the devil is in the details here). I do think we'll want to prioritize co-expressivity before declaring a complete 1.0 though.

lukewagner avatar Dec 05 '24 23:12 lukewagner