diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-03-26 12:31:41 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-03-27 08:20:06 +0000 |
| commit | 0f5911c62647601cbe6c81e935615a770e7fc3ff (patch) | |
| tree | 5d81c8fdd91c74508104227a38462fc415b44a08 /compiler | |
| parent | 32bd3c30d8d4d5909b9bafd4c7b554f46b58d9ab (diff) | |
| download | rust-0f5911c62647601cbe6c81e935615a770e7fc3ff.tar.gz rust-0f5911c62647601cbe6c81e935615a770e7fc3ff.zip | |
Move `CrateStore::expn_hash_to_expn_id` to a hook
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/hooks/mod.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/query/on_disk_cache.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_session/src/cstore.rs | 9 |
4 files changed, 13 insertions, 27 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 187364d8b44..1720a4642c5 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -21,7 +21,7 @@ use rustc_middle::ty::{self, TyCtxt}; 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 @@ impl CrateStore for CStore { 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); diff --git a/compiler/rustc_middle/src/hooks/mod.rs b/compiler/rustc_middle/src/hooks/mod.rs index b5267e42780..b0f08334c54 100644 --- a/compiler/rustc_middle/src/hooks/mod.rs +++ b/compiler/rustc_middle/src/hooks/mod.rs @@ -7,7 +7,7 @@ use crate::mir; 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 @@ declare_hooks! { /// 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; } diff --git a/compiler/rustc_middle/src/query/on_disk_cache.rs b/compiler/rustc_middle/src/query/on_disk_cache.rs index 06c5440849e..58df950ff16 100644 --- a/compiler/rustc_middle/src/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/query/on_disk_cache.rs @@ -632,12 +632,7 @@ impl<'a, 'tcx> SpanDecoder for CacheDecoder<'a, 'tcx> { 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); diff --git a/compiler/rustc_session/src/cstore.rs b/compiler/rustc_session/src/cstore.rs index 4e59cd09ec4..affd1c9df48 100644 --- a/compiler/rustc_session/src/cstore.rs +++ b/compiler/rustc_session/src/cstore.rs @@ -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; |
