Skip to content

Commit 6f782c4

Browse files
committed
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.
1 parent fb5ced0 commit 6f782c4

File tree

1 file changed

+13
-13
lines changed
  • compiler/rustc_middle/src/hir/map

1 file changed

+13
-13
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -969,22 +969,12 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
969969
.iter_enumerated()
970970
.filter_map(|(def_id, hod)| {
971971
let def_path_hash = tcx.untracked_resolutions.definitions.def_path_hash(def_id);
972-
let mut hasher = StableHasher::new();
973-
hod.as_ref()?.hash_stable(&mut hcx, &mut hasher);
974-
AttributeMap { map: &tcx.untracked_crate.attrs, prefix: def_id }
975-
.hash_stable(&mut hcx, &mut hasher);
976-
Some((def_path_hash, hasher.finish()))
972+
let hash = hod.as_ref()?.hash;
973+
Some((def_path_hash, hash, def_id))
977974
})
978975
.collect();
979976
hir_body_nodes.sort_unstable_by_key(|bn| bn.0);
980977

981-
let node_hashes = hir_body_nodes.iter().fold(
982-
Fingerprint::ZERO,
983-
|combined_fingerprint, &(def_path_hash, fingerprint)| {
984-
combined_fingerprint.combine(def_path_hash.0.combine(fingerprint))
985-
},
986-
);
987-
988978
let upstream_crates = upstream_crates(tcx);
989979

990980
// 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 {
1004994
source_file_names.sort_unstable();
1005995

1006996
let mut stable_hasher = StableHasher::new();
1007-
node_hashes.hash_stable(&mut hcx, &mut stable_hasher);
997+
for (def_path_hash, fingerprint, def_id) in hir_body_nodes.iter() {
998+
def_path_hash.0.hash_stable(&mut hcx, &mut stable_hasher);
999+
fingerprint.hash_stable(&mut hcx, &mut stable_hasher);
1000+
AttributeMap { map: &tcx.untracked_crate.attrs, prefix: *def_id }
1001+
.hash_stable(&mut hcx, &mut stable_hasher);
1002+
if tcx.sess.opts.debugging_opts.incremental_relative_spans {
1003+
let span = tcx.untracked_resolutions.definitions.def_span(*def_id);
1004+
debug_assert_eq!(span.parent(), None);
1005+
span.hash_stable(&mut hcx, &mut stable_hasher);
1006+
}
1007+
}
10081008
upstream_crates.hash_stable(&mut hcx, &mut stable_hasher);
10091009
source_file_names.hash_stable(&mut hcx, &mut stable_hasher);
10101010
tcx.sess.opts.dep_tracking_hash(true).hash_stable(&mut hcx, &mut stable_hasher);

0 commit comments

Comments
 (0)