Hello folk! Can I ask what is the use for (type .. )
in WebAssembly? I am reading the spec, but I can fully grasp what is the point of it.
These are signature types that can be used e.g. on call_indirect
s. In the binary format, indices into the type section are used everywhere a function signature is needed -- at function declarations (in the function section), in imports, and at indirect calls
does it make sense to generate them all the time or only when needed?
the binary format requires them (the indirection into the type section is how all function signatures are encoded)
in the text format, I think in every place you can say (type N) you can also say (func (param ...) (result ...))
ah alright, is there a need to define types manually in the text format? I may need to read more on that.
I don't think so, no, it's enough to write the signatures directly where you define or import functions
I'm 95% sure you can do it inline on call_indirect
instructions too but I'd have to double-check
it's correct that you don't need to define the types in the text format, and all locations that can use a type you can define the type inline as well
if you define the same type inline in multiple places in the text format it's deduplicated in the final binary produced
Last updated: Dec 23 2024 at 12:05 UTC