Adapt wasmTextToBinary for multi-value
Categories
(Core :: JavaScript: WebAssembly, enhancement, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox72 | --- | fixed |
People
(Reporter: lth, Assigned: lth)
References
Details
Attachments
(3 files, 3 obsolete files)
wasmTextToBinary needs to handle multi-value situations properly. This is probably a substantial job, see discussions on bug 1527871 comment 3 et seq, bug 1584097 for starters. In the former thread, wingo writes:
"If you were to fix wasmTextToBinary, I think you would start by removing AstExprType and AstExpr from WasmAST.h. Because we want to test cases in which values flow in through stack parameters rather than restricting to nested parameters, this abstraction doesn't work. Of course this means lots of adaptation both in WasmTextToBinary but also the AsmJS compiler and the wasm encoder. You would get to keep most concrete classes (e.g. AstCall) but they would inherit from AstNode and not store a type and not reference subexpressions. Then I think I would move to implement the unfolding algorithm from the spec. It would be a big couple patches and I would estimate it to take about 10 working days or so."
My only comment to that is that I don't think asm.js is actually affected, but it does look like a substantial piece of work in any case.
Assignee | ||
Comment 1•5 years ago
|
||
Assignee | ||
Comment 2•5 years ago
|
||
First patch gets rid of AstExprType and allows a FuncType reference to be encoded as part of the new AstBlockType, used for BLOCK, LOOP, and IF. We need access to the AstModule during parsing so this patch puts it into the parsing context and gets rid of the module argument, that can be factored out. The patch is otherwise not quite clean, probably some code can be merged / refactored.
Anyway this is enough to allow us to parse eg (block (result i32 i32) E1 E2) i32.add
, but other issues around expression parsing still disallow the parsing of the parenthesized form (i32.add (block (result i32 i32) E1 E2))
. I know that syntax is considered well-formed but frankly I'm uncertain that that's actually a feature.
But problems elsewhere - notably, function types are not allowed by the validator to have more than one result - prevent us from doing much more than parsing at the moment.
Assignee | ||
Comment 3•5 years ago
|
||
Updated•5 years ago
|
Assignee | ||
Comment 4•5 years ago
|
||
Depends on D51316
Assignee | ||
Comment 5•5 years ago
|
||
This patch set has a bug, it uses an overly elaborate (and incorrect) encoding for the function index. Fix coming.
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Comment 6•5 years ago
|
||
Clever hack! Thank you so much for this!!!
Assignee | ||
Comment 7•5 years ago
|
||
Updated•5 years ago
|
Updated•5 years ago
|
Assignee | ||
Comment 10•5 years ago
|
||
This probably needs to be amended to change the encoding of the function index, this should be a 33-bit sleb, not a 32-bit uleb as now. We won't notice any problems until we start testing wasm content from other producers.
Comment 11•5 years ago
|
||
Note that the maximum number of types is 1e7, if that makes encoding the s33 any easier: http://webassembly.github.io/spec/js-api/index.html#limits
Assignee | ||
Comment 12•5 years ago
|
||
Yeah, it means we can use writeVarS32 at least to write it, though I'm not sure yet about decoding whether readVarS32() has the exact semantics we want. It probably does, because it must read up to ceil(32/7) bytes and it's required to read up to ceil(33/7) bytes, and those two values are the same.
The problems I encountered before with readValType were probably spurious: in an older draft, I thought I needed to encode this type with a TypeCode::Func prefix, and that would have led the decoder into readValType, where it should not be.
Assignee | ||
Comment 13•5 years ago
|
||
Function indices must be encoded as sleb33 to disambiguate from
valtypes, which are slebs. The enclosed test demonstrates a case
where the uleb encoding results in an error.
Drive-by fix: change nomenclature in wasmTextToBinary to match
nomenclature used elsewhere.
Assignee | ||
Comment 14•5 years ago
|
||
Wingo will incorporate this into his tests when he lands them.
Depends on D51780
Updated•5 years ago
|
Assignee | ||
Updated•5 years ago
|
Comment 15•5 years ago
|
||
Comment 16•5 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/1ff758d2b677
https://hg.mozilla.org/mozilla-central/rev/0de1220699ef
https://hg.mozilla.org/mozilla-central/rev/1605a3463b56
https://hg.mozilla.org/mozilla-central/rev/57442cf2bb9d
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Description
•