Skip to content

fix parsing resume #53

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

Closed
wants to merge 1 commit into from
Closed

fix parsing resume #53

wants to merge 1 commit into from

Conversation

ahuoguo
Copy link

@ahuoguo ahuoguo commented Nov 26, 2024

Fixes #52, resume_instr_instr is a single instruction so it should go to instr1

PS: I'm also a bit lost for which reference interpreter maintains the newest information. There's also https://github.com/WebAssembly/stack-switching

@ahuoguo ahuoguo marked this pull request as draft November 26, 2024 07:52
@ahuoguo
Copy link
Author

ahuoguo commented Nov 26, 2024

Note that this doesn't fix wasmfx/wasmfx-tools#96. The issue there is the reference interpreter rejects resume/resume_throw to be in tail position, an easier example is the following:

(module
  (type $task (;0;) (func))
  (type $cont (;1;) (cont $task))
  (type (;2;) (func (param i32)))
  (import "spectest" "print_i32" (func $print_i32 (;0;) (type 2)))
  (tag $yield (;0;) (type $task))
  (export "_start" (func $main))
  (start $main)
  (elem (;0;) declare func $task0)
  (func $task0 (;1;) (type $task)
    i32.const 1
    call $print_i32
  )
  (func $main (;2;) (type $task)
    ref.func $task0
    cont.new $cont
    resume $cont
  )
)
> ./wasm try.wast
try.wast:18.3-18.4: syntax error: unexpected token

This can be fixed by replacing resume_instr_handler_instr as follows:

resume_instr_handler_instr :
  | LPAR ON var var RPAR resume_instr_handler_instr
    { fun c -> let hs, es = $6 c in ($3 c tag, OnLabel ($4 c label)) :: hs, es }
  | LPAR ON var SWITCH RPAR resume_instr_handler_instr
    { fun c -> let hs, es = $6 c in ($3 c tag, OnSwitch) :: hs, es }
  | instr_list (* changed from `instr1`*)
    { fun c -> [], $1 c }

but it introduce A LOT OF shift/reduce conflicts

@dhil
Copy link
Member

dhil commented Nov 26, 2024

Thanks. I think this needs to be factored like try and catch for exceptions.

PS: I'm also a bit lost for which reference interpreter maintains the newest information. There's also https://github.com/WebAssembly/stack-switching

The upstream reference interpreter is https://github.com/WebAssembly/stack-switching. This reference interpreter is downstream and used for experimental features and research.

@dhil
Copy link
Member

dhil commented Nov 26, 2024

Thanks. I think this needs to be factored like try and catch for exceptions.

On reflection (or rather code inspection), I think we simply have to add a recursive instance of instr_list nonterminal in the production rule containing resume_instr_instr. It seems to pass your example. I will check the bug from wasm-tools next.

@dhil
Copy link
Member

dhil commented Nov 26, 2024

Thanks. I think this needs to be factored like try and catch for exceptions.

On reflection (or rather code inspection), I think we simply have to add a recursive instance of instr_list nonterminal in the production rule containing resume_instr_instr. It seems to pass your example. I will check the bug from wasm-tools next.

OK, so the proper fix is to push the instr_list nonterminal all the down to replace the instr1 in resume_instr_handler_instr. I can open a PR momentarily upstream with the fix.

@dhil
Copy link
Member

dhil commented Nov 26, 2024

I've opened the PR upstream WebAssembly/stack-switching#100

@ahuoguo
Copy link
Author

ahuoguo commented Nov 26, 2024

Thanks!

@ahuoguo ahuoguo closed this Nov 26, 2024
dhil pushed a commit that referenced this pull request Dec 3, 2024
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.

Bug in parsing instructions after resume
2 participants