Skip to content

Conversation

@bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented May 10, 2016

Hi! I'd like to add test cases we ran into in our implementation and which could be useful for others:

  • a test for if/then/else where the depths are not labels, but raw integer indices.
  • a test for if/then/else where the label target of a br in the else is the label of the then block.

Unfortunately, the second test (at the end of the file) doesn't work: the parser complains that the label $l is unknown, which is exactly what we are testing here. The correct behavior would be to silently swallow the error and consider the test as passed. Am I missing something here?

@rossberg
Copy link
Member

The current behaviour is correct: the body of each if-branch is (implicitly) a block, and the labels name these respective blocks. Not sure why you expect a label to be in scope in a sibling block? It's no different from

(if (...) (then (block $l ...)) (else (block (br $l))))

which likewise is an error.

The other test look good.

@kripken
Copy link
Member

kripken commented May 10, 2016

@rossberg-chromium I think it's not meant to be in scope, it should be an error - it's an assert_invalid test.

@rossberg
Copy link
Member

Oh, sorry, totally missed that. Yeah, that's definitely a bug, I'll look into it.

@rossberg
Copy link
Member

Okay, I now see what's going on. The problem is that labels (and identifiers in general) are resolved in the parser, because the AST doesn't have them. An unbound name hence is a syntax error, rejecting the script before you ever get to run it.

So it's not really a bug but a limitation of scripts -- a script can't check for this kind of error, just like it can't check other syntax errors. You'll need to check externally against expected-output instead.

@binji
Copy link
Member

binji commented May 12, 2016

@rossberg-chromium I actually ran an issue in sexpr-wasm because of this; prior to having binary modules, I could assume that assert_invalid would only be given modules that were syntactically valid. So I moved the checking pass out of the parser, and the parser always returns a module as an AST, even inside assert_invalid. But now that binary modules can fail to parse, I need a second path for passing back binary data that is only later parsed and checked for errors.

@bnjbvr
Copy link
Member Author

bnjbvr commented May 13, 2016

So it's not really a bug but a limitation of scripts -- a script can't check for this kind of error, just like it can't check other syntax errors. You'll need to check externally against expected-output instead.

Thank you for the explanation, I can do this, however I wonder how https://github.com/WebAssembly/spec/blob/master/ml-proto/test/switch.wast#L155 doesn't trigger the exact same issue?

@rossberg
Copy link
Member

@bnjbvr, that test uses a raw numeric index. What's resolved in the parser is the use of symbolic labels, and their translation into numeric ones (because they are purely syntactic sugar, not a part of the Wasm AST).

I certainly won't argue that this difference is nice. :)

@bnjbvr
Copy link
Member Author

bnjbvr commented May 13, 2016

I've updated the PR. The code wasn't accepting non-zero exit codes, so I had to refactor this, by adding a way to specify that a test is expected to fail. Also, there were issues with redirecting stderr to stdout with a > in the command argument, so I've refactored the way output is written so that stdout and stderr goes to the output file, instead. How does this look?

@bnjbvr bnjbvr force-pushed the add-test-label-not-found branch from a0c3403 to 080aa4e Compare May 13, 2016 09:09

if headers[0] == ';;;':
for h in headers[1:]:
if h.strip() == 'expected-fail':
Copy link
Member

Choose a reason for hiding this comment

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

Instead of instrumenting comments in the file, what do you think about simply using a file name convention? Say, <test>.fail.wast for tests that ought to fail? That's easier and cheaper to process (including for other test harnesses).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, good idea.

@rossberg
Copy link
Member

Thanks! Looks good modulo a few comments.

@bnjbvr bnjbvr force-pushed the add-test-label-not-found branch from 080aa4e to e5e2123 Compare May 13, 2016 12:18
@bnjbvr
Copy link
Member Author

bnjbvr commented May 13, 2016

Updated the latest patch, thank you for the review!


def _runTestFile(self, shortName, fileName, interpreterPath):

expectedExitCode = 1 if "fail" in fileName else 0
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this a bit narrower? ".fail." should be good.

@bnjbvr bnjbvr force-pushed the add-test-label-not-found branch from e5e2123 to 561169f Compare May 13, 2016 12:25
@rossberg
Copy link
Member

Hm, Travis still barfs at the .fail test, although I can't immediately say why.

self.assertEqual(expectedExitCode, exitCode, "test runner failed with exit code %i, expected %i" % (exitCode, expectedExitCode))

if logPath is not None:
out.close()
Copy link
Member

Choose a reason for hiding this comment

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

One further style nit I just noted: inconsistent indentation, rest of the file uses 2

…ects output to the right places in all cases;
@bnjbvr bnjbvr force-pushed the add-test-label-not-found branch from 561169f to 9223278 Compare May 17, 2016 15:11
@bnjbvr
Copy link
Member Author

bnjbvr commented May 17, 2016

Right, the test was failing because we are now very tied to line numbers, which is unfortunate. Addressed the two styles nits and updated the expected output to match line numbers.

@rossberg
Copy link
Member

Cool, thanks! LGTM and landing.

@rossberg rossberg merged commit 040e28e into WebAssembly:master May 19, 2016
@bnjbvr bnjbvr deleted the add-test-label-not-found branch January 27, 2017 19:45
dhil pushed a commit to dhil/webassembly-spec that referenced this pull request Oct 3, 2023
rossberg added a commit that referenced this pull request Feb 28, 2024
* Reintroduce exnref

* Fix type_of

* Simplify parser

* Implement 1b

* Change opcodes for catch/catch_all to avoid conflict

* Put catch clauses first

* Remove obsolete Delegating cases

* Change exn type opcode to -0x17

* Switch to B' variant

* [interpreter] Add boilerplate for ref.exn result patterns

* [ci] Deactivate node run, since it can't handle try_table yet

* Try -> TryTable in AST

* [spec] Update spec for option B' (#283)

* Deactivate Bikeshed

* [spec/tests] Specification of legacy exceptions + tests (#284)

* [legacy] Create specification doc for legacy exception handling

* [test] Create infra for legacy tests
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.

4 participants