Skip to content

Commit 4fb62e3

Browse files
committed
Cleanup
1 parent 6295d6b commit 4fb62e3

File tree

4 files changed

+37
-32
lines changed

4 files changed

+37
-32
lines changed

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# Change Log
22

3-
## [0.5.2] - 2024-05-30
3+
## [0.6.0] - 2024-06-03
44

55
### Changed
66

7-
* Updated MemDbg to 0.2.1
8-
* Added const generic parameters values and names to type hash.
7+
* Updated MemDbg to 0.2.1.
98

109
### Fixed
1110

11+
* Added const generic parameters values and names to type hash. Note that
12+
this change will invalidate type hashes for structures with generic
13+
constants.
14+
1215
* Fixed handling of zero-sized zero-copy structs eps_deserialization.
1316

1417

epserde-derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "epserde-derive"
33
authors = ["Tommaso Fontana <tommaso.fontana.96@gmail.com>", "Sebastiano Vigna <sebastiano.vigna@unimi.it>"]
44
description = "Procedural macros for ε-serde"
5-
version = "0.4.0"
5+
version = "0.6.0"
66
edition = "2021"
77
repository = "https://github.com/vigna/epserde-rs/"
88
license = "Apache-2.0 OR LGPL-2.1-or-later"

epserde-derive/src/lib.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ struct CommonDeriveInput {
2323
/// The identifier of the struct.
2424
name: syn::Ident,
2525
/// The token stream to be used after `impl` in angle brackets. It contains
26-
/// the generics, lifetimes, and consts, with their trait bounds.
26+
/// the generic types, lifetimes, and constants, with their trait bounds.
2727
generics: proc_macro2::TokenStream,
2828
/// A vector containing the identifiers of the generics.
2929
generics_name_vec: Vec<proc_macro2::TokenStream>,
3030
/// Same as `generics_name_vec`, but names are concatenated
31-
/// and separated by commans.
31+
/// and separated by commas.
3232
generics_names: proc_macro2::TokenStream,
3333
/// A vector containing the name of generics types, represented as strings.
34-
generics_names_raw: Vec<String>,
35-
/// The where clause.
36-
where_clause: proc_macro2::TokenStream,
37-
/// A vector containing the identifier of the constants, represented as strings.
38-
/// Used to include the const values into the type hash.
39-
//const_names_raw: Vec<String>,
34+
/// Used to include the identifiers of generic types into the type hash.
35+
type_names_raw: Vec<String>,
4036
/// A vector containing the identifiers of the generic constants.
37+
/// Used to include the generic constant values into the type hash.
4138
const_names_vec: Vec<syn::Ident>,
42-
/// A vector containing the identifier of the constants, represented as strings.
43-
/// Used to include the const values into the type hash.
39+
/// A vector containing the identifier of the generic constants, represented
40+
/// as strings. Used to include the identifiers of generic constants into
41+
/// the type hash.
4442
const_names_raw: Vec<String>,
43+
/// The where clause.
44+
where_clause: proc_macro2::TokenStream,
4545
}
4646

