Skip to content

Commit 0f01c3b

Browse files
author
Stjepan Glavina
committed
[Experiment] Replace HashMap with OrderMap
1 parent 2d75213 commit 0f01c3b

Some content is hidden

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

46 files changed

+2079
-29
lines changed

src/librustc/Cargo.toml

+1
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 = { path = "../ordermap" }
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

+2-2
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

+2-2
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

+1-1
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

+1-1
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

+1
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

+1-1
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

+4-3
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ 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 ordermap::{self, Entry};
6465
use std::hash::{Hash, Hasher};
6566
use std::mem;
6667
use std::ops::Deref;
@@ -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,7 @@ 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(&mut self, id: hir::HirId) -> Entry<hir::ItemLocalId, V, ::std::hash::BuildHasherDefault<rustc_data_structures::fx::FxHasher>> {
303304
validate_hir_id_for_typeck_tables(self.local_id_root, id, true);
304305
self.data.entry(id.local_id)
305306
}

src/librustc_data_structures/Cargo.toml

+1
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 = { path = "../ordermap" }

src/librustc_data_structures/fx.rs

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

11-
use std::collections::{HashMap, HashSet};
11+
use std::collections::HashSet;
1212
use std::default::Default;
1313
use std::hash::{Hasher, Hash, BuildHasherDefault};
1414
use std::ops::BitXor;
15+
use ordermap::OrderMap;
1516

16-
pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
17+
// pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
1718
pub type FxHashSet<V> = HashSet<V, BuildHasherDefault<FxHasher>>;
1819

20+
pub type FxHashMap<K, V> = OrderMap<K, V, BuildHasherDefault<FxHasher>>;
21+
1922
#[allow(non_snake_case)]
2023
pub fn FxHashMap<K: Hash + Eq, V>() -> FxHashMap<K, V> {
21-
HashMap::default()
24+
Default::default()
2225
}
2326

2427
#[allow(non_snake_case)]

src/librustc_data_structures/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ extern crate log;
4040
extern crate serialize as rustc_serialize; // used by deriving
4141
#[cfg(unix)]
4242
extern crate libc;
43+
extern crate ordermap;
4344

4445
pub use rustc_serialize::hex::ToHex;
4546

src/librustc_data_structures/obligation_forest/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use fx::{FxHashMap, FxHashSet};
1919

2020
use std::cell::Cell;
21-
use std::collections::hash_map::Entry;
21+
use super::ordermap::Entry;
2222
use std::fmt::Debug;
2323
use std::hash;
2424
use std::marker::PhantomData;

src/librustc_data_structures/stable_hasher.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::marker::PhantomData;
1313
use std::mem;
1414
use blake2b::Blake2bHasher;
1515
use rustc_serialize::leb128;
16+
use ordermap::OrderMap;
1617

