Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steps towards reproducible builds #35984

Merged
merged 6 commits into from
Aug 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/librustc/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@

use ty::{self, Ty, TyCtxt, TypeFoldable};
use ty::fold::TypeFolder;
use std::collections::hash_map::{self, Entry};
use util::nodemap::FnvHashMap;
use std::collections::hash_map::Entry;

use super::InferCtxt;
use super::unify_key::ToType;

pub struct TypeFreshener<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
freshen_count: u32,
Copy link
Contributor

@arielb1 arielb1 Aug 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a performance problem (I mean, using a non-FNV hash here). This is a rather hot function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was surprised to see this, too. I'll try to do a little benchmark to see if this patch improves type checking performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests on syntex_syntax:

With this PR:

time: 0.557; rss: 230MB item-types checking
time: 5.720; rss: 262MB item-bodies checking

time: 0.574; rss: 230MB item-types checking
time: 5.779; rss: 262MB item-bodies checking

time: 0.559; rss: 231MB item-types checking
time: 5.761; rss: 261MB item-bodies checking

time: 0.566; rss: 232MB item-types checking
time: 5.708; rss: 263MB item-bodies checking

Without this PR (current master):

time: 0.560; rss: 232MB item-types checking
time: 5.768; rss: 263MB item-bodies checking

time: 0.565; rss: 230MB item-types checking
time: 5.907; rss: 261MB item-bodies checking

time: 0.561; rss: 230MB item-types checking
time: 5.810; rss: 261MB item-bodies checking

time: 0.557; rss: 231MB item-types checking
time: 5.812; rss: 261MB item-bodies checking

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

freshen_map: hash_map::HashMap<ty::InferTy, Ty<'tcx>>,
freshen_map: FnvHashMap<ty::InferTy, Ty<'tcx>>,
}

impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
Expand All @@ -49,7 +50,7 @@ impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
TypeFreshener {
infcx: infcx,
freshen_count: 0,
freshen_map: hash_map::HashMap::new(),
freshen_map: FnvHashMap(),
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use ty::{self, TyCtxt};
use hir::def::Def;
use hir::def_id::{DefId};
use lint;
use util::nodemap::FnvHashSet;

use std::collections::HashSet;
use syntax::{ast, codemap};
use syntax::attr;
use syntax_pos;
Expand All @@ -48,7 +48,7 @@ fn should_explore<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
struct MarkSymbolVisitor<'a, 'tcx: 'a> {
worklist: Vec<ast::NodeId>,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
live_symbols: Box<HashSet<ast::NodeId>>,
live_symbols: Box<FnvHashSet<ast::NodeId>>,
struct_has_extern_repr: bool,
ignore_non_const_paths: bool,
inherited_pub_visibility: bool,
Expand All @@ -61,7 +61,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
MarkSymbolVisitor {
worklist: worklist,
tcx: tcx,
live_symbols: box HashSet::new(),
live_symbols: box FnvHashSet(),
struct_has_extern_repr: false,
ignore_non_const_paths: false,
inherited_pub_visibility: false,
Expand Down Expand Up @@ -162,7 +162,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}

fn mark_live_symbols(&mut self) {
let mut scanned = HashSet::new();
let mut scanned = FnvHashSet();
while !self.worklist.is_empty() {
let id = self.worklist.pop().unwrap();
if scanned.contains(&id) {
Expand Down Expand Up @@ -395,7 +395,7 @@ fn create_and_seed_worklist<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
fn find_live<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
access_levels: &privacy::AccessLevels,
krate: &hir::Crate)
-> Box<HashSet<ast::NodeId>> {
-> Box<FnvHashSet<ast::NodeId>> {
let worklist = create_and_seed_worklist(tcx, access_levels, krate);
let mut symbol_visitor = MarkSymbolVisitor::new(tcx, worklist);
symbol_visitor.mark_live_symbols();
Expand All @@ -413,7 +413,7 @@ fn get_struct_ctor_id(item: &hir::Item) -> Option<ast::NodeId> {

struct DeadVisitor<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
live_symbols: Box<HashSet<ast::NodeId>>,
live_symbols: Box<FnvHashSet<ast::NodeId>>,
}

impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ use hir::def_id::DefId;
use ty::{self, TyCtxt};
use middle::privacy;
use session::config;
use util::nodemap::NodeSet;
use util::nodemap::{NodeSet, FnvHashSet};

use std::collections::HashSet;
use syntax::abi::Abi;
use syntax::ast;
use syntax::attr;
Expand Down Expand Up @@ -204,7 +203,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {

// Step 2: Mark all symbols that the symbols on the worklist touch.
fn propagate(&mut self) {
let mut scanned = HashSet::new();
let mut scanned = FnvHashSet();
loop {
let search_item = match self.worklist.pop() {
Some(item) => item,
Expand Down
7 changes: 6 additions & 1 deletion src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,13 @@ fn encode_xrefs<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
xrefs: FnvHashMap<XRef<'tcx>, u32>)
{
let mut xref_positions = vec![0; xrefs.len()];

// Encode XRefs sorted by their ID
let mut sorted_xrefs: Vec<_> = xrefs.into_iter().collect();
sorted_xrefs.sort_by_key(|&(_, id)| id);

rbml_w.start_tag(tag_xref_data);
for (xref, id) in xrefs.into_iter() {
for (xref, id) in sorted_xrefs.into_iter() {
xref_positions[id as usize] = rbml_w.mark_stable_position() as u32;
match xref {
XRef::Predicate(p) => {
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ use rustc::session::Session;
use rustc::session::filesearch::{FileSearch, FileMatches, FileDoesntMatch};
use rustc::session::search_paths::PathKind;
use rustc::util::common;
use rustc::util::nodemap::FnvHashMap;

use rustc_llvm as llvm;
use rustc_llvm::{False, ObjectFile, mk_section_iter};
Expand All @@ -230,7 +231,6 @@ use syntax_pos::Span;
use rustc_back::target::Target;

use std::cmp;
use std::collections::HashMap;
use std::fmt;
use std::fs;
use std::io;
Expand Down Expand Up @@ -413,7 +413,7 @@ impl<'a> Context<'a> {
let rlib_prefix = format!("lib{}", self.crate_name);
let staticlib_prefix = format!("{}{}", staticpair.0, self.crate_name);

let mut candidates = HashMap::new();
let mut candidates = FnvHashMap();
let mut staticlibs = vec!();

// First, find all possible candidate rlibs and dylibs purely based on
Expand Down Expand Up @@ -456,7 +456,7 @@ impl<'a> Context<'a> {

let hash_str = hash.to_string();
let slot = candidates.entry(hash_str)
.or_insert_with(|| (HashMap::new(), HashMap::new()));
.or_insert_with(|| (FnvHashMap(), FnvHashMap()));
let (ref mut rlibs, ref mut dylibs) = *slot;
fs::canonicalize(path).map(|p| {
if rlib {
Expand All @@ -477,7 +477,7 @@ impl<'a> Context<'a> {
// A Library candidate is created if the metadata for the set of
// libraries corresponds to the crate id and hash criteria that this
// search is being performed for.
let mut libraries = HashMap::new();
let mut libraries = FnvHashMap();
for (_hash, (rlibs, dylibs)) in candidates {
let mut slot = None;
let rlib = self.extract_one(rlibs, CrateFlavor::Rlib, &mut slot);
Expand Down Expand Up @@ -527,7 +527,7 @@ impl<'a> Context<'a> {
// read the metadata from it if `*slot` is `None`. If the metadata couldn't
// be read, it is assumed that the file isn't a valid rust library (no
// errors are emitted).
fn extract_one(&mut self, m: HashMap<PathBuf, PathKind>, flavor: CrateFlavor,
fn extract_one(&mut self, m: FnvHashMap<PathBuf, PathKind>, flavor: CrateFlavor,
slot: &mut Option<(Svh, MetadataBlob)>) -> Option<(PathBuf, PathKind)> {
let mut ret: Option<(PathBuf, PathKind)> = None;
let mut error = 0;
Expand Down Expand Up @@ -669,8 +669,8 @@ impl<'a> Context<'a> {
// rlibs/dylibs.
let sess = self.sess;
let dylibname = self.dylibname();
let mut rlibs = HashMap::new();
let mut dylibs = HashMap::new();
let mut rlibs = FnvHashMap();
let mut dylibs = FnvHashMap();
{
let locs = locs.map(|l| PathBuf::from(l)).filter(|loc| {
if !loc.exists() {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_metadata/macro_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use creader::CrateReader;
use cstore::CStore;

use rustc::session::Session;
use rustc::util::nodemap::{FnvHashSet, FnvHashMap};

use std::collections::{HashSet, HashMap};
use syntax::parse::token;
use syntax::ast;
use syntax::attr;
Expand Down Expand Up @@ -45,13 +45,13 @@ pub fn call_bad_macro_reexport(a: &Session, b: Span) {
span_err!(a, b, E0467, "bad macro reexport");
}

pub type MacroSelection = HashMap<token::InternedString, Span>;
pub type MacroSelection = FnvHashMap<token::InternedString, Span>;

impl<'a> ext::base::MacroLoader for MacroLoader<'a> {
fn load_crate(&mut self, extern_crate: &ast::Item, allows_macros: bool) -> Vec<ast::MacroDef> {
// Parse the attributes relating to macros.
let mut import = Some(HashMap::new()); // None => load all
let mut reexport = HashMap::new();
let mut import = Some(FnvHashMap()); // None => load all
let mut reexport = FnvHashMap();

for attr in &extern_crate.attrs {
let mut used = true;
Expand Down Expand Up @@ -120,7 +120,7 @@ impl<'a> MacroLoader<'a> {
}

let mut macros = Vec::new();
let mut seen = HashSet::new();
let mut seen = FnvHashSet();

for mut def in self.reader.read_exported_macros(vi) {
let name = def.ident.name.as_str();
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/assign_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

use Resolver;
use rustc::session::Session;
use rustc::util::nodemap::FnvHashMap;
use syntax::ast;
use syntax::ext::hygiene::Mark;
use syntax::fold::{self, Folder};
use syntax::ptr::P;
use syntax::util::move_map::MoveMap;
use syntax::util::small_vector::SmallVector;

use std::collections::HashMap;
use std::mem;

impl<'a> Resolver<'a> {
Expand All @@ -31,7 +31,7 @@ impl<'a> Resolver<'a> {

struct NodeIdAssigner<'a> {
sess: &'a Session,
macros_at_scope: &'a mut HashMap<ast::NodeId, Vec<Mark>>,
macros_at_scope: &'a mut FnvHashMap<ast::NodeId, Vec<Mark>>,
}

impl<'a> Folder for NodeIdAssigner<'a> {
Expand Down
Loading