Skip to content

Commit 9e161f5

Browse files
committed
Fix some remaining hash violations
1 parent 065c2cf commit 9e161f5

4 files changed

Lines changed: 23 additions & 30 deletions

File tree

editor/src/messages/portfolio/document/utility_types/network_interface/memo_network.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use graph_craft::document::NodeNetwork;
22
use std::cell::Cell;
3-
use std::hash::{Hash, Hasher};
43

54
#[derive(Debug, Default, Clone, PartialEq)]
65
pub struct MemoNetwork {
@@ -26,9 +25,9 @@ impl serde::Serialize for MemoNetwork {
2625
}
2726
}
2827

29-
impl Hash for MemoNetwork {
30-
fn hash<H: Hasher>(&self, state: &mut H) {
31-
self.current_hash().hash(state);
28+
impl core_types::CacheHash for MemoNetwork {
29+
fn cache_hash<H: ::core::hash::Hasher>(&self, state: &mut H) {
30+
self.current_hash().cache_hash(state);
3231
}
3332
}
3433

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -546,29 +546,34 @@ pub struct NodeNetwork {
546546
pub generated: bool,
547547
}
548548

549-
impl Hash for NodeNetwork {
550-
fn hash<H: Hasher>(&self, state: &mut H) {
551-
self.exports.hash(state);
549+
impl core_types::CacheHash for NodeNetwork {
550+
fn cache_hash<H: ::core::hash::Hasher>(&self, state: &mut H) {
551+
use core_types::CacheHash;
552+
self.exports.cache_hash(state);
552553
let mut nodes: Vec<_> = self.nodes.iter().collect();
553554
nodes.sort_by_key(|(id, _)| *id);
554555
for (id, node) in nodes {
555-
id.hash(state);
556-
node.hash(state);
556+
id.cache_hash(state);
557+
node.cache_hash(state);
557558
}
558559
}
559560
}
560561

561562
impl PartialEq for NodeNetwork {
562563
fn eq(&self, other: &Self) -> bool {
563-
self.exports == other.exports
564+
self.exports == other.exports && self.nodes == other.nodes && self.scope_injections == other.scope_injections
564565
}
565566
}
566567

567568
/// Graph modification functions
568569
impl NodeNetwork {
569570
pub fn current_hash(&self) -> u64 {
570-
use std::hash::BuildHasher;
571-
FxBuildHasher.hash_one(self)
571+
use core_types::graphene_hash::CacheHash;
572+
use rustc_hash::FxHasher;
573+
use std::hash::Hasher;
574+
let mut hasher = FxHasher::default();
575+
self.cache_hash(&mut hasher);
576+
hasher.finish()
572577
}
573578

574579
pub fn value_network(node: DocumentNode) -> Self {

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -517,22 +517,10 @@ impl CacheHash for RenderOutputType {
517517
}
518518
}
519519

520-
impl Hash for RenderOutputType {
521-
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
522-
CacheHash::cache_hash(self, state);
523-
}
524-
}
525-
526520
// Metadata is excluded because it's editor-side auxiliary data (click targets, transforms)
527521
// that shouldn't affect render cache invalidation, and it contains HashMaps with non-deterministic iteration order
528522
impl CacheHash for RenderOutput {
529523
fn cache_hash<H: core::hash::Hasher>(&self, state: &mut H) {
530524
self.data.cache_hash(state);
531525
}
532526
}
533-
534-
impl Hash for RenderOutput {
535-
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
536-
CacheHash::cache_hash(self, state);
537-
}
538-
}

node-graph/nodes/gcore/src/context_modification.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ async fn context_modification<T>(
5151
#[cfg(test)]
5252
mod tests {
5353
use super::*;
54+
use core_types::graphene_hash::CacheHash;
5455
use core_types::transform::Footprint;
5556
use std::collections::hash_map::DefaultHasher;
56-
use std::hash::{Hash, Hasher};
57+
use std::hash::Hasher;
5758

5859
/// Test that the hash of a nullified context remains stable even when nullified inputs change
5960
#[test]
@@ -77,9 +78,9 @@ mod tests {
7778
// Create nullified context - this should only keep features specified in features_to_keep
7879
let nullified_ctx = OwnedContextImpl::from_flags(original_ctx.clone().unwrap(), features_to_keep);
7980

80-
// Calculate hash of nullified context
81+
// Calculate cache hash of nullified context
8182
let mut hasher1 = DefaultHasher::new();
82-
nullified_ctx.hash(&mut hasher1);
83+
nullified_ctx.cache_hash(&mut hasher1);
8384
let hash1 = hasher1.finish();
8485

8586
// Create a different original context with changed values
@@ -96,7 +97,7 @@ mod tests {
9697
let nullified_changed_ctx = OwnedContextImpl::from_flags(changed_ctx.clone().unwrap(), features_to_keep);
9798

9899
let mut hasher2 = DefaultHasher::new();
99-
nullified_changed_ctx.hash(&mut hasher2);
100+
nullified_changed_ctx.cache_hash(&mut hasher2);
100101
let hash2 = hasher2.finish();
101102

102103
// Hash should be the same because all features were nullified
@@ -109,11 +110,11 @@ mod tests {
109110
let partial_nullified2 = OwnedContextImpl::from_flags(changed_ctx.clone().unwrap(), partial_features);
110111

111112
let mut hasher3 = DefaultHasher::new();
112-
partial_nullified1.hash(&mut hasher3);
113+
partial_nullified1.cache_hash(&mut hasher3);
113114
let hash3 = hasher3.finish();
114115

115116
let mut hasher4 = DefaultHasher::new();
116-
partial_nullified2.hash(&mut hasher4);
117+
partial_nullified2.cache_hash(&mut hasher4);
117118
let hash4 = hasher4.finish();
118119

119120
// These should be the same because both have the same footprint (Footprint::default()) and varargs

0 commit comments

Comments
 (0)