Change:
<!-- Thank you for finding an Internal Compiler Error! If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. --Assuming that you copied to . <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --: <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongBacktrace</strong</summary<p</p</details
I reproduced this ICE locally. On my end I did it by copying the git checkout of into , because I wasn't able to figure out the right invocation to get it setup with files in (Oh, whoops, I think I was accidentally passing instead of . Of course that wasn't going to work.) well, not 100%, my query stack was a little different: but it seemed like a similar bug, nonetheless.
modify labels: +I-prioritize
Assigning as discussed as part of the and removing .
Now happens for when retrying the repro. (with replaced with as it was changed in rustc) <details<summarybacktrace</summary</detailsIt also gives an unstable fingerprint ICE for when compiling : <details<summarybacktrace</summary</details
The compilation now fails when accessing session in : It looks that decodes which in turn decodes which in turn requires access to a session, but by the time of call, the session in no longer threaded through. cc
I can confirm it works now. Pushed to re-enable incremental compilation for compiling the sysroot.

Discussion:
self.def_path_hash_map.def_path_hash_to_def_index(&hash) } <del> fn expn_hash_to_expn_id(&self, index_guess: u32, hash: ExpnHash) -> ExpnId { </del> <ins> fn expn_hash_to_expn_id(&self, sess: &Session, index_guess: u32, hash: ExpnHash) -> ExpnId { </ins> debug_assert_eq!(ExpnId::from_hash(hash), None); let index_guess = ExpnIndex::from_u32(index_guess); let old_hash = self.root.expn_hashes.get(self, index_guess).map(|lazy| lazy.decode(self));

let i = ExpnIndex::from_u32(i); if let Some(hash) = self.root.expn_hashes.get(self, i) { map.insert(hash.decode(self), i); <del> } else { panic!("Missing expn_hash entry for {:?}", i); </del> } } map

map[&hash] }; <del> let data = self.root.expn_data.get(self, index).unwrap().decode(self); </del> <ins> let data = self.root.expn_data.get(self, index).unwrap().decode((self, sess)); </ins> rustc_span::hygiene::register_expn_id(self.cnum, index, data, hash) }

DefId { krate: cnum, index: def_index } } <del> fn expn_hash_to_expn_id(&self, cnum: CrateNum, index_guess: u32, hash: ExpnHash) -> ExpnId { self.get_crate_data(cnum).expn_hash_to_expn_id(index_guess, hash) </del> <ins> fn expn_hash_to_expn_id( &self, sess: &Session, cnum: CrateNum, index_guess: u32, hash: ExpnHash, ) -> ExpnId { self.get_crate_data(cnum).expn_hash_to_expn_id(sess, index_guess, hash) </ins> } }

let data: ExpnData = decoder .with_position(pos.to_usize(), |decoder| decode_tagged(decoder, TAG_EXPN_DATA))?; <del> rustc_span::hygiene::register_local_expn_id(data, hash) </del> <ins> 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 </ins> } else { let index_guess = decoder.foreign_expn_data[&hash]; <del> decoder.tcx.cstore_untracked().expn_hash_to_expn_id(krate, index_guess, hash) </del> <ins> decoder.tcx.cstore_untracked().expn_hash_to_expn_id( decoder.tcx.sess, krate, index_guess, hash, ) </ins> }; <del> #[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); } </del> <ins> debug_assert_eq!(expn_id.krate, krate); </ins> Ok(expn_id) } }

use crate::search_paths::PathKind; use crate::utils::NativeLibKind; <ins> use crate::Session; </ins> use rustc_ast as ast; use rustc_data_structures::sync::{self, MetadataRef}; use rustc_hir::def_id::{CrateNum, DefId, StableCrateId, LOCAL_CRATE};

/// Fetch a DefId from a DefPathHash for a foreign crate. fn def_path_hash_to_def_id(&self, cnum: CrateNum, hash: DefPathHash) -> DefId; <del> fn expn_hash_to_expn_id(&self, cnum: CrateNum, index_guess: u32, hash: ExpnHash) -> ExpnId; </del> <ins> fn expn_hash_to_expn_id( &self, sess: &Session, cnum: CrateNum, index_guess: u32, hash: ExpnHash, ) -> ExpnId; </ins> } pub type CrateStoreDyn = dyn CrateStore + sync::Sync;

<ins> // 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"); } } </ins>