Prevent feeding CRATE_DEF_ID
queries outside the resolver
This commit is contained in:
parent
890dd58650
commit
3845be6b37
3 changed files with 18 additions and 13 deletions
|
@ -8,8 +8,7 @@ use rustc_codegen_ssa::CodegenResults;
|
|||
use rustc_data_structures::steal::Steal;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, OnceLock, WorkerLocal};
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::{StableCrateId, CRATE_DEF_ID, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::Definitions;
|
||||
use rustc_incremental::setup_dep_graph;
|
||||
use rustc_metadata::creader::CStore;
|
||||
|
@ -144,10 +143,8 @@ impl<'tcx> Queries<'tcx> {
|
|||
stable_crate_id,
|
||||
)) as _);
|
||||
let definitions = FreezeLock::new(Definitions::new(stable_crate_id));
|
||||
let source_span = AppendOnlyIndexVec::new();
|
||||
let _id = source_span.push(krate.spans.inner_span);
|
||||
debug_assert_eq!(_id, CRATE_DEF_ID);
|
||||
let untracked = Untracked { cstore, source_span, definitions };
|
||||
let untracked =
|
||||
Untracked { cstore, source_span: AppendOnlyIndexVec::new(), definitions };
|
||||
|
||||
let qcx = passes::create_global_ctxt(
|
||||
self.compiler,
|
||||
|
@ -172,9 +169,6 @@ impl<'tcx> Queries<'tcx> {
|
|||
)));
|
||||
feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs))));
|
||||
feed.output_filenames(Arc::new(outputs));
|
||||
|
||||
let feed = tcx.feed_local_crate_def_id();
|
||||
feed.def_kind(DefKind::Mod);
|
||||
});
|
||||
Ok(qcx)
|
||||
})
|
||||
|
|
|
@ -545,6 +545,10 @@ impl<T: fmt::Debug + Copy> fmt::Debug for Feed<'_, T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Some workarounds to use cases that cannot use `create_def`.
|
||||
/// Do not add new ways to create `TyCtxtFeed` without consulting
|
||||
/// with T-compiler and making an analysis about why your addition
|
||||
/// does not cause incremental compilation issues.
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
pub fn feed_unit_query(self) -> TyCtxtFeed<'tcx, ()> {
|
||||
TyCtxtFeed { tcx: self, key: () }
|
||||
|
@ -553,8 +557,12 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
TyCtxtFeed { tcx: self, key: LOCAL_CRATE }
|
||||
}
|
||||
|
||||
pub fn feed_local_crate_def_id(self) -> TyCtxtFeed<'tcx, LocalDefId> {
|
||||
TyCtxtFeed { tcx: self, key: CRATE_DEF_ID }
|
||||
/// Only used in the resolver to register the `CRATE_DEF_ID` `DefId` and feed
|
||||
/// some queries for it. It will panic if used twice.
|
||||
pub fn create_local_crate_def_id(self, span: Span) -> TyCtxtFeed<'tcx, LocalDefId> {
|
||||
let key = self.untracked().source_span.push(span);
|
||||
assert_eq!(key, CRATE_DEF_ID);
|
||||
TyCtxtFeed { tcx: self, key }
|
||||
}
|
||||
|
||||
/// In order to break cycles involving `AnonConst`, we need to set the expected type by side
|
||||
|
|
|
@ -53,7 +53,7 @@ use rustc_middle::middle::privacy::EffectiveVisibilities;
|
|||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{self, MainDefinition, RegisteredTools, TyCtxt, TyCtxtFeed};
|
||||
use rustc_middle::ty::{ResolverGlobalCtxt, ResolverOutputs, Feed};
|
||||
use rustc_middle::ty::{Feed, ResolverGlobalCtxt, ResolverOutputs};
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
use rustc_session::lint::builtin::PRIVATE_MACRO_USE;
|
||||
use rustc_session::lint::LintBuffer;
|
||||
|
@ -1340,7 +1340,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let mut def_id_to_node_id = IndexVec::default();
|
||||
assert_eq!(def_id_to_node_id.push(CRATE_NODE_ID), CRATE_DEF_ID);
|
||||
let mut node_id_to_def_id = NodeMap::default();
|
||||
let crate_feed = tcx.feed_local_crate_def_id().downgrade();
|
||||
let crate_feed = tcx.create_local_crate_def_id(crate_span);
|
||||
|
||||
crate_feed.def_kind(DefKind::Mod);
|
||||
let crate_feed = crate_feed.downgrade();
|
||||
node_id_to_def_id.insert(CRATE_NODE_ID, crate_feed);
|
||||
|
||||
let mut invocation_parents = FxHashMap::default();
|
||||
|
|
Loading…
Add table
Reference in a new issue