SCORU/WASM: add host function implementation registry
Context
Currently, to introduce host functions, the toplevel initialization inserts in the interpreter's table of named modules (Import.registry) some ad-hoc modules wrapping the concrete host function implementations (e.g. modules env and spectest). The implementations are bare OCaml anonymous closures. At the instance initialization step, the Import machinery will copy and move these closures around.
This is an issue when encoding the instance, as we need a way to identify these closures, to restore them during future decodings.
This MR adds a table of host function implementations indexed by global names (unique symbols) to the config, changes the runtime type of host functions from anonymous functions to symbols, and adds a lookup step at call time. This should make encoding/decoding trivial.
Until the penultimate patch, the registry is global, the last patch makes it local, it is a bit more intrusive, so we could choose to drop it and keep the simple global table.
This MR also:
- icludes some simplifications (removes some useless parameters and type parameters).
- shows how to plug the PVM's host function into the interpreter, even though it's pretty useless until we actually plug the interpreter
As a followup, we could:
- Refactor the
Importmechanism and make it local to the interpreter's config too, if/when we want to support odules - Maybe backtrack the choice to add an extra parameter to the host functions (for inputs) and capture them in the closures when building the registry? This or we'll need to add more parameters for host functions that access other parts of the state such as access to the durable storage
Manually testing the MR
- See that the PVM host function is not broken
dune runtest src/lib_scoru_wasm - Run the WASM test suite:
make test-webassembly
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Document any change to the user interface, including configuration parameters (see node configuration) -
Provide automatic testing (see the testing guide). -
For new features and bug fixes, add an item in the appropriate changelog ( docs/protocols/alpha.rstfor the protocol and the environment,CHANGES.rstat the root of the repository for everything else). -
Select suitable reviewers using the Reviewersfield below. -
Select as Assigneethe next person who should take action on that MR