From ce21756ed3acdd6bb4c222725214c24e1bc70915 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 2 Oct 2021 17:35:27 +0200 Subject: Access Session while decoding expn_id. --- compiler/rustc_query_impl/src/on_disk_cache.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_query_impl/src/on_disk_cache.rs') diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index d8cff0bd188..f93623e445c 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -667,7 +667,12 @@ impl<'a, 'tcx> Decodable> for ExpnId { rustc_span::hygiene::register_local_expn_id(data, hash) } else { let index_guess = decoder.foreign_expn_data[&hash]; - decoder.tcx.cstore_untracked().expn_hash_to_expn_id(krate, index_guess, hash) + decoder.tcx.cstore_untracked().expn_hash_to_expn_id( + decoder.tcx.sess, + krate, + index_guess, + hash, + ) }; #[cfg(debug_assertions)] -- cgit 1.4.1-3-g733a5 From daf8903e8ed1f4704077e02479f841b84ebc82d3 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 2 Oct 2021 21:14:52 +0200 Subject: Do not re-hash foreign spans. --- compiler/rustc_query_impl/src/on_disk_cache.rs | 27 +++++++++++++++----------- src/test/incremental/mir-opt.rs | 11 +++++++++++ 2 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 src/test/incremental/mir-opt.rs (limited to 'compiler/rustc_query_impl/src/on_disk_cache.rs') diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index f93623e445c..48eb488792d 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -664,7 +664,21 @@ impl<'a, 'tcx> Decodable> for ExpnId { let data: ExpnData = decoder .with_position(pos.to_usize(), |decoder| decode_tagged(decoder, TAG_EXPN_DATA))?; - rustc_span::hygiene::register_local_expn_id(data, hash) + let expn_id = rustc_span::hygiene::register_local_expn_id(data, hash); + + #[cfg(debug_assertions)] + { + use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; + let mut hcx = decoder.tcx.create_stable_hashing_context(); + let mut hasher = StableHasher::new(); + hcx.while_hashing_spans(true, |hcx| { + expn_id.expn_data().hash_stable(hcx, &mut hasher) + }); + let local_hash: u64 = hasher.finish(); + debug_assert_eq!(hash.local_hash(), local_hash); + } + + expn_id } else { let index_guess = decoder.foreign_expn_data[&hash]; decoder.tcx.cstore_untracked().expn_hash_to_expn_id( @@ -675,16 +689,7 @@ impl<'a, 'tcx> Decodable> for ExpnId { ) }; - #[cfg(debug_assertions)] - { - use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; - let mut hcx = decoder.tcx.create_stable_hashing_context(); - let mut hasher = StableHasher::new(); - hcx.while_hashing_spans(true, |hcx| expn_id.expn_data().hash_stable(hcx, &mut hasher)); - let local_hash: u64 = hasher.finish(); - debug_assert_eq!(hash.local_hash(), local_hash); - } - + debug_assert_eq!(expn_id.krate, krate); Ok(expn_id) } } diff --git a/src/test/incremental/mir-opt.rs b/src/test/incremental/mir-opt.rs new file mode 100644 index 00000000000..5bd863439df --- /dev/null +++ b/src/test/incremental/mir-opt.rs @@ -0,0 +1,11 @@ +// MIR optimizations can create expansions after the TyCtxt has been created. +// This test verifies that those expansions can be decoded correctly. + +// revisions:rpass1 rpass2 +// compile-flags: -Z query-dep-graph -Z mir-opt-level=3 + +fn main() { + if std::env::var("a").is_ok() { + println!("b"); + } +} -- cgit 1.4.1-3-g733a5