Skip to content

Commit daf8903

Browse files
committed
Do not re-hash foreign spans.
1 parent ce21756 commit daf8903

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

compiler/rustc_query_impl/src/on_disk_cache.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,21 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for ExpnId {
664664

665665
let data: ExpnData = decoder
666666
.with_position(pos.to_usize(), |decoder| decode_tagged(decoder, TAG_EXPN_DATA))?;
667-
rustc_span::hygiene::register_local_expn_id(data, hash)
667+
let expn_id = rustc_span::hygiene::register_local_expn_id(data, hash);
668+
669+
#[cfg(debug_assertions)]
670+
{
671+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
672+
let mut hcx = decoder.tcx.create_stable_hashing_context();
673+
let mut hasher = StableHasher::new();
674+
hcx.while_hashing_spans(true, |hcx| {
675+
expn_id.expn_data().hash_stable(hcx, &mut hasher)
676+
});
677+
let local_hash: u64 = hasher.finish();
678+
debug_assert_eq!(hash.local_hash(), local_hash);
679+
}
680+
681+
expn_id
668682
} else {
669683
let index_guess = decoder.foreign_expn_data[&hash];
670684
decoder.tcx.cstore_untracked().expn_hash_to_expn_id(
@@ -675,16 +689,7 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for ExpnId {
675689
)
676690
};
677691

678-
#[cfg(debug_assertions)]
679-
{
680-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
681-
let mut hcx = decoder.tcx.create_stable_hashing_context();
682-
let mut hasher = StableHasher::new();
683-
hcx.while_hashing_spans(true, |hcx| expn_id.expn_data().hash_stable(hcx, &mut hasher));
684-
let local_hash: u64 = hasher.finish();
685-
debug_assert_eq!(hash.local_hash(), local_hash);
686-
}
687-
692+
debug_assert_eq!(expn_id.krate, krate);
688693
Ok(expn_id)
689694
}
690695
}

src/test/incremental/mir-opt.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// MIR optimizations can create expansions after the TyCtxt has been created.
2+
// This test verifies that those expansions can be decoded correctly.
3+
4+
// revisions:rpass1 rpass2
5+
// compile-flags: -Z query-dep-graph -Z mir-opt-level=3
6+
7+
fn main() {
8+
if std::env::var("a").is_ok() {
9+
println!("b");
10+
}
11+
}

0 commit comments

Comments
 (0)