Code review feedback.
* Move `Module::compile` to `Engine::precompile_module`. * Remove `Module::deserialize` method. * Make `Module::serialize` the same format as `Engine::precompile_module`. * Make `Engine::precompile_module` return a `Vec<u8>`. * Move the remaining serialization-related code to `serialization.rs`.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use anyhow::Result;
|
||||
use std::io::BufWriter;
|
||||
use wasmtime::*;
|
||||
|
||||
#[test]
|
||||
@@ -28,18 +27,18 @@ fn caches_across_engines() {
|
||||
.serialize()
|
||||
.unwrap();
|
||||
|
||||
let res = Module::deserialize(&Engine::new(&Config::new()).unwrap(), &bytes);
|
||||
let res = Module::new(&Engine::new(&Config::new()).unwrap(), &bytes);
|
||||
assert!(res.is_ok());
|
||||
|
||||
// differ in shared cranelift flags
|
||||
let res = Module::deserialize(
|
||||
let res = Module::new(
|
||||
&Engine::new(Config::new().cranelift_nan_canonicalization(true)).unwrap(),
|
||||
&bytes,
|
||||
);
|
||||
assert!(res.is_err());
|
||||
|
||||
// differ in cranelift settings
|
||||
let res = Module::deserialize(
|
||||
let res = Module::new(
|
||||
&Engine::new(Config::new().cranelift_opt_level(OptLevel::None)).unwrap(),
|
||||
&bytes,
|
||||
);
|
||||
@@ -47,7 +46,7 @@ fn caches_across_engines() {
|
||||
|
||||
// Missing required cpu flags
|
||||
if cfg!(target_arch = "x86_64") {
|
||||
let res = Module::deserialize(
|
||||
let res = Module::new(
|
||||
&Engine::new(
|
||||
Config::new()
|
||||
.target(&target_lexicon::Triple::host().to_string())
|
||||
@@ -63,14 +62,10 @@ fn caches_across_engines() {
|
||||
#[test]
|
||||
fn aot_compiles() -> Result<()> {
|
||||
let engine = Engine::default();
|
||||
let mut writer = BufWriter::new(Vec::new());
|
||||
Module::compile(
|
||||
&engine,
|
||||
let bytes = engine.precompile_module(
|
||||
"(module (func (export \"f\") (param i32) (result i32) local.get 0))".as_bytes(),
|
||||
&mut writer,
|
||||
)?;
|
||||
|
||||
let bytes = writer.into_inner()?;
|
||||
let module = Module::from_binary(&engine, &bytes)?;
|
||||
|
||||
let store = Store::new(&engine);
|
||||
|
||||
@@ -39,7 +39,7 @@ fn compile() -> Result<()> {
|
||||
assert_eq!(m.imports().len(), 0);
|
||||
assert_eq!(m.exports().len(), 0);
|
||||
let bytes = m.serialize()?;
|
||||
Module::deserialize(&engine, &bytes)?;
|
||||
Module::new(&engine, &bytes)?;
|
||||
assert_eq!(m.imports().len(), 0);
|
||||
assert_eq!(m.exports().len(), 0);
|
||||
Ok(())
|
||||
|
||||
@@ -7,7 +7,7 @@ fn serialize(engine: &Engine, wat: &'static str) -> Result<Vec<u8>> {
|
||||
}
|
||||
|
||||
fn deserialize_and_instantiate(store: &Store, buffer: &[u8]) -> Result<Instance> {
|
||||
let module = Module::deserialize(store.engine(), buffer)?;
|
||||
let module = Module::new(store.engine(), buffer)?;
|
||||
Ok(Instance::new(&store, &module, &[])?)
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ fn deserialize_and_instantiate(store: &Store, buffer: &[u8]) -> Result<Instance>
|
||||
fn test_version_mismatch() -> Result<()> {
|
||||
let engine = Engine::default();
|
||||
let mut buffer = serialize(&engine, "(module)")?;
|
||||
buffer[1] = 'x' as u8;
|
||||
buffer[13 /* header length */ + 1 /* version length */] = 'x' as u8;
|
||||
|
||||
match Module::deserialize(&engine, &buffer) {
|
||||
match Module::new(&engine, &buffer) {
|
||||
Ok(_) => bail!("expected deserialization to fail"),
|
||||
Err(e) => assert_eq!(
|
||||
e.to_string(),
|
||||
|
||||
Reference in New Issue
Block a user