After I run the wasm-tools compose
example, I cannot run wasm-tools component wit
on the composed component. I get the following error:
Error: failed to decode WIT document
Caused by:
0: failed to decode WIT from import `streams`
1: unexpected unnamed type
Is this expected?
If not I can look into tomorrow and see if there’s a possible fix.
That looks like a bug, possibly in wasm-tools compose
, but I'd have to dig in to say for sure
Ok cool. I’ll debug it tomorrow and try to push a fix.
So the current error seems to be caused by an incorrect encoding of an instance during the composition:
(component
(type (;0;)
(instance
(type (;0;) u32)
(export (;1;) "wall-clock" (type (eq 0)))
(type (;2;) (record (field "seconds" u64) (field "nanoseconds" u32)))
(export (;3;) "datetime" (type (eq 2)))
(type (;4;) (func (param "this" 1) (result 3))) ;; NOTE: the result points to the "datetime" export
(export (;0;) "now" (func (type 4)))
)
)
(component
(type (;0;)
(instance
(type (;0;) u32)
(export (;1;) "wall-clock" (type (eq 0)))
(type (;2;) (record (field "seconds" u64) (field "nanoseconds" u32)))
(export (;3;) "datetime" (type (eq 2)))
(type (;4;) (func (param "this" 0) (result 2))) ;; NOTE: the result type points directly to the record
(export (;0;) "now" (func (type 4)))
)
)
At some point this instance seems to have one of its functions changed so that its result type points directly to a record field (which is illegal) instead of pointing to a type.
This particular instance is not itself being composed (i.e., it should be fine for the composer to just round trip).
So I'm not sure if this is some mistake in how the compose code decodes instances or if its an issue with the encoder.
I suspect that this may be an issue with both the decoder and encoder perhaps? The constructs used here were added after the initial implementation of wasm-compose
so it hasn't been updated to use exports in the same way. The decoder probably needs an update to read the structure of use-the-exported-item and the encoder needs to be updated to use items as they're exported. Shouldn't be too hard ideally as wit-component
deals with similar problems as well, but if you'd like I think opening an issue for this would be good
Done https://github.com/bytecodealliance/wasm-tools/issues/977
Last updated: Dec 23 2024 at 12:05 UTC