Rollup merge of #48162 - michaelwoerister:stabler-svh, r=nikomatsakis

Handle path prefix mapping in a more stable way when computing the crate hash

This hopefully fixes issue https://github.com/rust-lang/rust/issues/48019.

cc @luser @infinity0
This commit is contained in:
kennytm 2018-02-14 16:14:43 +08:00
commit d38e11ee10
No known key found for this signature in database
GPG key ID: FEF6C8051D0E013C
3 changed files with 22 additions and 5 deletions

View file

@ -9,14 +9,15 @@
// except according to those terms.
use super::*;
use dep_graph::{DepGraph, DepKind, DepNodeIndex};
use hir::def_id::{LOCAL_CRATE, CrateNum};
use hir::intravisit::{Visitor, NestedVisitorMap};
use hir::svh::Svh;
use middle::cstore::CrateStore;
use session::CrateDisambiguator;
use std::iter::repeat;
use syntax::ast::{NodeId, CRATE_NODE_ID};
use syntax::codemap::CodeMap;
use syntax_pos::Span;
use ich::StableHashingContext;
@ -123,6 +124,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
pub(super) fn finalize_and_compute_crate_hash(self,
crate_disambiguator: CrateDisambiguator,
cstore: &CrateStore,
codemap: &CodeMap,
commandline_args_hash: u64)
-> (Vec<MapEntry<'hir>>, Svh) {
let mut node_hashes: Vec<_> = self
@ -147,11 +149,25 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
(name1, dis1).cmp(&(name2, dis2))
});
// We hash the final, remapped names of all local source files so we
// don't have to include the path prefix remapping commandline args.
// If we included the full mapping in the SVH, we could only have
// reproducible builds by compiling from the same directory. So we just
// hash the result of the mapping instead of the mapping itself.
let mut source_file_names: Vec<_> = codemap
.files()
.iter()
.filter(|filemap| CrateNum::from_u32(filemap.crate_of_origin) == LOCAL_CRATE)
.map(|filemap| filemap.name_hash)
.collect();
source_file_names.sort_unstable();
let (_, crate_dep_node_index) = self
.dep_graph
.with_task(DepNode::new_no_params(DepKind::Krate),
&self.hcx,
((node_hashes, upstream_crates),
(((node_hashes, upstream_crates), source_file_names),
(commandline_args_hash,
crate_disambiguator.to_fingerprint())),
identity_fn);

View file

@ -1065,6 +1065,7 @@ pub fn map_crate<'hir>(sess: &::session::Session,
let cmdline_args = sess.opts.dep_tracking_hash();
collector.finalize_and_compute_crate_hash(crate_disambiguator,
cstore,
sess.codemap(),
cmdline_args)
};

View file

@ -1269,9 +1269,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"set the optimization fuel quota for a crate"),
print_fuel: Option<String> = (None, parse_opt_string, [TRACKED],
"make Rustc print the total optimization fuel used by a crate"),
remap_path_prefix_from: Vec<PathBuf> = (vec![], parse_pathbuf_push, [TRACKED],
remap_path_prefix_from: Vec<PathBuf> = (vec![], parse_pathbuf_push, [UNTRACKED],
"add a source pattern to the file path remapping config"),
remap_path_prefix_to: Vec<PathBuf> = (vec![], parse_pathbuf_push, [TRACKED],
remap_path_prefix_to: Vec<PathBuf> = (vec![], parse_pathbuf_push, [UNTRACKED],
"add a mapping target to the file path remapping config"),
force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
"force all crates to be `rustc_private` unstable"),
@ -1719,7 +1719,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
}
let remap_path_prefix_sources = debugging_opts.remap_path_prefix_from.len();
let remap_path_prefix_targets = debugging_opts.remap_path_prefix_from.len();
let remap_path_prefix_targets = debugging_opts.remap_path_prefix_to.len();
if remap_path_prefix_targets < remap_path_prefix_sources {
for source in &debugging_opts.remap_path_prefix_from[remap_path_prefix_targets..] {