1718
fn write_unsigned_leb128_to_buf(buf: &mut [u8; 16], value: u64) -> usize {
1819
leb128::write_unsigned_leb128_to(value as u128, |i, v| buf[i] = v)
@@ -482,7 +483,7 @@ impl<I: ::indexed_vec::Idx, CTX> HashStable<CTX> for ::indexed_set::IdxSetBuf<I>
482483
impl_stable_hash_via_hash!(::std::path::Path);
483484
impl_stable_hash_via_hash!(::std::path::PathBuf);
484485

485-
impl<K, V, R, HCX> HashStable<HCX> for ::std::collections::HashMap<K, V, R>
486+
impl<K, V, R, HCX> HashStable<HCX> for OrderMap<K, V, R>
486487
where K: ToStableHashKey<HCX> + Eq + Hash,
487488
V: HashStable<HCX>,
488489
R: BuildHasher,
@@ -542,7 +543,7 @@ impl<K, HCX> HashStable<HCX> for ::std::collections::BTreeSet<K>
542543
pub fn hash_stable_hashmap<HCX, K, V, R, SK, F, W>(
543544
hcx: &mut HCX,
544545
hasher: &mut StableHasher<W>,
545-
map: &::std::collections::HashMap<K, V, R>,
546+
map: &OrderMap<K, V, R>,
546547
to_stable_hash_key: F)
547548
where K: Eq + Hash,
548549
V: HashStable<HCX>,

src/librustc_lint/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ rustc_back = { path = "../librustc_back" }
1616
rustc_const_eval = { path = "../librustc_const_eval" }
1717
syntax = { path = "../libsyntax" }
1818
syntax_pos = { path = "../libsyntax_pos" }
19+
ordermap = { path = "../ordermap" }

src/librustc_lint/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern crate log;
4141
extern crate rustc_back;
4242
extern crate rustc_const_eval;
4343
extern crate syntax_pos;
44+
extern crate ordermap;
4445

4546
use rustc::lint;
4647
use rustc::middle;

src/librustc_lint/unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use util::nodemap::FxHashMap;
1515
use lint::{LateContext, EarlyContext, LintContext, LintArray};
1616
use lint::{LintPass, EarlyLintPass, LateLintPass};
1717

18-
use std::collections::hash_map::Entry::{Occupied, Vacant};
18+
use ordermap::Entry::{Occupied, Vacant};
1919

2020
use syntax::ast;
2121
use syntax::attr;

src/librustc_metadata/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ serialize = { path = "../libserialize" }
2121
syntax = { path = "../libsyntax" }
2222
syntax_ext = { path = "../libsyntax_ext" }
2323
syntax_pos = { path = "../libsyntax_pos" }
24+
ordermap = { path = "../ordermap" }

src/librustc_metadata/cstore_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
290290
// external item to be parents).
291291
visible_parent_map: |tcx, cnum| {
292292
use std::collections::vec_deque::VecDeque;
293-
use std::collections::hash_map::Entry;
293+
use ordermap::Entry;
294294

295295
assert_eq!(cnum, LOCAL_CRATE);
296296
let mut visible_parent_map: DefIdMap<DefId> = DefIdMap();
@@ -313,7 +313,7 @@ pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
313313
}
314314

315315
match visible_parent_map.entry(child) {
316-
Entry::Occupied(mut entry) => {
316+
Entry::Occupied(entry) => {
317317
// If `child` is defined in crate `cnum`, ensure
318318
// that it is mapped to a parent in `cnum`.
319319
if child.krate == cnum && entry.get().krate != cnum {

src/librustc_metadata/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern crate proc_macro;
3939
extern crate rustc;
4040
extern crate rustc_back;
4141
extern crate rustc_data_structures;
42+
extern crate ordermap;
4243

4344
mod diagnostics;
4445

src/librustc_mir/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ rustc_errors = { path = "../librustc_errors" }
2020
serialize = { path = "../libserialize" }
2121
syntax = { path = "../libsyntax" }
2222
syntax_pos = { path = "../libsyntax_pos" }
23+
ordermap = { path = "../ordermap" }

src/librustc_mir/dataflow/impls/borrows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
117117
}
118118

119119
pub fn region_span(&self, region: &Region) -> Span {
120-
let opt_span = self.region_span_map.get(region);
120+
let opt_span = self.region_span_map.get(*region);
121121
assert!(opt_span.is_some(), "end region not found for {:?}", region);
122122
*opt_span.unwrap()
123123
}

src/librustc_mir/dataflow/move_paths/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_data_structures::indexed_vec::{IndexVec};
1616

1717
use syntax::codemap::DUMMY_SP;
1818

19-
use std::collections::hash_map::Entry;
19+
use ordermap::Entry;
2020
use std::mem;
2121

2222
use super::abs_domain::Lift;

src/librustc_mir/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern crate syntax_pos;
4141
extern crate rustc_const_math;
4242
extern crate rustc_const_eval;
4343
extern crate core; // for NonZero
44+
extern crate ordermap;
4445

4546
mod diagnostics;
4647

src/librustc_passes/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ rustc_const_math = { path = "../librustc_const_math" }
1616
syntax = { path = "../libsyntax" }
1717
syntax_pos = { path = "../libsyntax_pos" }
1818
rustc_errors = { path = "../librustc_errors" }
19+
ordermap = { path = "../ordermap" }

src/librustc_passes/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use syntax::ast;
5050
use syntax_pos::{Span, DUMMY_SP};
5151
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
5252

53-
use std::collections::hash_map::Entry;
53+
use ordermap::Entry;
5454
use std::cmp::Ordering;
5555

5656
struct CheckCrateVisitor<'a, 'tcx: 'a> {

src/librustc_passes/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extern crate log;
3232
extern crate syntax;
3333
extern crate syntax_pos;
3434
extern crate rustc_errors as errors;
35+
extern crate ordermap;
3536

3637
mod diagnostics;
3738

src/librustc_trans/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ rustc_trans_utils = { path = "../librustc_trans_utils" }
3030
serialize = { path = "../libserialize" }
3131
syntax = { path = "../libsyntax" }
3232
syntax_pos = { path = "../libsyntax_pos" }
33+
ordermap = { path = "../ordermap" }
3334

3435
[target."cfg(windows)".dependencies]
3536
cc = "1.0"

src/librustc_trans/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ extern crate rustc_trans_utils;
5454
extern crate rustc_demangle;
5555
extern crate jobserver;
5656
extern crate num_cpus;
57+
extern crate ordermap;
5758

5859
#[macro_use] extern crate log;
5960
#[macro_use] extern crate syntax;

src/librustc_trans/partitioning.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ use rustc::middle::trans::{Linkage, Visibility};
111111
use rustc::ty::{self, TyCtxt, InstanceDef};
112112
use rustc::ty::item_path::characteristic_def_id_of_type;
113113
use rustc::util::nodemap::{FxHashMap, FxHashSet};
114-
use std::collections::hash_map::Entry;
114+
use ordermap::Entry;
115115
use syntax::ast::NodeId;
116116
use syntax::symbol::{Symbol, InternedString};
117117
use trans_item::{TransItem, TransItemExt, InstantiationMode};
@@ -398,7 +398,7 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
398398
let mut smallest = codegen_units.pop().unwrap();
399399
let second_smallest = codegen_units.last_mut().unwrap();
400400

401-
for (k, v) in smallest.items_mut().drain() {
401+
for (k, v) in smallest.items_mut().drain(..) {
402402
second_smallest.items_mut().insert(k, v);
403403
}
404404
}

src/librustc_typeck/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ rustc_data_structures = { path = "../librustc_data_structures" }
2121
rustc_platform_intrinsics = { path = "../librustc_platform_intrinsics" }
2222
syntax_pos = { path = "../libsyntax_pos" }
2323
rustc_errors = { path = "../librustc_errors" }
24+
ordermap = { path = "../ordermap" }

src/librustc_typeck/check/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use check::{FnCtxt, Expectation, Diverges};
1919
use check::coercion::CoerceMany;
2020
use util::nodemap::FxHashMap;
2121

22-
use std::collections::hash_map::Entry::{Occupied, Vacant};
22+
use ordermap::Entry::{Occupied, Vacant};
2323
use std::cmp;
2424
use syntax::ast;
2525
use syntax::codemap::Spanned;

src/librustc_typeck/check/generator_interior.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn resolve_interior<'a, 'gcx, 'tcx>(fcx: &'a FnCtxt<'a, 'gcx, 'tcx>,
8181
let region_expr_count = visitor.region_scope_tree.body_expr_count(body_id).unwrap();
8282
assert_eq!(region_expr_count, visitor.expr_count);
8383

84-
let mut types: Vec<_> = visitor.types.drain().collect();
84+
let mut types: Vec<_> = visitor.types.drain(..).collect();
8585

8686
// Sort types by insertion order
8787
types.sort_by_key(|t| t.1);

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ use util::common::{ErrorReported, indenter};
108108
use util::nodemap::{DefIdMap, FxHashMap, NodeMap};
109109

110110
use std::cell::{Cell, RefCell, Ref, RefMut};
111-
use std::collections::hash_map::Entry;
111+
use ordermap::Entry;
112112
use std::cmp;
113113
use std::fmt::Display;
114114
use std::mem::replace;

src/librustc_typeck/check/upvar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use rustc::hir::def_id::DefIndex;
5454
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
5555
use rustc::util::nodemap::FxHashMap;
5656

57-
use std::collections::hash_map::Entry;
57+
use ordermap::Entry;
5858

5959
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
6060
pub fn closure_analyze(&self, body: &'gcx hir::Body) {

src/librustc_typeck/impl_wf_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor;
2424
use rustc::hir::def_id::DefId;
2525
use rustc::ty::{self, TyCtxt};
2626
use rustc::util::nodemap::{FxHashMap, FxHashSet};
27-
use std::collections::hash_map::Entry::{Occupied, Vacant};
27+
use ordermap::Entry::{Occupied, Vacant};
2828

2929
use syntax_pos::Span;
3030

src/librustc_typeck/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ extern crate rustc_back;
9090
extern crate rustc_const_math;
9191
extern crate rustc_data_structures;
9292
extern crate rustc_errors as errors;
93+
extern crate ordermap;
9394

9495
use rustc::hir;
9596
use rustc::lint;

src/libserialize/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ version = "0.0.0"
77
name = "serialize"
88
path = "lib.rs"
99
crate-type = ["dylib", "rlib"]
10+
11+
[dependencies]
12+
ordermap = { path = "../ordermap" }

0 commit comments

Comments
 (0)