get rid of trait

This commit is contained in:
vms 2020-08-22 13:40:05 +03:00
parent b3a8f3cc31
commit f312b09fec
6 changed files with 14 additions and 37 deletions

View File

@ -49,19 +49,6 @@ pub use result::get_result_size;
pub use result::set_result_ptr; pub use result::set_result_ptr;
pub use result::set_result_size; 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<u8>, 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)] #[allow(unused_variables)]
pub(crate) fn log<S: AsRef<str>>(msg: S) { pub(crate) fn log<S: AsRef<str>>(msg: S) {
// logs will be printed only if debug feature is enabled // logs will be printed only if debug feature is enabled

View File

@ -60,8 +60,10 @@ impl ForeignModEpilogGlueCodeGenerator for Option<ParsedType> {
}, },
Some(ParsedType::Record(record_name)) => { Some(ParsedType::Record(record_name)) => {
let record_ident = new_ident!(record_name); let record_ident = new_ident!(record_name);
let crate_path = get_crate_path();
quote! { quote! {
#record_ident::__fce_generated_deserialize(fluence::internal::get_result_ptr() as _) #record_ident::__fce_generated_deserialize(#crate_path::get_result_ptr() as _)
} }
} }
_ => panic!( _ => panic!(
@ -70,3 +72,13 @@ impl ForeignModEpilogGlueCodeGenerator for Option<ParsedType> {
} }
} }
} }
#[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}
}

View File

@ -69,10 +69,6 @@ impl quote::ToTokens for fce_ast_types::AstFunctionItem {
#[doc(hidden)] #[doc(hidden)]
#[allow(clippy::all)] #[allow(clippy::all)]
pub unsafe fn #func_name(#(#raw_arg_names: #raw_arg_types),*) #fn_return_type { 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 // arguments conversation from Wasm types to Rust types
#prolog #prolog

View File

@ -121,10 +121,6 @@ fn generate_wrapper_functions(extern_item: &fce_ast_types::AstExternModItem) ->
#[doc(hidden)] #[doc(hidden)]
#[allow(clippy::all)] #[allow(clippy::all)]
#visibility fn #func_name(#(#arg_names: #arg_types), *) #return_type { #visibility fn #func_name(#(#arg_names: #arg_types), *) #return_type {
// brings serialize/deserialize methods for records
#[allow(dead_code)]
use fluence::internal::FCEStructSerializable;
unsafe { unsafe {
// calling the original function with converted args // calling the original function with converted args
#return_expression #import_func_name(#(#raw_args), *); #return_expression #import_func_name(#(#raw_args), *);

View File

@ -40,25 +40,13 @@ impl quote::ToTokens for fce_ast_types::AstRecordItem {
let serializer_fn = generate_serializer_fn(self); let serializer_fn = generate_serializer_fn(self);
let deserializer_fn = generate_deserializer_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! { let glue_code = quote::quote! {
#original #original
#[cfg(any(target_arch = "wasm32", feature = "fce"))] #[cfg(any(target_arch = "wasm32", feature = "fce"))]
#[doc(hidden)] #[doc(hidden)]
#[allow(clippy::all)] #[allow(clippy::all)]
impl #trait_path for #record_name { impl #record_name {
#serializer_fn #serializer_fn
#deserializer_fn #deserializer_fn

View File

@ -83,6 +83,4 @@ pub mod internal {
pub use fluence_sdk_main::get_result_size; pub use fluence_sdk_main::get_result_size;
pub use fluence_sdk_main::set_result_ptr; pub use fluence_sdk_main::set_result_ptr;
pub use fluence_sdk_main::set_result_size; pub use fluence_sdk_main::set_result_size;
pub use fluence_sdk_main::FCEStructSerializable;
} }