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:
@@ -3,6 +3,8 @@
|
||||
use crate::instantiate::SetupError;
|
||||
use crate::object::{build_object, ObjectUnwindInfo};
|
||||
use object::write::Object;
|
||||
#[cfg(feature = "parallel-compilation")]
|
||||
use rayon::prelude::*;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::mem;
|
||||
use wasmparser::WasmFeatures;
|
||||
@@ -127,31 +129,21 @@ impl Compiler {
|
||||
translation: &mut ModuleTranslation,
|
||||
) -> Result<Compilation, SetupError> {
|
||||
let functions = mem::take(&mut translation.function_body_inputs);
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "parallel-compilation")] {
|
||||
use rayon::prelude::*;
|
||||
let iter = functions
|
||||
.into_iter()
|
||||
.collect::<Vec<_>>()
|
||||
.into_par_iter();
|
||||
} else {
|
||||
let iter = functions.into_iter();
|
||||
}
|
||||
}
|
||||
let funcs = iter
|
||||
let functions = functions.into_iter().collect::<Vec<_>>();
|
||||
let funcs = maybe_parallel!(functions.(into_iter | into_par_iter))
|
||||
.map(|(index, func)| {
|
||||
self.compiler
|
||||
.compile_function(translation, index, func, &*self.isa)
|
||||
.compile_function(translation, index, func, &*self.isa, &self.tunables)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?
|
||||
.into_iter()
|
||||
.collect::<CompiledFunctions>();
|
||||
|
||||
let dwarf_sections = if translation.debuginfo.is_some() && !funcs.is_empty() {
|
||||
let dwarf_sections = if self.tunables.debug_info && !funcs.is_empty() {
|
||||
transform_dwarf_data(
|
||||
&*self.isa,
|
||||
&translation.module,
|
||||
translation.debuginfo.as_ref().unwrap(),
|
||||
&translation.debuginfo,
|
||||
&funcs,
|
||||
)?
|
||||
} else {
|
||||
@@ -191,6 +183,9 @@ impl Hash for Compiler {
|
||||
isa.frontend_config().hash(hasher);
|
||||
tunables.hash(hasher);
|
||||
|
||||
// Catch accidental bugs of reusing across crate versions.
|
||||
env!("CARGO_PKG_VERSION").hash(hasher);
|
||||
|
||||
// TODO: ... and should we hash anything else? There's a lot of stuff in
|
||||
// `TargetIsa`, like registers/encodings/etc. Should we be hashing that
|
||||
// too? It seems like wasmtime doesn't configure it too too much, but
|
||||
|
||||
Reference in New Issue
Block a user