wit: propose to propogate World's name to inline Interfaces' names #1805
Description
Consider the following WIT file
package example:name;
interface exports {
foo: func();
}
world only-exports {
export exports;
export exports: interface {
foo: func();
}
}
The Resolve
representation of the above World will have two interfaces, one with name: Some("exports")
and the other with name: None
, but it left some ambiguity on how to interpret the name of the second "annonymous" interface. For example, in wit-bindgen
, the interpretation of the name of the seond interface is the World's key name, namely "exports"
.
I am proposing to change the type of Interface::name
from Option<String>
to String
, and should use the correct naming mechanism so that tools like wit-bindgen
or wit-bindgen-go
do not have to guess what interface names are in case when they are inlinedly defined.
The first export's name should be "example:name/exports"
, and the second export's name should be "exports"
, so that there is no colliding. It also matches the definition in the component model spec.
For reference, this is the wat
representation of the above WIT
(component
(type (;0;)
(component
(type (;0;)
(instance
(type (;0;) (func))
(export (;0;) "foo" (func (type 0)))
)
)
(export (;0;) "example:name/exports" (instance (type 0)))
)
)
(export (;1;) "exports" (type 0))
(type (;2;)
(component
(type (;0;)
(component
(type (;0;)
(instance
(type (;0;) (func))
(export (;0;) "foo" (func (type 0)))
)
)
(export (;0;) "example:name/exports" (instance (type 0)))
(type (;1;)
(instance
(type (;0;) (func))
(export (;0;) "foo" (func (type 0)))
)
)
(export (;1;) "exports" (instance (type 1)))
)
)
(export (;0;) "example:name/only-exports" (component (type 0)))
)
)
(export (;3;) "only-exports" (type 2))
(@custom "package-docs" "\00{}")
(@producers
(processed-by "wit-component" "0.216.0")
)
)
Discussion
In addition to the proposal, I found that it's a bit strange that I can't reference the first export using a fully qualified name like the one below:
world only-exports {
export example:name/exports;
export exports: interface {
foo: func();
}
}
wasm-tools will throw an error saying
error: package depends on itself
--> testdata/issues/issue170.wit:8:10
|
8 | export example:name/exports;
| ^-----------
I realized this is, by design, prohibited, but I have to admit that it striked me as a surprise.