Start compiling module-linking modules (#2093)

This commit is intended to be the first of many in implementing the
module linking proposal. At this time this builds on #2059 so it
shouldn't land yet. The goal of this commit is to compile bare-bones
modules which use module linking, e.g. those with nested modules.

My hope with module linking is that almost everything in wasmtime only
needs mild refactorings to handle it. The goal is that all per-module
structures are still per-module and at the top level there's just a
`Vec` containing a bunch of modules. That's implemented currently where
`wasmtime::Module` contains `Arc<[CompiledModule]>` and an index of
which one it's pointing to. This should enable
serialization/deserialization of any module in a nested modules
scenario, no matter how you got it.

Tons of features of the module linking proposal are missing from this
commit. For example instantiation flat out doesn't work, nor does
import/export of modules or instances. That'll be coming as future
commits, but the purpose here is to start laying groundwork in Wasmtime
for handling lots of modules in lots of places.
This commit is contained in:
Alex Crichton
2020-11-06 13:32:30 -06:00
committed by GitHub
parent d2daf5064e
commit 77827a48a9
17 changed files with 414 additions and 257 deletions

View File

@@ -82,6 +82,7 @@ fn loop_interrupt_from_afar() -> anyhow::Result<()> {
while HITS.load(SeqCst) <= 100_000 {
// continue ...
}
println!("interrupting");
handle.interrupt();
});

View File

@@ -12,6 +12,7 @@ mod instance;
mod invoke_func_via_table;
mod linker;
mod memory_creator;
mod module_linking;
mod module_serialize;
mod name;
mod stack_overflow;

View File

@@ -0,0 +1,46 @@
use anyhow::Result;
use wasmtime::*;
fn engine() -> Engine {
let mut config = Config::new();
config.wasm_module_linking(true);
Engine::new(&config)
}
#[test]
fn compile() -> Result<()> {
let engine = engine();
Module::new(&engine, "(module (module))")?;
Module::new(&engine, "(module (module) (module))")?;
Module::new(&engine, "(module (module (module)))")?;
Module::new(
&engine,
"
(module
(func)
(module (func))
(module (func))
)
",
)?;
let m = Module::new(
&engine,
"
(module
(global i32 (i32.const 0))
(func)
(module (memory 1) (func))
(module (memory 2) (func))
(module (table 2 funcref) (func))
(module (global i64 (i64.const 0)) (func))
)
",
)?;
assert_eq!(m.imports().len(), 0);
assert_eq!(m.exports().len(), 0);
let bytes = m.serialize()?;
Module::deserialize(&engine, &bytes)?;
assert_eq!(m.imports().len(), 0);
assert_eq!(m.exports().len(), 0);
Ok(())
}