4747
impl CommonDeriveInput {
@@ -51,7 +51,7 @@ impl CommonDeriveInput {
5151
fn new(input: DeriveInput, traits_to_add: Vec<syn::Path>) -> Self {
5252
let name = input.ident;
5353
let mut generics = quote!();
54-
let mut generics_names_raw = vec![];
54+
let mut type_names_raw = vec![];
5555
let mut generics_name_vec = vec![];
5656
let mut generics_names = quote!();
5757

@@ -63,7 +63,7 @@ impl CommonDeriveInput {
6363
match x {
6464
syn::GenericParam::Type(mut t) => {
6565
generics_names.extend(t.ident.to_token_stream());
66-
generics_names_raw.push(t.ident.to_string());
66+
type_names_raw.push(t.ident.to_string());
6767

6868
t.default = None;
6969
for trait_to_add in traits_to_add.iter() {
@@ -92,7 +92,6 @@ impl CommonDeriveInput {
9292
generics.extend(quote!(#c,));
9393
generics_name_vec.push(c.ident.to_token_stream());
9494
const_names_vec.push(c.ident.clone());
95-
const_names_raw.push(c.ident.to_string());
9695
}
9796
};
9897
generics_names.extend(quote!(,))
@@ -111,7 +110,7 @@ impl CommonDeriveInput {
111110
generics,
112111
generics_names,
113112
where_clause,
114-
generics_names_raw,
113+
type_names_raw,
115114
generics_name_vec,
116115
const_names_raw,
117116
const_names_vec,
@@ -176,7 +175,7 @@ pub fn epserde_derive(input: TokenStream) -> TokenStream {
176175
let CommonDeriveInput {
177176
name,
178177
generics_names,
179-
generics_names_raw,
178+
type_names_raw,
180179
generics_name_vec,
181180
generics,
182181
..
@@ -212,7 +211,7 @@ pub fn epserde_derive(input: TokenStream) -> TokenStream {
212211
.map(|x| x.to_token_stream())
213212
.unwrap_or_else(|| syn::Index::from(field_idx).to_token_stream());
214213

215-
if generics_names_raw.contains(&ty.to_token_stream().to_string()) {
214+
if type_names_raw.contains(&ty.to_token_stream().to_string()) {
216215
generic_fields.push(field_name.clone());
217216
generic_types.push(ty);
218217
} else {
@@ -229,7 +228,7 @@ pub fn epserde_derive(input: TokenStream) -> TokenStream {
229228

230229
s.fields.iter().for_each(|field| {
231230
let ty = &field.ty;
232-
if generics_names_raw.contains(&ty.to_token_stream().to_string()) {
231+
if type_names_raw.contains(&ty.to_token_stream().to_string()) {
233232
methods.push(syn::parse_quote!(_deserialize_eps_inner));
234233
} else {
235234
methods.push(syn::parse_quote!(_deserialize_full_inner));
@@ -479,7 +478,7 @@ pub fn epserde_derive(input: TokenStream) -> TokenStream {
479478
.iter()
480479
.map(|named| (named.ident.as_ref().unwrap(), &named.ty))
481480
.for_each(|(ident, ty)| {
482-
if generics_names_raw.contains(&ty.to_token_stream().to_string()) {
481+
if type_names_raw.contains(&ty.to_token_stream().to_string()) {
483482
generic_fields.push(ident.to_token_stream());
484483
generic_types.push(ty.to_token_stream());
485484
} else {
@@ -514,7 +513,7 @@ pub fn epserde_derive(input: TokenStream) -> TokenStream {
514513
bounds: bounds_des,
515514
}));
516515

517-
if generics_names_raw.contains(&ty.to_token_stream().to_string()) {
516+
if type_names_raw.contains(&ty.to_token_stream().to_string()) {
518517
methods.push(syn::parse_quote!(_deserialize_eps_inner));
519518
} else {
520519
methods.push(syn::parse_quote!(_deserialize_full_inner));
@@ -555,7 +554,7 @@ pub fn epserde_derive(input: TokenStream) -> TokenStream {
555554
.for_each(|(field_idx, unnamed)| {
556555
let ty = &unnamed.ty;
557556
let ident = syn::Index::from(field_idx);
558-
if generics_names_raw.contains(&ty.to_token_stream().to_string()) {
557+
if type_names_raw.contains(&ty.to_token_stream().to_string()) {
559558
generic_fields.push(ident.to_token_stream());
560559
generic_types.push(ty.to_token_stream());
561560
} else {
@@ -595,7 +594,7 @@ pub fn epserde_derive(input: TokenStream) -> TokenStream {
595594
bounds: bounds_des,
596595
}));
597596

598-
if generics_names_raw.contains(&ty.to_token_stream().to_string()) {
597+
if type_names_raw.contains(&ty.to_token_stream().to_string()) {
599598
methods.push(syn::parse_quote!(_deserialize_eps_inner));
600599
} else {
601600
methods.push(syn::parse_quote!(_deserialize_full_inner));
@@ -778,7 +777,6 @@ pub fn epserde_type_hash(input: TokenStream) -> TokenStream {
778777
generics: generics_typehash,
779778
generics_names,
780779
where_clause,
781-
//generics_names_raw,
782780
const_names_vec,
783781
const_names_raw,
784782
..
@@ -847,10 +845,11 @@ pub fn epserde_type_hash(input: TokenStream) -> TokenStream {
847845
use core::hash::Hash;
848846
// Hash in ZeroCopy
849847
"ZeroCopy".hash(hasher);
850-
// Hash the generic const values and names
848+
// Hash the values of generic constants
851849
#(
852850
#const_names_vec.hash(hasher);
853851
)*
852+
// Hash the identifiers of generic constants
854853
#(
855854
#const_names_raw.hash(hasher);
856855
)*
@@ -917,10 +916,11 @@ pub fn epserde_type_hash(input: TokenStream) -> TokenStream {
917916
// No alignment, so we do not hash in anything.
918917
// Hash in DeepCopy
919918
"DeepCopy".hash(hasher);
920-
// Hash the generic const values and names
919+
// Hash the values of generic constants
921920
#(
922921
#const_names_vec.hash(hasher);
923922
)*
923+
// Hash the identifiers of generic constants
924924
#(
925925
#const_names_raw.hash(hasher);
926926
)*
@@ -1052,10 +1052,11 @@ pub fn epserde_type_hash(input: TokenStream) -> TokenStream {
10521052
use core::hash::Hash;
10531053
// Hash in ZeroCopy
10541054
"ZeroCopy".hash(hasher);
1055-
// Hash the generic const values and names
1055+
// Hash the values of generic constants
10561056
#(
10571057
#const_names_vec.hash(hasher);
10581058
)*
1059+
// Hash the identifiers of generic constants
10591060
#(
10601061
#const_names_raw.hash(hasher);
10611062
)*
@@ -1114,10 +1115,11 @@ pub fn epserde_type_hash(input: TokenStream) -> TokenStream {
11141115
// No alignment, so we do not hash in anything.
11151116
// Hash in DeepCopy
11161117
"DeepCopy".hash(hasher);
1117-
// Hash the generic const values and names
1118+
// Hash the values of generic constants
11181119
#(
11191120
#const_names_vec.hash(hasher);
11201121
)*
1122+
// Hash the identifiers of generic constants
11211123
#(
11221124
#const_names_raw.hash(hasher);
11231125
)*

epserde/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ keywords = ["serialization", "zero-copy", "mmap"]
1313
mmap-rs = { version="0.6.0", optional=true }
1414
bitflags = {version="2.4.2", default-features=false }
1515
xxhash-rust = {version="0.8.8", default-features=false, features=["xxh3"] }
16-
epserde-derive = { version="=0.4.0", optional = true }
17-
#epserde-derive = { path="../epserde-derive", optional = true }
16+
#epserde-derive = { version="=0.4.0", optional = true }
17+
epserde-derive = { path="../epserde-derive", optional = true }
1818
anyhow = "1.0.79"
1919
sealed = "0.5.0"
2020
maligned = "0.2.1"

0 commit comments

Comments
 (0)