Skip to content

Commit e4791e0

Browse files
authored
Auto merge of #35984 - jonas-schievink:reproducible-builds, r=eddyb
Steps towards reproducible builds cc #34902 Running `make dist` twice will result in a rustc tarball where only `librustc_back.so`, `librustc_llvm.so` and `librustc_trans.so` differ. Building `libstd` and `libcore` twice with the same compiler and flags produces identical artifacts. The third commit should close #24473
2 parents 6fd13fa + 8766c18 commit e4791e0

File tree

21 files changed

+135
-133
lines changed

21 files changed

+135
-133
lines changed

src/librustc/infer/freshen.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@
3232
3333
use ty::{self, Ty, TyCtxt, TypeFoldable};
3434
use ty::fold::TypeFolder;
35-
use std::collections::hash_map::{self, Entry};
35+
use util::nodemap::FnvHashMap;
36+
use std::collections::hash_map::Entry;
3637

3738
use super::InferCtxt;
3839
use super::unify_key::ToType;
3940

4041
pub struct TypeFreshener<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
4142
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
4243
freshen_count: u32,
43-
freshen_map: hash_map::HashMap<ty::InferTy, Ty<'tcx>>,
44+
freshen_map: FnvHashMap<ty::InferTy, Ty<'tcx>>,
4445
}
4546

4647
impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
@@ -49,7 +50,7 @@ impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
4950
TypeFreshener {
5051
infcx: infcx,
5152
freshen_count: 0,
52-
freshen_map: hash_map::HashMap::new(),
53+
freshen_map: FnvHashMap(),
5354
}
5455
}
5556

src/librustc/middle/dead.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use ty::{self, TyCtxt};
2222
use hir::def::Def;
2323
use hir::def_id::{DefId};
2424
use lint;
25+
use util::nodemap::FnvHashSet;
2526

26-
use std::collections::HashSet;
2727
use syntax::{ast, codemap};
2828
use syntax::attr;
2929
use syntax_pos;
@@ -48,7 +48,7 @@ fn should_explore<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
4848
struct MarkSymbolVisitor<'a, 'tcx: 'a> {
4949
worklist: Vec<ast::NodeId>,
5050
tcx: TyCtxt<'a, 'tcx, 'tcx>,
51-
live_symbols: Box<HashSet<ast::NodeId>>,
51+
live_symbols: Box<FnvHashSet<ast::NodeId>>,
5252
struct_has_extern_repr: bool,
5353
ignore_non_const_paths: bool,
5454
inherited_pub_visibility: bool,
@@ -61,7 +61,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
6161
MarkSymbolVisitor {
6262
worklist: worklist,
6363
tcx: tcx,
64-
live_symbols: box HashSet::new(),
64+
live_symbols: box FnvHashSet(),
6565
struct_has_extern_repr: false,
6666
ignore_non_const_paths: false,
6767
inherited_pub_visibility: false,
@@ -162,7 +162,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
162162
}
163163

