Skip to content

Commit 0f5911c

Browse files
committed
Move CrateStore::expn_hash_to_expn_id to a hook
1 parent 32bd3c3 commit 0f5911c

File tree

4 files changed

+13
-27
lines changed

4 files changed

+13
-27
lines changed

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::ty::{self, TyCtxt};
2121
use rustc_middle::util::Providers;
2222
use rustc_session::cstore::{CrateStore, ExternCrate};
2323
use rustc_session::{Session, StableCrateId};
24-
use rustc_span::hygiene::{ExpnHash, ExpnId};
24+
use rustc_span::hygiene::ExpnId;
2525
use rustc_span::symbol::{kw, Symbol};
2626
use rustc_span::Span;
2727

@@ -655,19 +655,13 @@ impl CrateStore for CStore {
655655
let def_index = self.get_crate_data(cnum).def_path_hash_to_def_index(hash);
656656
DefId { krate: cnum, index: def_index }
657657
}
658-
659-
fn expn_hash_to_expn_id(
660-
&self,
661-
sess: &Session,
662-
cnum: CrateNum,
663-
index_guess: u32,
664-
hash: ExpnHash,
665-
) -> ExpnId {
666-
self.get_crate_data(cnum).expn_hash_to_expn_id(sess, index_guess, hash)
667-
}
668658
}
669659

670660
fn provide_cstore_hooks(providers: &mut Providers) {
661+
providers.hooks.expn_hash_to_expn_id = |tcx, cnum, index_guess, hash| {
662+
let cstore = CStore::from_tcx(tcx.tcx);
663+
cstore.get_crate_data(cnum).expn_hash_to_expn_id(tcx.sess, index_guess, hash)
664+
};
671665
providers.hooks.import_source_files = |tcx, cnum| {
672666
let cstore = CStore::from_tcx(tcx.tcx);
673667
let cdata = cstore.get_crate_data(cnum);

compiler/rustc_middle/src/hooks/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::mir;
77
use crate::query::TyCtxtAt;
88
use crate::ty::{Ty, TyCtxt};
99
use rustc_span::def_id::{CrateNum, LocalDefId};
10-
use rustc_span::DUMMY_SP;
10+
use rustc_span::{ExpnHash, ExpnId, DUMMY_SP};
1111

1212
macro_rules! declare_hooks {
1313
($($(#[$attr:meta])*hook $name:ident($($arg:ident: $K:ty),*) -> $V:ty;)*) => {
@@ -88,4 +88,10 @@ declare_hooks! {
8888
/// that crate's metadata - however, the incr comp cache needs
8989
/// to trigger this manually when decoding a foreign `Span`
9090
hook import_source_files(key: CrateNum) -> ();
91+
92+
hook expn_hash_to_expn_id(
93+
cnum: CrateNum,
94+
index_guess: u32,
95+
hash: ExpnHash
96+
) -> ExpnId;
9197
}

compiler/rustc_middle/src/query/on_disk_cache.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,7 @@ impl<'a, 'tcx> SpanDecoder for CacheDecoder<'a, 'tcx> {
632632
expn_id
633633
} else {
634634
let index_guess = self.foreign_expn_data[&hash];
635-
self.tcx.cstore_untracked().expn_hash_to_expn_id(
636-
self.tcx.sess,
637-
krate,
638-
index_guess,
639-
hash,
640-
)
635+
self.tcx.expn_hash_to_expn_id(krate, index_guess, hash)
641636
};
642637

643638
debug_assert_eq!(expn_id.krate, krate);

compiler/rustc_session/src/cstore.rs

-9
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
55
use crate::search_paths::PathKind;
66
use crate::utils::NativeLibKind;
7-
use crate::Session;
87
use rustc_ast as ast;
98
use rustc_data_structures::sync::{self, AppendOnlyIndexVec, FreezeLock};
109
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, StableCrateId, LOCAL_CRATE};
1110
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash, Definitions};
12-
use rustc_span::hygiene::{ExpnHash, ExpnId};
1311
use rustc_span::symbol::Symbol;
1412
use rustc_span::Span;
1513
use rustc_target::spec::abi::Abi;
@@ -223,13 +221,6 @@ pub trait CrateStore: std::fmt::Debug {
223221

224222
/// Fetch a DefId from a DefPathHash for a foreign crate.
225223
fn def_path_hash_to_def_id(&self, cnum: CrateNum, hash: DefPathHash) -> DefId;
226-
fn expn_hash_to_expn_id(
227-
&self,
228-
sess: &Session,
229-
cnum: CrateNum,
230-
index_guess: u32,
231-
hash: ExpnHash,
232-
) -> ExpnId;
233224
}
234225

235226
pub type CrateStoreDyn = dyn CrateStore + sync::DynSync + sync::DynSend;

0 commit comments

Comments
 (0)