From ddb5c9881a32debc65c0442546a0d5c669ada519 Mon Sep 17 00:00:00 2001 From: vms Date: Tue, 2 Jun 2020 00:12:23 +0300 Subject: [PATCH] code cleaning --- Cargo.toml | 8 ++++++++ fce/Cargo.toml | 9 --------- wit_embedder/Cargo.toml | 8 -------- wit_fce/Cargo.toml | 8 -------- wit_fce/src/instance/wit_function.rs | 22 ++++++++++------------ wit_fce/src/instance/wit_instance.rs | 13 +++---------- wit_fce/src/instance/wit_module.rs | 23 +++++++++++++---------- wit_fce/src/main.rs | 2 +- 8 files changed, 35 insertions(+), 58 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 25eabfdc..f38e0a0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,11 @@ members = [ "wit_fce/examples/ipfs_node", "wit_fce/examples/ipfs_rpc", ] + +[profile.release] +opt-level = 3 +debug = false +lto = true +debug-assertions = false +overflow-checks = false +panic = "abort" diff --git a/fce/Cargo.toml b/fce/Cargo.toml index 5d220b90..dc98fcba 100644 --- a/fce/Cargo.toml +++ b/fce/Cargo.toml @@ -7,7 +7,6 @@ edition = "2018" license = "Apache-2.0" keywords = ["fluence", "webassembly", "wasmer", "execution environment"] categories = ["webassembly"] -maintenance = { status = "actively-developed" } [lib] name = "fce" @@ -35,11 +34,3 @@ pwasm-utils = "0.12.0" reqwest = "0.10.4" bytes = "0.5.4" tokio = { version = "0.2.20", features = ["blocking", "macros"] } - -[profile.release] -#opt-level = 3 -#debug = false -#lto = true -#debug-assertions = false -#overflow-checks = false -#panic = "abort" diff --git a/wit_embedder/Cargo.toml b/wit_embedder/Cargo.toml index 09165568..9547ffda 100644 --- a/wit_embedder/Cargo.toml +++ b/wit_embedder/Cargo.toml @@ -12,11 +12,3 @@ either = "1.5.3" clap = "2.33.1" exitfailure = "0.5.1" failure = "0.1.5" - -[profile.release] -opt-level = 3 -debug = false -lto = true -debug-assertions = false -overflow-checks = false -panic = "abort" diff --git a/wit_fce/Cargo.toml b/wit_fce/Cargo.toml index 0591b155..718e7029 100644 --- a/wit_fce/Cargo.toml +++ b/wit_fce/Cargo.toml @@ -9,11 +9,3 @@ wasmer-runtime = "0.17.0" wasmer-runtime-core = { version = "0.17.0", features = ["dynamicfunc-fat-closures"] } wasmer-interface-types = { git = "http://github.com/fluencelabs/interface-types" } multimap = "0.8.1" - -[profile.release] -opt-level = 3 -debug = false -lto = true -debug-assertions = false -overflow-checks = false -panic = "abort" diff --git a/wit_fce/src/instance/wit_function.rs b/wit_fce/src/instance/wit_function.rs index 6cb4127b..502afc28 100644 --- a/wit_fce/src/instance/wit_function.rs +++ b/wit_fce/src/instance/wit_function.rs @@ -127,25 +127,23 @@ impl wasm::structures::LocalImport for WITFunction { use super::{ival_to_wval, wval_to_ival}; match &self.inner { - WITFunctionInner::Export { func, .. } => { - func.as_ref() - .call(&arguments.iter().map(ival_to_wval).collect::>()) - .map(|results| results.iter().map(wval_to_ival).collect()) - .map_err(|_| ()) - } + WITFunctionInner::Export { func, .. } => func + .as_ref() + .call(&arguments.iter().map(ival_to_wval).collect::>()) + .map(|results| results.iter().map(wval_to_ival).collect()) + .map_err(|_| ()), WITFunctionInner::Import { wit_module, func_name, .. } => { - let mut tt = wit_module.clone(); + let mut wit_module_caller = wit_module.clone(); unsafe { - let result = Arc::get_mut_unchecked(&mut tt) + // get_mut_unchecked here is safe because it is single-threaded environment + // without cyclic reference between modules + Arc::get_mut_unchecked(&mut wit_module_caller) .call(func_name, arguments) - .map_err(|_| ()); - - // println!("result is {:?}", result); - result + .map_err(|_| ()) } } } diff --git a/wit_fce/src/instance/wit_instance.rs b/wit_fce/src/instance/wit_instance.rs index 0e8fadb2..86d586af 100644 --- a/wit_fce/src/instance/wit_instance.rs +++ b/wit_fce/src/instance/wit_instance.rs @@ -57,6 +57,7 @@ impl WITInstance { Ok(Self { funcs, memories }) } + #[allow(unused)] pub fn get_func_signature( &self, func_idx: usize, @@ -88,9 +89,7 @@ impl WITInstance { // here it is safe because dyn func is never lives WITInstance let export_func = std::mem::transmute::, DynFunc<'static>>(export_func); - let tt = WITFunction::from_export(export_func)?; - println!("{}, {} - {:?}", export_id, export.name, tt.inputs()); - Ok((export_id, tt)) + Ok((export_id, WITFunction::from_export(export_func)?)) } }) .collect() @@ -112,19 +111,13 @@ impl WITInstance { let mut non_wit_callable_imports = HashMap::new(); for import in interfaces.imports.iter() { - if let Some(_) = core_to_adapter.get(&import.function_type) { + if core_to_adapter.get(&import.function_type).is_some() { continue; } match modules.get(import.namespace) { Some(module) => { let func = WITFunction::from_import(module.clone(), import.name.to_string())?; - println!( - "{}, {} - {:?}", - start_index + non_wit_callable_imports.len(), - import.name, - func.inputs() - ); non_wit_callable_imports .insert(start_index + non_wit_callable_imports.len() as usize, func); } diff --git a/wit_fce/src/instance/wit_module.rs b/wit_fce/src/instance/wit_module.rs index 95107572..bf37096d 100644 --- a/wit_fce/src/instance/wit_module.rs +++ b/wit_fce/src/instance/wit_module.rs @@ -41,6 +41,7 @@ type WITInterpreter = Interpreter>; pub struct WITModule { + #[allow(unused)] instance: WasmerInstance, wit_instance: Arc, funcs: HashMap, Vec)>, @@ -77,6 +78,8 @@ impl WITModule { let wasmer_instance = wasmer_instance.instantiate(&import_object)?; let wit_instance = unsafe { + // get_mut_unchecked here is safe because currently only this modules have reference to + // it and the environment is single-threaded *Arc::get_mut_unchecked(&mut wit_instance) = MaybeUninit::new(WITInstance::new(&wasmer_instance, &interfaces, modules)?); std::mem::transmute::<_, Arc>(wit_instance) @@ -96,17 +99,17 @@ impl WITModule { ) -> Result, WITFCEError> { match self.funcs.get(function_name) { Some(func) => { - let tt = Arc::make_mut(&mut self.wit_instance); - - let result = func.0.run(args, tt)?.as_slice().to_owned(); + let result = func + .0 + .run(args, Arc::make_mut(&mut self.wit_instance))? + .as_slice() + .to_owned(); Ok(result) } - None => { - Err(WITFCEError::NoSuchFunction(format!( - "{} hasn't been found while calling", - function_name - ))) - } + None => Err(WITFCEError::NoSuchFunction(format!( + "{} hasn't been found while calling", + function_name + ))), } } @@ -195,7 +198,7 @@ impl WITModule { use crate::instance::{itype_to_wtype, wval_to_ival}; use wasmer_interface_types::ast::Type as IType; use wasmer_runtime_core::typed_func::DynamicFunc; - use wasmer_runtime_core::types::{FuncSig, Type as WType, Value}; + use wasmer_runtime_core::types::{FuncSig, Value}; use wasmer_runtime_core::vm::Ctx; // returns function that will be called from imports of Wasmer module diff --git a/wit_fce/src/main.rs b/wit_fce/src/main.rs index fa7c1823..2c2d74d6 100644 --- a/wit_fce/src/main.rs +++ b/wit_fce/src/main.rs @@ -57,7 +57,7 @@ fn main() { .expect("module successfully created"); let result1 = ipfs_rpc - .call("invoke", &[InterfaceValue::String("aaaaaa".to_string())]) + .call("invoke", &[InterfaceValue::String("0xffffff".to_string())]) .unwrap(); println!("stack state {:?}", result1);