Skip to content

Commit

Permalink
Rollup merge of rust-lang#53472 - eddyb:fx-pls, r=pnkfelix
Browse files Browse the repository at this point in the history
Use FxHash{Map,Set} instead of the default Hash{Map,Set} everywhere in rustc.

Most of the compiler uses the `Fx` hasher but some places ended up with the default one.
  • Loading branch information
pietroalbini authored Aug 29, 2018
2 parents 474cda8 + 93f3f5b commit 64ff1e5
Show file tree
Hide file tree
Showing 34 changed files with 156 additions and 152 deletions.
7 changes: 4 additions & 3 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ use hir::GenericArg;
use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
ELIDED_LIFETIMES_IN_PATHS};
use middle::cstore::CrateStore;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::small_vec::OneVector;
use rustc_data_structures::thin_vec::ThinVec;
use session::Session;
use util::common::FN_OUTPUT_NAME;
use util::nodemap::{DefIdMap, NodeMap};

use std::collections::{BTreeMap, HashSet};
use std::collections::BTreeMap;
use std::fmt::Debug;
use std::iter;
use std::mem;
Expand Down Expand Up @@ -1342,7 +1343,7 @@ impl<'a> LoweringContext<'a> {
exist_ty_id: NodeId,
collect_elided_lifetimes: bool,
currently_bound_lifetimes: Vec<hir::LifetimeName>,
already_defined_lifetimes: HashSet<hir::LifetimeName>,
already_defined_lifetimes: FxHashSet<hir::LifetimeName>,
output_lifetimes: Vec<hir::GenericArg>,
output_lifetime_params: Vec<hir::GenericParam>,
}
Expand Down Expand Up @@ -1476,7 +1477,7 @@ impl<'a> LoweringContext<'a> {
exist_ty_id,
collect_elided_lifetimes: true,
currently_bound_lifetimes: Vec::new(),
already_defined_lifetimes: HashSet::new(),
already_defined_lifetimes: FxHashSet::default(),
output_lifetimes: Vec::new(),
output_lifetime_params: Vec::new(),
};
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/weak_lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use session::config;
use middle::lang_items;

use rustc_data_structures::fx::FxHashSet;
use rustc_target::spec::PanicStrategy;
use syntax::ast;
use syntax::symbol::Symbol;
Expand All @@ -23,8 +24,6 @@ use hir::intravisit;
use hir;
use ty::TyCtxt;

use std::collections::HashSet;

