Skip to content

Commit

Permalink
Move CrateStore::expn_hash_to_expn_id to a hook
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Mar 27, 2024
1 parent 32bd3c3 commit 0f5911c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
16 changes: 5 additions & 11 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_middle/src/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;)*) => {
Expand Down Expand Up @@ -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;
}
7 changes: 1 addition & 6 deletions compiler/rustc_middle/src/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_session/src/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0f5911c

Please sign in to comment.