Skip to content

Commit cca6421

Browse files
Scott Caofacebook-github-bot
Scott Cao
authored andcommitted
impl StrongHash for Hashed
Summary: Implement `StrongHash` for `Hashed<T>` if T also uses `StrongHash`. This is working up to implementing `StrongHash` for configuration data structures so we can fix hash collision in configuration hashes. Reviewed By: samkevich Differential Revision: D68197230 fbshipit-source-id: aa236b070fb20004930e631abab352bd017d8be9
1 parent d0531c0 commit cca6421

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ members = [
44
"allocative/allocative_derive",
55
"gazebo/display_container",
66
"gazebo/dupe",
7+
"gazebo/strong_hash",
8+
"gazebo/strong_hash_derive",
79
"starlark",
810
"starlark_bin",
911
"starlark_derive",
@@ -24,6 +26,8 @@ allocative_derive = { version = "0.3.3", path = "allocative/allocative_derive" }
2426
cmp_any = { version = "0.8.1", path = "gazebo/cmp_any" }
2527
display_container = { version = "0.9.0", path = "gazebo/display_container" }
2628
dupe = { version = "0.9.1", path = "gazebo/dupe" }
29+
strong_hash = { path = "gazebo/strong_hash" }
30+
strong_hash_derive = { path = "gazebo/strong_hash_derive" }
2731

2832
starlark_lsp = { version = "0.13", path = "starlark_lsp" }
2933
starlark_map = { version = "0.13", path = "starlark_map" }

starlark_map/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ equivalent = { workspace = true }
1818
fxhash = "0.2.1"
1919
hashbrown = { version = "0.14.3", features = ["raw"] }
2020
serde = { version = "1.0", features = ["derive"] }
21+
strong_hash = { workspace = true }
2122

2223
[dev-dependencies]
2324
serde_json = "1.0.48"

starlark_map/src/hashed.rs

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use std::ops::Deref;
2424
use allocative::Allocative;
2525
use dupe::Dupe;
2626
use equivalent::Equivalent;
27+
use strong_hash::StrongHash;
28+
use strong_hash::StrongHasher;
2729

2830
use crate::hash_value::StarlarkHashValue;
2931

@@ -43,6 +45,13 @@ impl<K> Hash for Hashed<K> {
4345
}
4446
}
4547

48+
impl<K: StrongHash> StrongHash for Hashed<K> {
49+
fn strong_hash<S: StrongHasher>(&self, state: &mut S) {
50+
// Only hash the key, not the (weak) hash.
51+
self.key.strong_hash(state);
52+
}
53+
}
54+
4655
impl<K> Deref for Hashed<K> {
4756
type Target = K;
4857

0 commit comments

Comments
 (0)