Skip to content

Commit 43308d4

Browse files
committed
Auto merge of #45282 - stjepang:experiment-ordermap, r=<try>
[Experiment] Replace HashMap with OrderMap Do not merge. This is just a simple experiment where I modified `FxHashMap` to use `OrderMap` instead of `HashMap`, as explained in #45273. Don't expect the code to look good. :) cc @Mark-Simulacrum - Can we please run performance tests to see how this PR impacts compile times? cc @bluss @kennytm @eddyb said on IRC that we shouldn't blindly swap the implementation just yet - let's investigate a bit further. If changing the hash map implementation affects performance a lot, then we can probably gain even more by using a different data structure.
2 parents af7de7b + 5dbe2e4 commit 43308d4

File tree

40 files changed

+114
-30
lines changed

40 files changed

+114
-30
lines changed

src/Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rustc_errors = { path = "../librustc_errors" }
2323
serialize = { path = "../libserialize" }
2424
syntax = { path = "../libsyntax" }
2525
syntax_pos = { path = "../libsyntax_pos" }
26+
ordermap = "0.3.0"
2627

2728
# Note that these dependencies are a lie, they're just here to get linkage to
2829
# work.

src/librustc/dep_graph/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl DepGraphQuery {
4141
}
4242

4343
pub fn contains_node(&self, node: &DepNode) -> bool {
44-
self.indices.contains_key(&node)
44+
self.indices.contains_key(node)
4545
}
4646

4747
pub fn nodes(&self) -> Vec<&DepNode> {
@@ -83,7 +83,7 @@ impl DepGraphQuery {
8383

8484
/// Just the outgoing edges from `node`.
8585
pub fn immediate_successors(&self, node: &DepNode) -> Vec<&DepNode> {
86-
if let Some(&index) = self.indices.get(&node) {
86+
if let Some(&index) = self.indices.get(node) {
8787
self.graph.successor_nodes(index)
8888
.map(|s| self.graph.node_data(s))
8989
.collect()

src/librustc/ich/hcx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use session::Session;
2121
use std::cmp::Ord;
2222
use std::hash as std_hash;
2323
use std::cell::RefCell;
24-
use std::collections::HashMap;
24+
use ordermap::OrderMap;
2525

2626
use syntax::ast;
2727
use syntax::attr;
@@ -426,7 +426,7 @@ pub fn hash_stable_trait_impls<'gcx, W, R>(
426426
hcx: &mut StableHashingContext<'gcx>,
427427
hasher: &mut StableHasher<W>,
428428
blanket_impls: &Vec<DefId>,
429-
non_blanket_impls: &HashMap<fast_reject::SimplifiedType, Vec<DefId>, R>)
429+
non_blanket_impls: &OrderMap<fast_reject::SimplifiedType, Vec<DefId>, R>)
430430
where W: StableHasherResult,
431431
R: std_hash::BuildHasher,
432432
{

src/librustc/infer/freshen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use ty::subst::Substs;
4747
use util::nodemap::FxHashMap;
4848
use hir::def_id::DefId;
4949

50-
use std::collections::hash_map::Entry;
50+
use ordermap::Entry;
5151

5252
use super::InferCtxt;
5353
use super::unify_key::ToType;

src/librustc/infer/region_inference/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use infer::region_inference::RegionVarBindings;
2828
use util::nodemap::{FxHashMap, FxHashSet};
2929

3030
use std::borrow::Cow;
31-
use std::collections::hash_map::Entry::Vacant;
31+
use ordermap::Entry::Vacant;
3232
use std::env;
3333
use std::fs::File;
3434
use std::io;

src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
#![recursion_limit="256"]
6464

65+
extern crate ordermap;
6566
extern crate arena;
6667
#[macro_use] extern crate bitflags;
6768
extern crate core;

src/librustc/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
12631263
let trait_ref = &cache_fresh_trait_pred.0.trait_ref;
12641264
if self.can_use_global_caches(param_env) {
12651265
let cache = tcx.selection_cache.hashmap.borrow();
1266-
if let Some(cached) = cache.get(&trait_ref) {
1266+
if let Some(cached) = cache.get(trait_ref) {
12671267
return Some(cached.get(tcx));
12681268
}
12691269
}

src/librustc/ty/context.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ use rustc_data_structures::accumulate_vec::AccumulateVec;
5353
use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
5454
StableHasher, StableHasherResult,
5555
StableVec};
56+
use rustc_data_structures;
5657
use arena::{TypedArena, DroplessArena};
5758
use rustc_const_math::{ConstInt, ConstUsize};
5859
use rustc_data_structures::indexed_vec::IndexVec;
5960
use std::any::Any;
6061
use std::borrow::Borrow;
6162
use std::cell::{Cell, RefCell};
6263
use std::cmp::Ordering;
63-
use std::collections::hash_map::{self, Entry};
64-
use std::hash::{Hash, Hasher};
64+
use ordermap::{self, Entry};
65+
use std::hash::{BuildHasherDefault, Hash, Hasher};
6566
use std::mem;
6667
use std::ops::Deref;
6768
use std::iter;
@@ -275,7 +276,7 @@ impl<'a, V> LocalTableInContext<'a, V> {
275276
self.data.get(&id.local_id)
276277
}
277278

278-
pub fn iter(&self) -> hash_map::Iter<hir::ItemLocalId, V> {
279+
pub fn iter(&self) -> ordermap::Iter<hir::ItemLocalId, V> {
279280
self.data.iter()
280281
}
281282
}
@@ -299,7 +300,10 @@ impl<'a, V> LocalTableInContextMut<'a, V> {
299300
self.data.get_mut(&id.local_id)
300301
}
301302

302-
pub fn entry(&mut self, id: hir::HirId) -> Entry<hir::ItemLocalId, V> {
303+
pub fn entry(
304+
&mut self,
305+
id: hir::HirId
306+
) -> Entry<hir::ItemLocalId, V, BuildHasherDefault<rustc_data_structures::fx::FxHasher>> {
303307
validate_hir_id_for_typeck_tables(self.local_id_root, id, true);
304308
self.data.entry(id.local_id)
305309
}

src/librustc_data_structures/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ crate-type = ["dylib"]
1111
[dependencies]
1212
log = "0.3"
1313
serialize = { path = "../libserialize" }
14+
ordermap = "0.3.0"

0 commit comments

Comments
 (0)