so, just before break my witx-test tool (a proptest generator for witx specs, plus a driver to use wasi-headers to generate a header and validate the header with clang) found some parts of the witx grammar that wasi-headers couldn't handle correctly
most of it is easy to fix, the tough part to crack is that the representation of witx arrays in C is tricky/inconstient
we currently don't have any way to deal with an array as a member of a struct, or a variant in a union
i think the correct way to deal with arrays in either of those cases is to define a struct array_$typename { $typename *ptr; size_t len; };
this is going to complicate the one-pass nature of the tool, but i dont think theres any other way to handle it correctly. does anyone have objections?
along those same lines - right now the wasi-headers tool hard codes its input files and output files. im going to extend the main to take an optional input and output path - if both are blank it will do what it does now, which is use the latest snapshot and output to the right spot in the libc. but in general i think its a pretty useful tool to use elsewhere
One option is just to return an error; WASI itself has no arrays inside of structs or unions
id argue that it already does have arrays inside structs, $iovec
and $ciovec
which are a pair of pointer and len
those should be arrays, i think, in order to get rid of pointers in witx. i dont want to figure out how to get rid of pointers today, but i want to eventaully :)
(reason being that pointers arent an interface type, but arrays are)
also, i just realized this issue would happen if you ever put a string
inside a struct or union as well
Yeah, that does make sense. I guess I'm just feeling a little conservative about supporting "arrays" which become pointers with not-entirely-obvious lifetimes outside of function parameters.
hmm. thats a fair concern
well, we can punt on it for now.
ill make a PR that fixes some simpler stuff, and panics in the code generator in these unsupported cases
Admittadly, the existing pointer
type isn't exactly watertight either.
But it feels different -- with interface types focusing on by-value semantics, if we have something that we describe as an "array", the value of the array should be passed by copy.
Also, there are ongoing discussions at the interface types level about the possibilty of making memory slices a proper thing in interface types, and if we get that, that could change how all of these things work.
i havent kept up to date on those discussions
So my instinct here is to not get too far ahead of those discussions.
ok, works for me
Last updated: Dec 23 2024 at 12:05 UTC