Start replacing CStore
trait methods with hooks.
This also avoids the cyclic definition issues with CrateStore being defined after TyCtxt, but needing to be used in TyCtxt.
This commit is contained in:
parent
b13a71a2e7
commit
32bd3c30d8
4 changed files with 20 additions and 19 deletions
|
@ -378,6 +378,7 @@ provide! { tcx, def_id, other, cdata,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
pub(in crate::rmeta) fn provide(providers: &mut Providers) {
|
||||||
|
provide_cstore_hooks(providers);
|
||||||
// FIXME(#44234) - almost all of these queries have no sub-queries and
|
// FIXME(#44234) - almost all of these queries have no sub-queries and
|
||||||
// therefore no actual inputs, they're just reading tables calculated in
|
// therefore no actual inputs, they're just reading tables calculated in
|
||||||
// resolve! Does this work? Unsure! That's what the issue is about
|
// resolve! Does this work? Unsure! That's what the issue is about
|
||||||
|
@ -664,11 +665,14 @@ impl CrateStore for CStore {
|
||||||
) -> ExpnId {
|
) -> ExpnId {
|
||||||
self.get_crate_data(cnum).expn_hash_to_expn_id(sess, index_guess, hash)
|
self.get_crate_data(cnum).expn_hash_to_expn_id(sess, index_guess, hash)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fn import_source_files(&self, sess: &Session, cnum: CrateNum) {
|
|
||||||
let cdata = self.get_crate_data(cnum);
|
fn provide_cstore_hooks(providers: &mut Providers) {
|
||||||
for file_index in 0..cdata.root.source_map.size() {
|
providers.hooks.import_source_files = |tcx, cnum| {
|
||||||
cdata.imported_source_file(file_index as u32, sess);
|
let cstore = CStore::from_tcx(tcx.tcx);
|
||||||
}
|
let cdata = cstore.get_crate_data(cnum);
|
||||||
}
|
for file_index in 0..cdata.root.source_map.size() {
|
||||||
|
cdata.imported_source_file(file_index as u32, tcx.sess);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
use crate::mir;
|
use crate::mir;
|
||||||
use crate::query::TyCtxtAt;
|
use crate::query::TyCtxtAt;
|
||||||
use crate::ty::{Ty, TyCtxt};
|
use crate::ty::{Ty, TyCtxt};
|
||||||
use rustc_span::def_id::LocalDefId;
|
use rustc_span::def_id::{CrateNum, LocalDefId};
|
||||||
use rustc_span::DUMMY_SP;
|
use rustc_span::DUMMY_SP;
|
||||||
|
|
||||||
macro_rules! declare_hooks {
|
macro_rules! declare_hooks {
|
||||||
|
@ -16,7 +16,6 @@ macro_rules! declare_hooks {
|
||||||
$(
|
$(
|
||||||
$(#[$attr])*
|
$(#[$attr])*
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
|
||||||
pub fn $name(self, $($arg: $K,)*) -> $V
|
pub fn $name(self, $($arg: $K,)*) -> $V
|
||||||
{
|
{
|
||||||
self.at(DUMMY_SP).$name($($arg,)*)
|
self.at(DUMMY_SP).$name($($arg,)*)
|
||||||
|
@ -28,7 +27,6 @@ macro_rules! declare_hooks {
|
||||||
$(
|
$(
|
||||||
$(#[$attr])*
|
$(#[$attr])*
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
|
||||||
#[instrument(level = "debug", skip(self), ret)]
|
#[instrument(level = "debug", skip(self), ret)]
|
||||||
pub fn $name(self, $($arg: $K,)*) -> $V
|
pub fn $name(self, $($arg: $K,)*) -> $V
|
||||||
{
|
{
|
||||||
|
@ -83,4 +81,11 @@ declare_hooks! {
|
||||||
/// You do not want to call this yourself, instead use the cached version
|
/// You do not want to call this yourself, instead use the cached version
|
||||||
/// via `mir_built`
|
/// via `mir_built`
|
||||||
hook build_mir(key: LocalDefId) -> mir::Body<'tcx>;
|
hook build_mir(key: LocalDefId) -> mir::Body<'tcx>;
|
||||||
|
|
||||||
|
|
||||||
|
/// Imports all `SourceFile`s from the given crate into the current session.
|
||||||
|
/// This normally happens automatically when we decode a `Span` from
|
||||||
|
/// 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) -> ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -492,9 +492,7 @@ impl<'a, 'tcx> CacheDecoder<'a, 'tcx> {
|
||||||
// expansion, so we use `import_source_files` to ensure that the foreign
|
// expansion, so we use `import_source_files` to ensure that the foreign
|
||||||
// source files are actually imported before we call `source_file_by_stable_id`.
|
// source files are actually imported before we call `source_file_by_stable_id`.
|
||||||
if source_file_cnum != LOCAL_CRATE {
|
if source_file_cnum != LOCAL_CRATE {
|
||||||
self.tcx
|
self.tcx.import_source_files(source_file_cnum);
|
||||||
.cstore_untracked()
|
|
||||||
.import_source_files(self.tcx.sess, source_file_cnum);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
source_map
|
source_map
|
||||||
|
|
|
@ -230,12 +230,6 @@ pub trait CrateStore: std::fmt::Debug {
|
||||||
index_guess: u32,
|
index_guess: u32,
|
||||||
hash: ExpnHash,
|
hash: ExpnHash,
|
||||||
) -> ExpnId;
|
) -> ExpnId;
|
||||||
|
|
||||||
/// Imports all `SourceFile`s from the given crate into the current session.
|
|
||||||
/// This normally happens automatically when we decode a `Span` from
|
|
||||||
/// that crate's metadata - however, the incr comp cache needs
|
|
||||||
/// to trigger this manually when decoding a foreign `Span`
|
|
||||||
fn import_source_files(&self, sess: &Session, cnum: CrateNum);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type CrateStoreDyn = dyn CrateStore + sync::DynSync + sync::DynSend;
|
pub type CrateStoreDyn = dyn CrateStore + sync::DynSync + sync::DynSend;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue