Skip to content

Commit 4e8aae3

Browse files
committed
Try using AHash as the default hasher (again)
This still uses std::collections::HashMap since there were a lot of issues with AHashMap. This also enables the `specialize` feature in hopes of getting better performance.
1 parent 828461b commit 4e8aae3

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed

Cargo.lock

+11-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ dependencies = [
2222
"rustc-std-workspace-core",
2323
]
2424

25+
[[package]]
26+
name = "ahash"
27+
version = "0.5.8"
28+
source = "registry+https://github.com/rust-lang/crates.io-index"
29+
checksum = "4eb6ec8807cd25b59e6b8100815afc73f54e294f1a425a2e555971969889a8f8"
30+
dependencies = [
31+
"getrandom 0.2.0",
32+
"lazy_static",
33+
]
34+
2535
[[package]]
2636
name = "aho-corasick"
2737
version = "0.7.13"
@@ -3572,6 +3582,7 @@ dependencies = [
35723582
name = "rustc_data_structures"
35733583
version = "0.0.0"
35743584
dependencies = [
3585+
"ahash",
35753586
"arrayvec",
35763587
"bitflags",
35773588
"cfg-if 0.1.10",
@@ -3582,7 +3593,6 @@ dependencies = [
35823593
"libc",
35833594
"measureme",
35843595
"parking_lot 0.11.0",
3585-
"rustc-hash",
35863596
"rustc-rayon",
35873597
"rustc-rayon-core",
35883598
"rustc_graphviz",

compiler/rustc_data_structures/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ crossbeam-utils = { version = "0.7", features = ["nightly"] }
2121
stable_deref_trait = "1.0.0"
2222
rayon = { version = "0.3.0", package = "rustc-rayon" }
2323
rayon-core = { version = "0.3.0", package = "rustc-rayon-core" }
24-
rustc-hash = "1.1.0"
24+
#rustc-hash = "1.1.0"
25+
ahash = { version = "0.5.6", features = ["specialize"] }
2526
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
2627
rustc_index = { path = "../rustc_index", package = "rustc_index" }
2728
bitflags = "1.2.1"

compiler/rustc_data_structures/src/fx.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
pub use ahash::AHasher as FxHasher;
2+
use ahash::RandomState;
3+
use std::collections::{HashMap, HashSet};
14
use std::hash::BuildHasherDefault;
25

3-
pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
6+
//pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
7+
8+
pub type FxHashMap<K, V> = HashMap<K, V, RandomState>;
9+
pub type FxHashSet<T> = HashSet<T, RandomState>;
410

511
pub type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
612
pub type FxIndexSet<V> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>>;

compiler/rustc_data_structures/src/stable_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub use rustc_hash::FxHashMap;
1+
pub use crate::fx::FxHashMap;
22
use std::borrow::Borrow;
33
use std::collections::hash_map::Entry;
44
use std::fmt;

compiler/rustc_data_structures/src/stable_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub use rustc_hash::FxHashSet;
1+
pub use crate::fx::FxHashSet;
22
use std::borrow::Borrow;
33
use std::fmt;
44
use std::hash::Hash;

src/tools/clippy/clippy_lints/src/utils/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use std::mem;
3434
use if_chain::if_chain;
3535
use rustc_ast::ast::{self, Attribute, LitKind};
3636
use rustc_attr as attr;
37-
use rustc_data_structures::fx::FxHashMap;
37+
use rustc_data_structures::fx::FxHasher;
3838
use rustc_errors::Applicability;
3939
use rustc_hir as hir;
4040
use rustc_hir::def::{DefKind, Res};
@@ -1500,8 +1500,9 @@ where
15001500

15011501
let mut match_expr_list: Vec<(&T, &T)> = Vec::new();
15021502

1503-
let mut map: FxHashMap<_, Vec<&_>> =
1504-
FxHashMap::with_capacity_and_hasher(exprs.len(), BuildHasherDefault::default());
1503+
use std::collections::HashMap;
1504+
let mut map: HashMap<_, Vec<&_>, BuildHasherDefault<FxHasher>> =
1505+
HashMap::with_capacity_and_hasher(exprs.len(), BuildHasherDefault::default());
15051506

15061507
for expr in exprs {
15071508
match map.entry(hash(expr)) {

0 commit comments

Comments
 (0)