Move CrateStore::expn_hash_to_expn_id to a hook

This commit is contained in:
Oli Scherer 2024-03-26 12:31:41 +00:00
parent 32bd3c30d8
commit 0f5911c626
4 changed files with 13 additions and 27 deletions

View File

@ -21,7 +21,7 @@
use rustc_middle::util::Providers;
use rustc_session::cstore::{CrateStore, ExternCrate};
use rustc_session::{Session, StableCrateId};
use rustc_span::hygiene::{ExpnHash, ExpnId};
use rustc_span::hygiene::ExpnId;
use rustc_span::symbol::{kw, Symbol};
use rustc_span::Span;
@ -655,19 +655,13 @@ fn def_path_hash_to_def_id(&self, cnum: CrateNum, hash: DefPathHash) -> DefId {
let def_index = self.get_crate_data(cnum).def_path_hash_to_def_index(hash);
DefId { krate: cnum, index: def_index }
}
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)
}
}
fn provide_cstore_hooks(providers: &mut Providers) {
providers.hooks.expn_hash_to_expn_id = |tcx, cnum, index_guess, hash| {
let cstore = CStore::from_tcx(tcx.tcx);
cstore.get_crate_data(cnum).expn_hash_to_expn_id(tcx.sess, index_guess, hash)
};
providers.hooks.import_source_files = |tcx, cnum| {
let cstore = CStore::from_tcx(tcx.tcx);
let cdata = cstore.get_crate_data(cnum);

View File

@ -7,7 +7,7 @@
use crate::query::TyCtxtAt;
use crate::ty::{Ty, TyCtxt};
use rustc_span::def_id::{CrateNum, LocalDefId};
use rustc_span::DUMMY_SP;
use rustc_span::{ExpnHash, ExpnId, DUMMY_SP};
macro_rules! declare_hooks {
($($(#[$attr:meta])*hook $name:ident($($arg:ident: $K:ty),*) -> $V:ty;)*) => {
@ -88,4 +88,10 @@ fn clone(&self) -> Self { *self }
/// that crate's metadata - however, the incr comp cache needs
/// to trigger this manually when decoding a foreign `Span`
hook import_source_files(key: CrateNum) -> ();
hook expn_hash_to_expn_id(
cnum: CrateNum,
index_guess: u32,
hash: ExpnHash
) -> ExpnId;
}

View File

@ -632,12 +632,7 @@ fn decode_expn_id(&mut self) -> ExpnId {
expn_id
} else {
let index_guess = self.foreign_expn_data[&hash];
self.tcx.cstore_untracked().expn_hash_to_expn_id(
self.tcx.sess,
krate,
index_guess,
hash,
)
self.tcx.expn_hash_to_expn_id(krate, index_guess, hash)
};
debug_assert_eq!(expn_id.krate, krate);

View File

@ -4,12 +4,10 @@
use crate::search_paths::PathKind;
use crate::utils::NativeLibKind;
use crate::Session;
use rustc_ast as ast;
use rustc_data_structures::sync::{self, AppendOnlyIndexVec, FreezeLock};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, StableCrateId, LOCAL_CRATE};
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash, Definitions};
use rustc_span::hygiene::{ExpnHash, ExpnId};
use rustc_span::symbol::Symbol;
use rustc_span::Span;
use rustc_target::spec::abi::Abi;
@ -223,13 +221,6 @@ 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,
sess: &Session,
cnum: CrateNum,
index_guess: u32,
hash: ExpnHash,
) -> ExpnId;
}
pub type CrateStoreDyn = dyn CrateStore + sync::DynSync + sync::DynSend;