bytecodealliance / bytecodealliance/wasm-tools
Validation of exporting instance types with resources is not correct
- Dominant language
- Rust
- Stars
- 1.8k
- Forks
- 351
- Avg merge
- 16h 57m
- Merged PRs (30d)
- 38
Description
This component is currently rejected:
```wasm
(component
(type $t (instance
(export $x1 "x1" (type (sub resource)))
(export "f1" (func (result (own $x1))))
))
(export "t" (type $t))
)
```
```
$ cargo run validate foo.wat --features component-model
Finished dev [unoptimized + debuginfo] target(s) in 3.71s
Running `target/debug/wasm-tools validate foo.wat --features component-model`
error: type not valid to be used as export (at offset 0x26)
```
but this component should be valid.
https://github.com/bytecodealliance/wasm-tools/pull/1251 was a historical version of starting this, but required solving the problem of going from `ResourceId` to `TypeId` in a more robust way. That'd require some extra fields to be tracked in component instance types.
One reason we decided not to fix it at the time of that PR is that this starts opening some larger questions which we're not entirely sure the answer to about what possible ways to fix this are in scope and which modules are valid and not. To sidestep these questions we figured it'd be best to leave the current validation in place which effectively rejects any instance types with resources in them. This is not correct but hopefully won't cause any road bumps for anyone else down the line for awhile at least. The thinking is that when there's a more formal definition of the component model's validation rules we can rely on that for providing better answers of what's valid and what's not and better design a solution within those constraints.
Contributor guide
Assessment
This issue has not been assessed yet.