diff --git a/crates/timestamp-macro/Cargo.toml b/crates/timestamp-macro/Cargo.toml index 329e972..54fa417 100644 --- a/crates/timestamp-macro/Cargo.toml +++ b/crates/timestamp-macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fce-timestamp-macro" -version = "0.5.0" # remember to update html_root_url +version = "0.6.0" # remember to update html_root_url edition = "2018" description = "Definition of the `#[build_timestamp]` macro" repository = "https://github.com/fluencelabs/rust-sdk/crates/timestamp-macro" diff --git a/crates/wit/src/parsed_type/fn_prolog.rs b/crates/wit/src/parsed_type/fn_prolog.rs index 984b719..798f55a 100644 --- a/crates/wit/src/parsed_type/fn_prolog.rs +++ b/crates/wit/src/parsed_type/fn_prolog.rs @@ -129,20 +129,17 @@ fn generate_type_lifting_prolog( let #type_modifier #converted_arg_ident = String::from_raw_parts(#ptr as _, #size as _ , #size as _); }, ParsedType::Vector(ty, _) => { - let generated_deserializer_name = - 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, - &generated_deserializer_name, - ); + let generated_der_name = + format!("__fce_generated_vec_deserializer_{}", supplied_arg_start_id); + let generated_der_name = crate::utils::prepare_ident(generated_der_name); + let generated_der_ident = new_ident!(generated_der_name); + + let vector_deserializer = + super::vector_utils::generate_vector_deserializer(ty, &generated_der_name); quote! { #vector_deserializer - let #type_modifier #converted_arg_ident = #generated_deserializer_ident(#ptr as _, #size as _); + let #type_modifier #converted_arg_ident = #generated_der_ident(#ptr as _, #size as _); } } ParsedType::Record(record_name, _) => { diff --git a/crates/wit/src/parsed_type/foreign_mod_prolog.rs b/crates/wit/src/parsed_type/foreign_mod_prolog.rs index edf51e9..87d6a0c 100644 --- a/crates/wit/src/parsed_type/foreign_mod_prolog.rs +++ b/crates/wit/src/parsed_type/foreign_mod_prolog.rs @@ -82,15 +82,16 @@ impl ForeignModPrologGlueCodeGenerator for Vec { arg_drops.extend(quote::quote! { std::mem::ManuallyDrop::drop(&mut #arg_ident); }); }, ParsedType::Vector(ty, passing_style) => { - let generated_serializer_name = format!("__fce_generated_vec_serializer_{}", arg_name).replace("&<>", "_"); + let generated_ser_name = format!("__fce_generated_vec_serializer_{}", arg_name); + let generated_ser_name = crate::utils::prepare_ident(generated_ser_name); + let generated_ser_ident = new_ident!(generated_ser_name); - let generated_serializer_ident = new_ident!(generated_serializer_name); - let vector_serializer = super::vector_utils::generate_vector_serializer(ty, *passing_style, &generated_serializer_name); + let vector_serializer = super::vector_utils::generate_vector_serializer(ty, *passing_style, &generated_ser_name); let arg_transform = quote::quote! { #vector_serializer - let #arg_ident = #generated_serializer_ident(&#arg_ident); + let #arg_ident = #generated_ser_ident(&#arg_ident); }; arg_transforms.extend(arg_transform); diff --git a/crates/wit/src/parsed_type/vector_utils.rs b/crates/wit/src/parsed_type/vector_utils.rs index 8fa495a..4263022 100644 --- a/crates/wit/src/parsed_type/vector_utils.rs +++ b/crates/wit/src/parsed_type/vector_utils.rs @@ -95,13 +95,12 @@ pub(crate) fn generate_vector_serializer( } } ParsedType::Vector(ty, passing_style) => { - let serializer_name = format!("{}_{}", arg_name, ty) - .replace("<", "_") - .replace(">", "_") - .replace("&", "_"); + let serializer_name = format!("{}_{}", arg_name, ty); + let serializer_name = crate::utils::prepare_ident(serializer_name); + let serializer_ident = crate::new_ident!(serializer_name); + let inner_vector_serializer = generate_vector_serializer(&*ty, *passing_style, &serializer_name); - let serializer_ident = crate::new_ident!(serializer_name); quote! { #inner_vector_serializer @@ -198,13 +197,12 @@ pub(crate) fn generate_vector_deserializer( } } ParsedType::Vector(ty, _) => { - let deserializer_name = format!("{}_{}", arg_name, ty) - .replace("&", "_") - .replace("<", "_") - .replace(">", "_"); - let inner_vector_deserializer = generate_vector_deserializer(&*ty, &deserializer_name); + let deserializer_name = format!("{}_{}", arg_name, ty); + let deserializer_name = crate::utils::prepare_ident(deserializer_name); let deserializer_ident = crate::new_ident!(deserializer_name); + let inner_vector_deserializer = generate_vector_deserializer(&*ty, &deserializer_name); + quote! { #inner_vector_deserializer 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 9953a9a..3df4112 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,11 +105,11 @@ impl RecordDeserializerGlueCodeGenerator for fce_ast_types::AstRecordItem { } ParsedType::Vector(ty, _) => { let generated_deserializer_name = - format!("__fce_generated_vec_deserializer_{}", value_id) - .replace("&", "_") - .replace("<", "_") - .replace(">", "_"); + format!("__fce_generated_vec_deserializer_{}", value_id); + let generated_deserializer_name = + crate::utils::prepare_ident(generated_deserializer_name); let generated_deserializer_ident = new_ident!(generated_deserializer_name); + let vector_deserializer = crate::parsed_type::generate_vector_deserializer( ty, &generated_deserializer_name, diff --git a/crates/wit/src/utils.rs b/crates/wit/src/utils.rs index 0d7a862..f936385 100644 --- a/crates/wit/src/utils.rs +++ b/crates/wit/src/utils.rs @@ -71,3 +71,14 @@ pub fn get_record_size<'a>( size } + +pub(crate) fn prepare_ident(str: String) -> String { + str.chars() + .map(|c| match c { + '<' => '_', + '&' => '_', + '>' => '_', + c => c, + }) + .collect() +}