macro_rules! weak_lang_items {
($($name:ident, $item:ident, $sym:ident;)*) => (

Expand Down Expand Up @@ -101,7 +100,7 @@ fn verify<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
return
}

let mut missing = HashSet::new();
let mut missing = FxHashSet::default();
for &cnum in tcx.crates().iter() {
for &item in tcx.missing_lang_items(cnum).iter() {
missing.insert(item);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ use std::collections::btree_map::Iter as BTreeMapIter;
use std::collections::btree_map::Keys as BTreeMapKeysIter;
use std::collections::btree_map::Values as BTreeMapValuesIter;

use rustc_data_structures::fx::FxHashSet;
use std::{fmt, str};
use std::hash::Hasher;
use std::collections::hash_map::DefaultHasher;
use std::collections::HashSet;
use std::iter::FromIterator;
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -1373,7 +1373,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
let max_atomic_width = sess.target.target.max_atomic_width();
let atomic_cas = sess.target.target.options.atomic_cas;

let mut ret = HashSet::new();
let mut ret = FxHashSet::default();
// Target bindings.
ret.insert((Symbol::intern("target_os"), Some(Symbol::intern(os))));
if let Some(ref fam) = sess.target.target.options.target_family {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/session/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

pub use self::FileMatch::*;

use rustc_data_structures::fx::FxHashSet;
use std::borrow::Cow;
use std::collections::HashSet;
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
Expand All @@ -40,7 +40,7 @@ impl<'a> FileSearch<'a> {
pub fn for_each_lib_search_path<F>(&self, mut f: F) where
F: FnMut(&Path, PathKind)
{
let mut visited_dirs = HashSet::new();
let mut visited_dirs = FxHashSet::default();

for (path, kind) in self.search_paths.iter(self.kind) {
f(path, kind);
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ use jobserver::Client;

use std;
use std::cell::{self, Cell, RefCell};
use std::collections::HashMap;
use std::env;
use std::fmt;
use std::io::Write;
Expand Down Expand Up @@ -122,7 +121,7 @@ pub struct Session {
/// Map from imported macro spans (which consist of
/// the localized span for the macro body) to the
/// macro name and definition span in the source crate.
pub imported_macro_spans: OneThread<RefCell<HashMap<Span, (String, Span)>>>,
pub imported_macro_spans: OneThread<RefCell<FxHashMap<Span, (String, Span)>>>,

incr_comp_session: OneThread<RefCell<IncrCompSession>>,

Expand Down Expand Up @@ -1122,7 +1121,7 @@ pub fn build_session_(
injected_allocator: Once::new(),
allocator_kind: Once::new(),
injected_panic_runtime: Once::new(),
imported_macro_spans: OneThread::new(RefCell::new(HashMap::new())),
imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())),
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
self_profiling: Lock::new(SelfProfiler::new()),
profile_channel: Lock::new(None),
Expand Down
11 changes: 6 additions & 5 deletions src/librustc/ty/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#![allow(warnings)]

use std::mem;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::{Lock, LockGuard, Lrc, Weak};
use rustc_data_structures::OnDrop;
use syntax_pos::Span;
Expand All @@ -21,7 +22,7 @@ use ty::context::TyCtxt;
use errors::Diagnostic;
use std::process;
use std::{fmt, ptr};
use std::collections::HashSet;

#[cfg(parallel_queries)]
use {
rayon_core,
Expand Down Expand Up @@ -282,7 +283,7 @@ where
fn cycle_check<'tcx>(query: Lrc<QueryJob<'tcx>>,
span: Span,
stack: &mut Vec<(Span, Lrc<QueryJob<'tcx>>)>,
visited: &mut HashSet<*const QueryJob<'tcx>>
visited: &mut FxHashSet<*const QueryJob<'tcx>>
) -> Option<Option<Waiter<'tcx>>> {
if visited.contains(&query.as_ptr()) {
return if let Some(p) = stack.iter().position(|q| q.1.as_ptr() == query.as_ptr()) {
Expand Down Expand Up @@ -321,7 +322,7 @@ fn cycle_check<'tcx>(query: Lrc<QueryJob<'tcx>>,
#[cfg(parallel_queries)]
fn connected_to_root<'tcx>(
query: Lrc<QueryJob<'tcx>>,
visited: &mut HashSet<*const QueryJob<'tcx>>
visited: &mut FxHashSet<*const QueryJob<'tcx>>
) -> bool {
// We already visited this or we're deliberately ignoring it
if visited.contains(&query.as_ptr()) {
Expand Down Expand Up @@ -357,7 +358,7 @@ fn remove_cycle<'tcx>(
wakelist: &mut Vec<Lrc<QueryWaiter<'tcx>>>,
tcx: TyCtxt<'_, 'tcx, '_>
) -> bool {
let mut visited = HashSet::new();
let mut visited = FxHashSet::default();
let mut stack = Vec::new();
// Look for a cycle starting with the last query in `jobs`
if let Some(waiter) = cycle_check(jobs.pop().unwrap(),
Expand Down Expand Up @@ -389,7 +390,7 @@ fn remove_cycle<'tcx>(
// connected to queries outside the cycle
let entry_points: Vec<Lrc<QueryJob<'tcx>>> = stack.iter().filter_map(|query| {
// Mark all the other queries in the cycle as already visited
let mut visited = HashSet::from_iter(stack.iter().filter_map(|q| {
let mut visited = FxHashSet::from_iter(stack.iter().filter_map(|q| {
if q.1.as_ptr() != query.1.as_ptr() {
Some(q.1.as_ptr())
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/util/time_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::collections::HashMap;
use rustc_data_structures::fx::FxHashMap;
use std::fs::File;
use std::io::prelude::*;
use std::marker::PhantomData;
Expand Down Expand Up @@ -40,7 +40,7 @@ struct PerThread {

#[derive(Clone)]
pub struct TimeGraph {
data: Arc<Mutex<HashMap<TimelineId, PerThread>>>,
data: Arc<Mutex<FxHashMap<TimelineId, PerThread>>>,
}

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Drop for RaiiToken {
impl TimeGraph {
pub fn new() -> TimeGraph {
TimeGraph {
data: Arc::new(Mutex::new(HashMap::new()))
data: Arc::new(Mutex::new(FxHashMap::default()))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::collections::HashMap;
use rustc_data_structures::fx::FxHashMap;
use std::ffi::{OsStr, OsString};
use std::fs::{self, File};
use std::io::prelude::*;
Expand All @@ -31,7 +31,7 @@ use llvm_util;
/// For all the linkers we support, and information they might
/// need out of the shared crate context before we get rid of it.
pub struct LinkerInfo {
exports: HashMap<CrateType, Vec<String>>,
exports: FxHashMap<CrateType, Vec<String>>,
}

impl LinkerInfo {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::collections::HashSet;
use rustc_data_structures::fx::FxHashSet;
use std::env;
use std::path::{Path, PathBuf};
use std::fs;
Expand Down Expand Up @@ -172,7 +172,7 @@ fn get_install_prefix_rpath(config: &mut RPathConfig) -> String {
}

fn minimize_rpaths(rpaths: &[String]) -> Vec<String> {
let mut set = HashSet::new();
let mut set = FxHashSet::default();
let mut minimized = Vec::new();
for rpath in rpaths {
if set.insert(rpath) {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_data_structures/graph/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::collections::HashMap;
use fx::FxHashMap;
use std::cmp::max;
use std::slice;
use std::iter;
Expand All @@ -18,17 +18,17 @@ use super::*;
pub struct TestGraph {
num_nodes: usize,
start_node: usize,
successors: HashMap<usize, Vec<usize>>,
predecessors: HashMap<usize, Vec<usize>>,
successors: FxHashMap<usize, Vec<usize>>,
predecessors: FxHashMap<usize, Vec<usize>>,
}

impl TestGraph {
pub fn new(start_node: usize, edges: &[(usize, usize)]) -> Self {
let mut graph = TestGraph {
num_nodes: start_node + 1,
start_node,
successors: HashMap::new(),
predecessors: HashMap::new(),
successors: FxHashMap::default(),
predecessors: FxHashMap::default(),
};
for &(source, target) in edges {
graph.num_nodes = max(graph.num_nodes, source + 1);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_driver/profile/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

use super::*;
use syntax_pos::SpanData;
use rustc_data_structures::fx::FxHashMap;
use rustc::util::common::QueryMsg;
use std::fs::File;
use std::time::{Duration, Instant};
use std::collections::hash_map::HashMap;
use rustc::dep_graph::{DepNode};

#[derive(Debug, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -149,7 +149,7 @@ fn write_traces_rec(file: &mut File, traces: &[Rec], total: Duration, depth: usi
}
}

fn compute_counts_rec(counts: &mut HashMap<String,QueryMetric>, traces: &[Rec]) {
fn compute_counts_rec(counts: &mut FxHashMap<String,QueryMetric>, traces: &[Rec]) {
for t in traces.iter() {
match t.effect {
Effect::TimeBegin(ref msg) => {
Expand Down Expand Up @@ -200,7 +200,7 @@ fn compute_counts_rec(counts: &mut HashMap<String,QueryMetric>, traces: &[Rec])
}
}

pub fn write_counts(count_file: &mut File, counts: &mut HashMap<String,QueryMetric>) {
pub fn write_counts(count_file: &mut File, counts: &mut FxHashMap<String,QueryMetric>) {
use rustc::util::common::duration_to_secs_str;
use std::cmp::Reverse;

Expand All @@ -219,7 +219,7 @@ pub fn write_counts(count_file: &mut File, counts: &mut HashMap<String,QueryMetr

pub fn write_traces(html_file: &mut File, counts_file: &mut File, traces: &[Rec]) {
let capacity = traces.iter().fold(0, |acc, t| acc + 1 + t.extent.len());
let mut counts : HashMap<String, QueryMetric> = HashMap::with_capacity(capacity);
let mut counts = FxHashMap::with_capacity_and_hasher(capacity, Default::default());
compute_counts_rec(&mut counts, traces);
write_counts(counts_file, &mut counts);

Expand Down
6 changes: 3 additions & 3 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, SourceMapperDyn, D
use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
use styled_buffer::StyledBuffer;

use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lrc;
use atty;
use std::borrow::Cow;
use std::io::prelude::*;
use std::io;
use std::collections::HashMap;
use std::cmp::{min, Reverse};
use termcolor::{StandardStream, ColorChoice, ColorSpec, BufferWriter};
use termcolor::{WriteColor, Color, Buffer};
Expand Down Expand Up @@ -1090,7 +1090,7 @@ impl EmitterWriter {
max_line_num_len + 1);

// Contains the vertical lines' positions for active multiline annotations
let mut multilines = HashMap::new();
let mut multilines = FxHashMap::default();

// Next, output the annotate source for this file
for line_idx in 0..annotated_file.lines.len() {
Expand All @@ -1109,7 +1109,7 @@ impl EmitterWriter {
width_offset,
code_offset);

let mut to_add = HashMap::new();
let mut to_add = FxHashMap::default();

for (depth, style) in depths {
if multilines.get(&depth).is_some() {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_errors/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::collections::HashMap;
use rustc_data_structures::fx::FxHashMap;

#[derive(Clone)]
pub struct Registry {
descriptions: HashMap<&'static str, &'static str>,
descriptions: FxHashMap<&'static str, &'static str>,
}

impl Registry {
Expand Down
Loading

0 comments on commit 64ff1e5

Please sign in to comment.