Skip to content
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

Basic EH instrucion support for the new spec #3487

Merged
merged 11 commits into from
Jan 15, 2021

Conversation

aheejin
Copy link
Member

@aheejin aheejin commented Jan 13, 2021

This updates try-catch-catch_all and rethrow instructions to
match the new spec. delegate is not included. Now Try contains not a
single catchBody expression but a vector of catch
bodies and events.

This updates most existing routines, optimizations, and tests modulo the
interpreter and the CFG traversal. Because the interpreter has not been
updated yet, the EH spec test is temporarily disabled in check.py. Also,
because the CFG traversal for EH is not yet updated, several EH tests in
rse_all-features.wast, which uses CFG traversal, are temporarily
commented out.

Also added a few more tests in existing EH test functions in
test/passes. In the previous spec, catch was catching all exceptions
so it was assumed that anything try body throws is caught by its
catch, but now we can assume the same only if there is a catch_all.
Newly added tests test cases when there is a catch_all and cases there
are only catches separately.

This updates `try`-`catch`-`catch_all` and `rethrow` instructions to
match the new spec. `delegate` is not included. Now `Try` contains not a
single `catchBody` expression but a vector of catch
bodies and events.

This updates most existing routines, optimizations, and tests modulo the
interpreter and the CFG traversal. Because the interpreter has not been
updated yet, the EH spec test is temporarily disabled in check.py. Also,
because the CFG traversal for EH is not yet updated, several EH tests in
`rse_all-features.wast`, which uses CFG traversal, are temporarily
commented out.
src/ir/cost.h Show resolved Hide resolved
src/wasm/wasm-stack.cpp Outdated Show resolved Hide resolved
test/break-within-catch.wasm.fromBinary Show resolved Hide resolved
test/exception-handling.wast.fromBinary Show resolved Hide resolved
@aheejin
Copy link
Member Author

aheejin commented Jan 13, 2021

Currently binaryen.js tests fail. They will pass after #3486 lands.

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Initial set of comments.

Great to see this update!

src/wasm.h Outdated Show resolved Hide resolved
src/binaryen-c.cpp Outdated Show resolved Hide resolved
src/binaryen-c.h Show resolved Hide resolved
src/cfg/cfg-traversal.h Outdated Show resolved Hide resolved
src/ir/ExpressionAnalyzer.cpp Outdated Show resolved Hide resolved
src/wasm-interpreter.h Show resolved Hide resolved
test/passes/vacuum_all-features.wast Outdated Show resolved Hide resolved
src/wasm/wasm-stack.cpp Outdated Show resolved Hide resolved
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

Looks good overall! Just a few questions and small suggestions.

src/js/binaryen.js-post.js Show resolved Hide resolved
src/passes/CodeFolding.cpp Outdated Show resolved Hide resolved
src/wasm/wasm-s-parser.cpp Show resolved Hide resolved
src/wasm/wasm-s-parser.cpp Outdated Show resolved Hide resolved
src/wasm/wasm-validator.cpp Outdated Show resolved Hide resolved
Comment on lines 2102 to 2104
// TODO Validate depth field if it becomes necessary in future. This requires
// a separate stack for 'catch', and the current LLVM toolchain only generates
// depth 0 for C++ support.
Copy link
Member

Choose a reason for hiding this comment

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

Would it be worth validating that depth is 0 for now? Or do you plan to resolve this TODO in the near future?

Copy link
Member Author

Choose a reason for hiding this comment

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

Validating this requires maintaining a separate stack within the validator, which is not difficult but I'm not very sure if it's worth it at the moment, so I don't have a plan to add that in near future, but if you think it's important we can change priorities. But at the same time I think rejecting values other than 0 can be risky, because binaryen is not guaranteed to take wasm code produced only by our LLVM toolchain.

Copy link
Member

Choose a reason for hiding this comment

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

My thinking here is that it would be better to reject a valid program that uses non-zero depths than to accidentally and silently mis-optimize the program because we don't reason about non-zero depths right now. Or do we handle non-zero depths correctly in the optimization passes already?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think optimization passes will change the depth field, because they don't have any way of reasoning about that field. But yeah, there can be optimizations that remove or alter try-catch structure that are targeted by rethrow. I can't think of any optimization pass that does that right now though.

For one, Vacuum removes try-catch altogether if the body of try does not throw. But this case is OK for rethrow because it removes the whole catch body. But there can be other passes that might interfere with rethrow, as you pointed out.

I'll reject non-zero depths for now for safe measure.

test/binaryen.js/exception-handling.js Show resolved Hide resolved
test/exception-handling.wast.fromBinary Show resolved Hide resolved
test/passes/simplify-locals_all-features.wast Outdated Show resolved Hide resolved
test/passes/simplify-locals_all-features.wast Show resolved Hide resolved
aheejin and others added 4 commits January 14, 2021 17:14
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Thanks, looks like my comments are all addressed, and I don't see anything else, lgtm. Nice work!

Btw, about debug info for catches, I can look into that eventually, unless you want to.

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

The only unresolved conversation from my comments is whether or not to reject programs with nonzero rethrow depths for now, but I don't feel strongly about it either way. Whatever you think is best there is fine with me 👍

@aheejin
Copy link
Member Author

aheejin commented Jan 15, 2021

Btw, about debug info for catches, I can look into that eventually, unless you want to.

Oh, I would appreciate that 😀

@aheejin aheejin merged commit beccdf7 into WebAssembly:master Jan 15, 2021
@aheejin aheejin deleted the eh_new_insts branch January 15, 2021 09:48
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.

None yet

3 participants