From 4e8aae3f1698b882df03fc6722e74e1de8d5f756 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 22 Nov 2020 15:13:49 -0500 Subject: [PATCH] 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. --- Cargo.lock | 12 +++++++++++- compiler/rustc_data_structures/Cargo.toml | 3 ++- compiler/rustc_data_structures/src/fx.rs | 8 +++++++- compiler/rustc_data_structures/src/stable_map.rs | 2 +- compiler/rustc_data_structures/src/stable_set.rs | 2 +- src/tools/clippy/clippy_lints/src/utils/mod.rs | 7 ++++--- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1a0eb7d0bd411..0be9f868d0f4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,6 +22,16 @@ dependencies = [ "rustc-std-workspace-core", ] +[[package]] +name = "ahash" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb6ec8807cd25b59e6b8100815afc73f54e294f1a425a2e555971969889a8f8" +dependencies = [ + "getrandom 0.2.0", + "lazy_static", +] + [[package]] name = "aho-corasick" version = "0.7.13" @@ -3572,6 +3582,7 @@ dependencies = [ name = "rustc_data_structures" version = "0.0.0" dependencies = [ + "ahash", "arrayvec", "bitflags", "cfg-if 0.1.10", @@ -3582,7 +3593,6 @@ dependencies = [ "libc", "measureme", "parking_lot 0.11.0", - "rustc-hash", "rustc-rayon", "rustc-rayon-core", "rustc_graphviz", diff --git a/compiler/rustc_data_structures/Cargo.toml b/compiler/rustc_data_structures/Cargo.toml index 23e689fcae796..c5c413a71e40e 100644 --- a/compiler/rustc_data_structures/Cargo.toml +++ b/compiler/rustc_data_structures/Cargo.toml @@ -21,7 +21,8 @@ crossbeam-utils = { version = "0.7", features = ["nightly"] } stable_deref_trait = "1.0.0" rayon = { version = "0.3.0", package = "rustc-rayon" } rayon-core = { version = "0.3.0", package = "rustc-rayon-core" } -rustc-hash = "1.1.0" +#rustc-hash = "1.1.0" +ahash = { version = "0.5.6", features = ["specialize"] } smallvec = { version = "1.0", features = ["union", "may_dangle"] } rustc_index = { path = "../rustc_index", package = "rustc_index" } bitflags = "1.2.1" diff --git a/compiler/rustc_data_structures/src/fx.rs b/compiler/rustc_data_structures/src/fx.rs index bbeb193dba32b..b1abeab3a6a13 100644 --- a/compiler/rustc_data_structures/src/fx.rs +++ b/compiler/rustc_data_structures/src/fx.rs @@ -1,6 +1,12 @@ +pub use ahash::AHasher as FxHasher; +use ahash::RandomState; +use std::collections::{HashMap, HashSet}; use std::hash::BuildHasherDefault; -pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher}; +//pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher}; + +pub type FxHashMap = HashMap; +pub type FxHashSet = HashSet; pub type FxIndexMap = indexmap::IndexMap>; pub type FxIndexSet = indexmap::IndexSet>; diff --git a/compiler/rustc_data_structures/src/stable_map.rs b/compiler/rustc_data_structures/src/stable_map.rs index 670452d0d8c5a..4e8982e2569b2 100644 --- a/compiler/rustc_data_structures/src/stable_map.rs +++ b/compiler/rustc_data_structures/src/stable_map.rs @@ -1,4 +1,4 @@ -pub use rustc_hash::FxHashMap; +pub use crate::fx::FxHashMap; use std::borrow::Borrow; use std::collections::hash_map::Entry; use std::fmt; diff --git a/compiler/rustc_data_structures/src/stable_set.rs b/compiler/rustc_data_structures/src/stable_set.rs index c7ca74f5fbd9d..74092b0608c64 100644 --- a/compiler/rustc_data_structures/src/stable_set.rs +++ b/compiler/rustc_data_structures/src/stable_set.rs @@ -1,4 +1,4 @@ -pub use rustc_hash::FxHashSet; +pub use crate::fx::FxHashSet; use std::borrow::Borrow; use std::fmt; use std::hash::Hash; diff --git a/src/tools/clippy/clippy_lints/src/utils/mod.rs b/src/tools/clippy/clippy_lints/src/utils/mod.rs index 270fdc9bf462f..c6670ffbeb411 100644 --- a/src/tools/clippy/clippy_lints/src/utils/mod.rs +++ b/src/tools/clippy/clippy_lints/src/utils/mod.rs @@ -34,7 +34,7 @@ use std::mem; use if_chain::if_chain; use rustc_ast::ast::{self, Attribute, LitKind}; use rustc_attr as attr; -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::FxHasher; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -1500,8 +1500,9 @@ where let mut match_expr_list: Vec<(&T, &T)> = Vec::new(); - let mut map: FxHashMap<_, Vec<&_>> = - FxHashMap::with_capacity_and_hasher(exprs.len(), BuildHasherDefault::default()); + use std::collections::HashMap; + let mut map: HashMap<_, Vec<&_>, BuildHasherDefault> = + HashMap::with_capacity_and_hasher(exprs.len(), BuildHasherDefault::default()); for expr in exprs { match map.entry(hash(expr)) {