Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vigna committed Jun 3, 2024
1 parent 6295d6b commit 4fb62e3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.


Expand Down
2 changes: 1 addition & 1 deletion epserde-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "epserde-derive"
authors = ["Tommaso Fontana <[email protected]>", "Sebastiano Vigna <[email protected]>"]
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"
Expand Down
54 changes: 28 additions & 26 deletions epserde-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<proc_macro2::TokenStream>,
/// 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<String>,
/// 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<String>,
/// Used to include the identifiers of generic types into the type hash.
type_names_raw: Vec<String>,
/// A vector containing the identifiers of the generic constants.
/// Used to include the generic constant values into the type hash.
const_names_vec: Vec<syn::Ident>,
/// 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<String>,
/// The where clause.
where_clause: proc_macro2::TokenStream,
}

impl CommonDeriveInput {
Expand All @@ -51,7 +51,7 @@ impl CommonDeriveInput {
fn new(input: DeriveInput, traits_to_add: Vec<syn::Path>) -> 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!();

Expand All @@ -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() {
Expand Down Expand Up @@ -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!(,))
Expand All @@ -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,
Expand Down Expand Up @@ -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,
..
Expand Down Expand Up @@ -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 {
Expand All @@ -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));
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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,
..
Expand Down Expand Up @@ -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);
)*
Expand Down Expand Up @@ -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);
)*
Expand Down Expand Up @@ -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);
)*
Expand Down Expand Up @@ -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);
)*
Expand Down
4 changes: 2 additions & 2 deletions epserde/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4fb62e3

Please sign in to comment.