164164
fn mark_live_symbols(&mut self) {
165-
let mut scanned = HashSet::new();
165+
let mut scanned = FnvHashSet();
166166
while !self.worklist.is_empty() {
167167
let id = self.worklist.pop().unwrap();
168168
if scanned.contains(&id) {
@@ -395,7 +395,7 @@ fn create_and_seed_worklist<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
395395
fn find_live<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
396396
access_levels: &privacy::AccessLevels,
397397
krate: &hir::Crate)
398-
-> Box<HashSet<ast::NodeId>> {
398+
-> Box<FnvHashSet<ast::NodeId>> {
399399
let worklist = create_and_seed_worklist(tcx, access_levels, krate);
400400
let mut symbol_visitor = MarkSymbolVisitor::new(tcx, worklist);
401401
symbol_visitor.mark_live_symbols();
@@ -413,7 +413,7 @@ fn get_struct_ctor_id(item: &hir::Item) -> Option<ast::NodeId> {
413413

414414
struct DeadVisitor<'a, 'tcx: 'a> {
415415
tcx: TyCtxt<'a, 'tcx, 'tcx>,
416-
live_symbols: Box<HashSet<ast::NodeId>>,
416+
live_symbols: Box<FnvHashSet<ast::NodeId>>,
417417
}
418418

419419
impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {

src/librustc/middle/reachable.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ use hir::def_id::DefId;
2222
use ty::{self, TyCtxt};
2323
use middle::privacy;
2424
use session::config;
25-
use util::nodemap::NodeSet;
25+
use util::nodemap::{NodeSet, FnvHashSet};
2626

27-
use std::collections::HashSet;
2827
use syntax::abi::Abi;
2928
use syntax::ast;
3029
use syntax::attr;
@@ -204,7 +203,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
204203

205204
// Step 2: Mark all symbols that the symbols on the worklist touch.
206205
fn propagate(&mut self) {
207-
let mut scanned = HashSet::new();
206+
let mut scanned = FnvHashSet();
208207
loop {
209208
let search_item = match self.worklist.pop() {
210209
Some(item) => item,

src/librustc_metadata/encoder.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,13 @@ fn encode_xrefs<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
862862
xrefs: FnvHashMap<XRef<'tcx>, u32>)
863863
{
864864
let mut xref_positions = vec![0; xrefs.len()];
865+
866+
// Encode XRefs sorted by their ID
867+
let mut sorted_xrefs: Vec<_> = xrefs.into_iter().collect();
868+
sorted_xrefs.sort_by_key(|&(_, id)| id);
869+
865870
rbml_w.start_tag(tag_xref_data);
866-
for (xref, id) in xrefs.into_iter() {
871+
for (xref, id) in sorted_xrefs.into_iter() {
867872
xref_positions[id as usize] = rbml_w.mark_stable_position() as u32;
868873
match xref {
869874
XRef::Predicate(p) => {

src/librustc_metadata/loader.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ use rustc::session::Session;
221221
use rustc::session::filesearch::{FileSearch, FileMatches, FileDoesntMatch};
222222
use rustc::session::search_paths::PathKind;
223223
use rustc::util::common;
224+
use rustc::util::nodemap::FnvHashMap;
224225

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

232233
use std::cmp;
233-
use std::collections::HashMap;
234234
use std::fmt;
235235
use std::fs;
236236
use std::io;
@@ -413,7 +413,7 @@ impl<'a> Context<'a> {
413413
let rlib_prefix = format!("lib{}", self.crate_name);
414414
let staticlib_prefix = format!("{}{}", staticpair.0, self.crate_name);
415415

416-
let mut candidates = HashMap::new();
416+
let mut candidates = FnvHashMap();
417417
let mut staticlibs = vec!();
418418

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

457457
let hash_str = hash.to_string();
458458
let slot = candidates.entry(hash_str)
459-
.or_insert_with(|| (HashMap::new(), HashMap::new()));
459+
.or_insert_with(|| (FnvHashMap(), FnvHashMap()));
460460
let (ref mut rlibs, ref mut dylibs) = *slot;
461461
fs::canonicalize(path).map(|p| {
462462
if rlib {
@@ -477,7 +477,7 @@ impl<'a> Context<'a> {
477477
// A Library candidate is created if the metadata for the set of
478478
// libraries corresponds to the crate id and hash criteria that this
479479
// search is being performed for.
480-
let mut libraries = HashMap::new();
480+
let mut libraries = FnvHashMap();
481481
for (_hash, (rlibs, dylibs)) in candidates {
482482
let mut slot = None;
483483
let rlib = self.extract_one(rlibs, CrateFlavor::Rlib, &mut slot);
@@ -527,7 +527,7 @@ impl<'a> Context<'a> {
527527
// read the metadata from it if `*slot` is `None`. If the metadata couldn't
528528
// be read, it is assumed that the file isn't a valid rust library (no
529529
// errors are emitted).
530-
fn extract_one(&mut self, m: HashMap<PathBuf, PathKind>, flavor: CrateFlavor,
530+
fn extract_one(&mut self, m: FnvHashMap<PathBuf, PathKind>, flavor: CrateFlavor,
531531
slot: &mut Option<(Svh, MetadataBlob)>) -> Option<(PathBuf, PathKind)> {
532532
let mut ret: Option<(PathBuf, PathKind)> = None;
533533
let mut error = 0;
@@ -669,8 +669,8 @@ impl<'a> Context<'a> {
669669
// rlibs/dylibs.
670670
let sess = self.sess;
671671
let dylibname = self.dylibname();
672-
let mut rlibs = HashMap::new();
673-
let mut dylibs = HashMap::new();
672+
let mut rlibs = FnvHashMap();
673+
let mut dylibs = FnvHashMap();
674674
{
675675
let locs = locs.map(|l| PathBuf::from(l)).filter(|loc| {
676676
if !loc.exists() {

src/librustc_metadata/macro_import.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use creader::CrateReader;
1414
use cstore::CStore;
1515

1616
use rustc::session::Session;
17+
use rustc::util::nodemap::{FnvHashSet, FnvHashMap};
1718

18-
use std::collections::{HashSet, HashMap};
1919
use syntax::parse::token;
2020
use syntax::ast;
2121
use syntax::attr;
@@ -45,13 +45,13 @@ pub fn call_bad_macro_reexport(a: &Session, b: Span) {
4545
span_err!(a, b, E0467, "bad macro reexport");
4646
}
4747

48-
pub type MacroSelection = HashMap<token::InternedString, Span>;
48+
pub type MacroSelection = FnvHashMap<token::InternedString, Span>;
4949

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

5656
for attr in &extern_crate.attrs {
5757
let mut used = true;
@@ -120,7 +120,7 @@ impl<'a> MacroLoader<'a> {
120120
}
121121

122122
let mut macros = Vec::new();
123-
let mut seen = HashSet::new();
123+
let mut seen = FnvHashSet();
124124

125125
for mut def in self.reader.read_exported_macros(vi) {
126126
let name = def.ident.name.as_str();

src/librustc_resolve/assign_ids.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
use Resolver;
1212
use rustc::session::Session;
13+
use rustc::util::nodemap::FnvHashMap;
1314
use syntax::ast;
1415
use syntax::ext::hygiene::Mark;
1516
use syntax::fold::{self, Folder};
1617
use syntax::ptr::P;
1718
use syntax::util::move_map::MoveMap;
1819
use syntax::util::small_vector::SmallVector;
1920

20-
use std::collections::HashMap;
2121
use std::mem;
2222

2323
impl<'a> Resolver<'a> {
@@ -31,7 +31,7 @@ impl<'a> Resolver<'a> {
3131

3232
struct NodeIdAssigner<'a> {
3333
sess: &'a Session,
34-
macros_at_scope: &'a mut HashMap<ast::NodeId, Vec<Mark>>,
34+
macros_at_scope: &'a mut FnvHashMap<ast::NodeId, Vec<Mark>>,
3535
}
3636

3737
impl<'a> Folder for NodeIdAssigner<'a> {

0 commit comments

Comments
 (0)