Skip to content

Commit 060e5a2

Browse files
committed
Code review
1 parent f015e14 commit 060e5a2

4 files changed

Lines changed: 14 additions & 17 deletions

File tree

node-graph/graph-craft/src/document/value.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,8 @@ impl Hash for RenderOutputType {
523523
}
524524
}
525525

526+
// Metadata is excluded because it's editor-side auxiliary data (click targets, transforms)
527+
// that shouldn't affect render cache invalidation, and it contains HashMaps with non-deterministic iteration order
526528
impl CacheHash for RenderOutput {
527529
fn cache_hash<H: core::hash::Hasher>(&self, state: &mut H) {
528530
self.data.cache_hash(state);

node-graph/libraries/graphene-hash/derive/src/lib.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,13 @@ use syn::{Data, DeriveInput, Fields, parse_macro_input};
2626
pub fn derive_cache_hash(input: TokenStream) -> TokenStream {
2727
let ast = parse_macro_input!(input as DeriveInput);
2828
let name = &ast.ident;
29-
let (impl_generics, ty_generics, where_clause) = ast.generics.split_for_impl();
30-
31-
// Build additional `T: CacheHash` bounds for each type parameter.
32-
let extra_bounds = ast.generics.type_params().map(|tp| {
33-
let ident = &tp.ident;
34-
quote! { #ident: graphene_hash::CacheHash }
35-
});
36-
let where_clause = if ast.generics.type_params().count() > 0 {
37-
let existing = where_clause.map(|w| quote! { #w }).unwrap_or_default();
38-
quote! {
39-
#existing
40-
where #(#extra_bounds,)*
29+
let mut generics = ast.generics.clone();
30+
for param in &mut generics.params {
31+
if let syn::GenericParam::Type(type_param) = param {
32+
type_param.bounds.push(syn::parse_quote!(graphene_hash::CacheHash));
4133
}
42-
} else {
43-
where_clause.map(|w| quote! { #w }).unwrap_or_default()
44-
};
34+
}
35+
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
4536

4637
let body = match &ast.data {
4738
Data::Struct(s) => hash_fields(&s.fields, quote! { self }),
@@ -89,7 +80,7 @@ pub fn derive_cache_hash(input: TokenStream) -> TokenStream {
8980
}
9081
}
9182
}
92-
Data::Union(_) => panic!("CacheHash cannot be derived for unions"),
83+
Data::Union(_) => return syn::Error::new(ast.ident.span(), "CacheHash cannot be derived for unions").to_compile_error().into(),
9384
};
9485

9586
quote! {

node-graph/libraries/raster-types/src/image.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ impl<P: Pixel + PartialEq> PartialEq for Image<P> {
6464
pub struct TransformImage(pub DAffine2);
6565

6666
impl core_types::CacheHash for TransformImage {
67-
fn cache_hash<H: ::core::hash::Hasher>(&self, _: &mut H) {}
67+
fn cache_hash<H: ::core::hash::Hasher>(&self, state: &mut H) {
68+
core_types::CacheHash::cache_hash(&self.0, state);
69+
}
6870
}
6971

7072
impl<P: Pixel + std::fmt::Debug> std::fmt::Debug for Image<P> {

node-graph/libraries/vector-types/src/vector/vector_modification.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,8 @@ impl Hash for VectorModification {
517517
}
518518
}
519519

520+
// Intentionally non-deterministic: fields contain HashMaps with non-deterministic iteration order,
521+
// so we use a UUID to always bust the cache and force re-evaluation when any modification is present
520522
impl graphene_hash::CacheHash for VectorModification {
521523
fn cache_hash<H: core::hash::Hasher>(&self, state: &mut H) {
522524
core::hash::Hash::hash(&generate_uuid(), state);

0 commit comments

Comments
 (0)