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

More stack height validation #319

Merged
merged 6 commits into from
May 21, 2020
Merged

More stack height validation #319

merged 6 commits into from
May 21, 2020

Conversation

chfast
Copy link
Collaborator

@chfast chfast commented May 19, 2020

This validates if frames leave enough results they promised, however this check is missing for function frames (function type information is missing, but this is fixed in #312 - see a TODO comment). The situation where there is more results left is also not reported, but is easy to add - see TODO comment. This cannot be applied now because a lot of false positives when function result arity is so far assumed 0.

The frame stack_height now uses absolute values what will be useful for jump resolving in #312 and makes computing code's max stack height straight forward (as it is max value of any frame.stack_height).

@chfast chfast force-pushed the max_stack_height branch 2 times, most recently from 49229ea to 0ee5474 Compare May 19, 2020 12:32
@chfast chfast marked this pull request as ready for review May 19, 2020 12:38
@chfast chfast requested review from axic and gumb0 May 19, 2020 12:38
@@ -76,6 +91,23 @@ void update_caller_frame(ControlFrame& frame, const FuncType& func_type)
frame.stack_height += stack_height_change;
}

void validate_result_count(const ControlFrame& frame)
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't this a helper or a constructor on ControlFrame?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Conceptually: because ControlFrame is pure data type, and it does not know how to do validation.
Also: there is update_caller_frame().

lib/fizzy/parser_expr.cpp Outdated Show resolved Hide resolved
lib/fizzy/parser_expr.cpp Outdated Show resolved Hide resolved
lib/fizzy/parser_expr.cpp Outdated Show resolved Hide resolved
@gumb0
Copy link
Collaborator

gumb0 commented May 19, 2020

This commit I think should be enough to get function arity information 5e86830

@chfast
Copy link
Collaborator Author

chfast commented May 19, 2020

This commit I think should be enough to get function arity information 5e86830

I'm leaving this for later, so we can parallelize validation and stack optimization PRs.

lib/fizzy/parser_expr.cpp Outdated Show resolved Hide resolved
@@ -87,7 +121,9 @@ parser_result<Code> parse_expr(const uint8_t* pos, const uint8_t* end, const Mod
// For a block/if/else instruction the value is the block/if/else's immediate offset.
std::stack<ControlFrame> control_stack;

control_stack.push({Instr::block}); // The function's implicit block.
// TODO: Get function result arity from the function type in Module.
Copy link
Member

Choose a reason for hiding this comment

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

In a later PR?

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 is done in #312. We can extract relevant part from #312, as a new PR later.

lib/fizzy/parser_expr.cpp Outdated Show resolved Hide resolved
lib/fizzy/parser_expr.cpp Outdated Show resolved Hide resolved
@chfast chfast merged commit aafc16b into master May 21, 2020
@chfast chfast deleted the max_stack_height branch May 21, 2020 19:15
@chfast chfast mentioned this pull request May 22, 2020
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