Convert compilation artifacts to just bytes (#3239)

* Convert compilation artifacts to just bytes

This commit strips the `CompilationArtifacts` type down to simply a list
of bytes. This moves all extra metadata elsewhere to live within the
list of bytes itself as `bincode`-encoded information.

Small affordance is made to avoid an in-process
serialize-then-deserialize round-trip for use cases like `Module::new`,
but otherwise this is mostly just moving some data around.

* Rename data section to `.rodata.wasm`
This commit is contained in:
Alex Crichton
2021-08-26 21:17:02 -05:00
committed by GitHub
parent a2a6be72c4
commit d12f1d77e6
7 changed files with 168 additions and 73 deletions

View File

@@ -147,6 +147,7 @@ impl Engine {
#[cfg(feature = "wat")]
let bytes = wat::parse_bytes(&bytes)?;
let (_, artifacts, types) = crate::Module::build_artifacts(self, &bytes)?;
let artifacts = artifacts.into_iter().map(|i| i.0).collect::<Vec<_>>();
crate::module::SerializedModule::from_artifacts(self, &artifacts, &types).to_bytes()
}

View File

@@ -10,7 +10,7 @@ use std::path::Path;
use std::sync::Arc;
use wasmparser::Validator;
use wasmtime_environ::{ModuleEnvironment, ModuleIndex, PrimaryMap};
use wasmtime_jit::{CompilationArtifacts, CompiledModule, TypeTables};
use wasmtime_jit::{CompilationArtifacts, CompiledModule, CompiledModuleInfo, TypeTables};
mod registry;
mod serialization;
@@ -312,8 +312,8 @@ impl Module {
}
};
let modules = engine.run_maybe_parallel(artifacts, |a| {
CompiledModule::from_artifacts(a, &*engine.config().profiler)
let modules = engine.run_maybe_parallel(artifacts, |(a, i)| {
CompiledModule::from_artifacts(a, Some(i), &*engine.config().profiler)
})?;
Self::from_parts(engine, modules, main_module, Arc::new(types), &[])
@@ -339,7 +339,11 @@ impl Module {
pub(crate) fn build_artifacts(
engine: &Engine,
wasm: &[u8],
) -> Result<(usize, Vec<CompilationArtifacts>, TypeTables)> {
) -> Result<(
usize,
Vec<(CompilationArtifacts, CompiledModuleInfo)>,
TypeTables,
)> {
let tunables = &engine.config().tunables;
// First a `ModuleEnvironment` is created which records type information

View File

@@ -246,7 +246,7 @@ impl<'a> SerializedModule<'a> {
self.check_features(&engine.config().features)?;
let modules = engine.run_maybe_parallel(self.artifacts, |i| {
CompiledModule::from_artifacts(i.unwrap_owned(), &*engine.config().profiler)
CompiledModule::from_artifacts(i.unwrap_owned(), None, &*engine.config().profiler)
})?;
assert!(!modules.is_empty());