Return JValue from call_json (#39)

This commit is contained in:
vms 2020-11-05 15:18:48 +03:00 committed by GitHub
parent c8114d48c6
commit d09c5b5d73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 925 additions and 1335 deletions

116
Cargo.lock generated
View File

@ -17,9 +17,9 @@ checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e"
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "0.7.14" version = "0.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b476ce7103678b0c6d3d395dbbae31d48ff910bd28be979ba5d48c6351131d0d" checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@ -35,9 +35,9 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.33" version = "1.0.34"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1fd36ffbb1fb7c834eac128ea8d0e310c5aeb635548f9d58861e1308d46e71c" checksum = "bf8dcb5b4bbaa28653b647d8c77bd4ed40183b48882e130c1f1ffb73de069fd7"
[[package]] [[package]]
name = "aquamarine-vm" name = "aquamarine-vm"
@ -132,9 +132,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]] [[package]]
name = "blake2b_simd" name = "blake2b_simd"
version = "0.5.10" version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a" checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587"
dependencies = [ dependencies = [
"arrayref", "arrayref",
"arrayvec", "arrayvec",
@ -250,9 +250,9 @@ checksum = "475bd7aa7680b4ed8f6bb59745e882bcbaeb39326532bb79ffb1716480d9a274"
[[package]] [[package]]
name = "const_fn" name = "const_fn"
version = "0.4.2" version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce90df4c658c62f12d78f7508cf92f9173e5184a539c10bfe54a3107b3ffd0f2" checksum = "c478836e029dcef17fb47c89023448c64f781a046e0300e257ad8225ae59afab"
[[package]] [[package]]
name = "constant_time_eq" name = "constant_time_eq"
@ -552,11 +552,11 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.24" version = "0.8.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a51b8cf747471cb9499b6d59e59b0444f4c90eba8968c4e44874e92b5b64ace2" checksum = "801bbab217d7f79c0062f4f7205b5d4427c6d1a7bd7aafdd1475f7c59d62b283"
dependencies = [ dependencies = [
"cfg-if 0.1.10", "cfg-if 1.0.0",
] ]
[[package]] [[package]]
@ -648,7 +648,7 @@ dependencies = [
[[package]] [[package]]
name = "fce" name = "fce"
version = "0.1.9" version = "0.1.10"
dependencies = [ dependencies = [
"boolinator", "boolinator",
"bytes", "bytes",
@ -681,7 +681,7 @@ dependencies = [
[[package]] [[package]]
name = "fce-wit-generator" name = "fce-wit-generator"
version = "0.1.9" version = "0.1.10"
dependencies = [ dependencies = [
"fce-wit-parser", "fce-wit-parser",
"fluence-sdk-wit 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "fluence-sdk-wit 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -694,7 +694,7 @@ dependencies = [
[[package]] [[package]]
name = "fce-wit-interfaces" name = "fce-wit-interfaces"
version = "0.1.6" version = "0.1.7"
dependencies = [ dependencies = [
"multimap", "multimap",
"wasmer-interface-types-fl", "wasmer-interface-types-fl",
@ -702,7 +702,7 @@ dependencies = [
[[package]] [[package]]
name = "fce-wit-parser" name = "fce-wit-parser"
version = "0.1.8" version = "0.1.9"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"fce-wit-interfaces", "fce-wit-interfaces",
@ -713,7 +713,7 @@ dependencies = [
[[package]] [[package]]
name = "fcli" name = "fcli"
version = "0.1.10" version = "0.1.11"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",
@ -724,15 +724,6 @@ dependencies = [
"serde_json", "serde_json",
] ]
[[package]]
name = "fluence"
version = "0.2.8"
source = "git+https://github.com/fluencelabs/rust-sdk#a6c587db0b6f22c3d3af81f10b187f148f8e9d30"
dependencies = [
"fluence-sdk-macro 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)",
"fluence-sdk-main 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)",
]
[[package]] [[package]]
name = "fluence" name = "fluence"
version = "0.2.8" version = "0.2.8"
@ -743,9 +734,18 @@ dependencies = [
"fluence-sdk-main 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "fluence-sdk-main 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "fluence"
version = "0.2.8"
source = "git+https://github.com/fluencelabs/rust-sdk#a6c587db0b6f22c3d3af81f10b187f148f8e9d30"
dependencies = [
"fluence-sdk-macro 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)",
"fluence-sdk-main 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)",
]
[[package]] [[package]]
name = "fluence-app-service" name = "fluence-app-service"
version = "0.1.10" version = "0.1.11"
dependencies = [ dependencies = [
"fluence-faas", "fluence-faas",
"log", "log",
@ -759,7 +759,7 @@ dependencies = [
[[package]] [[package]]
name = "fluence-faas" name = "fluence-faas"
version = "0.1.10" version = "0.1.11"
dependencies = [ dependencies = [
"cmd_lib", "cmd_lib",
"env_logger 0.7.1", "env_logger 0.7.1",
@ -780,14 +780,6 @@ dependencies = [
"wasmer-wasi-fl", "wasmer-wasi-fl",
] ]
[[package]]
name = "fluence-sdk-macro"
version = "0.2.8"
source = "git+https://github.com/fluencelabs/rust-sdk#a6c587db0b6f22c3d3af81f10b187f148f8e9d30"
dependencies = [
"fluence-sdk-wit 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)",
]
[[package]] [[package]]
name = "fluence-sdk-macro" name = "fluence-sdk-macro"
version = "0.2.8" version = "0.2.8"
@ -798,13 +790,11 @@ dependencies = [
] ]
[[package]] [[package]]
name = "fluence-sdk-main" name = "fluence-sdk-macro"
version = "0.2.8" version = "0.2.8"
source = "git+https://github.com/fluencelabs/rust-sdk#a6c587db0b6f22c3d3af81f10b187f148f8e9d30" source = "git+https://github.com/fluencelabs/rust-sdk#a6c587db0b6f22c3d3af81f10b187f148f8e9d30"
dependencies = [ dependencies = [
"fluence-sdk-macro 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", "fluence-sdk-wit 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)",
"log",
"serde",
] ]
[[package]] [[package]]
@ -819,9 +809,20 @@ dependencies = [
] ]
[[package]] [[package]]
name = "fluence-sdk-wit" name = "fluence-sdk-main"
version = "0.2.8" version = "0.2.8"
source = "git+https://github.com/fluencelabs/rust-sdk#a6c587db0b6f22c3d3af81f10b187f148f8e9d30" source = "git+https://github.com/fluencelabs/rust-sdk#a6c587db0b6f22c3d3af81f10b187f148f8e9d30"
dependencies = [
"fluence-sdk-macro 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)",
"log",
"serde",
]
[[package]]
name = "fluence-sdk-wit"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "560baf91197ded38a99a5c94ff366a3dd971ebf33f5d987ecce31d3dedf86d17"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -834,8 +835,7 @@ dependencies = [
[[package]] [[package]]
name = "fluence-sdk-wit" name = "fluence-sdk-wit"
version = "0.2.8" version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/fluencelabs/rust-sdk#a6c587db0b6f22c3d3af81f10b187f148f8e9d30"
checksum = "560baf91197ded38a99a5c94ff366a3dd971ebf33f5d987ecce31d3dedf86d17"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -868,7 +868,7 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]] [[package]]
name = "frepl" name = "frepl"
version = "0.1.13" version = "0.1.14"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",
@ -1114,9 +1114,9 @@ dependencies = [
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "0.13.8" version = "0.13.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f3afcfae8af5ad0576a31e768415edb627824129e8e5a29b8bfccb2f234e835" checksum = "f6ad767baac13b44d4529fcf58ba2cd0995e36e7b435bc5b039de6f47e880dbf"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-channel", "futures-channel",
@ -1128,7 +1128,7 @@ dependencies = [
"httparse", "httparse",
"httpdate", "httpdate",
"itoa", "itoa",
"pin-project 0.4.27", "pin-project 1.0.1",
"socket2", "socket2",
"tokio", "tokio",
"tower-service", "tower-service",
@ -1711,9 +1711,9 @@ checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
[[package]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
version = "0.2.9" version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]] [[package]]
name = "pretty_assertions" name = "pretty_assertions"
@ -1874,9 +1874,9 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.4.1" version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8963b85b8ce3074fecffde43b4b0dded83ce2f367dc8d363afc56679f3ee820b" checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@ -1886,9 +1886,9 @@ dependencies = [
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.6.20" version = "0.6.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cab7a364d15cde1e505267766a2d3c4e22a843e1a601f0fa7564c0f82ced11c" checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189"
[[package]] [[package]]
name = "remove_dir_all" name = "remove_dir_all"
@ -2294,18 +2294,18 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.21" version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "318234ffa22e0920fe9a40d7b8369b5f649d490980cf7aadcf1eb91594869b42" checksum = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "1.0.21" version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cae2447b6282786c3493999f40a9be2a6ad20cb8bd268b0a0dbf5a065535c0ab" checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2791,9 +2791,9 @@ dependencies = [
[[package]] [[package]]
name = "wasmer-interface-types-fl" name = "wasmer-interface-types-fl"
version = "0.17.10" version = "0.17.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1de496e366bd1c198942248fc1de4b94e4647b263dd60099d5f7776f0d621656" checksum = "e916b92f2d315ea27d5ff1d3d6410fe852c51d21bb91a8d1ba7adbf701de7f53"
dependencies = [ dependencies = [
"log", "log",
"nom", "nom",

View File

@ -11,7 +11,7 @@ name = "aquamarine_vm"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
fluence-faas = { path = "../fluence-faas", version = "0.1.10" } fluence-faas = { path = "../fluence-faas", version = "0.1.11" }
maplit = "1.0.2" maplit = "1.0.2"
serde_json = "1.0.57" serde_json = "1.0.57"

View File

@ -1,7 +1,7 @@
[package] [package]
name = "fce-wit-generator" name = "fce-wit-generator"
description = "Fluence FCE interface type helper crate" description = "Fluence FCE interface type helper crate"
version = "0.1.9" version = "0.1.10"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
license = "Apache-2.0" license = "Apache-2.0"
edition = "2018" edition = "2018"
@ -11,11 +11,11 @@ name = "fce_wit_generator"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
fce-wit-parser = { path = "../wit-parser", version = "0.1.8"} fce-wit-parser = { path = "../wit-parser", version = "0.1.9"}
fluence-sdk-wit = "0.2.8" fluence-sdk-wit = "0.2.8"
walrus = "0.17.0" walrus = "0.17.0"
wasmer-wit = { package = "wasmer-interface-types-fl", version = "=0.17.10" } wasmer-wit = { package = "wasmer-interface-types-fl", version = "=0.17.12" }
once_cell = "1.4.0" once_cell = "1.4.0"
serde = { version = "1.0.110", features = ["derive"] } serde = { version = "1.0.110", features = ["derive"] }
serde_json = "1.0.56" serde_json = "1.0.56"

View File

@ -19,6 +19,8 @@ use wasmer_wit::types::InterfaceType as IType;
use wasmer_wit::ast::FunctionArg as IFunctionArg; use wasmer_wit::ast::FunctionArg as IFunctionArg;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use std::rc::Rc;
pub(crate) struct ApiExportFuncDescriptor { pub(crate) struct ApiExportFuncDescriptor {
pub(crate) name: &'static str, pub(crate) name: &'static str,
pub(crate) id: u32, pub(crate) id: u32,
@ -29,8 +31,8 @@ pub(crate) struct ApiExportFuncDescriptor {
impl ApiExportFuncDescriptor { impl ApiExportFuncDescriptor {
pub fn update_interfaces(&self, interfaces: &mut Interfaces<'_>) { pub fn update_interfaces(&self, interfaces: &mut Interfaces<'_>) {
let func_type = wasmer_wit::ast::Type::Function { let func_type = wasmer_wit::ast::Type::Function {
arguments: self.arguments.clone(), arguments: Rc::new(self.arguments.clone()),
output_types: self.output_types.clone(), output_types: Rc::new(self.output_types.clone()),
}; };
interfaces.types.push(func_type); interfaces.types.push(func_type);

View File

@ -25,6 +25,8 @@ use wasmer_wit::types::InterfaceType as IType;
use wasmer_wit::ast::Interfaces; use wasmer_wit::ast::Interfaces;
use wasmer_wit::types::RecordType; use wasmer_wit::types::RecordType;
use std::rc::Rc;
#[derive(PartialEq, Debug, Default)] #[derive(PartialEq, Debug, Default)]
pub(crate) struct WITResolver<'a> { pub(crate) struct WITResolver<'a> {
types: std::collections::HashMap<String, usize>, types: std::collections::HashMap<String, usize>,
@ -54,7 +56,7 @@ impl<'a> WITResolver<'a> {
.insert(record_name.to_string(), self.interfaces.types.len()); .insert(record_name.to_string(), self.interfaces.types.len());
self.interfaces self.interfaces
.types .types
.push(Type::Record(RecordType::default())); .push(Type::Record(Rc::new(RecordType::default())));
self.not_resolved_types_count += 1; self.not_resolved_types_count += 1;
self.interfaces.types.len() self.interfaces.types.len()
@ -86,14 +88,14 @@ impl<'a> WITResolver<'a> {
match self.types.get(&record.name) { match self.types.get(&record.name) {
Some(pos) => { Some(pos) => {
self.interfaces.types[*pos] = Type::Record(record); self.interfaces.types[*pos] = Type::Record(Rc::new(record));
self.not_resolved_types_count -= 1; self.not_resolved_types_count -= 1;
} }
None => { None => {
self.types self.types
.insert(record.name.clone(), self.interfaces.types.len()); .insert(record.name.clone(), self.interfaces.types.len());
self.interfaces.types.push(Type::Record(record)); self.interfaces.types.push(Type::Record(Rc::new(record)));
} }
} }
} }

View File

@ -25,6 +25,8 @@ use fluence_sdk_wit::ParsedType;
use wasmer_wit::interpreter::Instruction; use wasmer_wit::interpreter::Instruction;
use wasmer_wit::ast::FunctionArg as IFunctionArg; use wasmer_wit::ast::FunctionArg as IFunctionArg;
use std::rc::Rc;
impl WITGenerator for AstFunctionItem { impl WITGenerator for AstFunctionItem {
fn generate_wit<'a>(&'a self, wit_resolver: &mut WITResolver<'a>) -> Result<()> { fn generate_wit<'a>(&'a self, wit_resolver: &mut WITResolver<'a>) -> Result<()> {
use wasmer_wit::ast::Type; use wasmer_wit::ast::Type;
@ -42,10 +44,13 @@ impl WITGenerator for AstFunctionItem {
}) })
.collect::<Result<Vec<_>>>()?; .collect::<Result<Vec<_>>>()?;
let arguments = Rc::new(arguments);
let output_types = match self.signature.output_type { let output_types = match self.signature.output_type {
Some(ref output_type) => vec![ptype_to_itype_checked(output_type, wit_resolver)?], Some(ref output_type) => vec![ptype_to_itype_checked(output_type, wit_resolver)?],
None => vec![], None => vec![],
}; };
let output_types = Rc::new(output_types);
let interfaces = &mut wit_resolver.interfaces; let interfaces = &mut wit_resolver.interfaces;
interfaces.types.push(Type::Function { interfaces.types.push(Type::Function {

View File

@ -27,6 +27,8 @@ use wasmer_wit::ast::FunctionArg as IFunctionArg;
use wasmer_wit::interpreter::Instruction; use wasmer_wit::interpreter::Instruction;
use crate::instructions_generator::utils::wtype_to_itype; use crate::instructions_generator::utils::wtype_to_itype;
use std::rc::Rc;
const HOST_NAMESPACE_NAME: &str = "host"; const HOST_NAMESPACE_NAME: &str = "host";
impl WITGenerator for AstExternModItem { impl WITGenerator for AstExternModItem {
@ -63,11 +65,13 @@ fn generate_wit_for_import<'a>(
}) })
}) })
.collect::<Result<Vec<_>>>()?; .collect::<Result<Vec<_>>>()?;
let arguments = Rc::new(arguments);
let output_types = match import.signature.output_type { let output_types = match import.signature.output_type {
Some(ref output_type) => vec![ptype_to_itype_checked(output_type, wit_resolver)?], Some(ref output_type) => vec![ptype_to_itype_checked(output_type, wit_resolver)?],
None => vec![], None => vec![],
}; };
let output_types = Rc::new(output_types);
let interfaces = &mut wit_resolver.interfaces; let interfaces = &mut wit_resolver.interfaces;
interfaces.types.push(Type::Function { interfaces.types.push(Type::Function {
@ -82,6 +86,7 @@ fn generate_wit_for_import<'a>(
.map(to_raw_input_types) .map(to_raw_input_types)
.flatten() .flatten()
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let raw_inputs = Rc::new(raw_inputs);
let raw_outputs = match import.signature.output_type { let raw_outputs = match import.signature.output_type {
Some(ref output_type) => to_raw_output_type(output_type) Some(ref output_type) => to_raw_output_type(output_type)
@ -90,6 +95,7 @@ fn generate_wit_for_import<'a>(
.collect(), .collect(),
None => vec![], None => vec![],
}; };
let raw_outputs = Rc::new(raw_outputs);
interfaces.types.push(Type::Function { interfaces.types.push(Type::Function {
arguments: raw_inputs.clone(), arguments: raw_inputs.clone(),

View File

@ -1,7 +1,7 @@
[package] [package]
name = "fce-wit-interfaces" name = "fce-wit-interfaces"
description = "Fluence FCE interface type helper crate" description = "Fluence FCE interface type helper crate"
version = "0.1.6" version = "0.1.7"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
license = "Apache-2.0" license = "Apache-2.0"
edition = "2018" edition = "2018"
@ -11,5 +11,5 @@ name = "fce_wit_interfaces"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
wasmer-wit = { package = "wasmer-interface-types-fl", version = "=0.17.10" } wasmer-wit = { package = "wasmer-interface-types-fl", version = "=0.17.12" }
multimap = "0.8.1" multimap = "0.8.1"

View File

@ -23,6 +23,7 @@ use multimap::MultiMap;
use std::iter::Iterator; use std::iter::Iterator;
use std::collections::HashMap; use std::collections::HashMap;
use std::rc::Rc;
pub type CoreFunctionType = u32; pub type CoreFunctionType = u32;
pub type AdapterFunctionType = u32; pub type AdapterFunctionType = u32;
@ -109,7 +110,7 @@ impl<'a> FCEWITInterfaces<'a> {
self.types.iter() self.types.iter()
} }
pub fn record_types(&self) -> impl Iterator<Item = (u64, &RecordType)> { pub fn record_types(&self) -> impl Iterator<Item = (u64, &Rc<RecordType>)> {
self.types.iter().enumerate().filter_map(|(id, t)| match t { self.types.iter().enumerate().filter_map(|(id, t)| match t {
WITAstType::Record(r) => Some((id as u64, r)), WITAstType::Record(r) => Some((id as u64, r)),
_ => None, _ => None,

View File

@ -1,7 +1,7 @@
[package] [package]
name = "fce-wit-parser" name = "fce-wit-parser"
description = "Fluence FCE interface type helper crate" description = "Fluence FCE interface type helper crate"
version = "0.1.8" version = "0.1.9"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
license = "Apache-2.0" license = "Apache-2.0"
edition = "2018" edition = "2018"
@ -11,9 +11,9 @@ name = "fce_wit_parser"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
fce-wit-interfaces = { path = "../wit-interfaces", version = "0.1.6" } fce-wit-interfaces = { path = "../wit-interfaces", version = "0.1.7" }
anyhow = "1.0.31" anyhow = "1.0.31"
walrus = "0.17.0" walrus = "0.17.0"
wasmer-core = { package = "wasmer-runtime-core-fl", version = "0.17.0"} wasmer-core = { package = "wasmer-runtime-core-fl", version = "0.17.0"}
wasmer-wit = { package = "wasmer-interface-types-fl", version = "=0.17.10" } wasmer-wit = { package = "wasmer-interface-types-fl", version = "=0.17.12" }

View File

@ -1,7 +1,7 @@
[package] [package]
name = "fce" name = "fce"
description = "Fluence Compute Engine" description = "Fluence Compute Engine"
version = "0.1.9" version = "0.1.10"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
license = "Apache-2.0" license = "Apache-2.0"
edition = "2018" edition = "2018"
@ -11,13 +11,13 @@ name = "fce"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
fce-wit-interfaces = { path = "../crates/wit-interfaces", version = "0.1.6" } fce-wit-interfaces = { path = "../crates/wit-interfaces", version = "0.1.7" }
fce-wit-parser = { path = "../crates/wit-parser", version = "0.1.8" } fce-wit-parser = { path = "../crates/wit-parser", version = "0.1.9" }
wasmer-runtime = { package = "wasmer-runtime-fl", version = "0.17.0" } wasmer-runtime = { package = "wasmer-runtime-fl", version = "0.17.0" }
# dynamicfunc-fat-closures allows using state inside DynamicFunc # dynamicfunc-fat-closures allows using state inside DynamicFunc
wasmer-core = { package = "wasmer-runtime-core-fl", version = "0.17.0", features = ["dynamicfunc-fat-closures"] } wasmer-core = { package = "wasmer-runtime-core-fl", version = "0.17.0", features = ["dynamicfunc-fat-closures"] }
wasmer-wit = { package = "wasmer-interface-types-fl", version = "=0.17.10" } wasmer-wit = { package = "wasmer-interface-types-fl", version = "=0.17.12" }
wasmer-wasi = { package = "wasmer-wasi-fl", version = "0.17.0" } wasmer-wasi = { package = "wasmer-wasi-fl", version = "0.17.0" }
multimap = "0.8.1" multimap = "0.8.1"

View File

@ -14,17 +14,19 @@
* limitations under the License. * limitations under the License.
*/ */
use super::module::FCEModule;
use super::*; use super::*;
use crate::module::FCEModule;
use crate::module::RecordTypes;
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::collections::HashMap; use std::collections::HashMap;
use std::rc::Rc;
/// Represent FCE module interface. /// Represent FCE module interface.
#[derive(PartialEq, Eq, Debug, Clone)] #[derive(PartialEq, Eq, Debug, Clone)]
pub struct FCEModuleInterface<'a> { pub struct FCEModuleInterface<'a> {
pub record_types: &'a HashMap<u64, IRecordType>, pub record_types: &'a RecordTypes,
pub function_signatures: Vec<FCEFunctionSignature<'a>>, pub function_signatures: Vec<FCEFunctionSignature>,
} }
/// The base struct of the Fluence Compute Engine. /// The base struct of the Fluence Compute Engine.
@ -128,10 +130,7 @@ impl FCE {
} }
/// Return record types exported by module with given name. /// Return record types exported by module with given name.
pub fn module_record_types<S: AsRef<str>>( pub fn module_record_types<S: AsRef<str>>(&self, module_name: S) -> Option<&RecordTypes> {
&self,
module_name: S,
) -> Option<&HashMap<u64, IRecordType>> {
self.modules self.modules
.get(module_name.as_ref()) .get(module_name.as_ref())
.map(|module| module.export_record_types()) .map(|module| module.export_record_types())
@ -142,7 +141,7 @@ impl FCE {
&self, &self,
module_name: S, module_name: S,
record_id: u64, record_id: u64,
) -> Option<&'_ IRecordType> { ) -> Option<&Rc<IRecordType>> {
self.modules self.modules
.get(module_name.as_ref()) .get(module_name.as_ref())
.and_then(|module| module.export_record_type_by_id(record_id)) .and_then(|module| module.export_record_type_by_id(record_id))

View File

@ -19,6 +19,7 @@ use super::ivalues_lifting::wvalues_to_ivalues;
use super::ivalues_lowering::ivalue_to_wvalues; use super::ivalues_lowering::ivalue_to_wvalues;
use super::utils::itypes_args_to_wtypes; use super::utils::itypes_args_to_wtypes;
use super::utils::itypes_output_to_wtypes; use super::utils::itypes_output_to_wtypes;
use crate::RecordTypes;
use crate::init_wasm_func_once; use crate::init_wasm_func_once;
use crate::call_wasm_func; use crate::call_wasm_func;
@ -29,15 +30,13 @@ use wasmer_core::vm::Ctx;
use wasmer_core::typed_func::DynamicFunc; use wasmer_core::typed_func::DynamicFunc;
use wasmer_core::types::Value as WValue; use wasmer_core::types::Value as WValue;
use wasmer_core::types::FuncSig; use wasmer_core::types::FuncSig;
use wasmer_wit::types::RecordType;
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc; use std::rc::Rc;
pub(crate) fn create_host_import_func( pub(crate) fn create_host_import_func(
descriptor: HostImportDescriptor, descriptor: HostImportDescriptor,
record_types: Rc<HashMap<u64, RecordType>>, record_types: Rc<RecordTypes>,
) -> DynamicFunc<'static> { ) -> DynamicFunc<'static> {
let allocate_func: AllocateFunc = Box::new(RefCell::new(None)); let allocate_func: AllocateFunc = Box::new(RefCell::new(None));
let set_result_ptr_func: SetResultPtrFunc = Box::new(RefCell::new(None)); let set_result_ptr_func: SetResultPtrFunc = Box::new(RefCell::new(None));

View File

@ -19,6 +19,7 @@ use super::WType;
use super::WValue; use super::WValue;
use super::HostImportError; use super::HostImportError;
use crate::IValue; use crate::IValue;
use crate::RecordTypes;
use crate::IType; use crate::IType;
use super::Result; use super::Result;
@ -27,14 +28,13 @@ use wasmer_core::vm::Ctx;
use wasmer_wit::types::RecordType; use wasmer_wit::types::RecordType;
use wasmer_wit::vec1::Vec1; use wasmer_wit::vec1::Vec1;
use std::collections::HashMap;
use std::rc::Rc; use std::rc::Rc;
pub(super) fn wvalues_to_ivalues( pub(super) fn wvalues_to_ivalues(
ctx: &Ctx, ctx: &Ctx,
wvalues: &[WValue], wvalues: &[WValue],
itypes: &[IType], itypes: &[IType],
record_types: &Rc<HashMap<u64, RecordType>>, record_types: &Rc<RecordTypes>,
) -> Result<Vec<IValue>> { ) -> Result<Vec<IValue>> {
let mut result = Vec::new(); let mut result = Vec::new();
let mut wvalue = wvalues.iter(); let mut wvalue = wvalues.iter();
@ -114,7 +114,7 @@ fn lift_array(
value_type: &IType, value_type: &IType,
offset: usize, offset: usize,
size: usize, size: usize,
record_types: &Rc<HashMap<u64, RecordType>>, record_types: &Rc<RecordTypes>,
) -> Result<Vec<IValue>> { ) -> Result<Vec<IValue>> {
if size == 0 { if size == 0 {
return Ok(vec![]); return Ok(vec![]);
@ -211,7 +211,7 @@ fn lift_record(
ctx: &Ctx, ctx: &Ctx,
record_type: &RecordType, record_type: &RecordType,
offset: usize, offset: usize,
record_types: &Rc<HashMap<u64, RecordType>>, record_types: &Rc<RecordTypes>,
) -> Result<IValue> { ) -> Result<IValue> {
// TODO: make it export from wasmer-interface-types crate // TODO: make it export from wasmer-interface-types crate
fn record_size(record_type: &RecordType) -> usize { fn record_size(record_type: &RecordType) -> usize {

View File

@ -45,6 +45,7 @@ pub use module::IValue;
pub use module::IRecordType; pub use module::IRecordType;
pub use module::IFunctionArg; pub use module::IFunctionArg;
pub use module::IType; pub use module::IType;
pub use module::RecordTypes;
pub use module::FCEFunctionSignature; pub use module::FCEFunctionSignature;
pub use module::from_interface_values; pub use module::from_interface_values;
pub use module::to_interface_value; pub use module::to_interface_value;

View File

@ -16,6 +16,7 @@
use super::wit_prelude::*; use super::wit_prelude::*;
use super::{IType, IRecordType, IFunctionArg, IValue, WValue}; use super::{IType, IRecordType, IFunctionArg, IValue, WValue};
use super::RecordTypes;
use crate::Result; use crate::Result;
use crate::FCEModuleConfig; use crate::FCEModuleConfig;
@ -31,6 +32,7 @@ use std::collections::HashMap;
use std::convert::TryInto; use std::convert::TryInto;
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use std::sync::Arc; use std::sync::Arc;
use std::rc::Rc;
type WITInterpreter = type WITInterpreter =
Interpreter<WITInstance, WITExport, WITFunction, WITMemory, WITMemoryView<'static>>; Interpreter<WITInstance, WITExport, WITFunction, WITMemory, WITMemoryView<'static>>;
@ -38,8 +40,16 @@ type WITInterpreter =
#[derive(Clone)] #[derive(Clone)]
pub(super) struct WITModuleFunc { pub(super) struct WITModuleFunc {
interpreter: Arc<WITInterpreter>, interpreter: Arc<WITInterpreter>,
pub(super) arguments: Vec<IFunctionArg>, pub(super) arguments: Rc<Vec<IFunctionArg>>,
pub(super) output_types: Vec<IType>, pub(super) output_types: Rc<Vec<IType>>,
}
/// Represent a function type inside FCE module.
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
pub struct FCEFunctionSignature {
pub name: Rc<String>,
pub arguments: Rc<Vec<IFunctionArg>>,
pub outputs: Rc<Vec<IType>>,
} }
#[derive(Clone)] #[derive(Clone)]
@ -48,14 +58,6 @@ pub(super) struct Callable {
pub(super) wit_module_func: WITModuleFunc, pub(super) wit_module_func: WITModuleFunc,
} }
/// Represent a function type inside FCE module.
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
pub struct FCEFunctionSignature<'a> {
pub name: &'a str,
pub arguments: &'a Vec<IFunctionArg>,
pub outputs: &'a Vec<IType>,
}
impl Callable { impl Callable {
pub fn call(&mut self, args: &[IValue]) -> Result<Vec<IValue>> { pub fn call(&mut self, args: &[IValue]) -> Result<Vec<IValue>> {
use wasmer_wit::interpreter::stack::Stackable; use wasmer_wit::interpreter::stack::Stackable;
@ -71,6 +73,17 @@ impl Callable {
} }
} }
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash)]
struct SharedString(pub Rc<String>);
impl std::borrow::Borrow<str> for SharedString {
fn borrow(&self) -> &str {
self.0.as_str()
}
}
type ExportFunctions = HashMap<SharedString, Rc<Callable>>;
pub(crate) struct FCEModule { pub(crate) struct FCEModule {
// wasmer_instance is needed because WITInstance contains dynamic functions // wasmer_instance is needed because WITInstance contains dynamic functions
// that internally keep pointer to it. // that internally keep pointer to it.
@ -93,10 +106,11 @@ pub(crate) struct FCEModule {
host_closures_import_object: ImportObject, host_closures_import_object: ImportObject,
// TODO: replace with dyn Trait // TODO: replace with dyn Trait
export_funcs: HashMap<String, Arc<Callable>>, export_funcs: ExportFunctions,
// TODO: save refs instead of copies // TODO: save refs instead copying of a record types HashMap.
record_types: HashMap<u64, IRecordType>, /// Record types used in exported functions as arguments or return values.
export_record_types: RecordTypes,
} }
impl FCEModule { impl FCEModule {
@ -125,7 +139,7 @@ impl FCEModule {
}; };
let export_funcs = Self::instantiate_wit_exports(&wit_instance, &fce_wit)?; let export_funcs = Self::instantiate_wit_exports(&wit_instance, &fce_wit)?;
let record_types = Self::extract_export_record_types(&export_funcs, &wit_instance)?; let export_record_types = Self::extract_export_record_types(&export_funcs, &wit_instance)?;
// call _start to populate the WASI state of the module // call _start to populate the WASI state of the module
#[rustfmt::skip] #[rustfmt::skip]
@ -139,7 +153,7 @@ impl FCEModule {
host_import_object: raw_imports, host_import_object: raw_imports,
host_closures_import_object, host_closures_import_object,
export_funcs, export_funcs,
record_types, export_record_types,
}) })
} }
@ -151,26 +165,26 @@ impl FCEModule {
function_name function_name
))) )))
}, },
|func| Arc::make_mut(func).call(args), |func| Rc::make_mut(func).call(args),
) )
} }
pub(crate) fn get_exports_signatures(&self) -> impl Iterator<Item = FCEFunctionSignature<'_>> { pub(crate) fn get_exports_signatures(&self) -> impl Iterator<Item = FCEFunctionSignature> + '_ {
self.export_funcs self.export_funcs
.iter() .iter()
.map(|(func_name, func)| FCEFunctionSignature { .map(|(func_name, func)| FCEFunctionSignature {
name: func_name.as_str(), name: func_name.0.clone(),
arguments: &func.wit_module_func.arguments, arguments: func.wit_module_func.arguments.clone(),
outputs: &func.wit_module_func.output_types, outputs: func.wit_module_func.output_types.clone(),
}) })
} }
pub(crate) fn export_record_types(&self) -> &HashMap<u64, IRecordType> { pub(crate) fn export_record_types(&self) -> &RecordTypes {
&self.record_types &self.export_record_types
} }
pub(crate) fn export_record_type_by_id(&self, record_type: u64) -> Option<&IRecordType> { pub(crate) fn export_record_type_by_id(&self, record_type: u64) -> Option<&Rc<IRecordType>> {
self.record_types.get(&record_type) self.export_record_types.get(&record_type)
} }
pub(crate) fn get_wasi_state(&mut self) -> &wasmer_wasi::state::WasiState { pub(crate) fn get_wasi_state(&mut self) -> &wasmer_wasi::state::WasiState {
@ -178,7 +192,7 @@ impl FCEModule {
} }
// TODO: change the cloning Callable behaviour after changes of Wasmer API // TODO: change the cloning Callable behaviour after changes of Wasmer API
pub(super) fn get_callable(&self, function_name: &str) -> Result<Arc<Callable>> { pub(super) fn get_callable(&self, function_name: &str) -> Result<Rc<Callable>> {
match self.export_funcs.get(function_name) { match self.export_funcs.get(function_name) {
Some(func) => Ok(func.clone()), Some(func) => Ok(func.clone()),
None => Err(FCEError::NoSuchFunction(format!( None => Err(FCEError::NoSuchFunction(format!(
@ -220,7 +234,7 @@ impl FCEModule {
.record_types() .record_types()
.map(|(id, r)| (id, r.clone())) .map(|(id, r)| (id, r.clone()))
.collect::<HashMap<_, _>>(); .collect::<HashMap<_, _>>();
let record_types = std::rc::Rc::new(record_types); let record_types = Rc::new(record_types);
for (import_name, descriptor) in config.host_imports { for (import_name, descriptor) in config.host_imports {
let host_import = create_host_import_func(descriptor, record_types.clone()); let host_import = create_host_import_func(descriptor, record_types.clone());
@ -239,7 +253,7 @@ impl FCEModule {
fn instantiate_wit_exports( fn instantiate_wit_exports(
wit_instance: &Arc<WITInstance>, wit_instance: &Arc<WITInstance>,
wit: &FCEWITInterfaces<'_>, wit: &FCEWITInterfaces<'_>,
) -> Result<HashMap<String, Arc<Callable>>> { ) -> Result<ExportFunctions> {
use fce_wit_interfaces::WITAstType; use fce_wit_interfaces::WITAstType;
wit.implementations() wit.implementations()
@ -275,13 +289,13 @@ impl FCEModule {
output_types: output_types.clone(), output_types: output_types.clone(),
}; };
Ok(( let shared_string = SharedString(Rc::new(export_function_name.to_string()));
export_function_name.to_string(), let callable = Rc::new(Callable {
Arc::new(Callable { wit_instance: wit_instance.clone(),
wit_instance: wit_instance.clone(), wit_module_func,
wit_module_func, });
}),
)) Ok((shared_string, callable))
} }
_ => Err(FCEError::IncorrectWIT(format!( _ => Err(FCEError::IncorrectWIT(format!(
"type with idx = {} isn't a function type", "type with idx = {} isn't a function type",
@ -289,7 +303,7 @@ impl FCEModule {
))), ))),
} }
}) })
.collect::<Result<HashMap<String, Arc<Callable>>>>() .collect::<Result<ExportFunctions>>()
} }
// this function deals only with import functions that have an adaptor implementation // this function deals only with import functions that have an adaptor implementation
@ -430,13 +444,13 @@ impl FCEModule {
} }
fn extract_export_record_types( fn extract_export_record_types(
export_funcs: &HashMap<String, Arc<Callable>>, export_funcs: &ExportFunctions,
wit_instance: &Arc<WITInstance>, wit_instance: &Arc<WITInstance>,
) -> Result<HashMap<u64, IRecordType>> { ) -> Result<RecordTypes> {
fn handle_record_type( fn handle_record_type(
record_type_id: u64, record_type_id: u64,
wit_instance: &Arc<WITInstance>, wit_instance: &Arc<WITInstance>,
export_record_types: &mut HashMap<u64, IRecordType>, export_record_types: &mut RecordTypes,
) -> Result<()> { ) -> Result<()> {
use wasmer_wit::interpreter::wasm::structures::Instance; use wasmer_wit::interpreter::wasm::structures::Instance;

View File

@ -21,6 +21,8 @@ mod wit_instance;
mod type_converters; mod type_converters;
mod fce_module; mod fce_module;
pub use wit_instance::RecordTypes;
pub use wasmer_wit::types::InterfaceType as IType; pub use wasmer_wit::types::InterfaceType as IType;
pub use wasmer_wit::types::RecordType as IRecordType; pub use wasmer_wit::types::RecordType as IRecordType;
pub use wasmer_wit::ast::FunctionArg as IFunctionArg; pub use wasmer_wit::ast::FunctionArg as IFunctionArg;

View File

@ -22,20 +22,21 @@ use crate::Result;
use wasmer_wit::interpreter::wasm; use wasmer_wit::interpreter::wasm;
use wasmer_core::instance::DynFunc; use wasmer_core::instance::DynFunc;
use std::sync::Arc; // use std::sync::Arc;
use std::rc::Rc;
#[derive(Clone)] #[derive(Clone)]
enum WITFunctionInner { enum WITFunctionInner {
Export { Export {
func: Arc<DynFunc<'static>>, func: Rc<DynFunc<'static>>,
arguments: Vec<IFunctionArg>, arguments: Rc<Vec<IFunctionArg>>,
outputs: Vec<IType>, outputs: Rc<Vec<IType>>,
}, },
Import { Import {
// TODO: use dyn Callable here // TODO: use dyn Callable here
callable: Arc<Callable>, callable: Rc<Callable>,
arguments: Vec<IFunctionArg>, arguments: Rc<Vec<IFunctionArg>>,
outputs: Vec<IType>, outputs: Rc<Vec<IType>>,
}, },
} }
@ -67,9 +68,9 @@ impl WITFunction {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let inner = WITFunctionInner::Export { let inner = WITFunctionInner::Export {
func: Arc::new(dyn_func), func: Rc::new(dyn_func),
arguments, arguments: Rc::new(arguments),
outputs, outputs: Rc::new(outputs),
}; };
Ok(Self { inner }) Ok(Self { inner })
@ -79,8 +80,8 @@ impl WITFunction {
pub(super) fn from_import( pub(super) fn from_import(
wit_module: &FCEModule, wit_module: &FCEModule,
function_name: &str, function_name: &str,
arguments: Vec<IFunctionArg>, arguments: Rc<Vec<IFunctionArg>>,
outputs: Vec<IType>, outputs: Rc<Vec<IType>>,
) -> Result<Self> { ) -> Result<Self> {
let callable = wit_module.get_callable(function_name)?; let callable = wit_module.get_callable(function_name)?;
@ -132,7 +133,7 @@ impl wasm::structures::LocalImport for WITFunction {
.call(&arguments.iter().map(ival_to_wval).collect::<Vec<WValue>>()) .call(&arguments.iter().map(ival_to_wval).collect::<Vec<WValue>>())
.map(|result| result.iter().map(wval_to_ival).collect()) .map(|result| result.iter().map(wval_to_ival).collect())
.map_err(|_| ()), .map_err(|_| ()),
WITFunctionInner::Import { callable, .. } => Arc::make_mut(&mut callable.clone()) WITFunctionInner::Import { callable, .. } => Rc::make_mut(&mut callable.clone())
.call(arguments) .call(arguments)
.map_err(|_| ()), .map_err(|_| ()),
} }

View File

@ -26,6 +26,9 @@ use wasmer_wit::interpreter::wasm::structures::{LocalImportIndex, TypedIndex};
use wasmer_core::Instance as WasmerInstance; use wasmer_core::Instance as WasmerInstance;
use std::collections::HashMap; use std::collections::HashMap;
use std::rc::Rc;
pub type RecordTypes = HashMap<u64, Rc<IRecordType>>;
/// Contains all import and export functions that could be called from WIT context by call-core. /// Contains all import and export functions that could be called from WIT context by call-core.
#[derive(Clone)] #[derive(Clone)]
@ -36,7 +39,8 @@ pub(super) struct WITInstance {
/// WIT memories. /// WIT memories.
memories: Vec<WITMemory>, memories: Vec<WITMemory>,
record_types_by_id: HashMap<u64, IRecordType>, /// All record types that instance contains.
record_types_by_id: RecordTypes,
} }
impl WITInstance { impl WITInstance {
@ -146,8 +150,8 @@ impl WITInstance {
memories memories
} }
fn extract_record_types(wit: &FCEWITInterfaces<'_>) -> HashMap<u64, IRecordType> { fn extract_record_types(wit: &FCEWITInterfaces<'_>) -> RecordTypes {
let record_types_by_id = wit.types().fold( let (record_types_by_id, _) = wit.types().fold(
(HashMap::new(), 0u64), (HashMap::new(), 0u64),
|(mut record_types_by_id, id), ty| { |(mut record_types_by_id, id), ty| {
match ty { match ty {
@ -160,7 +164,7 @@ impl WITInstance {
}, },
); );
record_types_by_id.0 record_types_by_id
} }
} }
@ -184,7 +188,7 @@ impl wasm::structures::Instance<WITExport, WITFunction, WITMemory, WITMemoryView
} }
} }
fn wit_record_by_id(&self, index: u64) -> Option<&IRecordType> { fn wit_record_by_id(&self, index: u64) -> Option<&Rc<IRecordType>> {
self.record_types_by_id.get(&index) self.record_types_by_id.get(&index)
} }
} }

View File

@ -1,13 +1,13 @@
[package] [package]
name = "fluence-app-service" name = "fluence-app-service"
description = "Fluence Application Service" description = "Fluence Application Service"
version = "0.1.10" version = "0.1.11"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
license = "Apache-2.0" license = "Apache-2.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
fluence-faas = { path = "../fluence-faas", version = "0.1.10" } fluence-faas = { path = "../fluence-faas", version = "0.1.11" }
maplit = "1.0.2" maplit = "1.0.2"
log = "0.4.8" log = "0.4.8"

View File

@ -17,9 +17,9 @@
use crate::Result; use crate::Result;
use crate::config::AppServiceConfig; use crate::config::AppServiceConfig;
use super::AppServiceError; use super::AppServiceError;
use super::IValue;
use fluence_faas::FluenceFaaS; use fluence_faas::FluenceFaaS;
use serde_json::Value as JValue;
use std::convert::TryInto; use std::convert::TryInto;
use std::collections::HashMap; use std::collections::HashMap;
@ -73,9 +73,9 @@ impl AppService {
pub fn call<S: AsRef<str>>( pub fn call<S: AsRef<str>>(
&mut self, &mut self,
func_name: S, func_name: S,
arguments: serde_json::Value, arguments: JValue,
call_parameters: crate::CallParameters, call_parameters: crate::CallParameters,
) -> Result<Vec<IValue>> { ) -> Result<JValue> {
self.faas self.faas
.call_with_json( .call_with_json(
&self.facade_module_name, &self.facade_module_name,
@ -177,9 +177,9 @@ impl AppService {
&mut self, &mut self,
module_name: MN, module_name: MN,
func_name: FN, func_name: FN,
arguments: serde_json::Value, arguments: JValue,
call_parameters: crate::CallParameters, call_parameters: crate::CallParameters,
) -> Result<Vec<IValue>> { ) -> Result<JValue> {
self.faas self.faas
.call_with_json(module_name, func_name, arguments, call_parameters) .call_with_json(module_name, func_name, arguments, call_parameters)
.map_err(Into::into) .map_err(Into::into)

View File

@ -1,20 +1,20 @@
[package] [package]
name = "fluence-faas" name = "fluence-faas"
description = "Fluence FaaS" description = "Fluence FaaS"
version = "0.1.10" version = "0.1.11"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
license = "Apache-2.0" license = "Apache-2.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
fce = { path = "../engine", version = "0.1.9" } fce = { path = "../engine", version = "0.1.10" }
fluence-sdk-main = "=0.2.8" fluence-sdk-main = "=0.2.8"
wasmer-runtime = { package = "wasmer-runtime-fl", version = "0.17.0" } wasmer-runtime = { package = "wasmer-runtime-fl", version = "0.17.0" }
# dynamicfunc-fat-closures allows using state inside DynamicFunc # dynamicfunc-fat-closures allows using state inside DynamicFunc
wasmer-core = { package = "wasmer-runtime-core-fl", version = "0.17.0", features = ["dynamicfunc-fat-closures"] } wasmer-core = { package = "wasmer-runtime-core-fl", version = "0.17.0", features = ["dynamicfunc-fat-closures"] }
wasmer-wasi = { package = "wasmer-wasi-fl", version = "0.17.0" } wasmer-wasi = { package = "wasmer-wasi-fl", version = "0.17.0" }
wasmer-wit = { package = "wasmer-interface-types-fl", version = "=0.17.10" } wasmer-wit = { package = "wasmer-interface-types-fl", version = "=0.17.12" }
toml = "0.5.6" toml = "0.5.6"
serde = { version = "1.0.111", features = ["derive"] } serde = { version = "1.0.111", features = ["derive"] }

View File

@ -16,8 +16,6 @@
use fce::FCEError; use fce::FCEError;
use serde_json::error::Error as SerdeError;
use std::io::Error as IOError; use std::io::Error as IOError;
use std::error::Error; use std::error::Error;
@ -41,16 +39,17 @@ pub enum FaaSError {
/// Returns when there is no module with such name. /// Returns when there is no module with such name.
NoSuchModule(String), NoSuchModule(String),
/// Not enough arguments provided for FCE call. /// Provided arguments aren't compatible with a called function signature.
JsonArgumentsDeserializationError(String), JsonArgumentsDeserializationError(String),
/// An error occurred when incorrect json argument is supplied. /// Returned outputs aren't compatible with a called function signature.
ArgumentDeserializationError(SerdeError), JsonOutputSerializationError(String),
/// Errors related to invalid config.
ParseConfigError(toml::de::Error),
/// FCE errors. /// FCE errors.
EngineError(FCEError), EngineError(FCEError),
ParseConfigError(toml::de::Error),
} }
impl Error for FaaSError {} impl Error for FaaSError {}
@ -70,7 +69,7 @@ impl std::fmt::Display for FaaSError {
write!(f, r#"module with name "{}" is missing"#, module_name) write!(f, r#"module with name "{}" is missing"#, module_name)
} }
FaaSError::JsonArgumentsDeserializationError(args) => write!(f, "{}", args), FaaSError::JsonArgumentsDeserializationError(args) => write!(f, "{}", args),
FaaSError::ArgumentDeserializationError(err_msg) => write!(f, "{:?}", err_msg), FaaSError::JsonOutputSerializationError(args) => write!(f, "{}", args),
FaaSError::IOError(err_msg) => write!(f, "{}", err_msg), FaaSError::IOError(err_msg) => write!(f, "{}", err_msg),
FaaSError::EngineError(err) => write!(f, "{}", err), FaaSError::EngineError(err) => write!(f, "{}", err),
FaaSError::ParseConfigError(err) => write!(f, "{}", err), FaaSError::ParseConfigError(err) => write!(f, "{}", err),

View File

@ -15,21 +15,22 @@
*/ */
use crate::config::FaaSConfig; use crate::config::FaaSConfig;
use crate::misc::ModulesLoadStrategy;
use crate::faas_interface::FaaSInterface; use crate::faas_interface::FaaSInterface;
use crate::FaaSError; use crate::FaaSError;
use crate::Result; use crate::Result;
use crate::IValue; use crate::IValue;
use crate::misc::load_modules_from_fs;
use crate::misc::ModulesLoadStrategy;
use fce::FCE; use fce::FCE;
use fluence_sdk_main::CallParameters; use fluence_sdk_main::CallParameters;
use serde_json::Value as JValue;
use std::cell::RefCell; use std::cell::RefCell;
use std::convert::TryInto; use std::convert::TryInto;
use std::collections::HashSet; use std::collections::HashSet;
use std::collections::HashMap; use std::collections::HashMap;
use std::rc::Rc; use std::rc::Rc;
use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
// TODO: remove and use mutex instead // TODO: remove and use mutex instead
@ -61,7 +62,7 @@ impl FluenceFaaS {
.modules_dir .modules_dir
.as_ref() .as_ref()
.map_or(Ok(HashMap::new()), |dir| { .map_or(Ok(HashMap::new()), |dir| {
Self::load_modules(dir, ModulesLoadStrategy::WasmOnly) load_modules_from_fs(dir, ModulesLoadStrategy::WasmOnly)
})?; })?;
Self::with_modules::<FaaSConfig>(modules, config) Self::with_modules::<FaaSConfig>(modules, config)
@ -112,62 +113,12 @@ impl FluenceFaaS {
.modules_dir .modules_dir
.as_ref() .as_ref()
.map_or(Ok(HashMap::new()), |dir| { .map_or(Ok(HashMap::new()), |dir| {
Self::load_modules(dir, ModulesLoadStrategy::Named(names)) load_modules_from_fs(dir, ModulesLoadStrategy::Named(names))
})?; })?;
Self::with_modules::<FaaSConfig>(modules, config) Self::with_modules::<FaaSConfig>(modules, config)
} }
/// Loads modules from a directory at a given path. Non-recursive, ignores subdirectories.
fn load_modules(
modules_dir: &PathBuf,
modules: ModulesLoadStrategy<'_>,
) -> Result<HashMap<String, Vec<u8>>> {
use FaaSError::IOError;
let mut dir_entries =
fs::read_dir(modules_dir).map_err(|e| IOError(format!("{:?}: {}", modules_dir, e)))?;
let loaded = dir_entries.try_fold(HashMap::new(), |mut hash_map, entry| {
let entry = entry?;
let path = entry.path();
// Skip directories
if path.is_dir() {
return Ok(hash_map);
}
let module_name = path
.file_name()
.ok_or_else(|| IOError(format!("No file name in path {:?}", path)))?
.to_os_string()
.into_string()
.map_err(|name| IOError(format!("invalid file name: {:?}", name)))?;
if modules.should_load(&module_name.as_ref()) {
let module_bytes = fs::read(path)?;
let module_name = modules.extract_module_name(module_name);
if hash_map.insert(module_name, module_bytes).is_some() {
return Err(FaaSError::ConfigParseError(String::from(
"module {} is duplicated in config",
)));
}
}
Ok(hash_map)
})?;
if modules.required_modules_len() > loaded.len() {
let loaded = loaded.iter().map(|(n, _)| n);
let not_found = modules.missing_modules(loaded);
return Err(FaaSError::ConfigParseError(format!(
"the following modules were not found: {:?}",
not_found
)));
}
Ok(loaded)
}
/// Call a specified function of loaded on a startup module by its name. /// Call a specified function of loaded on a startup module by its name.
pub fn call_with_ivalues<MN: AsRef<str>, FN: AsRef<str>>( pub fn call_with_ivalues<MN: AsRef<str>, FN: AsRef<str>>(
&mut self, &mut self,
@ -188,34 +139,36 @@ impl FluenceFaaS {
&mut self, &mut self,
module_name: MN, module_name: MN,
func_name: FN, func_name: FN,
json_args: serde_json::Value, json_args: JValue,
call_parameters: fluence_sdk_main::CallParameters, call_parameters: fluence_sdk_main::CallParameters,
) -> Result<Vec<IValue>> { ) -> Result<JValue> {
use crate::misc::json_to_ivalues;
use crate::misc::ivalues_to_json;
let module_name = module_name.as_ref(); let module_name = module_name.as_ref();
let func_name = func_name.as_ref(); let func_name = func_name.as_ref();
let iargs = { // TODO: cache module interface
// TODO: cache module interface let module_interface = self
let module_interface = self .fce
.fce .module_interface(module_name)
.module_interface(module_name) .ok_or_else(|| FaaSError::NoSuchModule(module_name.to_string()))?;
.ok_or_else(|| FaaSError::NoSuchModule(module_name.to_string()))?;
let func_signature = module_interface let func_signature = module_interface
.function_signatures .function_signatures
.iter() .iter()
.find(|sign| sign.name == func_name) .find(|sign| sign.name.as_str() == func_name)
.ok_or_else(|| FaaSError::MissingFunctionError(func_name.to_string()))?; .ok_or_else(|| FaaSError::MissingFunctionError(func_name.to_string()))?;
let record_types = module_interface.record_types; let record_types = module_interface.record_types.clone();
crate::misc::json_to_ivalues(json_args, func_signature, &record_types)? let iargs = json_to_ivalues(json_args, func_signature, &record_types)?;
}; let outputs = func_signature.outputs.clone();
self.call_parameters.replace(call_parameters); self.call_parameters.replace(call_parameters);
self.fce let result = self.fce.call(module_name, func_name, &iargs)?;
.call(module_name, func_name, &iargs)
.map_err(Into::into) ivalues_to_json(result, &outputs, &record_types)
} }
/// Return all export functions (name and signatures) of loaded modules. /// Return all export functions (name and signatures) of loaded modules.

View File

@ -19,12 +19,14 @@ use super::IRecordType;
use crate::FaaSModuleInterface; use crate::FaaSModuleInterface;
use crate::FaaSFunctionSignature; use crate::FaaSFunctionSignature;
use fce::RecordTypes;
use serde::Serialize; use serde::Serialize;
use serde::Serializer; use serde::Serializer;
use std::fmt; use std::fmt;
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::HashSet; use std::collections::HashSet;
use std::rc::Rc;
use itertools::Itertools; use itertools::Itertools;
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
@ -34,7 +36,7 @@ pub struct FaaSInterface<'a> {
impl<'a> fmt::Display for FaaSInterface<'a> { impl<'a> fmt::Display for FaaSInterface<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let type_text_view = |arg_ty: &IType, record_types: &HashMap<u64, IRecordType>| { let type_text_view = |arg_ty: &IType, record_types: &RecordTypes| {
match arg_ty { match arg_ty {
IType::Record(record_type_id) => { IType::Record(record_type_id) => {
// unwrap is safe because FaaSInterface here is well-formed // unwrap is safe because FaaSInterface here is well-formed
@ -88,7 +90,7 @@ impl<'a> fmt::Display for FaaSInterface<'a> {
}) })
.join(", "); .join(", ");
let outputs = function_signature.outputs; let outputs = &function_signature.outputs;
if outputs.is_empty() { if outputs.is_empty() {
writeln!(f, "{})", args)?; writeln!(f, "{})", args)?;
} else if outputs.len() == 1 { } else if outputs.len() == 1 {
@ -116,9 +118,9 @@ impl<'a> Serialize for FaaSInterface<'a> {
{ {
#[derive(Serialize)] #[derive(Serialize)]
pub struct FunctionSignature<'a> { pub struct FunctionSignature<'a> {
pub name: &'a str, pub name: &'a Rc<String>,
pub arguments: Vec<(&'a String, &'a IType)>, pub arguments: Vec<(&'a String, &'a IType)>,
pub output_types: &'a Vec<IType>, pub output_types: &'a Rc<Vec<IType>>,
} }
#[derive(Serialize)] #[derive(Serialize)]
@ -140,9 +142,9 @@ impl<'a> Serialize for FaaSInterface<'a> {
pub modules: Vec<Module<'a>>, pub modules: Vec<Module<'a>>,
} }
fn serialize_function_signature<'a>( fn serialize_function_signature(
signature: &'a FaaSFunctionSignature<'_>, signature: &FaaSFunctionSignature,
) -> FunctionSignature<'a> { ) -> FunctionSignature<'_> {
let arguments = signature let arguments = signature
.arguments .arguments
.iter() .iter()
@ -150,13 +152,13 @@ impl<'a> Serialize for FaaSInterface<'a> {
.collect(); .collect();
FunctionSignature { FunctionSignature {
name: signature.name, name: &signature.name,
arguments, arguments,
output_types: signature.outputs, output_types: &signature.outputs,
} }
} }
fn serialize_record_type<'a, 'b>(record: (&'a u64, &'b IRecordType)) -> RecordType<'b> { fn serialize_record_type<'a, 'b>(record: (&'a u64, &'b Rc<IRecordType>)) -> RecordType<'b> {
let fields = record let fields = record
.1 .1
.fields .fields

View File

@ -0,0 +1,102 @@
/*
* Copyright 2020 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::IValue;
use crate::IType;
use crate::Result;
use crate::errors::FaaSError::JsonOutputSerializationError as OutputDeError;
use fce::RecordTypes;
use serde_json::Value as JValue;
pub(crate) fn ivalues_to_json(
mut ivalues: Vec<IValue>,
outputs: &[IType],
record_types: &RecordTypes,
) -> Result<JValue> {
if outputs.len() != ivalues.len() {
return Err(OutputDeError(format!(
"resulted values {:?} and function signature {:?} aren't compatible",
ivalues, outputs
)));
}
match ivalues.len() {
0 => Ok(JValue::Null),
1 => ivalue_to_json(ivalues.remove(0), outputs.first().unwrap(), record_types),
_ => unimplemented!(
"multi-values aren't supported now - more then one result values aren't possible"
),
}
}
fn ivalue_to_json(ivalue: IValue, output: &IType, record_types: &RecordTypes) -> Result<JValue> {
use serde_json::json;
// clone here needed because binding by-value and by-ref in the same pattern in unstable
match (ivalue, output.clone()) {
(IValue::S8(value), IType::S8) => Ok(json!(value)),
(IValue::S16(value), IType::S16) => Ok(json!(value)),
(IValue::S32(value), IType::S32) => Ok(json!(value)),
(IValue::S64(value), IType::S64) => Ok(json!(value)),
(IValue::U8(value), IType::U8) => Ok(json!(value)),
(IValue::U16(value), IType::U16) => Ok(json!(value)),
(IValue::U32(value), IType::U32) => Ok(json!(value)),
(IValue::U64(value), IType::U64) => Ok(json!(value)),
(IValue::I32(value), IType::I32) => Ok(json!(value)),
(IValue::I64(value), IType::I64) => Ok(json!(value)),
(IValue::F32(value), IType::F32) => Ok(json!(value)),
(IValue::F64(value), IType::F64) => Ok(json!(value)),
(IValue::String(value), IType::String) => Ok(json!(value)),
(IValue::Array(value), IType::Array(array_ty)) => {
let result: Result<Vec<_>> = value
.into_iter()
.map(|v| ivalue_to_json(v, &array_ty, record_types))
.collect();
Ok(JValue::Array(result?))
}
(IValue::Record(field_values), IType::Record(record_id)) => {
let record_type = record_types.get(&record_id).ok_or_else(|| {
OutputDeError(format!(
"record id {} wasn't found in module record types",
record_id
))
})?;
let field_types = &record_type.fields;
if field_values.len() != field_types.len() {
return Err(OutputDeError(format!(
"output record {:?} isn't compatible to output record fields {:?}",
field_values, field_types
)));
}
let field_values = field_values.into_vec();
let mut result = serde_json::Map::with_capacity(field_values.len());
for (field_value, field_type) in field_values.into_iter().zip(field_types.iter()) {
let json_field_value = ivalue_to_json(field_value, &field_type.ty, record_types)?;
result.insert(field_type.name.clone(), json_field_value);
}
Ok(JValue::Object(result))
}
(ivalue, itype) => Err(OutputDeError(format!(
"value {:?} is incompatible to type {:?}",
ivalue, itype
))),
}
}

View File

@ -17,21 +17,21 @@
use crate::IValue; use crate::IValue;
use crate::IType; use crate::IType;
use crate::Result; use crate::Result;
use crate::FaaSError; use crate::FaaSError::JsonArgumentsDeserializationError as ArgDeError;
use serde_json::Value as SerdeValue; use fce::RecordTypes;
use serde_json::Value as JValue;
use wasmer_wit::vec1::Vec1; use wasmer_wit::vec1::Vec1;
use wasmer_wit::types::RecordType;
use std::collections::HashMap; use std::collections::HashMap;
pub(crate) fn json_to_ivalues( pub(crate) fn json_to_ivalues(
json_args: serde_json::Value, json_args: JValue,
func_signature: &crate::FaaSFunctionSignature<'_>, func_signature: &crate::FaaSFunctionSignature,
record_types: &HashMap<u64, RecordType>, record_types: &RecordTypes,
) -> Result<Vec<IValue>> { ) -> Result<Vec<IValue>> {
let ivalues = match json_args { let ivalues = match json_args {
SerdeValue::Object(json_map) => json_map_to_ivalues( JValue::Object(json_map) => json_map_to_ivalues(
json_map, json_map,
func_signature func_signature
.arguments .arguments
@ -39,37 +39,37 @@ pub(crate) fn json_to_ivalues(
.map(|arg| (&arg.name, &arg.ty)), .map(|arg| (&arg.name, &arg.ty)),
&record_types, &record_types,
)?, )?,
SerdeValue::Array(json_array) => json_array_to_ivalues( JValue::Array(json_array) => json_array_to_ivalues(
json_array, json_array,
func_signature.arguments.iter().map(|arg| &arg.ty), func_signature.arguments.iter().map(|arg| &arg.ty),
&record_types, &record_types,
)?, )?,
SerdeValue::String(json_string) => json_string_to_ivalue(json_string, func_signature)?, JValue::String(json_string) => json_string_to_ivalue(json_string, func_signature)?,
json_bool @ SerdeValue::Bool(_) => json_bool_to_ivalue(json_bool, func_signature)?, json_bool @ JValue::Bool(_) => json_bool_to_ivalue(json_bool, func_signature)?,
json_number @ SerdeValue::Number(_) => json_number_to_ivalue(json_number, func_signature)?, json_number @ JValue::Number(_) => json_number_to_ivalue(json_number, func_signature)?,
SerdeValue::Null => json_null_to_ivalue(func_signature)?, JValue::Null => json_null_to_ivalue(func_signature)?,
}; };
Ok(ivalues) Ok(ivalues)
} }
fn json_map_to_ivalues<'a, 'b>( fn json_map_to_ivalues<'a, 'b>(
mut json_map: serde_json::Map<String, SerdeValue>, mut json_map: serde_json::Map<String, JValue>,
signature: impl Iterator<Item = (&'a String, &'a IType)>, signature: impl Iterator<Item = (&'a String, &'a IType)>,
record_types: &'b HashMap<u64, RecordType>, record_types: &'b RecordTypes,
) -> Result<Vec<IValue>> { ) -> Result<Vec<IValue>> {
let mut iargs = Vec::new(); let mut iargs = Vec::new();
for (arg_name, arg_type) in signature { for (arg_name, arg_type) in signature {
let json_value = json_map let json_value = json_map
.remove(arg_name) .remove(arg_name)
.ok_or_else(|| FaaSError::MissingArgumentError(arg_name.clone()))?; .ok_or_else(|| ArgDeError(format!("missing argument with name {}", arg_name)))?;
let iarg = json_value_to_ivalue(json_value, arg_type, record_types)?; let iarg = json_value_to_ivalue(json_value, arg_type, record_types)?;
iargs.push(iarg); iargs.push(iarg);
} }
if !json_map.is_empty() { if !json_map.is_empty() {
return Err(FaaSError::JsonArgumentsDeserializationError(format!( return Err(ArgDeError(format!(
"function requires {} arguments, {} provided", "function requires {} arguments, {} provided",
iargs.len(), iargs.len(),
iargs.len() + json_map.len() iargs.len() + json_map.len()
@ -80,12 +80,12 @@ fn json_map_to_ivalues<'a, 'b>(
} }
fn json_array_to_ivalues<'a, 'b>( fn json_array_to_ivalues<'a, 'b>(
mut json_array: Vec<SerdeValue>, mut json_array: Vec<JValue>,
signature: impl Iterator<Item = &'a IType> + std::iter::ExactSizeIterator, signature: impl Iterator<Item = &'a IType> + std::iter::ExactSizeIterator,
record_types: &'b HashMap<u64, RecordType>, record_types: &'b RecordTypes,
) -> Result<Vec<IValue>> { ) -> Result<Vec<IValue>> {
if json_array.len() != signature.len() { if json_array.len() != signature.len() {
return Err(FaaSError::JsonArgumentsDeserializationError(format!( return Err(ArgDeError(format!(
"function requires {} arguments, {} provided", "function requires {} arguments, {} provided",
signature.len(), signature.len(),
json_array.len() json_array.len()
@ -106,10 +106,10 @@ fn json_array_to_ivalues<'a, 'b>(
fn json_string_to_ivalue( fn json_string_to_ivalue(
json_string: String, json_string: String,
func_signature: &fce::FCEFunctionSignature<'_>, func_signature: &fce::FCEFunctionSignature,
) -> Result<Vec<IValue>> { ) -> Result<Vec<IValue>> {
if func_signature.arguments.len() != 1 || func_signature.arguments[0].ty != IType::String { if func_signature.arguments.len() != 1 || func_signature.arguments[0].ty != IType::String {
return Err(FaaSError::JsonArgumentsDeserializationError(format!( return Err(ArgDeError(format!(
"the called function has the following signature: {:?}, but only one string argument is provided", "the called function has the following signature: {:?}, but only one string argument is provided",
func_signature func_signature
))); )));
@ -119,11 +119,11 @@ fn json_string_to_ivalue(
} }
fn json_bool_to_ivalue( fn json_bool_to_ivalue(
json_bool: SerdeValue, json_bool: JValue,
func_signature: &fce::FCEFunctionSignature<'_>, func_signature: &fce::FCEFunctionSignature,
) -> Result<Vec<IValue>> { ) -> Result<Vec<IValue>> {
if func_signature.arguments.len() != 1 { if func_signature.arguments.len() != 1 {
return Err(FaaSError::JsonArgumentsDeserializationError(format!( return Err(ArgDeError(format!(
"the called function has the following signature: {:?}, but only one bool argument is provided", "the called function has the following signature: {:?}, but only one bool argument is provided",
func_signature func_signature
))); )));
@ -137,11 +137,11 @@ fn json_bool_to_ivalue(
} }
fn json_number_to_ivalue( fn json_number_to_ivalue(
json_number: SerdeValue, json_number: JValue,
func_signature: &fce::FCEFunctionSignature<'_>, func_signature: &fce::FCEFunctionSignature,
) -> Result<Vec<IValue>> { ) -> Result<Vec<IValue>> {
if func_signature.arguments.len() != 1 { if func_signature.arguments.len() != 1 {
return Err(FaaSError::JsonArgumentsDeserializationError(format!( return Err(ArgDeError(format!(
"the called function has the following signature: {:?}, but only one number argument is provided", "the called function has the following signature: {:?}, but only one number argument is provided",
func_signature func_signature
))); )));
@ -154,9 +154,9 @@ fn json_number_to_ivalue(
)?]) )?])
} }
fn json_null_to_ivalue(func_signature: &fce::FCEFunctionSignature<'_>) -> Result<Vec<IValue>> { fn json_null_to_ivalue(func_signature: &fce::FCEFunctionSignature) -> Result<Vec<IValue>> {
if !func_signature.arguments.is_empty() { if !func_signature.arguments.is_empty() {
return Err(FaaSError::JsonArgumentsDeserializationError(format!( return Err(ArgDeError(format!(
"the called function has the following signature: {:?}, but no arguments is provided", "the called function has the following signature: {:?}, but no arguments is provided",
func_signature func_signature
))); )));
@ -166,80 +166,50 @@ fn json_null_to_ivalue(func_signature: &fce::FCEFunctionSignature<'_>) -> Result
} }
fn json_value_to_ivalue( fn json_value_to_ivalue(
json_value: SerdeValue, json_value: JValue,
ty: &IType, ty: &IType,
record_types: &HashMap<u64, RecordType>, record_types: &RecordTypes,
) -> Result<IValue> { ) -> Result<IValue> {
// TODO: get rid of copy-past macro_rules! to_ivalue(
($json_value:expr, $ty:ident) => {
{
let value = serde_json::from_value($json_value).map_err(|e| {
ArgDeError(format!(
"error {:?} occurred while deserialize output result to a json value",
e
))
})?;
Ok(IValue::$ty(value))
}
}
);
match ty { match ty {
IType::S8 => { IType::S8 => to_ivalue!(json_value, S8),
let value = serde_json::from_value(json_value) IType::S16 => to_ivalue!(json_value, S16),
.map_err(FaaSError::ArgumentDeserializationError)?; IType::S32 => to_ivalue!(json_value, S32),
Ok(IValue::S8(value)) IType::S64 => to_ivalue!(json_value, S64),
} IType::U8 => to_ivalue!(json_value, U8),
IType::S16 => { IType::U16 => to_ivalue!(json_value, U16),
let value = serde_json::from_value(json_value) IType::U32 => to_ivalue!(json_value, U32),
.map_err(FaaSError::ArgumentDeserializationError)?; IType::U64 => to_ivalue!(json_value, U64),
Ok(IValue::S16(value)) IType::F32 => to_ivalue!(json_value, F32),
} IType::F64 => to_ivalue!(json_value, F64),
IType::S32 => { IType::String => to_ivalue!(json_value, String),
let value = serde_json::from_value(json_value)
.map_err(FaaSError::ArgumentDeserializationError)?;
Ok(IValue::S32(value))
}
IType::S64 => {
let value = serde_json::from_value(json_value)
.map_err(FaaSError::ArgumentDeserializationError)?;
Ok(IValue::S64(value))
}
IType::U8 => {
let value = serde_json::from_value(json_value)
.map_err(FaaSError::ArgumentDeserializationError)?;
Ok(IValue::U8(value))
}
IType::U16 => {
let value = serde_json::from_value(json_value)
.map_err(FaaSError::ArgumentDeserializationError)?;
Ok(IValue::U16(value))
}
IType::U32 => {
let value = serde_json::from_value(json_value)
.map_err(FaaSError::ArgumentDeserializationError)?;
Ok(IValue::U32(value))
}
IType::U64 => {
let value = serde_json::from_value(json_value)
.map_err(FaaSError::ArgumentDeserializationError)?;
Ok(IValue::U64(value))
}
IType::F32 => {
let value = serde_json::from_value(json_value)
.map_err(FaaSError::ArgumentDeserializationError)?;
Ok(IValue::F32(value))
}
IType::F64 => {
let value = serde_json::from_value(json_value)
.map_err(FaaSError::ArgumentDeserializationError)?;
Ok(IValue::F64(value))
}
IType::String => {
let value = serde_json::from_value(json_value)
.map_err(FaaSError::ArgumentDeserializationError)?;
Ok(IValue::String(value))
}
IType::Array(value_type) => { IType::Array(value_type) => {
let value = match json_value { let value = match json_value {
SerdeValue::Array(json_array) => { JValue::Array(json_array) => {
let mut iargs = Vec::with_capacity(json_array.len()); let iargs: Result<Vec<_>> = json_array
.into_iter()
.map(|json_value| {
json_value_to_ivalue(json_value, value_type, record_types)
})
.collect();
for json_value in json_array { Ok(iargs?)
let iarg = json_value_to_ivalue(json_value, value_type, record_types)?;
iargs.push(iarg);
}
Ok(iargs)
} }
_ => Err(FaaSError::JsonArgumentsDeserializationError(format!( _ => Err(ArgDeError(format!(
"expected array of {:?} types, got {:?}", "expected array of {:?} types, got {:?}",
value_type, json_value value_type, json_value
))), ))),
@ -247,41 +217,31 @@ fn json_value_to_ivalue(
Ok(IValue::Array(value)) Ok(IValue::Array(value))
} }
IType::I32 => { IType::I32 => to_ivalue!(json_value, I32),
let value = serde_json::from_value(json_value) IType::I64 => to_ivalue!(json_value, I64),
.map_err(FaaSError::ArgumentDeserializationError)?;
Ok(IValue::I32(value))
}
IType::I64 => {
let value = serde_json::from_value(json_value)
.map_err(FaaSError::ArgumentDeserializationError)?;
Ok(IValue::I64(value))
}
IType::Record(record_type_id) => { IType::Record(record_type_id) => {
let value = json_record_type_to_ivalue(json_value, record_type_id, &record_types)?; let value = json_record_type_to_ivalue(json_value, record_type_id, &record_types)?;
Ok(IValue::Record(value)) Ok(IValue::Record(value))
} }
IType::Anyref => Err(FaaSError::JsonArgumentsDeserializationError(String::from( IType::Anyref => Err(ArgDeError(String::from("anyrefs aren't supported now"))),
"anyrefs aren't supported now",
))),
} }
} }
#[allow(clippy::ptr_arg)] #[allow(clippy::ptr_arg)]
fn json_record_type_to_ivalue( fn json_record_type_to_ivalue(
json_value: SerdeValue, json_value: JValue,
record_type_id: &u64, record_type_id: &u64,
record_types: &HashMap<u64, RecordType>, record_types: &RecordTypes,
) -> Result<Vec1<IValue>> { ) -> Result<Vec1<IValue>> {
let record_type = record_types.get(record_type_id).ok_or_else(|| { let record_type = record_types.get(record_type_id).ok_or_else(|| {
FaaSError::JsonArgumentsDeserializationError(format!( ArgDeError(format!(
"record with type id `{}` wasn't found", "record with type id `{}` wasn't found",
record_type_id record_type_id
)) ))
})?; })?;
match json_value { match json_value {
SerdeValue::Object(json_map) => Ok(Vec1::new(json_map_to_ivalues( JValue::Object(json_map) => Ok(Vec1::new(json_map_to_ivalues(
json_map, json_map,
record_type record_type
.fields .fields
@ -290,13 +250,13 @@ fn json_record_type_to_ivalue(
record_types, record_types,
)?) )?)
.unwrap()), .unwrap()),
SerdeValue::Array(json_array) => Ok(Vec1::new(json_array_to_ivalues( JValue::Array(json_array) => Ok(Vec1::new(json_array_to_ivalues(
json_array, json_array,
record_type.fields.iter().map(|field| (&field.ty)), record_type.fields.iter().map(|field| (&field.ty)),
record_types, record_types,
)?) )?)
.unwrap()), .unwrap()),
_ => Err(FaaSError::JsonArgumentsDeserializationError(format!( _ => Err(ArgDeError(format!(
"record with type id `{}` should be encoded as array or map of fields", "record with type id `{}` should be encoded as array or map of fields",
record_type_id record_type_id
))), ))),

View File

@ -14,14 +14,17 @@
* limitations under the License. * limitations under the License.
*/ */
mod ivalues_to_json;
mod json_to_ivalues; mod json_to_ivalues;
mod log_utf8_string_impl; mod log_utf8_string_impl;
mod modules_load_strategy; mod modules_load_strategy;
mod utils; mod utils;
pub(crate) use ivalues_to_json::ivalues_to_json;
pub(crate) use json_to_ivalues::json_to_ivalues; pub(crate) use json_to_ivalues::json_to_ivalues;
pub(crate) use modules_load_strategy::ModulesLoadStrategy; pub(crate) use modules_load_strategy::ModulesLoadStrategy;
pub(crate) use utils::create_host_import; pub(crate) use utils::create_host_import;
pub(crate) use utils::make_fce_config; pub(crate) use utils::make_fce_config;
pub(crate) use utils::load_modules_from_fs;
pub(self) use log_utf8_string_impl::log_utf8_string_closure; pub(self) use log_utf8_string_impl::log_utf8_string_closure;

View File

@ -14,8 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
use crate::config::FaaSModuleConfig;
use super::log_utf8_string_closure; use super::log_utf8_string_closure;
use crate::Result;
use crate::config::FaaSModuleConfig;
use crate::errors::FaaSError;
use fce::FCEModuleConfig; use fce::FCEModuleConfig;
use fce::HostImportDescriptor; use fce::HostImportDescriptor;
@ -28,6 +30,7 @@ use wasmer_wit::types::InterfaceType as IType;
use std::collections::HashMap; use std::collections::HashMap;
use std::cell::RefCell; use std::cell::RefCell;
use std::path::PathBuf;
use std::rc::Rc; use std::rc::Rc;
use std::ops::Deref; use std::ops::Deref;
@ -80,7 +83,7 @@ pub(crate) fn make_fce_config(
module_name: String, module_name: String,
faas_module_config: Option<FaaSModuleConfig>, faas_module_config: Option<FaaSModuleConfig>,
call_parameters: Rc<RefCell<fluence_sdk_main::CallParameters>>, call_parameters: Rc<RefCell<fluence_sdk_main::CallParameters>>,
) -> crate::Result<FCEModuleConfig> { ) -> Result<FCEModuleConfig> {
let mut fce_module_config = FCEModuleConfig::default(); let mut fce_module_config = FCEModuleConfig::default();
let faas_module_config = match faas_module_config { let faas_module_config = match faas_module_config {
@ -135,3 +138,55 @@ pub(crate) fn make_fce_config(
Ok(fce_module_config) Ok(fce_module_config)
} }
use crate::misc::ModulesLoadStrategy;
/// Loads modules from a directory at a given path. Non-recursive, ignores subdirectories.
pub(crate) fn load_modules_from_fs(
modules_dir: &PathBuf,
modules: ModulesLoadStrategy<'_>,
) -> Result<HashMap<String, Vec<u8>>> {
use FaaSError::IOError;
let mut dir_entries =
std::fs::read_dir(modules_dir).map_err(|e| IOError(format!("{:?}: {}", modules_dir, e)))?;
let loaded = dir_entries.try_fold(HashMap::new(), |mut hash_map, entry| {
let entry = entry?;
let path = entry.path();
// Skip directories
if path.is_dir() {
return Ok(hash_map);
}
let module_name = path
.file_name()
.ok_or_else(|| IOError(format!("No file name in path {:?}", path)))?
.to_os_string()
.into_string()
.map_err(|name| IOError(format!("invalid file name: {:?}", name)))?;
if modules.should_load(&module_name.as_ref()) {
let module_bytes = std::fs::read(path)?;
let module_name = modules.extract_module_name(module_name);
if hash_map.insert(module_name, module_bytes).is_some() {
return Err(FaaSError::ConfigParseError(String::from(
"module {} is duplicated in config",
)));
}
}
Ok(hash_map)
})?;
if modules.required_modules_len() > loaded.len() {
let loaded = loaded.iter().map(|(n, _)| n);
let not_found = modules.missing_modules(loaded);
return Err(FaaSError::ConfigParseError(format!(
"the following modules were not found: {:?}",
not_found
)));
}
Ok(loaded)
}

View File

@ -14,14 +14,17 @@
* limitations under the License. * limitations under the License.
*/ */
mod utils;
use fluence_faas::FluenceFaaS; use fluence_faas::FluenceFaaS;
use fluence_faas::IValue;
use fluence_faas::IType; use fluence_faas::IType;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use serde_json::json; use serde_json::json;
use std::rc::Rc;
static ARG_CONFIG: Lazy<fluence_faas::TomlFaaSConfig> = Lazy::new(|| { static ARG_CONFIG: Lazy<fluence_faas::TomlFaaSConfig> = Lazy::new(|| {
let mut arguments_passing_config = let mut arguments_passing_config =
fluence_faas::TomlFaaSConfig::load("./tests/wasm_tests/arguments_passing/Config.toml") fluence_faas::TomlFaaSConfig::load("./tests/wasm_tests/arguments_passing/Config.toml")
@ -50,9 +53,9 @@ pub fn get_interfaces() {
let string_type_outputs = vec![IType::String]; let string_type_outputs = vec![IType::String];
let string_type_sign = fluence_faas::FaaSFunctionSignature { let string_type_sign = fluence_faas::FaaSFunctionSignature {
name: "string_type", name: Rc::new(String::from("string_type")),
arguments: &string_type_arguments, arguments: Rc::new(string_type_arguments),
outputs: &string_type_outputs, outputs: Rc::new(string_type_outputs),
}; };
let bytearray_type_arguments = vec![fluence_faas::IFunctionArg { let bytearray_type_arguments = vec![fluence_faas::IFunctionArg {
@ -62,9 +65,9 @@ pub fn get_interfaces() {
let bytearray_type_outputs = vec![IType::Array(Box::new(IType::U8))]; let bytearray_type_outputs = vec![IType::Array(Box::new(IType::U8))];
let bytearray_type_sign = fluence_faas::FaaSFunctionSignature { let bytearray_type_sign = fluence_faas::FaaSFunctionSignature {
name: "bytearray_type", name: Rc::new(String::from("bytearray_type")),
arguments: &bytearray_type_arguments, arguments: Rc::new(bytearray_type_arguments),
outputs: &bytearray_type_outputs, outputs: Rc::new(bytearray_type_outputs),
}; };
let i32_type_arguments = vec![fluence_faas::IFunctionArg { let i32_type_arguments = vec![fluence_faas::IFunctionArg {
@ -74,9 +77,9 @@ pub fn get_interfaces() {
let i32_type_outputs = vec![IType::S32]; let i32_type_outputs = vec![IType::S32];
let i32_type_sign = fluence_faas::FaaSFunctionSignature { let i32_type_sign = fluence_faas::FaaSFunctionSignature {
name: "i32_type", name: Rc::new(String::from("i32_type")),
arguments: &i32_type_arguments, arguments: Rc::new(i32_type_arguments),
outputs: &i32_type_outputs, outputs: Rc::new(i32_type_outputs),
}; };
let i64_type_arguments = vec![fluence_faas::IFunctionArg { let i64_type_arguments = vec![fluence_faas::IFunctionArg {
@ -87,9 +90,9 @@ pub fn get_interfaces() {
let i64_type_outputs = vec![IType::S64]; let i64_type_outputs = vec![IType::S64];
let i64_type_sign = fluence_faas::FaaSFunctionSignature { let i64_type_sign = fluence_faas::FaaSFunctionSignature {
name: "i64_type", name: Rc::new(String::from("i64_type")),
arguments: &i64_type_arguments, arguments: Rc::new(i64_type_arguments),
outputs: &i64_type_outputs, outputs: Rc::new(i64_type_outputs),
}; };
let u32_type_arguments = vec![fluence_faas::IFunctionArg { let u32_type_arguments = vec![fluence_faas::IFunctionArg {
@ -99,9 +102,9 @@ pub fn get_interfaces() {
let u32_type_outputs = vec![IType::U32]; let u32_type_outputs = vec![IType::U32];
let u32_type_sign = fluence_faas::FaaSFunctionSignature { let u32_type_sign = fluence_faas::FaaSFunctionSignature {
name: "u32_type", name: Rc::new(String::from("u32_type")),
arguments: &u32_type_arguments, arguments: Rc::new(u32_type_arguments),
outputs: &u32_type_outputs, outputs: Rc::new(u32_type_outputs),
}; };
let u64_type_arguments = vec![fluence_faas::IFunctionArg { let u64_type_arguments = vec![fluence_faas::IFunctionArg {
@ -111,9 +114,9 @@ pub fn get_interfaces() {
let u64_type_outputs = vec![IType::U64]; let u64_type_outputs = vec![IType::U64];
let u64_type_sign = fluence_faas::FaaSFunctionSignature { let u64_type_sign = fluence_faas::FaaSFunctionSignature {
name: "u64_type", name: Rc::new(String::from("u64_type")),
arguments: &u64_type_arguments, arguments: Rc::new(u64_type_arguments),
outputs: &u64_type_outputs, outputs: Rc::new(u64_type_outputs),
}; };
let f32_type_arguments = vec![fluence_faas::IFunctionArg { let f32_type_arguments = vec![fluence_faas::IFunctionArg {
@ -123,9 +126,9 @@ pub fn get_interfaces() {
let f32_type_outputs = vec![IType::F32]; let f32_type_outputs = vec![IType::F32];
let f32_type_sign = fluence_faas::FaaSFunctionSignature { let f32_type_sign = fluence_faas::FaaSFunctionSignature {
name: "f32_type", name: Rc::new(String::from("f32_type")),
arguments: &f32_type_arguments, arguments: Rc::new(f32_type_arguments),
outputs: &f32_type_outputs, outputs: Rc::new(f32_type_outputs),
}; };
let f64_type_arguments = vec![fluence_faas::IFunctionArg { let f64_type_arguments = vec![fluence_faas::IFunctionArg {
@ -135,18 +138,18 @@ pub fn get_interfaces() {
let f64_type_outputs = vec![IType::F64]; let f64_type_outputs = vec![IType::F64];
let f64_type_sign = fluence_faas::FaaSFunctionSignature { let f64_type_sign = fluence_faas::FaaSFunctionSignature {
name: "f64_type", name: Rc::new(String::from("f64_type")),
arguments: &f64_type_arguments, arguments: Rc::new(f64_type_arguments),
outputs: &f64_type_outputs, outputs: Rc::new(f64_type_outputs),
}; };
let empty_type_arguments = vec![]; let empty_type_arguments = vec![];
let empty_type_outputs = vec![IType::String]; let empty_type_outputs = vec![IType::String];
let empty_type_sign = fluence_faas::FaaSFunctionSignature { let empty_type_sign = fluence_faas::FaaSFunctionSignature {
name: "empty_type", name: Rc::new(String::from("empty_type")),
arguments: &empty_type_arguments, arguments: Rc::new(empty_type_arguments),
outputs: &empty_type_outputs, outputs: Rc::new(empty_type_outputs),
}; };
let bool_type_arguments = vec![fluence_faas::IFunctionArg { let bool_type_arguments = vec![fluence_faas::IFunctionArg {
@ -156,9 +159,9 @@ pub fn get_interfaces() {
let bool_type_outputs = vec![IType::I32]; let bool_type_outputs = vec![IType::I32];
let bool_type_sign = fluence_faas::FaaSFunctionSignature { let bool_type_sign = fluence_faas::FaaSFunctionSignature {
name: "bool_type", name: Rc::new(String::from("bool_type")),
arguments: &bool_type_arguments, arguments: Rc::new(bool_type_arguments),
outputs: &bool_type_outputs, outputs: Rc::new(bool_type_outputs),
}; };
let all_types_arguments = vec![ let all_types_arguments = vec![
@ -214,9 +217,9 @@ pub fn get_interfaces() {
let all_types_outputs = vec![IType::Array(Box::new(IType::U8))]; let all_types_outputs = vec![IType::Array(Box::new(IType::U8))];
let all_types_sign = fluence_faas::FaaSFunctionSignature { let all_types_sign = fluence_faas::FaaSFunctionSignature {
name: "all_types", name: Rc::new(String::from("all_types")),
arguments: &all_types_arguments, arguments: Rc::new(all_types_arguments),
outputs: &all_types_outputs, outputs: Rc::new(all_types_outputs),
}; };
let functions = vec![ let functions = vec![
@ -282,79 +285,46 @@ pub fn all_types() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!([
.call_with_json( 0, 1, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 5, 0, 6, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0,
"arguments_passing_pure", 65, 1, 153, 154, 64, 34, 51, 51, 51, 51, 51, 51, 102, 108, 117, 101, 110, 99, 101, 19, 55,
"all_types", 0, 1, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 5, 0, 6, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0,
json!({ 65, 1, 153, 154, 64, 34, 51, 51, 51, 51, 51, 51, 102, 108, 117, 101, 110, 99, 101, 19, 55
"arg_0": 0, ]);
"arg_1": 1,
"arg_2": 2,
"arg_3": 3,
"arg_4": 4,
"arg_5": 5,
"arg_6": 6,
"arg_7": 7,
"arg_8": 8.1,
"arg_9": 9.1,
"arg_10": "fluence",
"arg_11": vec! [0x13, 0x37],
}),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke all_types: {:?}", e));
assert_eq!(
result3,
vec![IValue::Array(
vec![
0, 1, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 5, 0, 6, 0, 0, 0, 7, 0, 0, 0, 0, 0,
0, 0, 65, 1, 153, 154, 64, 34, 51, 51, 51, 51, 51, 51, 102, 108, 117, 101, 110, 99,
101, 19, 55, 0, 1, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 5, 0, 6, 0, 0, 0, 7,
0, 0, 0, 0, 0, 0, 0, 65, 1, 153, 154, 64, 34, 51, 51, 51, 51, 51, 51, 102, 108,
117, 101, 110, 99, 101, 19, 55
]
.iter()
.map(|v| IValue::U8(*v))
.collect::<Vec<_>>()
)]
);
let result4 = faas let faas_arg = json!({
.call_with_json( "arg_0": 0,
"arguments_passing_pure", "arg_1": 1,
"all_types", "arg_2": 2,
json!([ "arg_3": 3,
0, "arg_4": 4,
1, "arg_5": 5,
2, "arg_6": 6,
3, "arg_7": 7,
4, "arg_8": 8.1,
5, "arg_9": 9.1,
6, "arg_10": "fluence",
7, "arg_11": vec! [0x13, 0x37],
8.1, });
9.1, let result3 = call_faas!(faas, "arguments_passing_pure", "all_types", faas_arg);
"fluence", assert_eq!(result3, right_result);
vec![0x13, 0x37]
]), let faas_arg = json!([
<_>::default(), 0,
) 1,
.unwrap_or_else(|e| panic!("can't invoke all_types: {:?}", e)); 2,
assert_eq!( 3,
result4, 4,
vec![IValue::Array( 5,
vec![ 6,
0, 1, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 5, 0, 6, 0, 0, 0, 7, 0, 0, 0, 0, 0, 7,
0, 0, 65, 1, 153, 154, 64, 34, 51, 51, 51, 51, 51, 51, 102, 108, 117, 101, 110, 99, 8.1,
101, 19, 55, 0, 1, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 5, 0, 6, 0, 0, 0, 7, 9.1,
0, 0, 0, 0, 0, 0, 0, 65, 1, 153, 154, 64, 34, 51, 51, 51, 51, 51, 51, 102, 108, "fluence",
117, 101, 110, 99, 101, 19, 55 vec![0x13, 0x37]
] ]);
.iter() let result4 = call_faas!(faas, "arguments_passing_pure", "all_types", faas_arg);
.map(|v| IValue::U8(*v)) assert_eq!(result4, right_result);
.collect::<Vec<_>>()
)]
);
} }
#[test] #[test]
@ -378,25 +348,17 @@ pub fn i32_type() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!(3);
.call_with_json( let result3 = call_faas!(
"arguments_passing_pure", faas,
"i32_type", "arguments_passing_pure",
json!({ "arg": 1 }), "i32_type",
<_>::default(), json!({ "arg": 1 })
) );
.unwrap_or_else(|e| panic!("can't invoke i32_type: {:?}", e)); assert_eq!(result3, right_result);
assert_eq!(result3, vec![IValue::S32(3)]);
let result4 = faas let result4 = call_faas!(faas, "arguments_passing_pure", "i32_type", json!(1));
.call_with_json( assert_eq!(result4, right_result);
"arguments_passing_pure",
"i32_type",
json!(1),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke i32_type: {:?}", e));
assert_eq!(result4, vec![IValue::S32(3)]);
} }
#[test] #[test]
@ -420,25 +382,17 @@ pub fn i64_type() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!(3);
.call_with_json( let result3 = call_faas!(
"arguments_passing_pure", faas,
"i64_type", "arguments_passing_pure",
json!({ "arg": 1 }), "i64_type",
<_>::default(), json!({ "arg": 1 })
) );
.unwrap_or_else(|e| panic!("can't invoke i64_type: {:?}", e)); assert_eq!(result3, right_result);
assert_eq!(result3, vec![IValue::S64(3)]);
let result4 = faas let result4 = call_faas!(faas, "arguments_passing_pure", "i64_type", json!(1));
.call_with_json( assert_eq!(result4, right_result);
"arguments_passing_pure",
"i64_type",
json!(1),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke i64_type: {:?}", e));
assert_eq!(result4, vec![IValue::S64(3)]);
} }
#[test] #[test]
@ -462,25 +416,17 @@ pub fn u32_type() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!(3);
.call_with_json( let result3 = call_faas!(
"arguments_passing_pure", faas,
"u32_type", "arguments_passing_pure",
json!({ "arg": 1 }), "u32_type",
<_>::default(), json!({ "arg": 1 })
) );
.unwrap_or_else(|e| panic!("can't invoke u32_type: {:?}", e)); assert_eq!(result3, right_result);
assert_eq!(result3, vec![IValue::U32(3)]);
let result4 = faas let result4 = call_faas!(faas, "arguments_passing_pure", "u32_type", json!(1));
.call_with_json( assert_eq!(result4, right_result);
"arguments_passing_pure",
"u32_type",
json!(1),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke u32_type: {:?}", e));
assert_eq!(result4, vec![IValue::U32(3)]);
} }
#[test] #[test]
@ -504,25 +450,17 @@ pub fn u64_type() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!(3);
.call_with_json( let result3 = call_faas!(
"arguments_passing_pure", faas,
"u64_type", "arguments_passing_pure",
json!({ "arg": 1 }), "u64_type",
<_>::default(), json!({ "arg": 1 })
) );
.unwrap_or_else(|e| panic!("can't invoke u64_type: {:?}", e)); assert_eq!(result3, right_result);
assert_eq!(result3, vec![IValue::U64(3)]);
let result4 = faas let result4 = call_faas!(faas, "arguments_passing_pure", "u64_type", json!(1));
.call_with_json( assert_eq!(result4, right_result);
"arguments_passing_pure",
"u64_type",
json!(1),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke u64_type: {:?}", e));
assert_eq!(result4, vec![IValue::U64(3)]);
} }
#[test] #[test]
@ -546,25 +484,17 @@ pub fn f32_type() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!(3.0);
.call_with_json( let result3 = call_faas!(
"arguments_passing_pure", faas,
"f32_type", "arguments_passing_pure",
json!({ "arg": 1.0 }), "f32_type",
<_>::default(), json!({ "arg": 1.0 })
) );
.unwrap_or_else(|e| panic!("can't invoke f32_type: {:?}", e)); assert_eq!(result3, right_result);
assert_eq!(result3, vec![IValue::F32(3.0)]);
let result4 = faas let result4 = call_faas!(faas, "arguments_passing_pure", "f32_type", json!(1.0));
.call_with_json( assert_eq!(result4, right_result);
"arguments_passing_pure",
"f32_type",
json!(1.0),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke f32_type: {:?}", e));
assert_eq!(result4, vec![IValue::F32(3.0)]);
} }
#[test] #[test]
@ -588,25 +518,17 @@ pub fn f64_type() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!(3.0);
.call_with_json( let result3 = call_faas!(
"arguments_passing_pure", faas,
"f64_type", "arguments_passing_pure",
json!({ "arg": 1.0 }), "f64_type",
<_>::default(), json!({ "arg": 1.0 })
) );
.unwrap_or_else(|e| panic!("can't invoke f64_type: {:?}", e)); assert_eq!(result3, right_result);
assert_eq!(result3, vec![IValue::F64(3.0)]);
let result4 = faas let result4 = call_faas!(faas, "arguments_passing_pure", "f64_type", json!(1.0));
.call_with_json( assert_eq!(result4, right_result);
"arguments_passing_pure",
"f64_type",
json!(1.0),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke f64_type: {:?}", e));
assert_eq!(result4, vec![IValue::F64(3.0)]);
} }
#[test] #[test]
@ -630,35 +552,22 @@ pub fn string_type() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!("Fluence_Fluence_Fluence_Fluence");
.call_with_json( let result3 = call_faas!(
"arguments_passing_pure", faas,
"string_type", "arguments_passing_pure",
json!({ "arg": "Fluence" }), "string_type",
<_>::default(), json!({ "arg": "Fluence" })
)
.unwrap_or_else(|e| panic!("can't invoke string_type: {:?}", e));
assert_eq!(
result3,
vec![IValue::String(String::from(
"Fluence_Fluence_Fluence_Fluence"
))]
); );
assert_eq!(result3, right_result);
let result4 = faas let result4 = call_faas!(
.call_with_json( faas,
"arguments_passing_pure", "arguments_passing_pure",
"string_type", "string_type",
json!("Fluence"), json!("Fluence")
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke string_type: {:?}", e));
assert_eq!(
result4,
vec![IValue::String(String::from(
"Fluence_Fluence_Fluence_Fluence"
))]
); );
assert_eq!(result4, right_result);
} }
#[test] #[test]
@ -682,41 +591,22 @@ pub fn bytearray_type() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!([0x13, 0x37, 1, 1]);
.call_with_json( let result3 = call_faas!(
"arguments_passing_pure", faas,
"bytearray_type", "arguments_passing_pure",
json!({ "arg": [0x13, 0x37] }), "bytearray_type",
<_>::default(), json!({ "arg": [0x13, 0x37] })
)
.unwrap_or_else(|e| panic!("can't invoke bytearray_type: {:?}", e));
assert_eq!(
result3,
vec![IValue::Array(vec![
IValue::U8(0x13),
IValue::U8(0x37),
IValue::U8(1),
IValue::U8(1)
])]
); );
assert_eq!(result3, right_result);
let result4 = faas let result4 = call_faas!(
.call_with_json( faas,
"arguments_passing_pure", "arguments_passing_pure",
"bytearray_type", "bytearray_type",
json!([[0x13, 0x37]]), json!([[0x13, 0x37]])
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke bytearray_type: {:?}", e));
assert_eq!(
result4,
vec![IValue::Array(vec![
IValue::U8(0x13),
IValue::U8(0x37),
IValue::U8(1),
IValue::U8(1)
])]
); );
assert_eq!(result4, right_result);
} }
#[test] #[test]
@ -740,25 +630,17 @@ pub fn bool_type() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!(1);
.call_with_json( let result3 = call_faas!(
"arguments_passing_pure", faas,
"bool_type", "arguments_passing_pure",
json!({ "arg": 0 }), "bool_type",
<_>::default(), json!({ "arg": 0 })
) );
.unwrap_or_else(|e| panic!("can't invoke bool_type: {:?}", e)); assert_eq!(result3, right_result);
assert_eq!(result3, vec![IValue::I32(1)]);
let result4 = faas let result4 = call_faas!(faas, "arguments_passing_pure", "bool_type", json!(0));
.call_with_json( assert_eq!(result4, right_result);
"arguments_passing_pure",
"bool_type",
json!(0),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke bool_type: {:?}", e));
assert_eq!(result4, vec![IValue::I32(1)]);
} }
#[test] #[test]
@ -766,35 +648,15 @@ pub fn empty_type() {
let mut faas = FluenceFaaS::with_raw_config(ARG_CONFIG.clone()) let mut faas = FluenceFaaS::with_raw_config(ARG_CONFIG.clone())
.unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {:?}", e)); .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {:?}", e));
let result1 = faas let right_result = json!("success");
.call_with_json( let result1 = call_faas!(faas, "arguments_passing_pure", "empty_type", json!({}));
"arguments_passing_pure", assert_eq!(result1, right_result);
"empty_type",
json!({}),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke empty_type: {:?}", e));
assert_eq!(result1, vec![IValue::String(String::from("success"))]);
let result2 = faas let result2 = call_faas!(faas, "arguments_passing_pure", "empty_type", json!([]));
.call_with_json( assert_eq!(result2, right_result);
"arguments_passing_pure",
"empty_type",
json!([]),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke empty_type: {:?}", e));
assert_eq!(result2, vec![IValue::String(String::from("success"))]);
let result3 = faas let result3 = call_faas!(faas, "arguments_passing_pure", "empty_type", json!([]));
.call_with_json( assert_eq!(result3, right_result);
"arguments_passing_pure",
"empty_type",
json!([]),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke empty_type: {:?}", e));
assert_eq!(result3, vec![IValue::String(String::from("success"))]);
let result4 = faas.call_with_json( let result4 = faas.call_with_json(
"arguments_passing_pure", "arguments_passing_pure",

View File

@ -14,13 +14,16 @@
* limitations under the License. * limitations under the License.
*/ */
mod utils;
use fluence_faas::FluenceFaaS; use fluence_faas::FluenceFaaS;
use fluence_faas::IValue;
use fluence_faas::IType; use fluence_faas::IType;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use serde_json::json; use serde_json::json;
use std::rc::Rc;
static ARG_CONFIG: Lazy<fluence_faas::TomlFaaSConfig> = Lazy::new(|| { static ARG_CONFIG: Lazy<fluence_faas::TomlFaaSConfig> = Lazy::new(|| {
let mut arrays_passing_config = let mut arrays_passing_config =
fluence_faas::TomlFaaSConfig::load("./tests/wasm_tests/arrays_passing/Config.toml") fluence_faas::TomlFaaSConfig::load("./tests/wasm_tests/arrays_passing/Config.toml")
@ -48,9 +51,9 @@ pub fn get_interfaces() {
let byte_type_outputs = vec![IType::Array(Box::new(IType::U8))]; let byte_type_outputs = vec![IType::Array(Box::new(IType::U8))];
let byte_type_sign = fluence_faas::FaaSFunctionSignature { let byte_type_sign = fluence_faas::FaaSFunctionSignature {
name: "byte_type", name: Rc::new(String::from("byte_type")),
arguments: &byte_type_arguments, arguments: Rc::new(byte_type_arguments),
outputs: &byte_type_outputs, outputs: Rc::new(byte_type_outputs),
}; };
let inner_arrays_1_arguments = vec![fluence_faas::IFunctionArg { let inner_arrays_1_arguments = vec![fluence_faas::IFunctionArg {
@ -64,9 +67,9 @@ pub fn get_interfaces() {
))))]; ))))];
let inner_arrays_1_sign = fluence_faas::FaaSFunctionSignature { let inner_arrays_1_sign = fluence_faas::FaaSFunctionSignature {
name: "inner_arrays_1", name: Rc::new(String::from("inner_arrays_1")),
arguments: &inner_arrays_1_arguments, arguments: Rc::new(inner_arrays_1_arguments),
outputs: &inner_arrays_1_outputs, outputs: Rc::new(inner_arrays_1_outputs),
}; };
// save it until record will be refactored in the future // save it until record will be refactored in the future
@ -95,9 +98,9 @@ pub fn get_interfaces() {
let string_type_outputs = vec![IType::Array(Box::new(IType::String))]; let string_type_outputs = vec![IType::Array(Box::new(IType::String))];
let string_type_sign = fluence_faas::FaaSFunctionSignature { let string_type_sign = fluence_faas::FaaSFunctionSignature {
name: "string_type", name: Rc::new(String::from("string_type")),
arguments: &string_type_arguments, arguments: Rc::new(string_type_arguments),
outputs: &string_type_outputs, outputs: Rc::new(string_type_outputs),
}; };
let i32_type_arguments = vec![fluence_faas::IFunctionArg { let i32_type_arguments = vec![fluence_faas::IFunctionArg {
@ -107,9 +110,9 @@ pub fn get_interfaces() {
let i32_type_outputs = vec![IType::Array(Box::new(IType::S32))]; let i32_type_outputs = vec![IType::Array(Box::new(IType::S32))];
let i32_type_sign = fluence_faas::FaaSFunctionSignature { let i32_type_sign = fluence_faas::FaaSFunctionSignature {
name: "i32_type", name: Rc::new(String::from("i32_type")),
arguments: &i32_type_arguments, arguments: Rc::new(i32_type_arguments),
outputs: &i32_type_outputs, outputs: Rc::new(i32_type_outputs),
}; };
let i64_type_arguments = vec![fluence_faas::IFunctionArg { let i64_type_arguments = vec![fluence_faas::IFunctionArg {
@ -120,9 +123,9 @@ pub fn get_interfaces() {
let i64_type_outputs = vec![IType::Array(Box::new(IType::S64))]; let i64_type_outputs = vec![IType::Array(Box::new(IType::S64))];
let i64_type_sign = fluence_faas::FaaSFunctionSignature { let i64_type_sign = fluence_faas::FaaSFunctionSignature {
name: "i64_type", name: Rc::new(String::from("i64_type")),
arguments: &i64_type_arguments, arguments: Rc::new(i64_type_arguments),
outputs: &i64_type_outputs, outputs: Rc::new(i64_type_outputs),
}; };
let u32_type_arguments = vec![fluence_faas::IFunctionArg { let u32_type_arguments = vec![fluence_faas::IFunctionArg {
@ -132,9 +135,9 @@ pub fn get_interfaces() {
let u32_type_outputs = vec![IType::Array(Box::new(IType::U32))]; let u32_type_outputs = vec![IType::Array(Box::new(IType::U32))];
let u32_type_sign = fluence_faas::FaaSFunctionSignature { let u32_type_sign = fluence_faas::FaaSFunctionSignature {
name: "u32_type", name: Rc::new(String::from("u32_type")),
arguments: &u32_type_arguments, arguments: Rc::new(u32_type_arguments),
outputs: &u32_type_outputs, outputs: Rc::new(u32_type_outputs),
}; };
let u64_type_arguments = vec![fluence_faas::IFunctionArg { let u64_type_arguments = vec![fluence_faas::IFunctionArg {
@ -144,9 +147,9 @@ pub fn get_interfaces() {
let u64_type_outputs = vec![IType::Array(Box::new(IType::U64))]; let u64_type_outputs = vec![IType::Array(Box::new(IType::U64))];
let u64_type_sign = fluence_faas::FaaSFunctionSignature { let u64_type_sign = fluence_faas::FaaSFunctionSignature {
name: "u64_type", name: Rc::new(String::from("u64_type")),
arguments: &u64_type_arguments, arguments: Rc::new(u64_type_arguments),
outputs: &u64_type_outputs, outputs: Rc::new(u64_type_outputs),
}; };
let f32_type_arguments = vec![fluence_faas::IFunctionArg { let f32_type_arguments = vec![fluence_faas::IFunctionArg {
@ -156,9 +159,9 @@ pub fn get_interfaces() {
let f32_type_outputs = vec![IType::Array(Box::new(IType::F32))]; let f32_type_outputs = vec![IType::Array(Box::new(IType::F32))];
let f32_type_sign = fluence_faas::FaaSFunctionSignature { let f32_type_sign = fluence_faas::FaaSFunctionSignature {
name: "f32_type", name: Rc::new(String::from("f32_type")),
arguments: &f32_type_arguments, arguments: Rc::new(f32_type_arguments),
outputs: &f32_type_outputs, outputs: Rc::new(f32_type_outputs),
}; };
let f64_type_arguments = vec![fluence_faas::IFunctionArg { let f64_type_arguments = vec![fluence_faas::IFunctionArg {
@ -168,18 +171,18 @@ pub fn get_interfaces() {
let f64_type_outputs = vec![IType::Array(Box::new(IType::F64))]; let f64_type_outputs = vec![IType::Array(Box::new(IType::F64))];
let f64_type_sign = fluence_faas::FaaSFunctionSignature { let f64_type_sign = fluence_faas::FaaSFunctionSignature {
name: "f64_type", name: Rc::new(String::from("f64_type")),
arguments: &f64_type_arguments, arguments: Rc::new(f64_type_arguments),
outputs: &f64_type_outputs, outputs: Rc::new(f64_type_outputs),
}; };
let empty_type_arguments = vec![]; let empty_type_arguments = vec![];
let empty_type_outputs = vec![IType::Array(Box::new(IType::String))]; let empty_type_outputs = vec![IType::Array(Box::new(IType::String))];
let empty_type_sign = fluence_faas::FaaSFunctionSignature { let empty_type_sign = fluence_faas::FaaSFunctionSignature {
name: "empty_type", name: Rc::new(String::from("empty_type")),
arguments: &empty_type_arguments, arguments: Rc::new(empty_type_arguments),
outputs: &empty_type_outputs, outputs: Rc::new(empty_type_outputs),
}; };
/* /*
@ -227,12 +230,12 @@ pub fn get_interfaces() {
let pure_module_functions: HashSet<_> = pure_module_interface let pure_module_functions: HashSet<_> = pure_module_interface
.function_signatures .function_signatures
.iter() .iter()
.filter(|f| f.name != "inner_arrays_2") .filter(|f| f.name.as_str() != "inner_arrays_2")
.collect(); .collect();
let effector_module_functions: HashSet<_> = effector_module_interface let effector_module_functions: HashSet<_> = effector_module_interface
.function_signatures .function_signatures
.iter() .iter()
.filter(|f| f.name != "inner_arrays_2") .filter(|f| f.name.as_str() != "inner_arrays_2")
.collect(); .collect();
let functions: HashSet<_> = functions.iter().collect(); let functions: HashSet<_> = functions.iter().collect();
@ -246,6 +249,8 @@ pub fn i32_type() {
let mut faas = FluenceFaaS::with_raw_config(ARG_CONFIG.clone()) let mut faas = FluenceFaaS::with_raw_config(ARG_CONFIG.clone())
.unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {:?}", e)); .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {:?}", e));
let right_result = json!([0, 1, 2, 3, 4, 0, 2]);
let result1 = faas let result1 = faas
.call_with_json( .call_with_json(
"arrays_passing_pure", "arrays_passing_pure",
@ -254,18 +259,7 @@ pub fn i32_type() {
<_>::default(), <_>::default(),
) )
.unwrap_or_else(|e| panic!("can't invoke i32_type: {:?}", e)); .unwrap_or_else(|e| panic!("can't invoke i32_type: {:?}", e));
assert_eq!( assert_eq!(result1, right_result);
result1,
vec![IValue::Array(vec![
IValue::S32(0),
IValue::S32(1),
IValue::S32(2),
IValue::S32(3),
IValue::S32(4),
IValue::S32(0),
IValue::S32(2)
])]
);
let result2 = faas let result2 = faas
.call_with_json( .call_with_json(
@ -275,19 +269,9 @@ pub fn i32_type() {
<_>::default(), <_>::default(),
) )
.unwrap_or_else(|e| panic!("can't invoke i32_type: {:?}", e)); .unwrap_or_else(|e| panic!("can't invoke i32_type: {:?}", e));
assert_eq!( assert_eq!(result2, right_result);
result2,
vec![IValue::Array(vec![
IValue::S32(0),
IValue::S32(1),
IValue::S32(2),
IValue::S32(3),
IValue::S32(4),
IValue::S32(0),
IValue::S32(2)
])]
);
let right_result = json!([1, 0, 1, 2, 3, 4, 0, 2]);
let result3 = faas let result3 = faas
.call_with_json( .call_with_json(
"arrays_passing_pure", "arrays_passing_pure",
@ -296,19 +280,7 @@ pub fn i32_type() {
<_>::default(), <_>::default(),
) )
.unwrap_or_else(|e| panic!("can't invoke i32_type: {:?}", e)); .unwrap_or_else(|e| panic!("can't invoke i32_type: {:?}", e));
assert_eq!( assert_eq!(result3, right_result);
result3,
vec![IValue::Array(vec![
IValue::S32(1),
IValue::S32(0),
IValue::S32(1),
IValue::S32(2),
IValue::S32(3),
IValue::S32(4),
IValue::S32(0),
IValue::S32(2)
])]
);
} }
#[test] #[test]
@ -322,6 +294,8 @@ pub fn i64_type() {
let result2 = faas.call_with_json("arrays_passing_pure", "i64_type", json!([]), <_>::default()); let result2 = faas.call_with_json("arrays_passing_pure", "i64_type", json!([]), <_>::default());
assert!(result2.is_err()); assert!(result2.is_err());
let right_result = json!([1, 0, 1, 2, 3, 4, 1, 1]);
let result3 = faas let result3 = faas
.call_with_json( .call_with_json(
"arrays_passing_pure", "arrays_passing_pure",
@ -330,19 +304,7 @@ pub fn i64_type() {
<_>::default(), <_>::default(),
) )
.unwrap_or_else(|e| panic!("can't invoke i64_type: {:?}", e)); .unwrap_or_else(|e| panic!("can't invoke i64_type: {:?}", e));
assert_eq!( assert_eq!(result3, right_result);
result3,
vec![IValue::Array(vec![
IValue::S64(1),
IValue::S64(0),
IValue::S64(1),
IValue::S64(2),
IValue::S64(3),
IValue::S64(4),
IValue::S64(1),
IValue::S64(1)
])]
);
let result4 = faas let result4 = faas
.call_with_json( .call_with_json(
@ -352,19 +314,7 @@ pub fn i64_type() {
<_>::default(), <_>::default(),
) )
.unwrap_or_else(|e| panic!("can't invoke i64_type: {:?}", e)); .unwrap_or_else(|e| panic!("can't invoke i64_type: {:?}", e));
assert_eq!( assert_eq!(result4, right_result);
result4,
vec![IValue::Array(vec![
IValue::S64(1),
IValue::S64(0),
IValue::S64(1),
IValue::S64(2),
IValue::S64(3),
IValue::S64(4),
IValue::S64(1),
IValue::S64(1)
])]
);
} }
#[test] #[test]
@ -378,43 +328,18 @@ pub fn u32_type() {
let result2 = faas.call_with_json("arrays_passing_pure", "u32_type", json!([]), <_>::default()); let result2 = faas.call_with_json("arrays_passing_pure", "u32_type", json!([]), <_>::default());
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!([1, 0, 13, 37, 2]);
.call_with_json(
"arrays_passing_pure",
"u32_type",
json!({ "arg": [1] }),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke u32_type: {:?}", e));
assert_eq!(
result3,
vec![IValue::Array(vec![
IValue::U32(1),
IValue::U32(0),
IValue::U32(13),
IValue::U32(37),
IValue::U32(2),
])]
);
let result4 = faas let result3 = call_faas!(
.call_with_json( faas,
"arrays_passing_pure", "arrays_passing_pure",
"u32_type", "u32_type",
json!([[1]]), json!({ "arg": [1] })
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke u32_type: {:?}", e));
assert_eq!(
result4,
vec![IValue::Array(vec![
IValue::U32(1),
IValue::U32(0),
IValue::U32(13),
IValue::U32(37),
IValue::U32(2),
])]
); );
assert_eq!(result3, right_result);
let result4 = call_faas!(faas, "arrays_passing_pure", "u32_type", json!([[1]]));
assert_eq!(result4, right_result);
} }
#[test] #[test]
@ -428,47 +353,18 @@ pub fn u64_type() {
let result2 = faas.call_with_json("arrays_passing_pure", "u64_type", json!([]), <_>::default()); let result2 = faas.call_with_json("arrays_passing_pure", "u64_type", json!([]), <_>::default());
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!([1, 0, 1, 2, 3, 4, 2]);
.call_with_json(
"arrays_passing_pure",
"u64_type",
json!({ "arg": [1] }),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke u64_type: {:?}", e));
assert_eq!(
result3,
vec![IValue::Array(vec![
IValue::U64(1),
IValue::U64(0),
IValue::U64(1),
IValue::U64(2),
IValue::U64(3),
IValue::U64(4),
IValue::U64(2),
])]
);
let result4 = faas let result3 = call_faas!(
.call_with_json( faas,
"arrays_passing_pure", "arrays_passing_pure",
"u64_type", "u64_type",
json!([[1]]), json!({ "arg": [1] })
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke u64_type: {:?}", e));
assert_eq!(
result4,
vec![IValue::Array(vec![
IValue::U64(1),
IValue::U64(0),
IValue::U64(1),
IValue::U64(2),
IValue::U64(3),
IValue::U64(4),
IValue::U64(2),
])]
); );
assert_eq!(result3, right_result);
let result4 = call_faas!(faas, "arrays_passing_pure", "u64_type", json!([[1]]));
assert_eq!(result4, right_result);
} }
#[test] #[test]
@ -482,41 +378,18 @@ pub fn f64_type_() {
let result2 = faas.call_with_json("arrays_passing_pure", "f32_type", json!([]), <_>::default()); let result2 = faas.call_with_json("arrays_passing_pure", "f32_type", json!([]), <_>::default());
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!([1.0, 0.0, 13.37, 1.0]);
.call_with_json(
"arrays_passing_pure",
"f64_type",
json!({ "arg": [1.0] }),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke f64_type: {:?}", e));
assert_eq!(
result3,
vec![IValue::Array(vec![
IValue::F64(1.0),
IValue::F64(0.0),
IValue::F64(13.37),
IValue::F64(1.0),
])]
);
let result4 = faas let result3 = call_faas!(
.call_with_json( faas,
"arrays_passing_pure", "arrays_passing_pure",
"f64_type", "f64_type",
json!([[1.0]]), json!({ "arg": [1.0] })
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke f64_type: {:?}", e));
assert_eq!(
result4,
vec![IValue::Array(vec![
IValue::F64(1.0),
IValue::F64(0.0),
IValue::F64(13.37),
IValue::F64(1.0),
])]
); );
assert_eq!(result3, right_result);
let result4 = call_faas!(faas, "arrays_passing_pure", "f64_type", json!([[1.0]]));
assert_eq!(result4, right_result);
} }
#[test] #[test]
@ -531,25 +404,18 @@ pub fn f64_type() {
let result2 = faas.call_with_json("arrays_passing_pure", "f64_type", json!([]), <_>::default()); let result2 = faas.call_with_json("arrays_passing_pure", "f64_type", json!([]), <_>::default());
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!([3.0]);
.call_with_json(
"arrays_passing_pure",
"f64_type",
json!({ "arg": 1.0 }),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke f64_type: {:?}", e));
assert_eq!(result3, vec![IValue::F64(3.0)]);
let result4 = faas let result3 = call_faas!(
.call_with_json( faas,
"arrays_passing_pure", "arrays_passing_pure",
"f64_type", "f64_type",
json!(1.0), json!({ "arg": 1.0 })
<_>::default(), );
) assert_eq!(result3, right_result);
.unwrap_or_else(|e| panic!("can't invoke f64_type: {:?}", e));
assert_eq!(result4, vec![IValue::F64(3.0)]); let result4 = call_faas!(faas, "arrays_passing_pure", "f64_type", json!(1.0));
assert_eq!(result4, right_result);
} }
#[test] #[test]
@ -573,41 +439,23 @@ pub fn string_type() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!(["Fluence", "fce", "from effector", "test"]);
.call_with_json(
"arrays_passing_pure",
"string_type",
json!({ "arg": ["Fluence"] }),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke string_type: {:?}", e));
assert_eq!(
result3,
vec![IValue::Array(vec![
IValue::String(String::from("Fluence")),
IValue::String(String::from("fce")),
IValue::String(String::from("from effector")),
IValue::String(String::from("test")),
])]
);
let result4 = faas let result3 = call_faas!(
.call_with_json( faas,
"arrays_passing_pure", "arrays_passing_pure",
"string_type", "string_type",
json!([["Fluence"]]), json!({ "arg": ["Fluence"] })
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke string_type: {:?}", e));
assert_eq!(
result4,
vec![IValue::Array(vec![
IValue::String(String::from("Fluence")),
IValue::String(String::from("fce")),
IValue::String(String::from("from effector")),
IValue::String(String::from("test")),
])]
); );
assert_eq!(result3, right_result);
let result4 = call_faas!(
faas,
"arrays_passing_pure",
"string_type",
json!([["Fluence"]])
);
assert_eq!(result4, right_result);
} }
#[test] #[test]
@ -631,43 +479,22 @@ pub fn byte_type() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!([0x13, 0x37, 0, 1, 2]);
.call_with_json( let result3 = call_faas!(
"arrays_passing_pure", faas,
"byte_type", "arrays_passing_pure",
json!({ "arg": [0x13, 0x37] }), "byte_type",
<_>::default(), json!({ "arg": [0x13, 0x37] })
)
.unwrap_or_else(|e| panic!("can't invoke bytearray_type: {:?}", e));
assert_eq!(
result3,
vec![IValue::Array(vec![
IValue::U8(0x13),
IValue::U8(0x37),
IValue::U8(0),
IValue::U8(1),
IValue::U8(2),
])]
); );
assert_eq!(result3, right_result);
let result4 = faas let result4 = call_faas!(
.call_with_json( faas,
"arrays_passing_pure", "arrays_passing_pure",
"byte_type", "byte_type",
json!([[0x13, 0x37]]), json!([[0x13, 0x37]])
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke bytearray_type: {:?}", e));
assert_eq!(
result4,
vec![IValue::Array(vec![
IValue::U8(0x13),
IValue::U8(0x37),
IValue::U8(0),
IValue::U8(1),
IValue::U8(2),
])]
); );
assert_eq!(result4, right_result);
} }
#[test] #[test]
@ -691,83 +518,30 @@ pub fn inner_arrays_1_type() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!([
.call_with_json( [[[0x13, 0x37]]],
"arrays_passing_pure", [[[0]]],
"inner_arrays_1", [],
json!({ "arg": [[[[0x13, 0x37]]]] }), [[]],
<_>::default(), [[[]]],
) [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]],
.unwrap_or_else(|e| panic!("can't invoke bytearray_type: {:?}", e)); [[[2]]]
assert_eq!( ]);
result3, let result3 = call_faas!(
vec![IValue::Array(vec![ faas,
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![ "arrays_passing_pure",
IValue::U8(0x13), "inner_arrays_1",
IValue::U8(0x37), json!({ "arg": [[[[0x13, 0x37]]]] })
])])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![IValue::U8(
0
),])])]),
IValue::Array(vec![]),
IValue::Array(vec![IValue::Array(vec![])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![])])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![
IValue::U8(1),
IValue::U8(2),
IValue::U8(3),
IValue::U8(4),
IValue::U8(5),
IValue::U8(6),
IValue::U8(7),
IValue::U8(8),
IValue::U8(9),
IValue::U8(10),
])])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![IValue::U8(
2
),])])]),
]),]
); );
assert_eq!(result3, right_result);
let result4 = faas let result4 = call_faas!(
.call_with_json( faas,
"arrays_passing_pure", "arrays_passing_pure",
"inner_arrays_1", "inner_arrays_1",
json!([[[[[0x13, 0x37]]]]]), json!([[[[[0x13, 0x37]]]]])
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke bytearray_type: {:?}", e));
assert_eq!(
result4,
vec![IValue::Array(vec![
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![
IValue::U8(0x13),
IValue::U8(0x37),
])])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![IValue::U8(
0
),])])]),
IValue::Array(vec![]),
IValue::Array(vec![IValue::Array(vec![])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![])])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![
IValue::U8(1),
IValue::U8(2),
IValue::U8(3),
IValue::U8(4),
IValue::U8(5),
IValue::U8(6),
IValue::U8(7),
IValue::U8(8),
IValue::U8(9),
IValue::U8(10),
])])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![IValue::U8(
2
),])])]),
]),]
); );
assert_eq!(result4, right_result);
} }
#[test] #[test]
@ -791,133 +565,55 @@ pub fn inner_arrays_2_type() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!([
.call_with_json( [[[{
"arrays_passing_pure", "field_0": 0,
"inner_arrays_2", "field_1": [[1]]
json!({ "arg": [[[[[0, [[1]]]]]]] }), }]]],
<_>::default(), [[[
) {
.unwrap_or_else(|e| panic!("can't invoke bytearray_type: {:?}", e)); "field_0": 0,
assert_eq!( "field_1": [[1]]
result3, },
vec![IValue::Array(vec![ {
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![ "field_0": 0,
IValue::Record( "field_1": []
fce::vec1::Vec1::new(vec![ },
IValue::S32(0), ]]],
IValue::Array(vec![IValue::Array(vec![IValue::U8(1)])]) [],
]) [[]],
.unwrap() [[[]]],
) [[[{
])])]), "field_0": 0,
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![ "field_1": [[1,2,3,4]]
IValue::Record( }]]],
fce::vec1::Vec1::new(vec![ [[[
IValue::S32(0), {
IValue::Array(vec![IValue::Array(vec![IValue::U8(1)])]) "field_0": 1,
]) "field_1": [[2]]
.unwrap() },
), {
IValue::Record( "field_0": 0,
fce::vec1::Vec1::new(vec![IValue::S32(0), IValue::Array(vec![]),]).unwrap() "field_1": []
) },
])])]), ]]],
IValue::Array(vec![]), ]);
IValue::Array(vec![IValue::Array(vec![])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![])])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![
IValue::Record(
fce::vec1::Vec1::new(vec![
IValue::S32(0),
IValue::Array(vec![IValue::Array(vec![
IValue::U8(1),
IValue::U8(2),
IValue::U8(3),
IValue::U8(4),
])])
])
.unwrap()
),
])])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![
IValue::Record(
fce::vec1::Vec1::new(vec![
IValue::S32(1),
IValue::Array(vec![IValue::Array(vec![IValue::U8(2)])])
])
.unwrap()
),
IValue::Record(
fce::vec1::Vec1::new(vec![IValue::S32(0), IValue::Array(vec![])]).unwrap()
)
])])]),
]),]
);
let result4 = faas let result3 = call_faas!(
.call_with_json( faas,
"arrays_passing_pure", "arrays_passing_pure",
"inner_arrays_2", "inner_arrays_2",
json!([[[[[{"field_0": 0, "field_1": [[1]]}]]]]]), json!({ "arg": [[[[[0, [[1]]]]]]] })
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke bytearray_type: {:?}", e));
assert_eq!(
result4,
vec![IValue::Array(vec![
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![
IValue::Record(
fce::vec1::Vec1::new(vec![
IValue::S32(0),
IValue::Array(vec![IValue::Array(vec![IValue::U8(1)])])
])
.unwrap()
)
])])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![
IValue::Record(
fce::vec1::Vec1::new(vec![
IValue::S32(0),
IValue::Array(vec![IValue::Array(vec![IValue::U8(1)])])
])
.unwrap()
),
IValue::Record(
fce::vec1::Vec1::new(vec![IValue::S32(0), IValue::Array(vec![]),]).unwrap()
)
])])]),
IValue::Array(vec![]),
IValue::Array(vec![IValue::Array(vec![])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![])])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![
IValue::Record(
fce::vec1::Vec1::new(vec![
IValue::S32(0),
IValue::Array(vec![IValue::Array(vec![
IValue::U8(1),
IValue::U8(2),
IValue::U8(3),
IValue::U8(4),
])])
])
.unwrap()
),
])])]),
IValue::Array(vec![IValue::Array(vec![IValue::Array(vec![
IValue::Record(
fce::vec1::Vec1::new(vec![
IValue::S32(1),
IValue::Array(vec![IValue::Array(vec![IValue::U8(2)])])
])
.unwrap()
),
IValue::Record(
fce::vec1::Vec1::new(vec![IValue::S32(0), IValue::Array(vec![])]).unwrap()
)
])])]),
]),]
); );
assert_eq!(result3, right_result);
let result4 = call_faas!(
faas,
"arrays_passing_pure",
"inner_arrays_2",
json!([[[[[{"field_0": 0, "field_1": [[1]]}]]]]])
);
assert_eq!(result4, right_result);
} }
#[test] #[test]
@ -942,20 +638,18 @@ pub fn bool_type() {
); );
assert!(result2.is_err()); assert!(result2.is_err());
let result3 = faas let right_result = json!(1);
.call_with_json(
"arrays_passing_pure",
"bool_type",
json!({ "arg": 0 }),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke bool_type: {:?}", e));
assert_eq!(result3, vec![IValue::I32(1)]);
let result4 = faas let result3 = call_faas!(
.call_with_json("arrays_passing_pure", "bool_type", json!(0), <_>::default()) faas,
.unwrap_or_else(|e| panic!("can't invoke bool_type: {:?}", e)); "arrays_passing_pure",
assert_eq!(result4, vec![IValue::I32(1)]); "bool_type",
json!({ "arg": 0 })
);
assert_eq!(result3, right_result);
let result4 = call_faas!(faas, "arrays_passing_pure", "bool_type", json!(0));
assert_eq!(result4, right_result);
} }
#[test] #[test]
@ -963,50 +657,15 @@ pub fn empty_type() {
let mut faas = FluenceFaaS::with_raw_config(ARG_CONFIG.clone()) let mut faas = FluenceFaaS::with_raw_config(ARG_CONFIG.clone())
.unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {:?}", e)); .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {:?}", e));
let result1 = faas let right_result = json!(["from effector"]);
.call_with_json( let result1 = call_faas!(faas, "arrays_passing_pure", "empty_type", json!({}));
"arrays_passing_pure", assert_eq!(result1, right_result);
"empty_type",
json!({}),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke empty_type: {:?}", e));
assert_eq!(
result1,
vec![IValue::Array(vec![IValue::String(String::from(
"from effector"
))])]
);
let result2 = faas let result2 = call_faas!(faas, "arrays_passing_pure", "empty_type", json!([]));
.call_with_json( assert_eq!(result2, right_result);
"arrays_passing_pure",
"empty_type",
json!([]),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke empty_type: {:?}", e));
assert_eq!(
result2,
vec![IValue::Array(vec![IValue::String(String::from(
"from effector"
))])]
);
let result3 = faas let result3 = call_faas!(faas, "arrays_passing_pure", "empty_type", json!([]));
.call_with_json( assert_eq!(result3, right_result);
"arrays_passing_pure",
"empty_type",
json!([]),
<_>::default(),
)
.unwrap_or_else(|e| panic!("can't invoke empty_type: {:?}", e));
assert_eq!(
result3,
vec![IValue::Array(vec![IValue::String(String::from(
"from effector"
))])]
);
let result4 = faas.call_with_json( let result4 = faas.call_with_json(
"arrays_passing_pure", "arrays_passing_pure",

View File

@ -20,6 +20,8 @@ use fluence_faas::IValue;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use std::rc::Rc;
#[test] #[test]
pub fn greeting() { pub fn greeting() {
let greeting_config_path = "../examples/greeting/Config.toml"; let greeting_config_path = "../examples/greeting/Config.toml";
@ -79,9 +81,9 @@ pub fn get_interfaces() {
let output_types = vec![fluence_faas::IType::String]; let output_types = vec![fluence_faas::IType::String];
let greeting_sign = fluence_faas::FaaSFunctionSignature { let greeting_sign = fluence_faas::FaaSFunctionSignature {
name: "greeting", name: Rc::new(String::from("greeting")),
arguments: &arguments, arguments: Rc::new(arguments),
outputs: &output_types, outputs: Rc::new(output_types),
}; };
let record_types = std::collections::HashMap::new(); let record_types = std::collections::HashMap::new();

View File

@ -38,6 +38,22 @@ pub fn records() {
.call_with_ivalues("records_pure", "invoke", &[], <_>::default()) .call_with_ivalues("records_pure", "invoke", &[], <_>::default())
.unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e)); .unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e));
let right_result = json!({
"field_0": 1,
"field_1": 1,
"field_2": 2,
"field_3": 3,
"field_4": 4,
"field_5": 5,
"field_6": 6,
"field_7": 7,
"field_8": 8,
"field_9": 9.0,
"field_10": 10.0,
"field_11": "field_11",
"field_12": [0x13, 0x37],
});
assert_eq!( assert_eq!(
result1, result1,
vec![IValue::Record( vec![IValue::Record(
@ -86,27 +102,7 @@ pub fn records() {
) )
.unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e)); .unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e));
assert_eq!( assert_eq!(result2, right_result);
result2,
vec![IValue::Record(
wasmer_wit::vec1::Vec1::new(vec![
IValue::I32(1),
IValue::S8(1),
IValue::S16(2),
IValue::S32(3),
IValue::S64(4),
IValue::U8(5),
IValue::U16(6),
IValue::U32(7),
IValue::U64(8),
IValue::F32(9.0),
IValue::F64(10.0),
IValue::String(String::from("field_11")),
IValue::Array(vec![IValue::U8(0x13), IValue::U8(0x37)])
])
.unwrap()
)]
);
let result3 = faas let result3 = faas
.call_with_json( .call_with_json(
@ -120,27 +116,7 @@ pub fn records() {
) )
.unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e)); .unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e));
assert_eq!( assert_eq!(result3, right_result);
result3,
vec![IValue::Record(
wasmer_wit::vec1::Vec1::new(vec![
IValue::I32(1),
IValue::S8(1),
IValue::S16(2),
IValue::S32(3),
IValue::S64(4),
IValue::U8(5),
IValue::U16(6),
IValue::U32(7),
IValue::U64(8),
IValue::F32(9.0),
IValue::F64(10.0),
IValue::String(String::from("field_11")),
IValue::Array(vec![IValue::U8(0x13), IValue::U8(0x37)])
])
.unwrap()
)]
);
let result4 = faas let result4 = faas
.call_with_json( .call_with_json(
@ -166,27 +142,7 @@ pub fn records() {
) )
.unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e)); .unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e));
assert_eq!( assert_eq!(result4, right_result);
result4,
vec![IValue::Record(
wasmer_wit::vec1::Vec1::new(vec![
IValue::I32(1),
IValue::S8(1),
IValue::S16(2),
IValue::S32(3),
IValue::S64(4),
IValue::U8(5),
IValue::U16(6),
IValue::U32(7),
IValue::U64(8),
IValue::F32(9.0),
IValue::F64(10.0),
IValue::String(String::from("field_11")),
IValue::Array(vec![IValue::U8(0x13), IValue::U8(0x37)])
])
.unwrap()
)]
);
let result5 = faas let result5 = faas
.call_with_json( .call_with_json(
@ -197,27 +153,7 @@ pub fn records() {
) )
.unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e)); .unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e));
assert_eq!( assert_eq!(result5, right_result);
result5,
vec![IValue::Record(
wasmer_wit::vec1::Vec1::new(vec![
IValue::I32(1),
IValue::S8(1),
IValue::S16(2),
IValue::S32(3),
IValue::S64(4),
IValue::U8(5),
IValue::U16(6),
IValue::U32(7),
IValue::U64(8),
IValue::F32(9.0),
IValue::F64(10.0),
IValue::String(String::from("field_11")),
IValue::Array(vec![IValue::U8(0x13), IValue::U8(0x37)])
])
.unwrap()
)]
);
} }
#[test] #[test]
@ -258,22 +194,19 @@ fn inner_records() {
) )
.unwrap_or_else(|e| panic!("can't invoke inner_records_pure: {:?}", e)); .unwrap_or_else(|e| panic!("can't invoke inner_records_pure: {:?}", e));
assert_eq!( let right_result = json!({
result, "test_record_0": {
vec![IValue::Record( "field_0": 1
wasmer_wit::vec1::Vec1::new(vec![ },
IValue::Record(wasmer_wit::vec1::Vec1::new(vec![IValue::S32(1),]).unwrap()), "test_record_1": {
IValue::Record( "field_0": 1,
wasmer_wit::vec1::Vec1::new(vec![ "field_1": "",
IValue::S32(1), "field_2": vec![1],
IValue::String(String::new()), "test_record_0": {
IValue::Array(vec![IValue::U8(1)]), "field_0": 1
IValue::Record(wasmer_wit::vec1::Vec1::new(vec![IValue::S32(1),]).unwrap()) }
]) }
.unwrap() });
),
]) assert_eq!(result, right_result);
.unwrap()
)]
);
} }

View File

@ -0,0 +1,24 @@
/*
* Copyright 2020 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#[macro_export]
macro_rules! call_faas {
($faas:expr, $module_name:expr, $func_name:expr, $args:expr) => {
$faas
.call_with_json($module_name, $func_name, $args, <_>::default())
.unwrap_or_else(|e| panic!("faas failed with {:?}", e))
};
}

View File

@ -1,7 +1,7 @@
[package] [package]
name = "fcli" name = "fcli"
description = "Fluence FCE command line tool" description = "Fluence FCE command line tool"
version = "0.1.10" version = "0.1.11"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
repository = "https://github.com/fluencelabs/fce/tools/cli" repository = "https://github.com/fluencelabs/fce/tools/cli"
license = "Apache-2.0" license = "Apache-2.0"
@ -12,8 +12,8 @@ name = "fce"
path = "src/main.rs" path = "src/main.rs"
[dependencies] [dependencies]
fce-wit-generator = { path = "../../crates/wit-generator", version = "0.1.9" } fce-wit-generator = { path = "../../crates/wit-generator", version = "0.1.10" }
fce-wit-parser = { path = "../../crates/wit-parser", version = "0.1.8" } fce-wit-parser = { path = "../../crates/wit-parser", version = "0.1.9" }
anyhow = "1.0.31" anyhow = "1.0.31"
clap = "2.33.1" clap = "2.33.1"

View File

@ -1,7 +1,7 @@
[package] [package]
name = "frepl" name = "frepl"
description = "Fluence FCE REPL intended for testing purposes" description = "Fluence FCE REPL intended for testing purposes"
version = "0.1.13" version = "0.1.14"
authors = ["Fluence Labs"] authors = ["Fluence Labs"]
repository = "https://github.com/fluencelabs/fce/tools/repl" repository = "https://github.com/fluencelabs/fce/tools/repl"
license = "Apache-2.0" license = "Apache-2.0"
@ -12,7 +12,7 @@ name = "fce-repl"
path = "src/main.rs" path = "src/main.rs"
[dependencies] [dependencies]
fluence-app-service = { path = "../../fluence-app-service", version = "0.1.9", features = ["raw-module-api"] } fluence-app-service = { path = "../../fluence-app-service", version = "0.1.10", features = ["raw-module-api"] }
anyhow = "1.0.31" anyhow = "1.0.31"
clap = "2.33.1" clap = "2.33.1"