Stream: general

Topic: formatting component-model-typed values


view this post on Zulip Dan Gohman (Aug 17 2023 at 19:22):

Are there any conventions yet for formatting component-model-typed values to text? Like, a common way of rendering variant/result/flags/etc. to JSON, or some other format?

view this post on Zulip Lann Martin (Aug 17 2023 at 20:20):

I've been working on this JSON repr: https://hackmd.io/@lann/rJFNJ2Mhn

For the best language interoperability, numbers > (2^53 – 1) or < -(2^53 - 1) should be serialized as base-10 strings.

view this post on Zulip Lann Martin (Aug 17 2023 at 20:21):

I tried to follow web api conventions wrt e.g. results, which may make it a little odd-looking to some

view this post on Zulip Robin Brown (Aug 21 2023 at 13:31):

How well do the representation of specialized types map to their despecialized equivalents as defined in e.g. the Canonical ABI doc?

view this post on Zulip Lann Martin (Aug 21 2023 at 13:47):

Not well; I prioritized concision and some broad "JSON conventionality"

view this post on Zulip Lann Martin (Aug 21 2023 at 13:49):

Note though that WIT itself can't represent all of the despecialized equivalents since several of them use numeric field/variant labels.

view this post on Zulip Lann Martin (Sep 12 2023 at 20:17):

I have an initial implementation of the above serialization format: https://github.com/lann/wasmtime-component-serde

Contribute to lann/wasmtime-component-serde development by creating an account on GitHub.

view this post on Zulip Dan Gohman (Sep 12 2023 at 20:34):

Cool!

view this post on Zulip Dan Gohman (Sep 12 2023 at 20:34):

Perhaps at some point we should move wasmtime::component::{Type, Val} out into a separate crate so that tools like this can use them without pulling in all of wasmtime

view this post on Zulip Lann Martin (Sep 12 2023 at 20:37):

You currently can't construct recursively-defined Types without instantiating a (dummy) component either.

view this post on Zulip Lann Martin (Sep 12 2023 at 20:37):

At least not via publicly documented interfaces that I've seen.

view this post on Zulip Lann Martin (Sep 12 2023 at 20:39):

I had to resort to this and this to test complex types.

view this post on Zulip Dan Gohman (Sep 12 2023 at 20:49):

I'm a little surprised serde-json doesn't handle things like serializing big numbers or Infinity into strings automatically. I think that means that the comment is right; we may eventually need different serde serializations for different backends.

view this post on Zulip Pat Hickey (Sep 12 2023 at 21:14):

wrt moving component::{Type, Val} out to a separate crate, it would also be really cool if we could move the Lift, Lower, ComponentVal traits as well, so that wasmtime-wit-bindgen wouldnt actually imply a dependency on wasmtime unless the user wants it. that would let us make wasmtime-wasi work across runtimes again

view this post on Zulip Pat Hickey (Sep 12 2023 at 21:15):

well, again as in, like wasi-common did before i got rid of lucet compatibility in wiggle.

view this post on Zulip Pat Hickey (Sep 12 2023 at 21:16):

i believe the story was that wasm3 was using wasi-common somewhere? tbh i cant remember who reported they were sad that i broke it

view this post on Zulip Pat Hickey (Sep 12 2023 at 21:18):

but idk, maybe the counter-argument is that ComponentVal is a huge chunk of the component runtime's complexity and it cant be extracted. i havent tried to do it.


Last updated: Dec 23 2024 at 13:07 UTC