Access Session while decoding expn_id.

This commit is contained in:
Camille GILLOT 2021-10-02 17:35:27 +02:00
parent 25ec827385
commit ce21756ed3
4 changed files with 24 additions and 6 deletions

View File

@ -1624,7 +1624,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
self.def_path_hash_map.def_path_hash_to_def_index(&hash)
}
fn expn_hash_to_expn_id(&self, index_guess: u32, hash: ExpnHash) -> ExpnId {
fn expn_hash_to_expn_id(&self, sess: &Session, index_guess: u32, hash: ExpnHash) -> ExpnId {
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));
@ -1655,7 +1655,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
map[&hash]
};
let data = self.root.expn_data.get(self, index).unwrap().decode(self);
let data = self.root.expn_data.get(self, index).unwrap().decode((self, sess));
rustc_span::hygiene::register_expn_id(self.cnum, index, data, hash)
}

View File

@ -506,7 +506,13 @@ impl CrateStore for CStore {
DefId { krate: cnum, index: def_index }
}
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)
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)
}
}

View File

@ -667,7 +667,12 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> 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)]

View File

@ -4,6 +4,7 @@
use crate::search_paths::PathKind;
use crate::utils::NativeLibKind;
use crate::Session;
use rustc_ast as ast;
use rustc_data_structures::sync::{self, MetadataRef};
use rustc_hir::def_id::{CrateNum, DefId, StableCrateId, LOCAL_CRATE};
@ -193,7 +194,13 @@ pub trait CrateStore: std::fmt::Debug {
/// Fetch a DefId from a DefPathHash for a foreign crate.
fn def_path_hash_to_def_id(&self, cnum: CrateNum, hash: DefPathHash) -> DefId;
fn expn_hash_to_expn_id(&self, cnum: CrateNum, index_guess: u32, hash: ExpnHash) -> ExpnId;
fn expn_hash_to_expn_id(
&self,
sess: &Session,
cnum: CrateNum,
index_guess: u32,
hash: ExpnHash,
) -> ExpnId;
}
pub type CrateStoreDyn = dyn CrateStore + sync::Sync;