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 types at branch instructions #408

Merged
merged 6 commits into from
Jul 28, 2020
Merged

Validate types at branch instructions #408

merged 6 commits into from
Jul 28, 2020

Conversation

gumb0
Copy link
Collaborator

@gumb0 gumb0 commented Jul 6, 2020

No description provided.

@codecov
Copy link

codecov bot commented Jul 6, 2020

Codecov Report

Merging #408 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           master     #408    +/-   ##
========================================
  Coverage   99.36%   99.37%            
========================================
  Files          49       49            
  Lines       14169    14345   +176     
========================================
+ Hits        14079    14255   +176     
  Misses         90       90            

@gumb0 gumb0 force-pushed the validate-types-br branch 3 times, most recently from fc8f134 to fa95a20 Compare July 7, 2020 14:07
@gumb0 gumb0 force-pushed the validate-types-br branch from fa95a20 to d400c57 Compare July 14, 2020 12:24
@gumb0 gumb0 changed the base branch from master to validate-types-block July 14, 2020 12:24
@gumb0 gumb0 force-pushed the validate-types-block branch 2 times, most recently from e8db0dc to 98ae70c Compare July 17, 2020 15:17
Base automatically changed from validate-types-block to master July 20, 2020 09:39
@axic
Copy link
Member

axic commented Jul 20, 2020

@gumb0 rebase please

@gumb0 gumb0 force-pushed the validate-types-br branch 5 times, most recently from ce7e981 to 294425e Compare July 20, 2020 13:36
// How many stack items to drop when taking the branch.
// This value can be negative for unreachable instructions.
const auto stack_drop = stack_height - branch_frame.parent_stack_height - arity;
const auto stack_drop = stack_height - branch_frame.parent_stack_height;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not needed to subtract arity now, because now we pop the result from stack before calling this function (in update_branch_stack)

@@ -557,6 +550,14 @@ parser_result<Code> parse_expr(const uint8_t* pos, const uint8_t* end, FuncIdx f

if (instr == Instr::br)
mark_frame_unreachable(frame, operand_stack);
else
{
// For the case when branch is not taken for br_if,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Validation Algorithm does something similar:

image

@gumb0 gumb0 force-pushed the validate-types-br branch from 012d40a to f0962f4 Compare July 20, 2020 18:34
@@ -455,7 +455,7 @@ TEST(validation, br_table_invalid_type)
(func (param $x i32)
(block $a (result i32)
(block $b (result i64)
i32.const 1
i64.const 1
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This fix is needed because now it fist checks the return type on the stack against default label type before iterating over all labels and checking there consistency.
(Without the fix it's "type mismatch" error instead of "inconsistent labels")

@gumb0 gumb0 marked this pull request as ready for review July 20, 2020 18:38
@gumb0 gumb0 requested review from chfast and axic July 20, 2020 18:44
@gumb0 gumb0 force-pushed the validate-types-br branch from f0962f4 to b977028 Compare July 27, 2020 12:40
@gumb0 gumb0 force-pushed the validate-types-br branch from b977028 to 053b6fe Compare July 28, 2020 09:48
@gumb0
Copy link
Collaborator Author

gumb0 commented Jul 28, 2020

Rebased.

@gumb0 gumb0 force-pushed the validate-types-br branch from 053b6fe to 935c588 Compare July 28, 2020 10:16

// Push frame start location as br immediates - these are final if frame is loop,
// but for block/if/else these are just placeholders, to be filled at end instruction.
push(immediates, static_cast<uint32_t>(branch_frame.code_offset));
push(immediates, static_cast<uint32_t>(branch_frame.immediates_offset));
push(immediates, static_cast<uint32_t>(stack_drop));
push(immediates, arity);
push(immediates, get_branch_arity(branch_frame));
Copy link
Member

Choose a reason for hiding this comment

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

What is the return type of get_branch_arity?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's uint8_t

Copy link
Member

Choose a reason for hiding this comment

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

I know the code prior was not clear too (with using auto), but can you leave a comment here stating it is uint8_t?

We have a separate PR which tries to change the types to unified uint32_t, but that showed slowdown: #376

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added comment.

@gumb0 gumb0 force-pushed the validate-types-br branch from 935c588 to a16aa56 Compare July 28, 2020 11:32
@gumb0 gumb0 force-pushed the validate-types-br branch from a16aa56 to 33eede1 Compare July 28, 2020 11:35
@axic axic merged commit 40011a9 into master Jul 28, 2020
@axic axic deleted the validate-types-br branch July 28, 2020 12:07
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