Skip to content

Fix v8 validation error in -O0 builds #897

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

Closed
wants to merge 2 commits into from
Closed

Fix v8 validation error in -O0 builds #897

wants to merge 2 commits into from

Conversation

kripken
Copy link
Member

@kripken kripken commented Feb 4, 2017

v8 changed the validation rules to be closer to the spec interpreter, and we had a bug where we emitted the toplevel block of a returning function with an unreachable type, when it should be the return type.

…ust have the right type. ensure we generate it that way in asm2wasm, and keep it that way through refinalizations
@kripken
Copy link
Member Author

kripken commented Feb 4, 2017

As a followup, we should probably change wasm-validator to assert on this. However, doing so naively brings up errors, so let's leave that for later.

Copy link
Member

@dschuff dschuff left a comment

Choose a reason for hiding this comment

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

So this bug only affects the implicit function-scope block?

I guess i was confused about that last time I looked at that too, actually. In the binaryen IR it seems like the function body is not always a block (indicating that it could be implicit) but if it is a block, sometimes it is printed, and sometimes not. And sometimes it has a name, (and therefore can be targeted by breaks). Am I just confused? What are/should be the conventions for the function-level block (is it real or just a construct to make the IR cleaner? is it printed? does it have a name? does the function body have to be a block?)

@@ -107,6 +107,10 @@
cmd += ['-O0'] # test that -O0 does nothing
else:
cmd += ['-O']
if 'PRINT_FULL' in asm:
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is adding a class of tests that can be ran with BINARYEN_PRINT_FULL set, then the test that this PR adds should have a name besides just PRINT_FULL.asm, something like PRINT_FULL.unreachable_function_block_type.asm.js I'd think

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I considered that, but instead I documented this in more detail in the test itself. i.e., we might have just one PRINT_FULL file with multiple small unit tests inside it eventually, with some text describing each one in the file. I prefer that because a filename isn't much room to go into detail. if i'm in the minority though i can change that.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case why not have the test script only set this if asm == 'PRINT_FULL.asm.js'? That way the intent of multiple small tests in this one special file is documented by the code itself.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair point, I wanted to keep my options open ;) In case we do want multiple files, this would mean we don't need to change anything.

Anyhow, I don't feel strongly about any of it. If you do, let me know what you'd prefer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't feel strongly enough about it to block

Actually a best-of-both-worlds thing would be to leave the PRINT_FULL substring check, and rename the test to PRINT_FULL_generic.asm.js or something. That way both are reasonably-well supported, and it's more clear that generic tests go there.

@dschuff
Copy link
Member

dschuff commented Feb 4, 2017

Yeah the validator should definitely match whatever the spec and/or browsers do. I think validation is pretty ad-hoc right now because of the history of the IR (and the ways it differs now from wasm?). Anyway for now we can just fix this.

@kripken
Copy link
Member Author

kripken commented Feb 4, 2017

So this bug only affects the implicit function-scope block?

That seemed to be the case until I compiled bigger things ;) This fixes hello world, but there is a more complex validation error on hello_libcxx.cpp for example. As I mentioned on email, I don't understand the validation rules, so not sure what to do. But, probably we shouldn't merge this, as maybe the fix should be a more general one.

I guess i was confused about that last time I looked at that too, actually. In the binaryen IR it seems like the function body is not always a block (indicating that it could be implicit) but if it is a block, sometimes it is printed, and sometimes not. And sometimes it has a name, (and therefore can be targeted by breaks). Am I just confused?

Binaryen IR has the function body as an expression - not a list. Similar to loop, if, etc. - the only thing with a list is block.

We have an optimization to not print the block, if it's the toplevel of a function, loop or if, as the s-expression format allows them to have lists. PRINT_FULL overrides that, showing the full ast + types.

@kripken kripken mentioned this pull request Feb 6, 2017
@kripken
Copy link
Member Author

kripken commented Feb 7, 2017

This is obsoleted by #899.

@kripken kripken closed this Feb 7, 2017
@kripken kripken deleted the fix-O0-v8 branch February 17, 2017 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants