Skip to content

Commit 814a560

Browse files
committed
Auto merge of rust-lang#84233 - jyn514:track-path-prefix, r=michaelwoerister
Add TRACKED_NO_CRATE_HASH and use it for `--remap-path-prefix` I verified locally that this fixes rust-lang#66955. r? `@Aaron1011` (feel free to reassign)
2 parents 10a51c0 + 5a692a7 commit 814a560

File tree

10 files changed

+251
-184
lines changed

10 files changed

+251
-184
lines changed

compiler/rustc_incremental/src/persist/load.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
104104
// Fortunately, we just checked that this isn't the case.
105105
let path = dep_graph_path_from(&sess.incr_comp_session_dir());
106106
let report_incremental_info = sess.opts.debugging_opts.incremental_info;
107-
let expected_hash = sess.opts.dep_tracking_hash();
107+
let expected_hash = sess.opts.dep_tracking_hash(false);
108108

109109
let mut prev_work_products = FxHashMap::default();
110110
let nightly_build = sess.is_nightly_build();

compiler/rustc_incremental/src/persist/save.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub fn build_dep_graph(
219219
}
220220

221221
// First encode the commandline arguments hash
222-
if let Err(err) = sess.opts.dep_tracking_hash().encode(&mut encoder) {
222+
if let Err(err) = sess.opts.dep_tracking_hash(false).encode(&mut encoder) {
223223
sess.err(&format!(
224224
"failed to write dependency graph hash `{}`: {}",
225225
path_buf.display(),

compiler/rustc_interface/src/tests.rs

+78-65
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_span::symbol::sym;
1919
use rustc_span::SourceFileHashAlgorithm;
2020
use rustc_target::spec::{CodeModel, LinkerFlavor, MergeFunctions, PanicStrategy};
2121
use rustc_target::spec::{RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, TlsModel};
22+
2223
use std::collections::{BTreeMap, BTreeSet};
2324
use std::iter::FromIterator;
2425
use std::num::NonZeroUsize;
@@ -74,6 +75,27 @@ fn mk_map<K: Ord, V>(entries: Vec<(K, V)>) -> BTreeMap<K, V> {
7475
BTreeMap::from_iter(entries.into_iter())
7576
}
7677

78+
fn assert_same_clone(x: &Options) {
79+
assert_eq!(x.dep_tracking_hash(true), x.clone().dep_tracking_hash(true));
80+
assert_eq!(x.dep_tracking_hash(false), x.clone().dep_tracking_hash(false));
81+
}
82+
83+
fn assert_same_hash(x: &Options, y: &Options) {
84+
assert_eq!(x.dep_tracking_hash(true), y.dep_tracking_hash(true));
85+
assert_eq!(x.dep_tracking_hash(false), y.dep_tracking_hash(false));
86+
// Check clone
87+
assert_same_clone(x);
88+
assert_same_clone(y);
89+
}
90+
91+
fn assert_different_hash(x: &Options, y: &Options) {
92+
assert_ne!(x.dep_tracking_hash(true), y.dep_tracking_hash(true));
93+
assert_ne!(x.dep_tracking_hash(false), y.dep_tracking_hash(false));
94+
// Check clone
95+
assert_same_clone(x);
96+
assert_same_clone(y);
97+
}
98+
7799
// When the user supplies --test we should implicitly supply --cfg test
78100
#[test]
79101
fn test_switch_implies_cfg_test() {
@@ -130,14 +152,9 @@ fn test_output_types_tracking_hash_different_paths() {
130152
v2.output_types = OutputTypes::new(&[(OutputType::Exe, Some(PathBuf::from("/some/thing")))]);
131153
v3.output_types = OutputTypes::new(&[(OutputType::Exe, None)]);
132154

133-
assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
134-
assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash());
135-
assert!(v2.dep_tracking_hash() != v3.dep_tracking_hash());
136-
137-
// Check clone
138-
assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
139-
assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
140-
assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
155+
assert_different_hash(&v1, &v2);
156+
assert_different_hash(&v1, &v3);
157+
assert_different_hash(&v2, &v3);
141158
}
142159

143160
#[test]
@@ -155,10 +172,7 @@ fn test_output_types_tracking_hash_different_construction_order() {
155172
(OutputType::Exe, Some(PathBuf::from("./some/thing"))),
156173
]);
157174

158-
assert_eq!(v1.dep_tracking_hash(), v2.dep_tracking_hash());
159-
160-
// Check clone
161-
assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
175+
assert_same_hash(&v1, &v2);
162176
}
163177

164178
#[test]
@@ -182,14 +196,9 @@ fn test_externs_tracking_hash_different_construction_order() {
182196
(String::from("d"), new_public_extern_entry(vec!["f", "e"])),
183197
]));
184198

185-
assert_eq!(v1.dep_tracking_hash(), v2.dep_tracking_hash());
186-
assert_eq!(v1.dep_tracking_hash(), v3.dep_tracking_hash());
187-
assert_eq!(v2.dep_tracking_hash(), v3.dep_tracking_hash());
188-
189-
// Check clone
190-
assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
191-
assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
192-
assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
199+
assert_same_hash(&v1, &v2);
200+
assert_same_hash(&v1, &v3);
201+
assert_same_hash(&v2, &v3);
193202
}
194203

195204
#[test]
@@ -219,14 +228,9 @@ fn test_lints_tracking_hash_different_values() {
219228
(String::from("d"), Level::Deny),
220229
];
221230

222-
assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
223-
assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash());
224-
assert!(v2.dep_tracking_hash() != v3.dep_tracking_hash());
225-
226-
// Check clone
227-
assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
228-
assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
229-
assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
231+
assert_different_hash(&v1, &v2);
232+
assert_different_hash(&v1, &v3);
233+
assert_different_hash(&v2, &v3);
230234
}
231235

232236
#[test]
@@ -248,11 +252,7 @@ fn test_lints_tracking_hash_different_construction_order() {
248252
(String::from("d"), Level::Forbid),
249253
];
250254

251-
assert_eq!(v1.dep_tracking_hash(), v2.dep_tracking_hash());
252-
253-
// Check clone
254-
assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
255-
assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
255+
assert_same_hash(&v1, &v2);
256256
}
257257

258258
#[test]
@@ -292,15 +292,9 @@ fn test_search_paths_tracking_hash_different_order() {
292292
v4.search_paths.push(SearchPath::from_cli_opt("dependency=ghi", JSON));
293293
v4.search_paths.push(SearchPath::from_cli_opt("framework=jkl", JSON));
294294

295-
assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash());
296-
assert!(v1.dep_tracking_hash() == v3.dep_tracking_hash());
297-
assert!(v1.dep_tracking_hash() == v4.dep_tracking_hash());
298-
299-
// Check clone
300-
assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
301-
assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
302-
assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
303-
assert_eq!(v4.dep_tracking_hash(), v4.clone().dep_tracking_hash());
295+
assert_same_hash(&v1, &v2);
296+
assert_same_hash(&v1, &v3);
297+
assert_same_hash(&v1, &v4);
304298
}
305299

306300
#[test]
@@ -338,15 +332,9 @@ fn test_native_libs_tracking_hash_different_values() {
338332
(String::from("c"), None, NativeLibKind::Unspecified),
339333
];
340334

341-
assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
342-
assert!(v1.dep_tracking_hash() != v3.dep_tracking_hash());
343-
assert!(v1.dep_tracking_hash() != v4.dep_tracking_hash());
344-
345-
// Check clone
346-
assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
347-
assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
348-
assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
349-
assert_eq!(v4.dep_tracking_hash(), v4.clone().dep_tracking_hash());
335+
assert_different_hash(&v1, &v2);
336+
assert_different_hash(&v1, &v3);
337+
assert_different_hash(&v1, &v4);
350338
}
351339

352340
#[test]
@@ -374,14 +362,9 @@ fn test_native_libs_tracking_hash_different_order() {
374362
(String::from("b"), None, NativeLibKind::Framework),
375363
];
376364

377-
assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash());
378-
assert!(v1.dep_tracking_hash() == v3.dep_tracking_hash());
379-
assert!(v2.dep_tracking_hash() == v3.dep_tracking_hash());
380-
381-
// Check clone
382-
assert_eq!(v1.dep_tracking_hash(), v1.clone().dep_tracking_hash());
383-
assert_eq!(v2.dep_tracking_hash(), v2.clone().dep_tracking_hash());
384-
assert_eq!(v3.dep_tracking_hash(), v3.clone().dep_tracking_hash());
365+
assert_same_hash(&v1, &v2);
366+
assert_same_hash(&v1, &v3);
367+
assert_same_hash(&v2, &v3);
385368
}
386369

387370
#[test]
@@ -391,8 +374,9 @@ fn test_codegen_options_tracking_hash() {
391374

392375
macro_rules! untracked {
393376
($name: ident, $non_default_value: expr) => {
377+
assert_ne!(opts.cg.$name, $non_default_value);
394378
opts.cg.$name = $non_default_value;
395-
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
379+
assert_same_hash(&reference, &opts);
396380
};
397381
}
398382

@@ -416,8 +400,9 @@ fn test_codegen_options_tracking_hash() {
416400
macro_rules! tracked {
417401
($name: ident, $non_default_value: expr) => {
418402
opts = reference.clone();
403+
assert_ne!(opts.cg.$name, $non_default_value);
419404
opts.cg.$name = $non_default_value;
420-
assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
405+
assert_different_hash(&reference, &opts);
421406
};
422407
}
423408

@@ -454,15 +439,42 @@ fn test_codegen_options_tracking_hash() {
454439
tracked!(target_feature, String::from("all the features, all of them"));
455440
}
456441

442+
#[test]
443+
fn test_top_level_options_tracked_no_crate() {
444+
let reference = Options::default();
445+
let mut opts;
446+
447+
macro_rules! tracked {
448+
($name: ident, $non_default_value: expr) => {
449+
opts = reference.clone();
450+
assert_ne!(opts.$name, $non_default_value);
451+
opts.$name = $non_default_value;
452+
// The crate hash should be the same
453+
assert_eq!(reference.dep_tracking_hash(true), opts.dep_tracking_hash(true));
454+
// The incremental hash should be different
455+
assert_ne!(reference.dep_tracking_hash(false), opts.dep_tracking_hash(false));
456+
};
457+
}
458+
459+
// Make sure that changing a [TRACKED_NO_CRATE_HASH] option leaves the crate hash unchanged but changes the incremental hash.
460+
// This list is in alphabetical order.
461+
tracked!(remap_path_prefix, vec![("/home/bors/rust".into(), "src".into())]);
462+
tracked!(
463+
real_rust_source_base_dir,
464+
Some("/home/bors/rust/.rustup/toolchains/nightly/lib/rustlib/src/rust".into())
465+
);
466+
}
467+
457468
#[test]
458469
fn test_debugging_options_tracking_hash() {
459470
let reference = Options::default();
460471
let mut opts = Options::default();
461472

462473
macro_rules! untracked {
463474
($name: ident, $non_default_value: expr) => {
475+
assert_ne!(opts.debugging_opts.$name, $non_default_value);
464476
opts.debugging_opts.$name = $non_default_value;
465-
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
477+
assert_same_hash(&reference, &opts);
466478
};
467479
}
468480

@@ -471,7 +483,7 @@ fn test_debugging_options_tracking_hash() {
471483
untracked!(ast_json, true);
472484
untracked!(ast_json_noexpand, true);
473485
untracked!(borrowck, String::from("other"));
474-
untracked!(deduplicate_diagnostics, true);
486+
untracked!(deduplicate_diagnostics, false);
475487
untracked!(dep_tasks, true);
476488
untracked!(dont_buffer_diagnostics, true);
477489
untracked!(dump_dep_graph, true);
@@ -515,7 +527,7 @@ fn test_debugging_options_tracking_hash() {
515527
untracked!(self_profile_events, Some(vec![String::new()]));
516528
untracked!(span_debug, true);
517529
untracked!(span_free_formats, true);
518-
untracked!(strip, Strip::None);
530+
untracked!(strip, Strip::Debuginfo);
519531
untracked!(terminal_width, Some(80));
520532
untracked!(threads, 99);
521533
untracked!(time, true);
@@ -532,8 +544,9 @@ fn test_debugging_options_tracking_hash() {
532544
macro_rules! tracked {
533545
($name: ident, $non_default_value: expr) => {
534546
opts = reference.clone();
547+
assert_ne!(opts.debugging_opts.$name, $non_default_value);
535548
opts.debugging_opts.$name = $non_default_value;
536-
assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
549+
assert_different_hash(&reference, &opts);
537550
};
538551
}
539552

compiler/rustc_metadata/src/rmeta/decoder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
16171617
.map(Path::new)
16181618
.filter(|_| {
16191619
// Only spend time on further checks if we have what to translate *to*.
1620-
sess.real_rust_source_base_dir.is_some()
1620+
sess.opts.real_rust_source_base_dir.is_some()
16211621
})
16221622
.filter(|virtual_dir| {
16231623
// Don't translate away `/rustc/$hash` if we're still remapping to it,
@@ -1629,11 +1629,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
16291629
debug!(
16301630
"try_to_translate_virtual_to_real(name={:?}): \
16311631
virtual_rust_source_base_dir={:?}, real_rust_source_base_dir={:?}",
1632-
name, virtual_rust_source_base_dir, sess.real_rust_source_base_dir,
1632+
name, virtual_rust_source_base_dir, sess.opts.real_rust_source_base_dir,
16331633
);
16341634

16351635
if let Some(virtual_dir) = virtual_rust_source_base_dir {
1636-
if let Some(real_dir) = &sess.real_rust_source_base_dir {
1636+
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir {
16371637
if let rustc_span::FileName::Real(old_name) = name {
16381638
if let rustc_span::RealFileName::Named(one_path) = old_name {
16391639
if let Ok(rest) = one_path.strip_prefix(virtual_dir) {

compiler/rustc_middle/src/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx Indexe
943943
intravisit::walk_crate(&mut collector, tcx.untracked_crate);
944944

945945
let crate_disambiguator = tcx.sess.local_crate_disambiguator();
946-
let cmdline_args = tcx.sess.opts.dep_tracking_hash();
946+
let cmdline_args = tcx.sess.opts.dep_tracking_hash(true);
947947
collector.finalize_and_compute_crate_hash(crate_disambiguator, &*tcx.cstore, cmdline_args)
948948
};
949949

0 commit comments

Comments
 (0)