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

interpreter: fails to parse a valid-looking wat #1566

Closed
nagisa opened this issue Dec 12, 2022 · 2 comments · Fixed by #1567
Closed

interpreter: fails to parse a valid-looking wat #1566

nagisa opened this issue Dec 12, 2022 · 2 comments · Fixed by #1567

Comments

@nagisa
Copy link

nagisa commented Dec 12, 2022

(module
  (type (func (param i32) (result i32)))
  (func (type 0) (param i32) (result i32)
    i32.const 2
    i32.const 3
    i32.const 0
    i32.const 1
    local.get 0
    select
    select
  )
)

is a different, but equivalent, way to write

(func (export "as-select-last") (param i32) (result i32)
(select (i32.const 2) (i32.const 3) (select (i32.const 0) (i32.const 1) (local.get 0)))
)

but it fails to parse with the following error when fed to the reference interpreter

11.3-11.4: syntax error: unexpected token

If we parenthesize the last select, the parse succeeds. This appears to be the only such function in the spec-test suite where such an equivalent rewrite fails to parse in the test suite, as far as I can tell.

@rossberg
Copy link
Member

Darn, this is due to the hack necessary to parse the optional result signature. In fact, call_indirect has the same problem, none of the following work:

(func select select)
(func select call_indirect)
(func call_indirect select)
(func call_indirect call_indirect)

It works if you add another instruction at the end.

Unfortunately, the fix is rather non-obvious, it is easy to get shift/reduce conflicts here. Will have a look.

@rossberg
Copy link
Member

Please see #1567.

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 a pull request may close this issue.

2 participants