From 4fb62e3d1504490264d67ae421b8ed870f55a69e Mon Sep 17 00:00:00 2001 From: Sebastiano Vigna Date: Mon, 3 Jun 2024 14:49:31 +0200 Subject: [PATCH] Cleanup --- CHANGELOG.md | 9 ++++--- epserde-derive/Cargo.toml | 2 +- epserde-derive/src/lib.rs | 54 ++++++++++++++++++++------------------- epserde/Cargo.toml | 4 +-- 4 files changed, 37 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62fe8f9..6a6b76b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,17 @@ # Change Log -## [0.5.2] - 2024-05-30 +## [0.6.0] - 2024-06-03 ### Changed -* Updated MemDbg to 0.2.1 -* Added const generic parameters values and names to type hash. +* Updated MemDbg to 0.2.1. ### Fixed +* Added const generic parameters values and names to type hash. Note that + this change will invalidate type hashes for structures with generic + constants. + * Fixed handling of zero-sized zero-copy structs eps_deserialization. diff --git a/epserde-derive/Cargo.toml b/epserde-derive/Cargo.toml index 98d3c70..eec4b5d 100644 --- a/epserde-derive/Cargo.toml +++ b/epserde-derive/Cargo.toml @@ -2,7 +2,7 @@ name = "epserde-derive" authors = ["Tommaso Fontana ", "Sebastiano Vigna "] description = "Procedural macros for ε-serde" -version = "0.4.0" +version = "0.6.0" edition = "2021" repository = "https://github.com/vigna/epserde-rs/" license = "Apache-2.0 OR LGPL-2.1-or-later" diff --git a/epserde-derive/src/lib.rs b/epserde-derive/src/lib.rs index 688f703..8211fa8 100644 --- a/epserde-derive/src/lib.rs +++ b/epserde-derive/src/lib.rs @@ -23,25 +23,25 @@ struct CommonDeriveInput { /// The identifier of the struct. name: syn::Ident, /// The token stream to be used after `impl` in angle brackets. It contains - /// the generics, lifetimes, and consts, with their trait bounds. + /// the generic types, lifetimes, and constants, with their trait bounds. generics: proc_macro2::TokenStream, /// A vector containing the identifiers of the generics. generics_name_vec: Vec, /// Same as `generics_name_vec`, but names are concatenated - /// and separated by commans. + /// and separated by commas. generics_names: proc_macro2::TokenStream, /// A vector containing the name of generics types, represented as strings. - generics_names_raw: Vec, - /// The where clause. - where_clause: proc_macro2::TokenStream, - /// A vector containing the identifier of the constants, represented as strings. - /// Used to include the const values into the type hash. - //const_names_raw: Vec, + /// Used to include the identifiers of generic types into the type hash. + type_names_raw: Vec, /// A vector containing the identifiers of the generic constants. + /// Used to include the generic constant values into the type hash. const_names_vec: Vec, - /// A vector containing the identifier of the constants, represented as strings. - /// Used to include the const values into the type hash. + /// A vector containing the identifier of the generic constants, represented + /// as strings. Used to include the identifiers of generic constants into + /// the type hash. const_names_raw: Vec, + /// The where clause. + where_clause: proc_macro2::TokenStream, } impl CommonDeriveInput { @@ -51,7 +51,7 @@ impl CommonDeriveInput { fn new(input: DeriveInput, traits_to_add: Vec) -> Self { let name = input.ident; let mut generics = quote!(); - let mut generics_names_raw = vec![]; + let mut type_names_raw = vec![]; let mut generics_name_vec = vec![]; let mut generics_names = quote!(); @@ -63,7 +63,7 @@ impl CommonDeriveInput { match x { syn::GenericParam::Type(mut t) => { generics_names.extend(t.ident.to_token_stream()); - generics_names_raw.push(t.ident.to_string()); + type_names_raw.push(t.ident.to_string()); t.default = None; for trait_to_add in traits_to_add.iter() { @@ -92,7 +92,6 @@ impl CommonDeriveInput { generics.extend(quote!(#c,)); generics_name_vec.push(c.ident.to_token_stream()); const_names_vec.push(c.ident.clone()); - const_names_raw.push(c.ident.to_string()); } }; generics_names.extend(quote!(,)) @@ -111,7 +110,7 @@ impl CommonDeriveInput { generics, generics_names, where_clause, - generics_names_raw, + type_names_raw, generics_name_vec, const_names_raw, const_names_vec, @@ -176,7 +175,7 @@ pub fn epserde_derive(input: TokenStream) -> TokenStream { let CommonDeriveInput { name, generics_names, - generics_names_raw, + type_names_raw, generics_name_vec, generics, .. @@ -212,7 +211,7 @@ pub fn epserde_derive(input: TokenStream) -> TokenStream { .map(|x| x.to_token_stream()) .unwrap_or_else(|| syn::Index::from(field_idx).to_token_stream()); - if generics_names_raw.contains(&ty.to_token_stream().to_string()) { + if type_names_raw.contains(&ty.to_token_stream().to_string()) { generic_fields.push(field_name.clone()); generic_types.push(ty); } else { @@ -229,7 +228,7 @@ pub fn epserde_derive(input: TokenStream) -> TokenStream { s.fields.iter().for_each(|field| { let ty = &field.ty; - if generics_names_raw.contains(&ty.to_token_stream().to_string()) { + if type_names_raw.contains(&ty.to_token_stream().to_string()) { methods.push(syn::parse_quote!(_deserialize_eps_inner)); } else { methods.push(syn::parse_quote!(_deserialize_full_inner)); @@ -479,7 +478,7 @@ pub fn epserde_derive(input: TokenStream) -> TokenStream { .iter() .map(|named| (named.ident.as_ref().unwrap(), &named.ty)) .for_each(|(ident, ty)| { - if generics_names_raw.contains(&ty.to_token_stream().to_string()) { + if type_names_raw.contains(&ty.to_token_stream().to_string()) { generic_fields.push(ident.to_token_stream()); generic_types.push(ty.to_token_stream()); } else { @@ -514,7 +513,7 @@ pub fn epserde_derive(input: TokenStream) -> TokenStream { bounds: bounds_des, })); - if generics_names_raw.contains(&ty.to_token_stream().to_string()) { + if type_names_raw.contains(&ty.to_token_stream().to_string()) { methods.push(syn::parse_quote!(_deserialize_eps_inner)); } else { methods.push(syn::parse_quote!(_deserialize_full_inner)); @@ -555,7 +554,7 @@ pub fn epserde_derive(input: TokenStream) -> TokenStream { .for_each(|(field_idx, unnamed)| { let ty = &unnamed.ty; let ident = syn::Index::from(field_idx); - if generics_names_raw.contains(&ty.to_token_stream().to_string()) { + if type_names_raw.contains(&ty.to_token_stream().to_string()) { generic_fields.push(ident.to_token_stream()); generic_types.push(ty.to_token_stream()); } else { @@ -595,7 +594,7 @@ pub fn epserde_derive(input: TokenStream) -> TokenStream { bounds: bounds_des, })); - if generics_names_raw.contains(&ty.to_token_stream().to_string()) { + if type_names_raw.contains(&ty.to_token_stream().to_string()) { methods.push(syn::parse_quote!(_deserialize_eps_inner)); } else { methods.push(syn::parse_quote!(_deserialize_full_inner)); @@ -778,7 +777,6 @@ pub fn epserde_type_hash(input: TokenStream) -> TokenStream { generics: generics_typehash, generics_names, where_clause, - //generics_names_raw, const_names_vec, const_names_raw, .. @@ -847,10 +845,11 @@ pub fn epserde_type_hash(input: TokenStream) -> TokenStream { use core::hash::Hash; // Hash in ZeroCopy "ZeroCopy".hash(hasher); - // Hash the generic const values and names + // Hash the values of generic constants #( #const_names_vec.hash(hasher); )* + // Hash the identifiers of generic constants #( #const_names_raw.hash(hasher); )* @@ -917,10 +916,11 @@ pub fn epserde_type_hash(input: TokenStream) -> TokenStream { // No alignment, so we do not hash in anything. // Hash in DeepCopy "DeepCopy".hash(hasher); - // Hash the generic const values and names + // Hash the values of generic constants #( #const_names_vec.hash(hasher); )* + // Hash the identifiers of generic constants #( #const_names_raw.hash(hasher); )* @@ -1052,10 +1052,11 @@ pub fn epserde_type_hash(input: TokenStream) -> TokenStream { use core::hash::Hash; // Hash in ZeroCopy "ZeroCopy".hash(hasher); - // Hash the generic const values and names + // Hash the values of generic constants #( #const_names_vec.hash(hasher); )* + // Hash the identifiers of generic constants #( #const_names_raw.hash(hasher); )* @@ -1114,10 +1115,11 @@ pub fn epserde_type_hash(input: TokenStream) -> TokenStream { // No alignment, so we do not hash in anything. // Hash in DeepCopy "DeepCopy".hash(hasher); - // Hash the generic const values and names + // Hash the values of generic constants #( #const_names_vec.hash(hasher); )* + // Hash the identifiers of generic constants #( #const_names_raw.hash(hasher); )* diff --git a/epserde/Cargo.toml b/epserde/Cargo.toml index d744714..48417bd 100644 --- a/epserde/Cargo.toml +++ b/epserde/Cargo.toml @@ -13,8 +13,8 @@ keywords = ["serialization", "zero-copy", "mmap"] mmap-rs = { version="0.6.0", optional=true } bitflags = {version="2.4.2", default-features=false } xxhash-rust = {version="0.8.8", default-features=false, features=["xxh3"] } -epserde-derive = { version="=0.4.0", optional = true } -#epserde-derive = { path="../epserde-derive", optional = true } +#epserde-derive = { version="=0.4.0", optional = true } +epserde-derive = { path="../epserde-derive", optional = true } anyhow = "1.0.79" sealed = "0.5.0" maligned = "0.2.1"