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
merged 5 commits into from
Mar 30, 2019
Merged

[interpreter] Fix JS generator #34

merged 5 commits into from
Mar 30, 2019

Conversation

rossberg
Copy link
Member

Fix bugs reported by @gahaas.

@rossberg rossberg requested a review from gahaas March 29, 2019 01:02
@@ -347,6 +346,8 @@ let wrap item_name wrap_action wrap_assertion at =
{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
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
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.

@@ -83,7 +83,7 @@ let harness =
"}\n" ^
"\n" ^
"function exports(instance) {\n" ^
" return {module: instance.exports, host: {ref: hostref}};\n" ^
" return {module: instance.exports, spectest: spectest};\n" ^
Copy link
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
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
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
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
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.

Copy link
Member Author

@rossberg rossberg left a comment

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.

@@ -83,7 +83,7 @@ let harness =
"}\n" ^
"\n" ^
"function exports(instance) {\n" ^
" return {module: instance.exports, host: {ref: hostref}};\n" ^
" return {module: instance.exports, spectest: spectest};\n" ^
Copy link
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?

@@ -347,6 +346,8 @@ let wrap item_name wrap_action wrap_assertion at =
{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
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