Improving std.wasm

Why doesn’t the std.wasm.Valtype match the valtype in the WASM specification?

std.wasm.Valtype contains only numtype and vectype, but according to Wasm Spec, valtype contains these and reftype.

I have several suggestions:

  1. std.wasm.Valtype should be separated into numtype and vectype defined as Wasm Spec.
  2. std.wasm.Valtype should contain numtype, vectype and reftype. One way is that defines std.wasm.Valtype as union.
  3. the fields of std.wasm.Type are not defined as Optional, so they cannot be represented as so-called void types (functions that do not take arguments and do not return results).

I have read about this issue:

I know only a part of std.wasm and WebAssembly, and would like to discuss this with Zig users.
Any questions or comments are welcome!

I think the simplist explanation is that the standard library currently serves the needs of the zig compiler, and the zig compiler does not currently use reftypes in wasm. At least that is my guess.

I have been working on a WebAssembly interpreter in Zig as a side project, and ran into this as well. From what I can tell, the Zig std library only contains the parts of wasm needed to compile zig to wasm. It does not contain all the things needed for decoding WASM in zig. There were a couple types that I had to implement myself but I was able to us a lot of the std library. It may also be that they just didn’t add reftype to valtype yet.

So the void types in Wasm are just 0 params and 0 returns, as far as I can tell. So a void type would just be a std.wasm.Type but with a slice of 0 elements for both the params and the returns.

2 Likes