From 6f782c4e114c2913d5f3e8034664852e7b36452a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 2 May 2021 12:16:59 +0200 Subject: [PATCH] Add actual spans to the crate hash. Now that we encode spans relative to the items, the item's own span is never actually hashed as part of the HIR. In consequence, we explicitly include it in the crate hash to avoid missing cross-crate invalidations. --- compiler/rustc_middle/src/hir/map/mod.rs | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index e0b6039fe348..10714a4b706f 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -969,22 +969,12 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { .iter_enumerated() .filter_map(|(def_id, hod)| { let def_path_hash = tcx.untracked_resolutions.definitions.def_path_hash(def_id); - let mut hasher = StableHasher::new(); - hod.as_ref()?.hash_stable(&mut hcx, &mut hasher); - AttributeMap { map: &tcx.untracked_crate.attrs, prefix: def_id } - .hash_stable(&mut hcx, &mut hasher); - Some((def_path_hash, hasher.finish())) + let hash = hod.as_ref()?.hash; + Some((def_path_hash, hash, def_id)) }) .collect(); hir_body_nodes.sort_unstable_by_key(|bn| bn.0); - let node_hashes = hir_body_nodes.iter().fold( - Fingerprint::ZERO, - |combined_fingerprint, &(def_path_hash, fingerprint)| { - combined_fingerprint.combine(def_path_hash.0.combine(fingerprint)) - }, - ); - let upstream_crates = upstream_crates(tcx); // We hash the final, remapped names of all local source files so we @@ -1004,7 +994,17 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { source_file_names.sort_unstable(); let mut stable_hasher = StableHasher::new(); - node_hashes.hash_stable(&mut hcx, &mut stable_hasher); + for (def_path_hash, fingerprint, def_id) in hir_body_nodes.iter() { + def_path_hash.0.hash_stable(&mut hcx, &mut stable_hasher); + fingerprint.hash_stable(&mut hcx, &mut stable_hasher); + AttributeMap { map: &tcx.untracked_crate.attrs, prefix: *def_id } + .hash_stable(&mut hcx, &mut stable_hasher); + if tcx.sess.opts.debugging_opts.incremental_relative_spans { + let span = tcx.untracked_resolutions.definitions.def_span(*def_id); + debug_assert_eq!(span.parent(), None); + span.hash_stable(&mut hcx, &mut stable_hasher); + } + } upstream_crates.hash_stable(&mut hcx, &mut stable_hasher); source_file_names.hash_stable(&mut hcx, &mut stable_hasher); tcx.sess.opts.dep_tracking_hash(true).hash_stable(&mut hcx, &mut stable_hasher);