-
Notifications
You must be signed in to change notification settings - Fork 758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix binary parser of declarative element segments #6618
Conversation
I'm not very familiar with this part of the spec, but it looks like there are broken tests on CI here so perhaps additional changes are needed? |
Thanks! Indeed, it seems like the problem is, we have to switch the ![]() And, also some tests need to be fixed. I'll take a look |
4269354
to
9b56e6d
Compare
I think I could fix the issue, but in my local environment some tests are still fail because of the following error message
which seems some kind of problem in my local setup(?) and unrelated to the change (actually it fails even in |
Maybe the local error is due to the Line 4 in 06cbe01
The code here looks right to me. Please add a test for this so we don't regress it. The test could be under |
Thanks @kripken ! Now, I'm struggling to test this change because
That's why, it is not possible to test parsing of declared element segments based on the output of binaryen. A possible approach would be to use another tool (e.g., the reference interpreter?) to generate a binary with declared elements and test if binaryen can parse that.
Ah, it looks like |
Note that the SExpressionWasmBuilder is deprecated and about to be removed in #6607. The parser your tests are using is implemented in the src/parser directory. It still doesn't preserve declarative segments in the IR, though. This is a case where checking in a binary test would be appropriate. Other such tests live in the test/lit/binary directory. |
The parser was incorrectly handling the parsing of declarative element segments whose `init` is a `vec(expr)`. https://webassembly.github.io/spec/core/binary/modules.html#element-section Binry parser was simply reading a single `u32LEB` value for `init` instead of parsing a expression regardless `usesExpressions = true`. This commit updates the `WasmBinaryReader::readElementSegments` function to correctly parse the expressions for declarative element segments by calling `readExpression` instead of `getU32LEB` when `usesExpressions = true`. Resolves the parsing exception: "[parse exception: bad section size, started at ... not being equal to new position ...]" Related discussion: tanishiking/scala-wasm#136
9b56e6d
to
36bb145
Compare
Thanks, I added a test for |
Can you move the test to |
…`vec(expr)` This commit adds a binary in `test/lit/binary` that is generated from the following WAT file with a reference-interpreter from the `wasm-3.0-exn` branch: WebAssembly/spec@b16745e ```wat (module (elem declare funcref (item ref.func $f)) (func $f (block (ref.func $f) (drop) )) ) ``` The disassembled result contains `(elem declare func $f)` instead of `(elem declare funcref (item ref.func $f))` because the binaryen parser doesn't preserve declarative segments. This is fine, as we test that the binary parser can parse the declarative element segment whose `init` is `vec(expr)` without trapping.
36bb145
to
02efecd
Compare
Sure, moved the test to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
The parser was incorrectly handling the parsing of declarative element segments (those with the
elemkind
ofdeclarative
).According to the spec, the
init
of the declarative element should be avec(expr)
if the prefix is 7.https://webassembly.github.io/spec/core/binary/modules.html#element-section
However, binaryen was simply reading a single
u32LEB
value for eachexpression instead of parsing a expression regardless
usesExpressions = true
.This commit updates the
WasmBinaryReader::readElementSegments
functionto correctly parse the expressions for declarative element segments by
calling
readExpression
instead ofgetU32LEB
ifusesExpressions = true
.Resolves the parsing exception:
"[parse exception: bad section size, started at ... not being equal to new position ...]"
Related discussion: tanishiking/scala-wasm#136