This PR provides the missing piece to support switch instructions, by adding the necessary codegen (but only for the optimized implementation, support in the baseline implementation is not included).
Thus, the main change is the addition of wasmtime_cranelift::wasmfx::optimized::translate_switch.
In general, the implementation piggybacks on #256: On resume, we now fill the HandlerList with m entries for all tags with suspend handlers, followed by n entries for all tags with switch handlers. The search_handler code is changed so that on suspend and switch, we look in the correct part of the HandlerList. We could use two separate HandlerLists instead, but then we would have yet another allocation to manage, so putting both kinds of tags into the same list, and then only searching part of it seems preferable.
A few more notes:
translate_resume and translate_switch now return a WasmResult. This is used so that the baseline implementation can bail out without needing to panic.
The test runner in stack_switchting.rs now takes an extra parameter that allows us to enable the gc proposal, which is required for the tests using recursive types.
This PR provides the missing piece to support
switch
instructions, by adding the necessary codegen (but only for the optimized implementation, support in the baseline implementation is not included).Thus, the main change is the addition of
wasmtime_cranelift::wasmfx::optimized::translate_switch
.In general, the implementation piggybacks on #256: On
resume
, we now fill theHandlerList
with m entries for all tags with suspend handlers, followed by n entries for all tags with switch handlers. Thesearch_handler
code is changed so that onsuspend
andswitch
, we look in the correct part of theHandlerList
. We could use two separateHandlerLists
instead, but then we would have yet another allocation to manage, so putting both kinds of tags into the same list, and then only searching part of it seems preferable.A few more notes:
translate_resume
andtranslate_switch
now return aWasmResult
. This is used so that the baseline implementation can bail out without needing topanic
.stack_switchting.rs
now takes an extra parameter that allows us to enable the gc proposal, which is required for the tests using recursive types.