Skip to content

Commit 00e48af

Browse files
committed
Replace FnvHasher use with FxHasher.
This speeds up compilation by 3--6% across most of rustc-benchmarks.
1 parent eca1cc9 commit 00e48af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+588
-588
lines changed

src/librustc/dep_graph/dep_tracking_map.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use hir::def_id::DefId;
12-
use rustc_data_structures::fnv::FnvHashMap;
12+
use rustc_data_structures::fx::FxHashMap;
1313
use std::cell::RefCell;
1414
use std::ops::Index;
1515
use std::hash::Hash;
@@ -24,7 +24,7 @@ use super::{DepNode, DepGraph};
2424
pub struct DepTrackingMap<M: DepTrackingMapConfig> {
2525
phantom: PhantomData<M>,
2626
graph: DepGraph,
27-
map: FnvHashMap<M::Key, M::Value>,
27+
map: FxHashMap<M::Key, M::Value>,
2828
}
2929

3030
pub trait DepTrackingMapConfig {
@@ -38,7 +38,7 @@ impl<M: DepTrackingMapConfig> DepTrackingMap<M> {
3838
DepTrackingMap {
3939
phantom: PhantomData,
4040
graph: graph,
41-
map: FnvHashMap()
41+
map: FxHashMap()
4242
}
4343
}
4444

src/librustc/dep_graph/edges.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use rustc_data_structures::fnv::{FnvHashMap, FnvHashSet};
11+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1212
use std::fmt::Debug;
1313
use std::hash::Hash;
1414
use super::{DepGraphQuery, DepNode};
1515

1616
pub struct DepGraphEdges<D: Clone + Debug + Eq + Hash> {
1717
nodes: Vec<DepNode<D>>,
18-
indices: FnvHashMap<DepNode<D>, IdIndex>,
19-
edges: FnvHashSet<(IdIndex, IdIndex)>,
18+
indices: FxHashMap<DepNode<D>, IdIndex>,
19+
edges: FxHashSet<(IdIndex, IdIndex)>,
2020
open_nodes: Vec<OpenNode>,
2121
}
2222

@@ -46,8 +46,8 @@ impl<D: Clone + Debug + Eq + Hash> DepGraphEdges<D> {
4646
pub fn new() -> DepGraphEdges<D> {
4747
DepGraphEdges {
4848
nodes: vec![],
49-
indices: FnvHashMap(),
50-
edges: FnvHashSet(),
49+
indices: FxHashMap(),
50+
edges: FxHashSet(),
5151
open_nodes: Vec::new()
5252
}
5353
}

src/librustc/dep_graph/graph.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use hir::def_id::DefId;
12-
use rustc_data_structures::fnv::FnvHashMap;
12+
use rustc_data_structures::fx::FxHashMap;
1313
use session::config::OutputType;
1414
use std::cell::{Ref, RefCell};
1515
use std::rc::Rc;
@@ -34,19 +34,19 @@ struct DepGraphData {
3434
/// things available to us. If we find that they are not dirty, we
3535
/// load the path to the file storing those work-products here into
3636
/// this map. We can later look for and extract that data.
37-
previous_work_products: RefCell<FnvHashMap<Arc<WorkProductId>, WorkProduct>>,
37+
previous_work_products: RefCell<FxHashMap<Arc<WorkProductId>, WorkProduct>>,
3838

3939
/// Work-products that we generate in this run.
40-
work_products: RefCell<FnvHashMap<Arc<WorkProductId>, WorkProduct>>,
40+
work_products: RefCell<FxHashMap<Arc<WorkProductId>, WorkProduct>>,
4141
}
4242

4343
impl DepGraph {
4444
pub fn new(enabled: bool) -> DepGraph {
4545
DepGraph {
4646
data: Rc::new(DepGraphData {
4747
thread: DepGraphThreadData::new(enabled),
48-
previous_work_products: RefCell::new(FnvHashMap()),
49-
work_products: RefCell::new(FnvHashMap()),
48+
previous_work_products: RefCell::new(FxHashMap()),
49+
work_products: RefCell::new(FxHashMap()),
5050
})
5151
}
5252
}
@@ -117,7 +117,7 @@ impl DepGraph {
117117

118118
/// Access the map of work-products created during this run. Only
119119
/// used during saving of the dep-graph.
120-
pub fn work_products(&self) -> Ref<FnvHashMap<Arc<WorkProductId>, WorkProduct>> {
120+
pub fn work_products(&self) -> Ref<FxHashMap<Arc<WorkProductId>, WorkProduct>> {
121121
self.data.work_products.borrow()
122122
}
123123
}

src/librustc/dep_graph/query.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use rustc_data_structures::fnv::FnvHashMap;
11+
use rustc_data_structures::fx::FxHashMap;
1212
use rustc_data_structures::graph::{Direction, INCOMING, Graph, NodeIndex, OUTGOING};
1313
use std::fmt::Debug;
1414
use std::hash::Hash;
@@ -17,15 +17,15 @@ use super::DepNode;
1717

1818
pub struct DepGraphQuery<D: Clone + Debug + Hash + Eq> {
1919
pub graph: Graph<DepNode<D>, ()>,
20-
pub indices: FnvHashMap<DepNode<D>, NodeIndex>,
20+
pub indices: FxHashMap<DepNode<D>, NodeIndex>,
2121
}
2222

2323
impl<D: Clone + Debug + Hash + Eq> DepGraphQuery<D> {
2424
pub fn new(nodes: &[DepNode<D>],
2525
edges: &[(DepNode<D>, DepNode<D>)])
2626
-> DepGraphQuery<D> {
2727
let mut graph = Graph::new();
28-
let mut indices = FnvHashMap();
28+
let mut indices = FxHashMap();
2929
for node in nodes {
3030
indices.insert(node.clone(), graph.next_node_index());
3131
graph.add_node(node.clone());

src/librustc/hir/map/definitions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
12-
use rustc_data_structures::fnv::FnvHashMap;
12+
use rustc_data_structures::fx::FxHashMap;
1313
use std::fmt::Write;
1414
use std::hash::{Hash, Hasher};
1515
use std::collections::hash_map::DefaultHasher;
@@ -22,7 +22,7 @@ use util::nodemap::NodeMap;
2222
#[derive(Clone)]
2323
pub struct Definitions {
2424
data: Vec<DefData>,
25-
key_map: FnvHashMap<DefKey, DefIndex>,
25+
key_map: FxHashMap<DefKey, DefIndex>,
2626
node_map: NodeMap<DefIndex>,
2727
}
2828

@@ -219,7 +219,7 @@ impl Definitions {
219219
pub fn new() -> Definitions {
220220
Definitions {
221221
data: vec![],
222-
key_map: FnvHashMap(),
222+
key_map: FxHashMap(),
223223
node_map: NodeMap(),
224224
}
225225
}

src/librustc/hir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub use self::PathParameters::*;
3333

3434
use hir::def::Def;
3535
use hir::def_id::DefId;
36-
use util::nodemap::{NodeMap, FnvHashSet};
36+
use util::nodemap::{NodeMap, FxHashSet};
3737

3838
use syntax_pos::{mk_sp, Span, ExpnId, DUMMY_SP};
3939
use syntax::codemap::{self, respan, Spanned};
@@ -1605,4 +1605,4 @@ pub type TraitMap = NodeMap<Vec<TraitCandidate>>;
16051605

16061606
// Map from the NodeId of a glob import to a list of items which are actually
16071607
// imported.
1608-
pub type GlobMap = NodeMap<FnvHashSet<Name>>;
1608+
pub type GlobMap = NodeMap<FxHashSet<Name>>;

src/librustc/infer/freshen.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
3333
use ty::{self, Ty, TyCtxt, TypeFoldable};
3434
use ty::fold::TypeFolder;
35-
use util::nodemap::FnvHashMap;
35+
use util::nodemap::FxHashMap;
3636
use std::collections::hash_map::Entry;
3737

3838
use super::InferCtxt;
@@ -41,7 +41,7 @@ use super::unify_key::ToType;
4141
pub struct TypeFreshener<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
4242
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
4343
freshen_count: u32,
44-
freshen_map: FnvHashMap<ty::InferTy, Ty<'tcx>>,
44+
freshen_map: FxHashMap<ty::InferTy, Ty<'tcx>>,
4545
}
4646

4747
impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
@@ -50,7 +50,7 @@ impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
5050
TypeFreshener {
5151
infcx: infcx,
5252
freshen_count: 0,
53-
freshen_map: FnvHashMap(),
53+
freshen_map: FxHashMap(),
5454
}
5555
}
5656

src/librustc/infer/higher_ranked/mod.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use ty::{self, TyCtxt, Binder, TypeFoldable};
2424
use ty::error::TypeError;
2525
use ty::relate::{Relate, RelateResult, TypeRelation};
2626
use syntax_pos::Span;
27-
use util::nodemap::{FnvHashMap, FnvHashSet};
27+
use util::nodemap::{FxHashMap, FxHashSet};
2828

2929
pub struct HrMatchResult<U> {
3030
pub value: U,
@@ -135,7 +135,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
135135
// Map each skolemized region to a vector of other regions that it
136136
// must be equated with. (Note that this vector may include other
137137
// skolemized regions from `skol_map`.)
138-
let skol_resolution_map: FnvHashMap<_, _> =
138+
let skol_resolution_map: FxHashMap<_, _> =
139139
skol_map
140140
.iter()
141141
.map(|(&br, &skol)| {
@@ -158,7 +158,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
158158
// `skol_map`. There should always be a representative if things
159159
// are properly well-formed.
160160
let mut unconstrained_regions = vec![];
161-
let skol_representatives: FnvHashMap<_, _> =
161+
let skol_representatives: FxHashMap<_, _> =
162162
skol_resolution_map
163163
.iter()
164164
.map(|(&skol, &(br, ref regions))| {
@@ -268,7 +268,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
268268
snapshot: &CombinedSnapshot,
269269
debruijn: ty::DebruijnIndex,
270270
new_vars: &[ty::RegionVid],
271-
a_map: &FnvHashMap<ty::BoundRegion, &'tcx ty::Region>,
271+
a_map: &FxHashMap<ty::BoundRegion, &'tcx ty::Region>,
272272
r0: &'tcx ty::Region)
273273
-> &'tcx ty::Region {
274274
// Regions that pre-dated the LUB computation stay as they are.
@@ -364,8 +364,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
364364
snapshot: &CombinedSnapshot,
365365
debruijn: ty::DebruijnIndex,
366366
new_vars: &[ty::RegionVid],
367-
a_map: &FnvHashMap<ty::BoundRegion,
368-
&'tcx ty::Region>,
367+
a_map: &FxHashMap<ty::BoundRegion, &'tcx ty::Region>,
369368
a_vars: &[ty::RegionVid],
370369
b_vars: &[ty::RegionVid],
371370
r0: &'tcx ty::Region)
@@ -434,7 +433,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
434433

435434
fn rev_lookup<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
436435
span: Span,
437-
a_map: &FnvHashMap<ty::BoundRegion, &'tcx ty::Region>,
436+
a_map: &FxHashMap<ty::BoundRegion, &'tcx ty::Region>,
438437
r: &'tcx ty::Region) -> &'tcx ty::Region
439438
{
440439
for (a_br, a_r) in a_map {
@@ -457,7 +456,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
457456
}
458457

459458
fn var_ids<'a, 'gcx, 'tcx>(fields: &CombineFields<'a, 'gcx, 'tcx>,
460-
map: &FnvHashMap<ty::BoundRegion, &'tcx ty::Region>)
459+
map: &FxHashMap<ty::BoundRegion, &'tcx ty::Region>)
461460
-> Vec<ty::RegionVid> {
462461
map.iter()
463462
.map(|(_, &r)| match *r {
@@ -504,7 +503,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
504503
snapshot: &CombinedSnapshot,
505504
r: &'tcx ty::Region,
506505
directions: TaintDirections)
507-
-> FnvHashSet<&'tcx ty::Region> {
506+
-> FxHashSet<&'tcx ty::Region> {
508507
self.region_vars.tainted(&snapshot.region_vars_snapshot, r, directions)
509508
}
510509

@@ -568,7 +567,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
568567
let escaping_types =
569568
self.type_variables.borrow_mut().types_escaping_snapshot(&snapshot.type_snapshot);
570569

571-
let mut escaping_region_vars = FnvHashSet();
570+
let mut escaping_region_vars = FxHashSet();
572571
for ty in &escaping_types {
573572
self.tcx.collect_regions(ty, &mut escaping_region_vars);
574573
}
@@ -764,7 +763,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
764763
// region back to the `ty::BoundRegion` that it originally
765764
// represented. Because `leak_check` passed, we know that
766765
// these taint sets are mutually disjoint.
767-
let inv_skol_map: FnvHashMap<&'tcx ty::Region, ty::BoundRegion> =
766+
let inv_skol_map: FxHashMap<&'tcx ty::Region, ty::BoundRegion> =
768767
skol_map
769768
.iter()
770769
.flat_map(|(&skol_br, &skol)| {
@@ -837,7 +836,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
837836
snapshot: &CombinedSnapshot)
838837
{
839838
debug!("pop_skolemized({:?})", skol_map);
840-
let skol_regions: FnvHashSet<_> = skol_map.values().cloned().collect();
839+
let skol_regions: FxHashSet<_> = skol_map.values().cloned().collect();
841840
self.region_vars.pop_skolemized(&skol_regions, &snapshot.region_vars_snapshot);
842841
if !skol_map.is_empty() {
843842
self.projection_cache.borrow_mut().rollback_skolemized(

src/librustc/infer/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use std::fmt;
3939
use syntax::ast;
4040
use errors::DiagnosticBuilder;
4141
use syntax_pos::{self, Span, DUMMY_SP};
42-
use util::nodemap::{FnvHashMap, FnvHashSet, NodeMap};
42+
use util::nodemap::{FxHashMap, FxHashSet, NodeMap};
4343

4444
use self::combine::CombineFields;
4545
use self::higher_ranked::HrMatchResult;
@@ -134,7 +134,7 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
134134

135135
// the set of predicates on which errors have been reported, to
136136
// avoid reporting the same error twice.
137-
pub reported_trait_errors: RefCell<FnvHashSet<traits::TraitErrorKey<'tcx>>>,
137+
pub reported_trait_errors: RefCell<FxHashSet<traits::TraitErrorKey<'tcx>>>,
138138

139139
// Sadly, the behavior of projection varies a bit depending on the
140140
// stage of compilation. The specifics are given in the
@@ -170,7 +170,7 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
170170

171171
/// A map returned by `skolemize_late_bound_regions()` indicating the skolemized
172172
/// region that each late-bound region was replaced with.
173-
pub type SkolemizationMap<'tcx> = FnvHashMap<ty::BoundRegion, &'tcx ty::Region>;
173+
pub type SkolemizationMap<'tcx> = FxHashMap<ty::BoundRegion, &'tcx ty::Region>;
174174

175175
/// Why did we require that the two types be related?
176176
///
@@ -492,7 +492,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
492492
selection_cache: traits::SelectionCache::new(),
493493
evaluation_cache: traits::EvaluationCache::new(),
494494
projection_cache: RefCell::new(traits::ProjectionCache::new()),
495-
reported_trait_errors: RefCell::new(FnvHashSet()),
495+
reported_trait_errors: RefCell::new(FxHashSet()),
496496
projection_mode: Reveal::NotSpecializable,
497497
tainted_by_errors_flag: Cell::new(false),
498498
err_count_on_creation: self.sess.err_count(),
@@ -531,7 +531,7 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
531531
parameter_environment: param_env,
532532
selection_cache: traits::SelectionCache::new(),
533533
evaluation_cache: traits::EvaluationCache::new(),
534-
reported_trait_errors: RefCell::new(FnvHashSet()),
534+
reported_trait_errors: RefCell::new(FxHashSet()),
535535
projection_mode: projection_mode,
536536
tainted_by_errors_flag: Cell::new(false),
537537
err_count_on_creation: tcx.sess.err_count(),
@@ -1530,7 +1530,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
15301530
span: Span,
15311531
lbrct: LateBoundRegionConversionTime,
15321532
value: &ty::Binder<T>)
1533-
-> (T, FnvHashMap<ty::BoundRegion, &'tcx ty::Region>)
1533+
-> (T, FxHashMap<ty::BoundRegion, &'tcx ty::Region>)
15341534
where T : TypeFoldable<'tcx>
15351535
{
15361536
self.tcx.replace_late_bound_regions(

src/librustc/infer/region_inference/graphviz.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use middle::region::CodeExtent;
2323
use super::Constraint;
2424
use infer::SubregionOrigin;
2525
use infer::region_inference::RegionVarBindings;
26-
use util::nodemap::{FnvHashMap, FnvHashSet};
26+
use util::nodemap::{FxHashMap, FxHashSet};
2727

2828
use std::borrow::Cow;
2929
use std::collections::hash_map::Entry::Vacant;
@@ -122,8 +122,8 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
122122
struct ConstraintGraph<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
123123
tcx: TyCtxt<'a, 'gcx, 'tcx>,
124124
graph_name: String,
125-
map: &'a FnvHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>,
126-
node_ids: FnvHashMap<Node, usize>,
125+
map: &'a FxHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>,
126+
node_ids: FxHashMap<Node, usize>,
127127
}
128128

129129
#[derive(Clone, Hash, PartialEq, Eq, Debug, Copy)]
@@ -145,7 +145,7 @@ impl<'a, 'gcx, 'tcx> ConstraintGraph<'a, 'gcx, 'tcx> {
145145
map: &'a ConstraintMap<'tcx>)
146146
-> ConstraintGraph<'a, 'gcx, 'tcx> {
147147
let mut i = 0;
148-
let mut node_ids = FnvHashMap();
148+
let mut node_ids = FxHashMap();
149149
{
150150
let mut add_node = |node| {
151151
if let Vacant(e) = node_ids.entry(node) {
@@ -235,7 +235,7 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
235235
type Node = Node;
236236
type Edge = Edge<'tcx>;
237237
fn nodes(&self) -> dot::Nodes<Node> {
238-
let mut set = FnvHashSet();
238+
let mut set = FxHashSet();
239239
for node in self.node_ids.keys() {
240240
set.insert(*node);
241241
}
@@ -261,7 +261,7 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
261261
}
262262
}
263263

264-
pub type ConstraintMap<'tcx> = FnvHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>;
264+
pub type ConstraintMap<'tcx> = FxHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>;
265265

266266
fn dump_region_constraints_to<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
267267
map: &ConstraintMap<'tcx>,

0 commit comments

Comments
 (0)