Closed 1046102779 closed 1 year ago
The actual order is given by the grammar that follows this explanation.
The actual order is given by the grammar that follows this explanation.
If there is no spec and it is up to the implementer to interpret it, then all implementers will follow the broadest spec (that is, there is no order), otherwise there may be incompatibility.
Sorry, I may not have been clear, the grammar is normative, so it is the specification.
In addition to custom section
, other sections
must strictly increase in accordance with the section
id ?
Yes, this is also a consequence of the specified binary grammar and the order in which the different sections appear in it. Can you clarify what you think is left undetermined by the grammar?
There may be some confusion about what @rossberg means by "grammar." He's not referring to the English language grammar, but rather the technical grammar given for the WebAssembly language.
When we implement the WebAssembly bytecode interpreter, must we read and parse it in the order of mandatory increment of section id?
For example: when the import section with section id
=2 is read sequentially, must the next section ID read be 3 (Function Section
) instead of other section IDs?
Also when encoding, must we serialize and write bytecodes in the strict increasing order of WebAssembly bytecode segment IDs?
ps: ex
custom section
can appear anywhere.
The entire binary format is specified in terms of a BNF-style grammar given throughout the chapter. It determines precisely what binary "syntax" is legal for Wasm, and all standard-conforming tools producing or consuming Wasm must adhere to it. Please see the grammar production for module
, I believe it answers all questions with yes (but note that that any section may also be empty).
Closing as answered.
https://www.w3.org/TR/wasm-core-2/binary/modules.html#binary-module
The preamble is followed by a sequence of sections. Custom sections may be inserted at any place in this sequence, while other sections must occur at most once and in the prescribed order. All sections can be empty.
I don't see a relevant specific order requirement in the specification?