Deduplicate creation of CompiledModule (#3986)
Push the creation of a module's `CompiledModule` into one location of `Module::from_parts` instead of duplicating it across two callers.
This commit is contained in:
@@ -332,14 +332,7 @@ impl Module {
|
||||
}
|
||||
};
|
||||
|
||||
let module = CompiledModule::from_artifacts(
|
||||
mmap,
|
||||
info,
|
||||
&*engine.config().profiler,
|
||||
engine.unique_id_allocator(),
|
||||
)?;
|
||||
|
||||
Self::from_parts(engine, module, Arc::new(types))
|
||||
Self::from_parts(engine, mmap, info, Arc::new(types))
|
||||
}
|
||||
|
||||
/// Converts an input binary-encoded WebAssembly module to compilation
|
||||
@@ -498,9 +491,17 @@ impl Module {
|
||||
|
||||
fn from_parts(
|
||||
engine: &Engine,
|
||||
module: Arc<CompiledModule>,
|
||||
mmap: MmapVec,
|
||||
info: Option<CompiledModuleInfo>,
|
||||
types: Arc<TypeTables>,
|
||||
) -> Result<Self> {
|
||||
let module = CompiledModule::from_artifacts(
|
||||
mmap,
|
||||
info,
|
||||
&*engine.config().profiler,
|
||||
engine.unique_id_allocator(),
|
||||
)?;
|
||||
|
||||
// Validate the module can be used with the current allocator
|
||||
engine.allocator().validate(module.module())?;
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use wasmtime_environ::{FlagValue, Tunables, TypeTables};
|
||||
use wasmtime_jit::{subslice_range, CompiledModule, CompiledModuleInfo};
|
||||
use wasmtime_jit::{subslice_range, CompiledModuleInfo};
|
||||
use wasmtime_runtime::MmapVec;
|
||||
|
||||
const HEADER: &[u8] = b"\0wasmtime-aot";
|
||||
@@ -206,14 +206,7 @@ impl<'a> SerializedModule<'a> {
|
||||
|
||||
pub fn into_module(self, engine: &Engine) -> Result<Module> {
|
||||
let (mmap, info, types) = self.into_parts(engine)?;
|
||||
let module = CompiledModule::from_artifacts(
|
||||
mmap,
|
||||
info,
|
||||
&*engine.config().profiler,
|
||||
engine.unique_id_allocator(),
|
||||
)?;
|
||||
|
||||
Module::from_parts(engine, module, Arc::new(types))
|
||||
Module::from_parts(engine, mmap, info, Arc::new(types))
|
||||
}
|
||||
|
||||
pub fn into_parts(
|
||||
|
||||
Reference in New Issue
Block a user