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

[spec+interpreter] Accepts "i32.const0" (missing space) #478

Closed
sunfishcode opened this issue May 15, 2017 · 10 comments
Closed

[spec+interpreter] Accepts "i32.const0" (missing space) #478

sunfishcode opened this issue May 15, 2017 · 10 comments
Assignees

Comments

@sunfishcode
Copy link
Member

The interpreter currently accepts the following:

(module (func (export "foo") (result i32) (i32.const0)))

(assert_return (invoke "foo") (i32.const0))

Note that there's no space between the i32.const and the 0. This doesn't create any actual ambiguity, but it doesn't seem to add meaningful flexibility either, and it's surprising.

For reference, wabt and binaryen both issue errors on this code.

@rossberg
Copy link
Member

Hm, interesting. That is a normal result of the usual longest match rule for lexing. But it seems that for an S-expression format that is not actually a desirable logic to use.

@binji
Copy link
Member

binji commented May 16, 2017

I don't remember doing it, but it looks like I added a rule a while back that prevented this in the wabt lexer: https://github.com/WebAssembly/wabt/blob/master/src/wast-lexer.cc#L464

Removing that rule makes wabt work the same, allowing you to parse modules like: (module(func(resulti32)i32.const0)) :-)

@rossberg
Copy link
Member

@binji, yes, I just implemented the same rule. It's a bit more interesting how to specify it, though. Probably gonna do a similar trick in the spec itself, defining a general syntax for atoms, wth all other ones being "reserved".

@rossberg
Copy link
Member

Okay, I refined PR #471 to rule out such cases and adjust the interpreter accordingly.

@AndrewScheidecker
Copy link
Contributor

@rossberg-chromium I don't think your change rejects a keyword following a number:
offset=1align=1

@rossberg
Copy link
Member

rossberg commented May 17, 2017

@AndrewScheidecker, works for me. Note that the sequence offset=1align=1 forms a single "keyword" under the given grammar. There is no number.

@rossberg
Copy link
Member

Ah, but you are right nevertheless! (module (func br 0nop)) is still accepted. Hm, darn, not sure how to solve this.

@AndrewScheidecker
Copy link
Contributor

I'm thinking about fixing this in WAVM by only matching a keyword or number if it's followed by a token separating character (without consuming that character).

@rossberg
Copy link
Member

Actually, it seems easy to fix by just removing the bit that a bogus "keyword" starts with a letter. See latest patch, which also adjusts the spec text.

@rossberg rossberg changed the title interpreter accepts "i32.const0" (missing space) [spec/interpreter] Accepts "i32.const0" (missing space) May 18, 2017
@rossberg rossberg changed the title [spec/interpreter] Accepts "i32.const0" (missing space) [spec+interpreter] Accepts "i32.const0" (missing space) May 18, 2017
@rossberg rossberg self-assigned this May 18, 2017
@rossberg
Copy link
Member

This has been resolved as part of PR #471.

dhil pushed a commit to dhil/webassembly-spec that referenced this issue Nov 15, 2023
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

No branches or pull requests

4 participants