From f312b09fec864898f9671f63f3810714c2ccf66c Mon Sep 17 00:00:00 2001 From: vms Date: Sat, 22 Aug 2020 13:40:05 +0300 Subject: [PATCH] get rid of trait --- crates/main/src/lib.rs | 13 ------------- crates/wit/src/parsed_type/foreign_mod_epilog.rs | 14 +++++++++++++- .../wit/src/token_stream_generator/fn_generator.rs | 4 ---- .../foreign_mod_generator.rs | 4 ---- .../src/token_stream_generator/record_generator.rs | 14 +------------- src/lib.rs | 2 -- 6 files changed, 14 insertions(+), 37 deletions(-) diff --git a/crates/main/src/lib.rs b/crates/main/src/lib.rs index 45ec430..c13f1db 100644 --- a/crates/main/src/lib.rs +++ b/crates/main/src/lib.rs @@ -49,19 +49,6 @@ pub use result::get_result_size; pub use result::set_result_ptr; pub use result::set_result_size; -/// This trait is used to convert structs to a form compatible with -/// record.lift_memory and record.lower_memory instructions. -/// Normally, this trait shouldn't be used directly. -pub trait FCEStructSerializable { - // Serialize the provided record to a Vec, returns pointer to it in a form compatible with - // record.lift_memory. - // The caller should manage the lifetime of returned pointer. - fn __fce_generated_serialize(&self) -> *const u8; - - // Deserialize record from a pointer (normally, come from record.lower_memory). - unsafe fn __fce_generated_deserialize(record_ptr: *const u8) -> Self; -} - #[allow(unused_variables)] pub(crate) fn log>(msg: S) { // logs will be printed only if debug feature is enabled diff --git a/crates/wit/src/parsed_type/foreign_mod_epilog.rs b/crates/wit/src/parsed_type/foreign_mod_epilog.rs index 1368370..3f3b79f 100644 --- a/crates/wit/src/parsed_type/foreign_mod_epilog.rs +++ b/crates/wit/src/parsed_type/foreign_mod_epilog.rs @@ -60,8 +60,10 @@ impl ForeignModEpilogGlueCodeGenerator for Option { }, Some(ParsedType::Record(record_name)) => { let record_ident = new_ident!(record_name); + let crate_path = get_crate_path(); + quote! { - #record_ident::__fce_generated_deserialize(fluence::internal::get_result_ptr() as _) + #record_ident::__fce_generated_deserialize(#crate_path::get_result_ptr() as _) } } _ => panic!( @@ -70,3 +72,13 @@ impl ForeignModEpilogGlueCodeGenerator for Option { } } } + +#[cfg(feature = "fce")] +fn get_crate_path() -> proc_macro2::TokenStream { + quote! {fluence::internal} +} + +#[cfg(not(feature = "fce"))] +fn get_crate_path() -> proc_macro2::TokenStream { + quote! {crate} +} diff --git a/crates/wit/src/token_stream_generator/fn_generator.rs b/crates/wit/src/token_stream_generator/fn_generator.rs index aaa61a5..1e847dc 100644 --- a/crates/wit/src/token_stream_generator/fn_generator.rs +++ b/crates/wit/src/token_stream_generator/fn_generator.rs @@ -69,10 +69,6 @@ impl quote::ToTokens for fce_ast_types::AstFunctionItem { #[doc(hidden)] #[allow(clippy::all)] pub unsafe fn #func_name(#(#raw_arg_names: #raw_arg_types),*) #fn_return_type { - // brings serialize/deserialize methods for records - #[allow(dead_code)] - use fluence::internal::FCEStructSerializable; - // arguments conversation from Wasm types to Rust types #prolog diff --git a/crates/wit/src/token_stream_generator/foreign_mod_generator.rs b/crates/wit/src/token_stream_generator/foreign_mod_generator.rs index 0b909c7..7e9df3c 100644 --- a/crates/wit/src/token_stream_generator/foreign_mod_generator.rs +++ b/crates/wit/src/token_stream_generator/foreign_mod_generator.rs @@ -121,10 +121,6 @@ fn generate_wrapper_functions(extern_item: &fce_ast_types::AstExternModItem) -> #[doc(hidden)] #[allow(clippy::all)] #visibility fn #func_name(#(#arg_names: #arg_types), *) #return_type { - // brings serialize/deserialize methods for records - #[allow(dead_code)] - use fluence::internal::FCEStructSerializable; - unsafe { // calling the original function with converted args #return_expression #import_func_name(#(#raw_args), *); diff --git a/crates/wit/src/token_stream_generator/record_generator.rs b/crates/wit/src/token_stream_generator/record_generator.rs index 88a5b65..e4fb73a 100644 --- a/crates/wit/src/token_stream_generator/record_generator.rs +++ b/crates/wit/src/token_stream_generator/record_generator.rs @@ -40,25 +40,13 @@ impl quote::ToTokens for fce_ast_types::AstRecordItem { let serializer_fn = generate_serializer_fn(self); let deserializer_fn = generate_deserializer_fn(self); - #[cfg(feature = "fce")] - let trait_path = || { - quote::quote! { crate::FCEStructSerializable } - }; - - #[cfg(not(feature = "fce"))] - let trait_path = || { - quote::quote! { fluence::internal::FCEStructSerializable } - }; - - let trait_path = trait_path(); - let glue_code = quote::quote! { #original #[cfg(any(target_arch = "wasm32", feature = "fce"))] #[doc(hidden)] #[allow(clippy::all)] - impl #trait_path for #record_name { + impl #record_name { #serializer_fn #deserializer_fn diff --git a/src/lib.rs b/src/lib.rs index 1fe278f..22f43bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,6 +83,4 @@ pub mod internal { pub use fluence_sdk_main::get_result_size; pub use fluence_sdk_main::set_result_ptr; pub use fluence_sdk_main::set_result_size; - - pub use fluence_sdk_main::FCEStructSerializable; }