Stream: general

Topic: webassembly type


view this post on Zulip Peter Bocan (Dec 01 2022 at 19:49):

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.

view this post on Zulip Chris Fallin (Dec 01 2022 at 19:51):

These are signature types that can be used e.g. on call_indirects. 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

view this post on Zulip Peter Bocan (Dec 01 2022 at 19:59):

does it make sense to generate them all the time or only when needed?

view this post on Zulip Chris Fallin (Dec 01 2022 at 20:01):

the binary format requires them (the indirection into the type section is how all function signatures are encoded)

view this post on Zulip Chris Fallin (Dec 01 2022 at 20:02):

in the text format, I think in every place you can say (type N) you can also say (func (param ...) (result ...))

view this post on Zulip Peter Bocan (Dec 01 2022 at 20:09):

ah alright, is there a need to define types manually in the text format? I may need to read more on that.

view this post on Zulip Chris Fallin (Dec 01 2022 at 20:15):

I don't think so, no, it's enough to write the signatures directly where you define or import functions

view this post on Zulip Chris Fallin (Dec 01 2022 at 20:15):

I'm 95% sure you can do it inline on call_indirect instructions too but I'd have to double-check

view this post on Zulip Alex Crichton (Dec 01 2022 at 20:27):

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

view this post on Zulip Alex Crichton (Dec 01 2022 at 20:27):

if you define the same type inline in multiple places in the text format it's deduplicated in the final binary produced


Last updated: Nov 22 2024 at 16:03 UTC