Description
Currently Wasmi's bytecode executor is in parts generic over a host provided T
which comes from the Store<T>
where T
represents the host data with which the host side can interact in host function calls.
Wasmi executor being generic in parts has big implications:
- Codegen: The compiler might codegen multiple versions of big parts of the executor which is a huge component in Wasmi.
- Tail Calls: Using tail call dispatch is not feasible as long as parts of the bytecode executor are still generic since it is hard to have a single source of execution handlers (and their function pointers).
- FFI: Compiling Wasmi to a shared object and then using it is very complicated. Users have to work around that fact. This is especially true for Wasmi's C-API and future projects such as Wasmi's Python bindings.
The trick that might work is a PrunedStore
that drops the T
generic parameter by instead storing a core::any::TypeId
in its place. And when converting back to a Store<T>
on the host side (because the host knows its type) the TypeId
can be checked against the T
. If they are not equal we can simply error or panic and thus the system remains safe.
This way Wasmi's executor can use a PrunedStore
instead of Store<T>
internally and let the host side do the conversions. Though those conversions need to be hidden from the actual user of the Wasmi library.