WebAssembly / spec

WebAssembly specification, reference interpreter, and test suite.
https://webassembly.github.io/spec/
Other
3.13k stars 445 forks source link

Is this explained in detail in spec? (in the prescribed order) #1600

Closed 1046102779 closed 1 year ago

1046102779 commented 1 year ago

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?

rossberg commented 1 year ago

The actual order is given by the grammar that follows this explanation.

1046102779 commented 1 year ago

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.

rossberg commented 1 year ago

Sorry, I may not have been clear, the grammar is normative, so it is the specification.

1046102779 commented 1 year ago

In addition to custom section, other sections must strictly increase in accordance with the section id ?

rossberg commented 1 year ago

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?

tlively commented 1 year ago

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.

1046102779 commented 1 year ago

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.

rossberg commented 1 year ago

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).

rossberg commented 1 year ago

Closing as answered.