diff --git a/crates/fce-test-macro-impl/src/fce_test/glue_code_generator.rs b/crates/fce-test-macro-impl/src/fce_test/glue_code_generator.rs index bdc7dc5..9f6b135 100644 --- a/crates/fce-test-macro-impl/src/fce_test/glue_code_generator.rs +++ b/crates/fce-test-macro-impl/src/fce_test/glue_code_generator.rs @@ -76,7 +76,7 @@ use std::path::PathBuf; /// let tmp_dir = tmp_dir.to_string_lossy().to_string(); /// std::fs::create_dir(&tmp_dir).expect("can't create a directory for service in tmp"); /// -/// let mut __fce__generated_fce_config = fluence_test::internal::TomlAppServiceConfig::load("/path/to/greeting/Config.toml".to_string()) +/// let mut __fce_generated_fce_config = fluence_test::internal::TomlAppServiceConfig::load("/path/to/greeting/Config.toml".to_string()) /// .unwrap_or_else(|e| { /// panic!( /// "app service located at `{}` config can't be loaded: {}", @@ -84,10 +84,10 @@ use std::path::PathBuf; /// ) /// }); /// -/// __fce__generated_fce_config.service_base_dir = Some("/path/to/tmp".to_string()); +/// __fce_generated_fce_config.service_base_dir = Some("/path/to/tmp".to_string()); /// /// let fce = fluence_test::internal::AppService::new_with_empty_facade( -/// __fce__generated_fce_config, +/// __fce_generated_fce_config, /// "3640e972-92e3-47cb-b95f-4e3c5bcf0f14", /// std::collections::HashMap::new(), /// ).unwrap_or_else(|e| panic!("app service can't be created: {}", e)); diff --git a/crates/wit/src/parsed_type/fn_prolog.rs b/crates/wit/src/parsed_type/fn_prolog.rs index adfb9bb..455b93e 100644 --- a/crates/wit/src/parsed_type/fn_prolog.rs +++ b/crates/wit/src/parsed_type/fn_prolog.rs @@ -130,7 +130,10 @@ fn generate_type_lifting_prolog( }, ParsedType::Vector(ty, _) => { let generated_deserializer_name = - format!("__fce_generated_vec_deserializer_{}", supplied_arg_start_id); + format!("__fce_generated_vec_deserializer_{}", supplied_arg_start_id) + .replace("&", "_") + .replace("<", "_") + .replace(">", "_"); let generated_deserializer_ident = new_ident!(generated_deserializer_name); let vector_deserializer = super::vector_utils::generate_vector_deserializer( ty, diff --git a/crates/wit/src/parsed_type/foreign_mod_prolog.rs b/crates/wit/src/parsed_type/foreign_mod_prolog.rs index 8f2d2aa..ce24ebe 100644 --- a/crates/wit/src/parsed_type/foreign_mod_prolog.rs +++ b/crates/wit/src/parsed_type/foreign_mod_prolog.rs @@ -64,10 +64,8 @@ impl ForeignModPrologGlueCodeGenerator for Vec { use crate::parsed_type::foreign_mod_arg::ForeignModArgGlueCodeGenerator; use quote::ToTokens; - let arg_types: Vec = self - .iter() - .map(|arg| arg.ty.to_token_stream()) - .collect(); + let arg_types: Vec = + self.iter().map(|arg| arg.ty.to_token_stream()).collect(); let (arg_names, arg_transforms, arg_drops) = self .iter() @@ -84,7 +82,7 @@ impl ForeignModPrologGlueCodeGenerator for Vec { arg_drops.extend(quote::quote! { std::mem::ManuallyDrop::drop(&mut #arg_ident); }); }, ParsedType::Vector(ty, _) => { - let generated_serializer_name = format!("__fce_generated_vec_serializer_{}", arg_name); + let generated_serializer_name = format!("__fce_generated_vec_serializer_{}", arg_name).replace("&<>", "_"); let generated_serializer_ident = new_ident!(generated_serializer_name); let vector_serializer = super::vector_utils::generate_vector_serializer(ty, &generated_serializer_name); diff --git a/crates/wit/src/parsed_type/vector_utils.rs b/crates/wit/src/parsed_type/vector_utils.rs index f799ef7..cec1d20 100644 --- a/crates/wit/src/parsed_type/vector_utils.rs +++ b/crates/wit/src/parsed_type/vector_utils.rs @@ -91,7 +91,10 @@ fn generate_vector_serializer_impl( } } ParsedType::Vector(ty, _) => { - let serializer_name = format!("{}_{}", arg_name, ty); + let serializer_name = format!("{}_{}", arg_name, ty) + .replace("<", "_") + .replace(">", "_") + .replace("&", "_"); let inner_vector_serializer = generate_vector_serializer(&*ty, &serializer_name); let serializer_ident = crate::new_ident!(serializer_name); @@ -182,7 +185,10 @@ pub(crate) fn generate_vector_deserializer( } } ParsedType::Vector(ty, _) => { - let deserializer_name = format!("{}_{}", arg_name, ty); + let deserializer_name = format!("{}_{}", arg_name, ty) + .replace("&", "_") + .replace("<", "_") + .replace(">", "_"); let inner_vector_deserializer = generate_vector_deserializer(&*ty, &deserializer_name); let deserializer_ident = crate::new_ident!(deserializer_name); diff --git a/crates/wit/src/token_stream_generator/record_generator/record_deserializer.rs b/crates/wit/src/token_stream_generator/record_generator/record_deserializer.rs index 8b8a745..9953a9a 100644 --- a/crates/wit/src/token_stream_generator/record_generator/record_deserializer.rs +++ b/crates/wit/src/token_stream_generator/record_generator/record_deserializer.rs @@ -105,7 +105,10 @@ impl RecordDeserializerGlueCodeGenerator for fce_ast_types::AstRecordItem { } ParsedType::Vector(ty, _) => { let generated_deserializer_name = - format!("__fce_generated_vec_deserializer_{}", value_id); + format!("__fce_generated_vec_deserializer_{}", value_id) + .replace("&", "_") + .replace("<", "_") + .replace(">", "_"); let generated_deserializer_ident = new_ident!(generated_deserializer_name); let vector_deserializer = crate::parsed_type::generate_vector_deserializer( ty, diff --git a/fluence/tests/export_functions/arrays.rs b/fluence/tests/export_functions/arrays.rs index 2b9c7f4..dd6281a 100644 --- a/fluence/tests/export_functions/arrays.rs +++ b/fluence/tests/export_functions/arrays.rs @@ -5,7 +5,7 @@ use fluence::fce; pub fn main() {} #[fce] -pub fn byte_type( __arg: Vec) -> Vec { +pub fn byte_type(_arg: Vec) -> Vec { unimplemented!() } diff --git a/fluence/tests/export_functions/basic_types.rs b/fluence/tests/export_functions/basic_types.rs index b0cd5fb..107df72 100644 --- a/fluence/tests/export_functions/basic_types.rs +++ b/fluence/tests/export_functions/basic_types.rs @@ -27,6 +27,11 @@ pub fn string_type(_arg: String) -> String { unimplemented!() } +#[fce] +pub fn str_type(_arg: &str) -> &str { + unimplemented!() +} + #[fce] pub fn bytearray_type(_arg: Vec) -> Vec { unimplemented!() diff --git a/fluence/tests/export_functions/ref_arrays.rs b/fluence/tests/export_functions/ref_arrays.rs new file mode 100644 index 0000000..3607282 --- /dev/null +++ b/fluence/tests/export_functions/ref_arrays.rs @@ -0,0 +1,77 @@ +#![allow(improper_ctypes)] + +use fluence::fce; + +pub fn main() {} + +#[fce] +pub fn byte_type(_arg: &Vec) -> &Vec { + unimplemented!() +} + +#[fce] +pub fn inner_arrays_1(_arg: &Vec>>>) -> &Vec>>> { + unimplemented!() +} + +#[fce] +pub fn inner_arrays_2(_arg: &Vec>>>) -> &Vec>>> { + unimplemented!() +} + +#[fce] +pub fn inner_arrays_3(_arg: &Vec>>>) -> &Vec<&Vec<&Vec<&Vec<&u8>>>> { + unimplemented!() +} + +#[fce] +#[derive(Default)] +pub struct TestRecord { + pub field_0: i32, + pub field_1: Vec>, +} + +#[fce] +pub fn inner_arrays_4(_arg: &Vec>>>) -> &Vec>>> { + unimplemented!() +} + +#[fce] +pub fn string_type(_arg: &Vec) -> &Vec { + unimplemented!() +} + +#[fce] +pub fn f32_type(_arg: &Vec) -> &Vec { + unimplemented!() +} + +#[fce] +pub fn f64_type(_arg: &Vec) -> &Vec { + unimplemented!() +} + +#[fce] +pub fn u32_type(_arg: &Vec) -> &Vec { + unimplemented!() +} + +#[fce] +pub fn u64_type(_arg: &Vec) -> &Vec { + unimplemented!() +} + +#[fce] +pub fn i32_type(_arg: &Vec) -> &Vec { + unimplemented!() +} + +#[fce] +pub fn i64_type(_arg: &Vec) -> &Vec { + unimplemented!() +} + +#[fce] +pub fn empty_type() -> &'static Vec { + unimplemented!() +} diff --git a/fluence/tests/export_functions/ref_basic_types.rs b/fluence/tests/export_functions/ref_basic_types.rs new file mode 100644 index 0000000..1e2f2d0 --- /dev/null +++ b/fluence/tests/export_functions/ref_basic_types.rs @@ -0,0 +1,73 @@ +#![allow(improper_ctypes)] + +use fluence::fce; + +pub fn main() {} + +#[fce] +pub fn all_types<'v>( + _arg_0: &i8, + _arg_1: &i16, + _arg_2: &i32, + _arg_3: &i64, + _arg_4: &u8, + _arg_5: &u16, + _arg_6: &u32, + _arg_7: &u64, + _arg_8: &f32, + _arg_9: &f64, + _arg_10: &String, + _arg_11: &'v Vec, +) -> &'v Vec { + unimplemented!() +} + +#[fce] +pub fn string_type(_arg: &String) -> &String { + unimplemented!() +} + +#[fce] +pub fn bytearray_type(_arg: &Vec) -> &Vec { + unimplemented!() +} + +#[fce] +pub fn bool_type(_arg: &bool) -> &bool { + unimplemented!() +} + +#[fce] +pub fn f32_type(_arg: &f32) -> &f32 { + unimplemented!() +} + +#[fce] +pub fn f64_type(_arg: &f64) -> &f64 { + unimplemented!() +} + +#[fce] +pub fn u32_type(_arg: &u32) -> &u32 { + unimplemented!() +} + +#[fce] +pub fn u64_type(_arg: &u64) -> &u64 { + unimplemented!() +} + +#[fce] +pub fn i32_type(_arg: &i32) -> &i32 { + unimplemented!() +} + +#[fce] +pub fn i64_type(_arg: &i64) -> &i64 { + unimplemented!() +} + +#[fce] +pub fn empty_type() -> &'static String { + unimplemented!() +} diff --git a/fluence/tests/import_functions/ref_arrays.rs b/fluence/tests/import_functions/ref_arrays.rs new file mode 100644 index 0000000..d38fee4 --- /dev/null +++ b/fluence/tests/import_functions/ref_arrays.rs @@ -0,0 +1,58 @@ +#![allow(improper_ctypes)] + +use fluence::fce; + +pub fn main() {} + +#[fce] +#[derive(Default)] +pub struct TestRecord { + pub field_0: i32, + pub field_1: Vec>, +} + +#[fce] +#[link(wasm_import_module = "arrays_passing_effector")] +extern "C" { + pub fn inner_arrays_1(arg: &Vec>>>) -> Vec>>>; + pub fn inner_arrays_2(arg: &Vec<&Vec>>>) -> Vec>>>; + pub fn inner_arrays_3(arg: &Vec<&Vec<&Vec>>>) -> Vec>>>; + pub fn inner_arrays_4(arg: &Vec<&Vec<&Vec<&Vec>>>) -> Vec>>>; + pub fn inner_arrays_5(arg: &Vec<&Vec<&Vec<&Vec<&u8>>>>) -> Vec>>>; + + pub fn inner_arrays_6( + arg: &Vec>>>, + ) -> Vec>>>; + + pub fn inner_arrays_7( + arg: &Vec<&Vec>>>, + ) -> Vec>>>; + + pub fn inner_arrays_8( + arg: &Vec<&Vec<&Vec>>>, + ) -> Vec>>>; + + pub fn inner_arrays_9( + arg: &Vec<&Vec<&Vec<&Vec>>>, + ) -> Vec>>>; + + pub fn inner_arrays_10( + arg: &Vec<&Vec<&Vec<&Vec<&TestRecord>>>>, + ) -> Vec>>>; + + pub fn string_type(arg: &Vec) -> Vec; + + pub fn byte_type(arg: &Vec) -> Vec; + + pub fn f32_type(arg: &Vec) -> Vec; + + pub fn f64_type(arg: &Vec) -> Vec; + + pub fn u32_type(arg: &Vec) -> Vec; + + pub fn u64_type(arg: &Vec) -> Vec; + + pub fn i32_type(arg: &Vec) -> Vec; + + pub fn i64_type(arg: &Vec) -> Vec; +} diff --git a/fluence/tests/import_functions/ref_basic_types.rs b/fluence/tests/import_functions/ref_basic_types.rs new file mode 100644 index 0000000..f7c2ecb --- /dev/null +++ b/fluence/tests/import_functions/ref_basic_types.rs @@ -0,0 +1,38 @@ +#![allow(improper_ctypes)] + +use fluence::fce; + +fn main() {} + +#[fce] +#[link(wasm_import_module = "arguments_passing_effector")] +extern "C" { + pub fn all_types( + arg_0: &i8, + arg_1: &i16, + arg_2: &i32, + arg_3: &i64, + arg_4: &u8, + arg_5: &u16, + arg_6: &u32, + arg_7: &u64, + arg_8: &f32, + arg_9: &f64, + arg_10: &String, + arg_11: &Vec, + ) -> Vec; + + pub fn string_type(arg: &String) -> String; + pub fn bytearray_type(arg: &Vec) -> Vec; + + pub fn bool_type(arg: &bool) -> bool; + + pub fn f32_type(arg: &f32) -> f32; + pub fn f64_type(arg: &f64) -> f64; + + pub fn u32_type(arg: &u32) -> u32; + pub fn u64_type(arg: &u64) -> u64; + + pub fn i32_type(arg: &i32) -> i32; + pub fn i64_type(arg: &i64) -> i64; +} diff --git a/fluence/tests/test_runner.rs b/fluence/tests/test_runner.rs index 38b8782..139c078 100644 --- a/fluence/tests/test_runner.rs +++ b/fluence/tests/test_runner.rs @@ -2,11 +2,15 @@ fn test() { let tests = trybuild::TestCases::new(); tests.pass("tests/export_functions/arrays.rs"); + tests.pass("tests/export_functions/ref_arrays.rs"); tests.pass("tests/export_functions/basic_types.rs"); + tests.pass("tests/export_functions/ref_basic_types.rs"); tests.compile_fail("tests/export_functions/improper_types.rs"); tests.pass("tests/import_functions/arrays.rs"); + tests.pass("tests/import_functions/ref_arrays.rs"); tests.pass("tests/import_functions/basic_types.rs"); + tests.pass("tests/import_functions/ref_basic_types.rs"); tests.compile_fail("tests/import_functions/improper_types.rs"); tests.pass("tests/records/basic_structs.rs");