bytecodealliance / bytecodealliance/wasm-tools

wasm-compose resource subtype mismatch

Open
#1,163 3 comments 1 reaction 0 assignees View on GitHub
component-model wasm-compose
Dominant language
Rust
Stars
1.8k
Forks
351
Avg merge
16h 57m
Merged PRs (30d)
38

Description

I have the following wit file:

```
package test:ser

interface serializer {
resource serializer-resource {
constructor()
serialize-i32: static func(self: serializer-resource, v: s32) -> string
}
}

world test-serialize {
import serializer
}

world test-serializer {
export serializer
}
```

and two WASM components which implement `test-serialize` and `test-serializer`, respectively (both are implemented in Rust and then transformed into components with `wasm-tools component new`).

I am trying to compose these two components such that the serialize component can construct a new `serializer-resource` and call a method on it, even though it imports both from another component, i.e. none of the functionality comes from the host.

When running `wasm-tools compose serialize.wasm -d serializer.wasm -o composed.wasm`, I get the following error:
```
error: failed to connect instance `$input` to definition component `./serializer.wasm`

Caused by:
0: source instance export `test:ser/serializer` is not compatible with target instance import `test:ser/serializer`
```

After a bit of digging, I found that the following two subtyping checks cause this error:
https://github.com/bytecodealliance/wasm-tools/blob/a0c46a7a16fef5cc9143ad30c77f19303c27d907/crates/wasmparser/src/validator/types.rs#L2521
and
https://github.com/bytecodealliance/wasm-tools/blob/a0c46a7a16fef5cc9143ad30c77f19303c27d907/crates/wasmparser/src/validator/types.rs#L3074

I have no idea why two independent resource IDs are generated even though the resource imported by the serialize component is the same as the resource exported by the serializer component. Crudely commenting out this check allows the components to be composed, and the composed component to be run in wasmtime, and the resource seems to work perfectly fine (constructor, method, and destructor are all called as expected).

Is there a way for the component subtyping match to succeed? Thank you for your help!

Attachments:
[serializer.zip](https://github.com/bytecodealliance/wasm-tools/files/12328877/serializer.zip)
[serialize.zip](https://github.com/bytecodealliance/wasm-tools/files/12328876/serialize.zip)

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.