Skip to content

Fix inner block problem with 'catch' #3129

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

Merged
merged 3 commits into from
Sep 15, 2020

Conversation

aheejin
Copy link
Member

@aheejin aheejin commented Sep 14, 2020

Fixes #3114.

@aheejin aheejin requested review from kripken and tlively September 14, 2020 18:55
// block. Can be used when we need to assume certain number of values are on top
// of the stack in the beginning.
Expression* WasmBinaryBuilder::getBlockOrSingleton(Type type,
unsigned numPops) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This numPops thing was added to be used by catch, but now it does not use this method anymore, so deleted it.

@@ -2757,12 +2747,12 @@ void WasmBinaryBuilder::visitLoop(Loop* curr) {
auto start = expressionStack.size();
processExpressions();
size_t end = expressionStack.size();
if (start > end) {
throwError("block cannot pop from outside");
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This was just moved to make code cleaner (in my opinion)

@@ -0,0 +1,19 @@
(module
Copy link
Member Author

Choose a reason for hiding this comment

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

The original break-within-catch.wasm's wasm2wat output is this:

(module
  (type (;0;) (func))
  (func (;0;) (type 0)
    try  ;; label = @1
      nop
    catch
      drop
      br 0 (;@1;)
    end))

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.

Nice!

Comment changes are just suggestions, not sure how much they help.

auto* block = allocator.alloc<Block>();
block->list.push_back(curr);
block->name = catchLabel;
block->finalize(curr->type);
Copy link
Member

Choose a reason for hiding this comment

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

this could use a Builder and builder.makeBlock(catchLabel, curr) on a single line.

(maybe the previous block allocation too, but it's not an obvious win there since you need to manually call pushBlockElements anyhow.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Left the previous allocation as is, because of pushBlockElements as you said.

@aheejin aheejin merged commit bced89d into WebAssembly:master Sep 15, 2020
@aheejin aheejin deleted the fix_catch_block branch September 15, 2020 14:46
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.

exnref-related error in writing binary
2 participants