bytecodealliance / bytecodealliance/wasm-tools

wit: propose to propogate World's name to inline Interfaces' names

Open
#1,805 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.8k
Forks
351
Avg merge
16h 57m
Merged PRs (30d)
38

Description

Consider the following WIT file

```wit
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](https://github.com/bytecodealliance/wit-bindgen/blob/main/crates/core/src/lib.rs#L66) 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` to `String`, and should use the correct naming mechanism so that tools like `wit-bindgen` or `wit-bindgen-go` do not have to [guess](https://github.com/bytecodealliance/wasm-tools-go/pull/173) 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

```wat
(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:

```wit
world only-exports {
export example:name/exports;
export exports: interface {
foo: func();
}
}
```

wasm-tools will throw an error saying
```bash
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.

CC @alexcrichton

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.