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:
@@ -82,6 +82,7 @@ fn loop_interrupt_from_afar() -> anyhow::Result<()> {
|
||||
while HITS.load(SeqCst) <= 100_000 {
|
||||
// continue ...
|
||||
}
|
||||
println!("interrupting");
|
||||
handle.interrupt();
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
46
tests/all/module_linking.rs
Normal file
46
tests/all/module_linking.rs
Normal 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(())
|
||||
}
|
||||
Reference in New Issue
Block a user