Stream: general

Topic: wasm-tools compose example


view this post on Zulip Ryan Levick (rylev) (Apr 10 2023 at 15:41):

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?

view this post on Zulip Ryan Levick (rylev) (Apr 10 2023 at 15:53):

If not I can look into tomorrow and see if there’s a possible fix.

view this post on Zulip Alex Crichton (Apr 10 2023 at 15:58):

That looks like a bug, possibly in wasm-tools compose, but I'd have to dig in to say for sure

view this post on Zulip Ryan Levick (rylev) (Apr 10 2023 at 16:06):

Ok cool. I’ll debug it tomorrow and try to push a fix.

view this post on Zulip Ryan Levick (rylev) (Apr 11 2023 at 12:26):

So the current error seems to be caused by an incorrect encoding of an instance during the composition:

Before 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)))
    )
  )

After 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" 0) (result 2))) ;; NOTE: the result type points directly to the record
      (export (;0;) "now" (func (type 4)))
    )
  )

view this post on Zulip Ryan Levick (rylev) (Apr 11 2023 at 12:29):

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.

view this post on Zulip Ryan Levick (rylev) (Apr 11 2023 at 12:43):

This particular instance is not itself being composed (i.e., it should be fine for the composer to just round trip).

view this post on Zulip Ryan Levick (rylev) (Apr 11 2023 at 12:43):

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.

view this post on Zulip Alex Crichton (Apr 11 2023 at 14:31):

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

view this post on Zulip Ryan Levick (rylev) (Apr 11 2023 at 15:17):

Done https://github.com/bytecodealliance/wasm-tools/issues/977

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 ...

Last updated: Nov 22 2024 at 16:03 UTC