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

Validate stack height after unreachable #384

Merged
merged 3 commits into from
Jun 17, 2020
Merged

Conversation

gumb0
Copy link
Collaborator

@gumb0 gumb0 commented Jun 10, 2020

This applies the logic of Validation algorithm regarding unreachable to stack height checks.

Specifically

  • After unreachable any underflowing pop is ignored, but pushes add to stack growth.
    image

  • When current frame is marked unreachable, stack height is reset.
    image

"Simplify" commit is not squashed yet to show the different nested organization of nested ifs. I find the final one better.

@codecov
Copy link

codecov bot commented Jun 10, 2020

Codecov Report

Merging #384 into master will increase coverage by 0.20%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #384      +/-   ##
==========================================
+ Coverage   99.11%   99.32%   +0.20%     
==========================================
  Files          42       42              
  Lines       12357    12489     +132     
==========================================
+ Hits        12248    12405     +157     
+ Misses        109       84      -25     

@gumb0 gumb0 force-pushed the validate-unreachable-stack branch 2 times, most recently from c4fd3cb to 9a68bb8 Compare June 10, 2020 12:58
lib/fizzy/parser_expr.cpp Outdated Show resolved Hide resolved
@gumb0 gumb0 force-pushed the validate-unreachable-stack branch 5 times, most recently from b965217 to 37756a2 Compare June 10, 2020 18:14
@gumb0 gumb0 changed the title Validate stack height in blocks with unreachable Validate stack height after unreachable Jun 10, 2020
@gumb0 gumb0 force-pushed the validate-unreachable-stack branch 2 times, most recently from 5a2d02c to b2453a4 Compare June 11, 2020 09:47
@gumb0 gumb0 marked this pull request as ready for review June 11, 2020 09:50
@gumb0 gumb0 force-pushed the validate-unreachable-stack branch from b2453a4 to 1e69b62 Compare June 11, 2020 10:40
// Update code's max_stack_height using frame.stack_height of the previous instruction.
// At this point frame.stack_height includes additional changes to the stack height
// if the previous instruction is a call/call_indirect.
// This way the update is skipped for end/else instructions (because their frame is
// already popped/reset), but it does not matter, as these instructions do not modify
// stack height anyway.
code.max_stack_height = std::max(code.max_stack_height, frame.stack_height);
}
if (!frame.unreachable)
Copy link
Collaborator Author

@gumb0 gumb0 Jun 11, 2020

Choose a reason for hiding this comment

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

If we pull this max_stack_height update out of outer if, it looks like we can unify stack height update/checks for instructions and for calls, not sure if it's worth it. The error message for stack underflow would not be specific for calls then...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this can be done in separate PR to confirm coverage of this version is full.

@gumb0 gumb0 requested review from chfast and axic June 11, 2020 10:45
@gumb0 gumb0 force-pushed the validate-unreachable-stack branch from 1e69b62 to ffc11b9 Compare June 11, 2020 13:53
Copy link
Collaborator

@chfast chfast left a comment

Choose a reason for hiding this comment

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

The final version looks good to me.

// Update code's max_stack_height using frame.stack_height of the previous instruction.
// At this point frame.stack_height includes additional changes to the stack height
// if the previous instruction is a call/call_indirect.
// This way the update is skipped for end/else instructions (because their frame is
// already popped/reset), but it does not matter, as these instructions do not modify
// stack height anyway.
code.max_stack_height = std::max(code.max_stack_height, frame.stack_height);
}
if (!frame.unreachable)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this can be done in separate PR to confirm coverage of this version is full.

@gumb0 gumb0 force-pushed the validate-unreachable-stack branch from ffc11b9 to 9b6d045 Compare June 17, 2020 10:06
@gumb0
Copy link
Collaborator Author

gumb0 commented Jun 17, 2020

Squashed "simplify" commit.

@gumb0 gumb0 merged commit 2fcaf8c into master Jun 17, 2020
@gumb0 gumb0 deleted the validate-unreachable-stack branch June 17, 2020 10:29
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.

2 participants