Currently, we inherit the following behavior from the wasmtime_fiber crate:
The toplevel function executed inside a Fiber is a Rust closure. However, this flexibility is not required for our use case: The function we want to run inside a continuation is always the array call trampoline of a wasm function.
This PR specializes our module wasmtime_runtime::fibre to our particular use case, getting rid of the involved closures. Instead, all the required data is passed around explicitly in function arguments, instead of being implicitly stored in a closure. This has the following advantages:
We do not need to allocate a Box holding the closure anymore.
The function wasmtime_runtime::fibre::unix::fiber_start, which is the Rust entry point for execution inside a Fiber, is no longer parameterized over a closure type F. Thus, we can call it directly from wasmtime_fibre_start, instead of needing to pass it around.
Since the internal layout of closures is not specified by Rust, their usage stands in the way of replacing wasmtime_runtime::fibre::unix::fiber_start with generated code eventually.
In a sense, what this PR does is some kind of manual closure conversion: Instead of creating a closure in wasmtime_runtime::continuation::cont_new and passing it to Fiber::new, we pass all of the necessary environment to Fiber::new. It is then stored on the Fiber stack by wasmtime_fibre_init, where it is read off and passed to fiber_start when resume-ing a continuation for the first time.
Currently, we inherit the following behavior from the
wasmtime_fiber
crate: The toplevel function executed inside aFiber
is a Rust closure. However, this flexibility is not required for our use case: The function we want to run inside a continuation is always the array call trampoline of a wasm function.This PR specializes our module
wasmtime_runtime::fibre
to our particular use case, getting rid of the involved closures. Instead, all the required data is passed around explicitly in function arguments, instead of being implicitly stored in a closure. This has the following advantages:Box
holding the closure anymore.wasmtime_runtime::fibre::unix::fiber_start
, which is the Rust entry point for execution inside a Fiber, is no longer parameterized over a closure typeF
. Thus, we can call it directly fromwasmtime_fibre_start
, instead of needing to pass it around.wasmtime_runtime::fibre::unix::fiber_start
with generated code eventually.In a sense, what this PR does is some kind of manual closure conversion: Instead of creating a closure in
wasmtime_runtime::continuation::cont_new
and passing it toFiber::new
, we pass all of the necessary environment toFiber::new
. It is then stored on the Fiber stack bywasmtime_fibre_init
, where it is read off and passed tofiber_start
whenresume
-ing a continuation for the first time.