From fde84aa79c76c01794989dba8d277a2b1d579e0e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 31 Mar 2022 15:37:16 -0500 Subject: [PATCH] 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. --- crates/wasmtime/src/module.rs | 19 ++++++++++--------- crates/wasmtime/src/module/serialization.rs | 11 ++--------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/crates/wasmtime/src/module.rs b/crates/wasmtime/src/module.rs index 011e7437fc..9abdcb1e10 100644 --- a/crates/wasmtime/src/module.rs +++ b/crates/wasmtime/src/module.rs @@ -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, + mmap: MmapVec, + info: Option, types: Arc, ) -> Result { + 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())?; diff --git a/crates/wasmtime/src/module/serialization.rs b/crates/wasmtime/src/module/serialization.rs index 14985fd640..1feaa2d5ff 100644 --- a/crates/wasmtime/src/module/serialization.rs +++ b/crates/wasmtime/src/module/serialization.rs @@ -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 { 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(