Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

[interpreter] Fix JS generator - #34

Merged
rossberg merged 5 commits into
masterfrom
fix-js
Mar 30, 2019
Merged

rossberg merged 5 commits into
masterfrom
fix-js

Conversation

@rossberg

Copy link
Copy Markdown
Member

Fix bugs reported by @gahaas.

@rossberg
rossberg requested a review from gahaas March 29, 2019 01:02
Comment thread interpreter/script/js.ml Outdated
{module_name = Utf8.decode "spectest"; item_name = Utf8.decode "eq_ref";
idesc = FuncImport (4l @@ at) @@ at} @@ at ]
in
let idesc_is_func = match idesc.it with FuncImport _ -> 1l | _ -> 0l in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't completely understand the logic here, but for me it causes an off-by-one error. Just using
let item = Lib.List32.length imports @@ at in in the next line fixes the problem for me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that went the wrong way round. Replaced with a correct and less brittle version.

Comment thread interpreter/script/js.ml
"\n" ^
"function exports(instance) {\n" ^
" return {module: instance.exports, host: {ref: hostref}};\n" ^
" return {module: instance.exports, spectest: spectest};\n" ^

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated module expects an import spectest::eq_ref. Could you extend spectest above with an eq_ref field?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, some tests expect that hostref(1) provide an exported wasm function, but it doesn't.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added missing eq_ref. I'm not sure I understand your other comment. Which test is this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the test in ref_is_null.wast:33, hostref(1) is passed in as a valid value of funcref. However, afaict, it is not a valid value. When I change hostref(1) with $1.exports["funcref-elem"], which is a valid funcref value, the test passes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks! That test actually was bogus (but the interpreter does not type-check script commands like invoke -- it probably should). I removed it.

@rossberg rossberg left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the mess, I had no way of testing this on my end.

Comment thread interpreter/script/js.ml
"\n" ^
"function exports(instance) {\n" ^
" return {module: instance.exports, host: {ref: hostref}};\n" ^
" return {module: instance.exports, spectest: spectest};\n" ^

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added missing eq_ref. I'm not sure I understand your other comment. Which test is this?

Comment thread interpreter/script/js.ml Outdated
{module_name = Utf8.decode "spectest"; item_name = Utf8.decode "eq_ref";
idesc = FuncImport (4l @@ at) @@ at} @@ at ]
in
let idesc_is_func = match idesc.it with FuncImport _ -> 1l | _ -> 0l in

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that went the wrong way round. Replaced with a correct and less brittle version.

@rossberg
rossberg merged commit d9ebd33 into master Mar 30, 2019
@rossberg
rossberg deleted the fix-js branch March 30, 2019 07:59
rossberg pushed a commit that referenced this pull request Nov 20, 2019
This commit fixes #34 by specifying that the flags field (which
indicates if a segment is passive) is a `varuint32` instead of a
`uint8`. It was discovered in #34 that the memory index located at that
position today is a `varuint32`, which can be validly encoded as `0x80
0x00` in addition to `0x00` (in addition to a number of other
encodings). This means that if the first field were repurposed as a
single byte of flags, it would break these existing modules that work
today.

It's not currently known how many modules in the wild actually take
advantage of such an encoding, but it's probably better to be safe than
sorry!

Closes #34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants