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

Rewrite wasm-shell to use new wast parser #6601

Merged
merged 2 commits into from
May 18, 2024
Merged

Rewrite wasm-shell to use new wast parser #6601

merged 2 commits into from
May 18, 2024

Conversation

tlively
Copy link
Member

@tlively tlively commented May 17, 2024

Use the new wast parser to parse a full script up front, then traverse the
parsed script data structure and execute the commands. wasm-shell had previously
used the new wat parser for top-level modules, but it now uses the new parser
for module assertions as well. Fix various bugs this uncovered.

After this change, wasm-shell supports all the assertions used in the upstream
spec tests (although not new kinds of assertions introduced in any proposals).
Uncomment various assert_exhaustion tests that we can now execute.

Other kinds of assertions remain commented out in our tests: wasm-shell now
supports assert_unlinkable, but the interpreter does not eagerly check for the
existence of imports, so those tests do not pass. Tests that check for NaNs also
remain commented out because they do not yet use the standard syntax that
wasm-shell now supports for canonical and arithmetic NaN results, and our
interpreter would not pass all of those tests even if they did use the standard
syntax.

Use the new wast parser to parse a full script up front, then traverse the
parsed script data structure and execute the commands. wasm-shell had previously
used the new wat parser for top-level modules, but it now uses the new parser
for module assertions as well. Fix various bugs this uncovered.

After this change, wasm-shell supports all the assertions used in the upstream
spec tests (although not new kinds of assertions introduced in any proposals).
Uncomment various `assert_exhaustion` tests that we can now execute.

Other kinds of assertions remain commented out in our tests: wasm-shell now
supports `assert_unlinkable`, but the interpreter does not eagerly check for the
existence of imports, so those tests do not pass. Tests that check for NaNs also
remain commented out because they do not yet use the standard syntax that
wasm-shell now supports for canonical and arithmetic NaN results, and our
interpreter would not pass all of those tests even if they did use the standard
syntax.
@tlively tlively requested review from aheejin and kripken May 17, 2024 02:09
Copy link
Member Author

tlively commented May 17, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @tlively and the rest of your teammates on Graphite Graphite

Copy link
Member Author

Choose a reason for hiding this comment

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

@aheejin, as far as I can tell by looking at the documentation for old exceptions, the new parser is correct in accepting the modules in the changed tests here. In both cases, the delegate ends up targeting the function scope in the IR. Does that seem right to you?

Copy link
Member

@aheejin aheejin May 18, 2024

Choose a reason for hiding this comment

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

I think it is correct. I wonder why was it being marked as assert_invalid passing, given that this PR does not change the logic related to delegate?

Also delegate can target any blocks per spec, but Binaryen didn't support it internally. Binaryen supported the special "function scope" target though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Until this change, modules inside assert_invalid assertions were still being parsed with the old parser. Only top-level modules were being parsed with the new parser.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah but the code should've been valid with the old parser as well, no? Because we handled the function level delegate correctly before.

Copy link
Member Author

Choose a reason for hiding this comment

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

But syntactically these delegates do not directly target the top level. It's only by searching for the next valid target scope that the parser ends up making them target the top level. The old parser did not do that search.

@@ -391,24 +389,30 @@ Result<WASTCommand> command(Lexer& in) {
return *mod;
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this keeps coming up... 😄 Oh well, this seems like the best solution, we don't want to disable this globally.

@@ -4103,7 +4103,7 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
// can use it (refactor?)
Literals callFunctionInternal(Name name, Literals arguments) {
if (callDepth > maxDepth) {
externalInterface->trap("stack limit");
hostLimit("stack limit");
Copy link
Member

Choose a reason for hiding this comment

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

Good catch...

Copy link
Member Author

Choose a reason for hiding this comment

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

Now that we support assert_exhaustion, we actually have test coverage for this!

@tlively tlively merged commit 921644c into main May 18, 2024
13 checks passed
@tlively tlively deleted the shell-rewrite branch May 18, 2024 00:49
Copy link
Member

@aheejin aheejin left a comment

Choose a reason for hiding this comment

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

I was reading the PR but it was merged.. 😅 I read like ~halfway and I like it; the flow is clean and easy to understand. Well, I guess the rest should be fine.

Comment on lines +59 to +60
std::cerr << i << ' ';
Colors::normal(std::cerr);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::cerr << i << ' ';
Colors::normal(std::cerr);
std::cerr << i++ << ' ';

Nit

}
++i;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
++i;

@tlively
Copy link
Member Author

tlively commented May 18, 2024

Oops, sorry for jumping the gun, @aheejin! I'd be happy to address any other comments you have in follow-ups as well.

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