Skip to content

Commit

Permalink
[Experiment] Replace HashMap with OrderMap
Browse files Browse the repository at this point in the history
  • Loading branch information
Stjepan Glavina committed Oct 14, 2017
1 parent 2d75213 commit 0f01c3b
Show file tree
Hide file tree
Showing 46 changed files with 2,079 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ rustc_errors = { path = "../librustc_errors" }
serialize = { path = "../libserialize" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
ordermap = { path = "../ordermap" }

# Note that these dependencies are a lie, they're just here to get linkage to
# work.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/dep_graph/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl DepGraphQuery {
}

pub fn contains_node(&self, node: &DepNode) -> bool {
self.indices.contains_key(&node)
self.indices.contains_key(node)
}

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

/// Just the outgoing edges from `node`.
pub fn immediate_successors(&self, node: &DepNode) -> Vec<&DepNode> {
if let Some(&index) = self.indices.get(&node) {
if let Some(&index) = self.indices.get(node) {
self.graph.successor_nodes(index)
.map(|s| self.graph.node_data(s))
.collect()
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use session::Session;
use std::cmp::Ord;
use std::hash as std_hash;
use std::cell::RefCell;
use std::collections::HashMap;
use ordermap::OrderMap;

use syntax::ast;
use syntax::attr;
Expand Down Expand Up @@ -426,7 +426,7 @@ pub fn hash_stable_trait_impls<'gcx, W, R>(
hcx: &mut StableHashingContext<'gcx>,
hasher: &mut StableHasher<W>,
blanket_impls: &Vec<DefId>,
non_blanket_impls: &HashMap<fast_reject::SimplifiedType, Vec<DefId>, R>)
non_blanket_impls: &OrderMap<fast_reject::SimplifiedType, Vec<DefId>, R>)
where W: StableHasherResult,
R: std_hash::BuildHasher,
{
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use ty::subst::Substs;
use util::nodemap::FxHashMap;
use hir::def_id::DefId;

use std::collections::hash_map::Entry;
use ordermap::Entry;

use super::InferCtxt;
use super::unify_key::ToType;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/region_inference/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use infer::region_inference::RegionVarBindings;
use util::nodemap::{FxHashMap, FxHashSet};

use std::borrow::Cow;
use std::collections::hash_map::Entry::Vacant;
use ordermap::Entry::Vacant;
use std::env;
use std::fs::File;
use std::io;
Expand Down
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

#![recursion_limit="256"]

extern crate ordermap;
extern crate arena;
#[macro_use] extern crate bitflags;
extern crate core;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
let trait_ref = &cache_fresh_trait_pred.0.trait_ref;
if self.can_use_global_caches(param_env) {
let cache = tcx.selection_cache.hashmap.borrow();
if let Some(cached) = cache.get(&trait_ref) {
if let Some(cached) = cache.get(trait_ref) {
return Some(cached.get(tcx));
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ use rustc_data_structures::accumulate_vec::AccumulateVec;
use rustc_data_structures::stable_hasher::{HashStable, hash_stable_hashmap,
StableHasher, StableHasherResult,
StableVec};
use rustc_data_structures;
use arena::{TypedArena, DroplessArena};
use rustc_const_math::{ConstInt, ConstUsize};
use rustc_data_structures::indexed_vec::IndexVec;
use std::any::Any;
use std::borrow::Borrow;
use std::cell::{Cell, RefCell};
use std::cmp::Ordering;
use std::collections::hash_map::{self, Entry};
use ordermap::{self, Entry};
use std::hash::{Hash, Hasher};
use std::mem;
use std::ops::Deref;
Expand Down Expand Up @@ -275,7 +276,7 @@ impl<'a, V> LocalTableInContext<'a, V> {
self.data.get(&id.local_id)
}

pub fn iter(&self) -> hash_map::Iter<hir::ItemLocalId, V> {
pub fn iter(&self) -> ordermap::Iter<hir::ItemLocalId, V> {
self.data.iter()
}
}
Expand All @@ -299,7 +300,7 @@ impl<'a, V> LocalTableInContextMut<'a, V> {
self.data.get_mut(&id.local_id)
}

pub fn entry(&mut self, id: hir::HirId) -> Entry<hir::ItemLocalId, V> {
pub fn entry(&mut self, id: hir::HirId) -> Entry<hir::ItemLocalId, V, ::std::hash::BuildHasherDefault<rustc_data_structures::fx::FxHasher>> {
validate_hir_id_for_typeck_tables(self.local_id_root, id, true);
self.data.entry(id.local_id)
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ crate-type = ["dylib"]
[dependencies]
log = "0.3"
serialize = { path = "../libserialize" }
ordermap = { path = "../ordermap" }
9 changes: 6 additions & 3 deletions src/librustc_data_structures/fx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::collections::{HashMap, HashSet};
use std::collections::HashSet;
use std::default::Default;
use std::hash::{Hasher, Hash, BuildHasherDefault};
use std::ops::BitXor;
use ordermap::OrderMap;

pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
// pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
pub type FxHashSet<V> = HashSet<V, BuildHasherDefault<FxHasher>>;

pub type FxHashMap<K, V> = OrderMap<K, V, BuildHasherDefault<FxHasher>>;

#[allow(non_snake_case)]
pub fn FxHashMap<K: Hash + Eq, V>() -> FxHashMap<K, V> {
HashMap::default()
Default::default()
}

#[allow(non_snake_case)]
Expand Down
1 change: 1 addition & 0 deletions src/librustc_data_structures/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern crate log;
extern crate serialize as rustc_serialize; // used by deriving
#[cfg(unix)]
extern crate libc;
extern crate ordermap;

pub use rustc_serialize::hex::ToHex;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_data_structures/obligation_forest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use fx::{FxHashMap, FxHashSet};

use std::cell::Cell;
use std::collections::hash_map::Entry;
use super::ordermap::Entry;
use std::fmt::Debug;
use std::hash;
use std::marker::PhantomData;
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_data_structures/stable_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::marker::PhantomData;
use std::mem;
use blake2b::Blake2bHasher;
use rustc_serialize::leb128;
use ordermap::OrderMap;

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

impl<K, V, R, HCX> HashStable<HCX> for ::std::collections::HashMap<K, V, R>
impl<K, V, R, HCX> HashStable<HCX> for OrderMap<K, V, R>
where K: ToStableHashKey<HCX> + Eq + Hash,
V: HashStable<HCX>,
R: BuildHasher,
Expand Down Expand Up @@ -542,7 +543,7 @@ impl<K, HCX> HashStable<HCX> for ::std::collections::BTreeSet<K>
pub fn hash_stable_hashmap<HCX, K, V, R, SK, F, W>(
hcx: &mut HCX,
hasher: &mut StableHasher<W>,
map: &::std::collections::HashMap<K, V, R>,
map: &OrderMap<K, V, R>,
to_stable_hash_key: F)
where K: Eq + Hash,
V: HashStable<HCX>,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_lint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ rustc_back = { path = "../librustc_back" }
rustc_const_eval = { path = "../librustc_const_eval" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
ordermap = { path = "../ordermap" }
1 change: 1 addition & 0 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extern crate log;
extern crate rustc_back;
extern crate rustc_const_eval;
extern crate syntax_pos;
extern crate ordermap;

use rustc::lint;
use rustc::middle;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use util::nodemap::FxHashMap;
use lint::{LateContext, EarlyContext, LintContext, LintArray};
use lint::{LintPass, EarlyLintPass, LateLintPass};

use std::collections::hash_map::Entry::{Occupied, Vacant};
use ordermap::Entry::{Occupied, Vacant};

use syntax::ast;
use syntax::attr;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ serialize = { path = "../libserialize" }
syntax = { path = "../libsyntax" }
syntax_ext = { path = "../libsyntax_ext" }
syntax_pos = { path = "../libsyntax_pos" }
ordermap = { path = "../ordermap" }
4 changes: 2 additions & 2 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
// external item to be parents).
visible_parent_map: |tcx, cnum| {
use std::collections::vec_deque::VecDeque;
use std::collections::hash_map::Entry;
use ordermap::Entry;

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

match visible_parent_map.entry(child) {
Entry::Occupied(mut entry) => {
Entry::Occupied(entry) => {
// If `child` is defined in crate `cnum`, ensure
// that it is mapped to a parent in `cnum`.
if child.krate == cnum && entry.get().krate != cnum {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_metadata/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern crate proc_macro;
extern crate rustc;
extern crate rustc_back;
extern crate rustc_data_structures;
extern crate ordermap;

mod diagnostics;

Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ rustc_errors = { path = "../librustc_errors" }
serialize = { path = "../libserialize" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
ordermap = { path = "../ordermap" }
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
}

pub fn region_span(&self, region: &Region) -> Span {
let opt_span = self.region_span_map.get(region);
let opt_span = self.region_span_map.get(*region);
assert!(opt_span.is_some(), "end region not found for {:?}", region);
*opt_span.unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/move_paths/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_data_structures::indexed_vec::{IndexVec};

use syntax::codemap::DUMMY_SP;

use std::collections::hash_map::Entry;
use ordermap::Entry;
use std::mem;

use super::abs_domain::Lift;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extern crate syntax_pos;
extern crate rustc_const_math;
extern crate rustc_const_eval;
extern crate core; // for NonZero
extern crate ordermap;

mod diagnostics;

Expand Down
1 change: 1 addition & 0 deletions src/librustc_passes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ rustc_const_math = { path = "../librustc_const_math" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
rustc_errors = { path = "../librustc_errors" }
ordermap = { path = "../ordermap" }
2 changes: 1 addition & 1 deletion src/librustc_passes/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use syntax::ast;
use syntax_pos::{Span, DUMMY_SP};
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};

use std::collections::hash_map::Entry;
use ordermap::Entry;
use std::cmp::Ordering;

struct CheckCrateVisitor<'a, 'tcx: 'a> {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_passes/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern crate log;
extern crate syntax;
extern crate syntax_pos;
extern crate rustc_errors as errors;
extern crate ordermap;

mod diagnostics;

Expand Down
1 change: 1 addition & 0 deletions src/librustc_trans/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ rustc_trans_utils = { path = "../librustc_trans_utils" }
serialize = { path = "../libserialize" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
ordermap = { path = "../ordermap" }

[target."cfg(windows)".dependencies]
cc = "1.0"
1 change: 1 addition & 0 deletions src/librustc_trans/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extern crate rustc_trans_utils;
extern crate rustc_demangle;
extern crate jobserver;
extern crate num_cpus;
extern crate ordermap;

#[macro_use] extern crate log;
#[macro_use] extern crate syntax;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ use rustc::middle::trans::{Linkage, Visibility};
use rustc::ty::{self, TyCtxt, InstanceDef};
use rustc::ty::item_path::characteristic_def_id_of_type;
use rustc::util::nodemap::{FxHashMap, FxHashSet};
use std::collections::hash_map::Entry;
use ordermap::Entry;
use syntax::ast::NodeId;
use syntax::symbol::{Symbol, InternedString};
use trans_item::{TransItem, TransItemExt, InstantiationMode};
Expand Down Expand Up @@ -398,7 +398,7 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
let mut smallest = codegen_units.pop().unwrap();
let second_smallest = codegen_units.last_mut().unwrap();

for (k, v) in smallest.items_mut().drain() {
for (k, v) in smallest.items_mut().drain(..) {
second_smallest.items_mut().insert(k, v);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_typeck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ rustc_data_structures = { path = "../librustc_data_structures" }
rustc_platform_intrinsics = { path = "../librustc_platform_intrinsics" }
syntax_pos = { path = "../libsyntax_pos" }
rustc_errors = { path = "../librustc_errors" }
ordermap = { path = "../ordermap" }
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use check::{FnCtxt, Expectation, Diverges};
use check::coercion::CoerceMany;
use util::nodemap::FxHashMap;

use std::collections::hash_map::Entry::{Occupied, Vacant};
use ordermap::Entry::{Occupied, Vacant};
use std::cmp;
use syntax::ast;
use syntax::codemap::Spanned;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/generator_interior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn resolve_interior<'a, 'gcx, 'tcx>(fcx: &'a FnCtxt<'a, 'gcx, 'tcx>,
let region_expr_count = visitor.region_scope_tree.body_expr_count(body_id).unwrap();
assert_eq!(region_expr_count, visitor.expr_count);

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

// Sort types by insertion order
types.sort_by_key(|t| t.1);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ use util::common::{ErrorReported, indenter};
use util::nodemap::{DefIdMap, FxHashMap, NodeMap};

use std::cell::{Cell, RefCell, Ref, RefMut};
use std::collections::hash_map::Entry;
use ordermap::Entry;
use std::cmp;
use std::fmt::Display;
use std::mem::replace;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use rustc::hir::def_id::DefIndex;
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
use rustc::util::nodemap::FxHashMap;

use std::collections::hash_map::Entry;
use ordermap::Entry;

impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
pub fn closure_analyze(&self, body: &'gcx hir::Body) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/impl_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor;
use rustc::hir::def_id::DefId;
use rustc::ty::{self, TyCtxt};
use rustc::util::nodemap::{FxHashMap, FxHashSet};
use std::collections::hash_map::Entry::{Occupied, Vacant};
use ordermap::Entry::{Occupied, Vacant};

use syntax_pos::Span;

Expand Down
1 change: 1 addition & 0 deletions src/librustc_typeck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ extern crate rustc_back;
extern crate rustc_const_math;
extern crate rustc_data_structures;
extern crate rustc_errors as errors;
extern crate ordermap;

use rustc::hir;
use rustc::lint;
Expand Down
3 changes: 3 additions & 0 deletions src/libserialize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ version = "0.0.0"
name = "serialize"
path = "lib.rs"
crate-type = ["dylib", "rlib"]

[dependencies]
ordermap = { path = "../ordermap" }
Loading

0 comments on commit 0f01c3b

Please sign in to comment.