diff --git a/crates/guest/Cargo.toml b/crates/guest/Cargo.toml index 08f4c3c3..bcceed65 100644 --- a/crates/guest/Cargo.toml +++ b/crates/guest/Cargo.toml @@ -14,7 +14,7 @@ crate-type = ["cdylib", "rlib"] path = "src/guest.rs" [dependencies] -holochain_serialized_bytes = { version = "=0.0.55", features = [] } +holochain_serialized_bytes = "=0.0.55" holochain_wasmer_common = { version = "=0.0.96", path = "../common" } serde = "1" tracing = "0.1" diff --git a/crates/host/src/module/mod.rs b/crates/host/src/module.rs similarity index 92% rename from crates/host/src/module/mod.rs rename to crates/host/src/module.rs index ee83528c..0d6fc181 100644 --- a/crates/host/src/module/mod.rs +++ b/crates/host/src/module.rs @@ -11,15 +11,11 @@ use std::fs::File; use std::fs::OpenOptions; use std::io::Write; use std::path::PathBuf; -use std::str::FromStr; use std::sync::Arc; -use wasmer::CpuFeature; use wasmer::Engine; use wasmer::Instance; use wasmer::Module; use wasmer::Store; -use wasmer::Target; -use wasmer::Triple; #[cfg(feature = "wasmer_sys")] mod wasmer_sys; @@ -36,9 +32,9 @@ pub use wasmer_wamr::*; pub type CacheKey = [u8; 32]; /// Plru uses a usize to track "recently used" so we need a map between 32 byte cache /// keys and the bits used to evict things from the cache. -pub type PlruKeyMap = BiMap; +type PlruKeyMap = BiMap; /// Modules serialize to a vec of bytes as per wasmer. -pub type SerializedModule = Bytes; +type SerializedModule = Bytes; #[derive(Clone, Debug)] pub struct ModuleWithStore { @@ -56,7 +52,7 @@ pub struct InstanceWithStore { /// with consistently. Default implementations for key functions are provided. /// Notably handles keeping the mapping between cache keys and items, and the /// plru tracking including touching and evicting. -pub trait PlruCache { +trait PlruCache { /// The type of items in the cache. type Item; /// Accessor for mutable reference to internal plru cache. @@ -102,24 +98,6 @@ pub trait PlruCache { self.plru_mut().touch(plru_key); } - /// Delete the plru for a given cache key. Care must be taken to ensure this - /// is not called before a subsequent call to `plru_key` or it will panic. - fn trash(&mut self, key: &CacheKey) { - let plru_key = self.plru_key(key); - self.plru_mut().trash(plru_key); - } - - /// Remove an item from the cache and the associated plru entry. - fn remove_item(&mut self, key: &CacheKey) -> Option> { - let maybe_item = self.cache_mut().remove(key); - if maybe_item.is_some() { - let plru_key = self.plru_key(key); - self.plru_mut().trash(plru_key); - self.key_map_mut().remove_by_left(&plru_key); - } - maybe_item - } - /// Attempt to retrieve an item from the cache by its cache key. fn get_item(&mut self, key: &CacheKey) -> Option> { let maybe_item = self.cache().get(key).cloned(); @@ -312,7 +290,7 @@ impl SerializedModuleCache { /// the cache to create callable instances is slow. Therefore modules are /// cached in memory after deserialization. #[derive(Default, Debug)] -pub struct DeserializedModuleCache { +struct DeserializedModuleCache { plru: MicroCache, key_map: PlruKeyMap, cache: BTreeMap>, @@ -385,16 +363,6 @@ impl ModuleCache { } } -/// Configuration of a Target for wasmer for iOS -pub fn wasmer_ios_target() -> Target { - // use what I see in - // platform ios headless example - // https://github.com/wasmerio/wasmer/blob/447c2e3a152438db67be9ef649327fabcad6f5b8/examples/platform_ios_headless.rs#L38-L53 - let triple = Triple::from_str("aarch64-apple-ios").unwrap(); - let cpu_feature = CpuFeature::set(); - Target::new(triple, cpu_feature) -} - #[cfg(test)] pub mod tests { use crate::module::{CacheKey, ModuleCache, PlruCache}; diff --git a/crates/host/src/module/wasmer_sys.rs b/crates/host/src/module/wasmer_sys.rs index 2eadd709..dbba3d35 100644 --- a/crates/host/src/module/wasmer_sys.rs +++ b/crates/host/src/module/wasmer_sys.rs @@ -23,7 +23,7 @@ pub const WASM_METERING_LIMIT: u64 = 10_000_000; /// Generate an engine with a wasm compiler /// and Metering (use limits) in place. -pub fn make_engine() -> Engine { +pub(crate) fn make_engine() -> Engine { let cost_function = |_operator: &wasmparser::Operator| -> u64 { 1 }; // @todo 100 giga-ops is totally arbitrary cutoff so we probably // want to make the limit configurable somehow. @@ -50,7 +50,7 @@ pub fn make_engine() -> Engine { engine } -pub fn make_runtime_engine() -> Engine { +pub(crate) fn make_runtime_engine() -> Engine { Engine::headless() } diff --git a/crates/host/src/module/wasmer_wamr.rs b/crates/host/src/module/wasmer_wamr.rs index 4852b240..07cf51b3 100644 --- a/crates/host/src/module/wasmer_wamr.rs +++ b/crates/host/src/module/wasmer_wamr.rs @@ -7,11 +7,11 @@ use wasmer::Module; /// Generate an engine with a wasm interpreter /// The interpreter used (wasm micro runtime) does not support metering /// See tracking issue: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2163 -pub fn make_engine() -> Engine { +pub(crate) fn make_engine() -> Engine { Engine::default() } -pub fn make_runtime_engine() -> Engine { +pub(crate) fn make_runtime_engine() -> Engine { Engine::default() } diff --git a/scripts/bench.sh b/scripts/bench.sh old mode 100644 new mode 100755 index 3dad9a66..ab0ff8aa --- a/scripts/bench.sh +++ b/scripts/bench.sh @@ -1,5 +1,5 @@ #! /usr/bin/env bash -./bench-wasmer_sys_dev.sh -./bench-wasmer_sys_prod.sh -./bench-wasmer_wamr.sh \ No newline at end of file +./scripts/bench-wasmer_sys_dev.sh +./scripts/bench-wasmer_sys_prod.sh +./scripts/bench-wasmer_wamr.sh \ No newline at end of file diff --git a/scripts/test.sh b/scripts/test.sh old mode 100644 new mode 100755 index f27eaeba..4e1cce97 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,5 +1,5 @@ #! /usr/bin/env bash -./test-wasmer_sys_dev.sh -./test-wasmer_sys_prod.sh -./test-wasmer_wamr.sh \ No newline at end of file +./scripts/test-wasmer_sys_dev.sh +./scripts/test-wasmer_sys_prod.sh +./scripts/test-wasmer_wamr.sh \ No newline at end of file diff --git a/test/benches/bench.rs b/test/benches/bench.rs index 72338627..1d566c5a 100644 --- a/test/benches/bench.rs +++ b/test/benches/bench.rs @@ -13,7 +13,7 @@ use wasmer::Store; pub fn wasm_module_compile(c: &mut Criterion) { let mut group = c.benchmark_group("wasm_module_compile"); - for wasm in vec![ + for wasm in [ TestWasm::Empty, TestWasm::Io, TestWasm::Test, @@ -31,7 +31,7 @@ pub fn wasm_module_compile(c: &mut Criterion) { pub fn wasm_module_deserialize_from_file(c: &mut Criterion) { let mut group = c.benchmark_group("wasm_module_deserialize_from_file"); - for wasm in vec![ + for wasm in [ TestWasm::Empty, TestWasm::Io, TestWasm::Test, @@ -56,7 +56,7 @@ pub fn wasm_module_deserialize_from_file(c: &mut Criterion) { pub fn wasm_module(c: &mut Criterion) { let mut group = c.benchmark_group("wasm_module"); - for wasm in vec![ + for wasm in [ TestWasm::Empty, TestWasm::Io, TestWasm::Test, @@ -76,7 +76,7 @@ pub fn wasm_module(c: &mut Criterion) { pub fn wasm_instance(c: &mut Criterion) { let mut group = c.benchmark_group("wasm_instance"); - for wasm in vec![ + for wasm in [ TestWasm::Empty, TestWasm::Io, TestWasm::Test, @@ -213,7 +213,7 @@ pub fn test_process_string(c: &mut Criterion) { let instance_with_store = TestWasm::Test.unmetered_instance(); - for n in vec![0, 1, 1_000, 1_000_000] { + for n in [0, 1, 1_000, 1_000_000] { group.throughput(Throughput::Bytes(n)); group.sample_size(10); let input = test_common::StringType::from(".".repeat(n.try_into().unwrap())); diff --git a/test/src/test.rs b/test/src/test.rs index 0e4c12a7..db18b2cd 100644 --- a/test/src/test.rs +++ b/test/src/test.rs @@ -239,7 +239,7 @@ pub mod tests { &mut store.lock().as_store_mut(), instance, "ignore_args_process_string", - &StringType::from(String::new()), + StringType::from(String::new()), ) .expect("ignore_args_process_string call"); assert_eq!(String::new(), String::from(result)); @@ -254,7 +254,7 @@ pub mod tests { &mut store.lock().as_store_mut(), instance, "process_string", - &StringType::from(s.clone()), + StringType::from(s.clone()), ) .expect("process string call"); @@ -267,15 +267,15 @@ pub mod tests { fn process_string_test() { // use a "crazy" string that is much longer than a single wasm page to show that pagination // and utf-8 are both working OK - let starter_string = "╰▐ ✖ 〜 ✖ ▐╯" - .repeat(usize::try_from(10_u32 * u32::try_from(std::u16::MAX).unwrap()).unwrap()); + let starter_string = + "╰▐ ✖ 〜 ✖ ▐╯".repeat(usize::try_from(10_u32 * u32::from(u16::MAX)).unwrap()); let InstanceWithStore { store, instance } = TestWasm::Test.instance(); let result: StringType = guest::call( &mut store.lock().as_store_mut(), instance, "process_string", // This is by reference just to show that it can be done as borrowed or owned. - &StringType::from(starter_string.clone()), + StringType::from(starter_string.clone()), ) .expect("process string call"); @@ -320,8 +320,8 @@ pub mod tests { ) } }); - assert!(matches!(call_1.join(), Ok(_))); - assert!(matches!(call_2.join(), Ok(_))); + assert!(call_1.join().is_ok()); + assert!(call_2.join().is_ok()); } #[test]