titzer / wizard-engine

Research WebAssembly Engine
381 stars 40 forks source link

Bug in import tag #232

Open ahuoguo opened 6 days ago

ahuoguo commented 6 days ago

The following code

(module $a
  (tag $yield (export "yield") )
)
(register "a")

(module
  (type $task (func))
  (type $cont (cont $task))

  (import "spectest" "print_i32" (func $print_i32 (param i32)))
  (tag $yield (import "a" "yield"))

  (elem declare func $task)

  (func $task
    (suspend $yield)
  )

  (func $run (export "run")
    (block $h
        (block $on_yield (result (ref $cont))
          (resume $cont (on $yield $on_yield)
            (cont.new $cont (ref.func $task)))
          (call $print_i32 (i32.const 42))
          (br $h)
        )
        (drop)
        (call $print_i32 (i32.const 1))
    )
  )
)
(invoke "run")

Wizard seems to parse incorrect Module information when tag is imported. It successfully runs when I remove (import "a" "yield") in tag.

> wasm -d try.wast -o  try.bin.wast &&  spectest.jvm -ext:stack-switching try.bin.wast
##+try.bin.wast
##-fail: try.bin.wast @ 21:2 expected valid module, got invalid: overflow import section, expected 32 bytes, read 32

Context:

I was trying to run this stack switching wast file on wizard and I received the following error message:

> wasm -d control-lwt.wast -o  control-lwt.bin.wast &&  spectest.jvm -ext:stack-switching control-lwt.bin.wast
##+control-lwt.bin.wast
Exception in thread "main" java.lang.NullPointerException
        at V3C_SpecTestInterpreter.doInstantiate(Unknown Source)
        at V3C_SpecTestInterpreter.doModule(Unknown Source)
        at V3C_SpecTestInterpreter.doCommand(Unknown Source)
        at V3C_SpecTestInterpreter.run(Unknown Source)
        at V3K_spectest.runTest(Unknown Source)
        at V3K_spectest.main(Unknown Source)
        at V3K_spectest.main(Unknown Source)
titzer commented 5 days ago

I looked into this and it seems like the stack-switching reference interpreter is not in agreement with the exception handling proposal's encoding of import/export tags.