From ae9ce4de4eb66aaf54296b8cf3d69105fcd585ba Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 14 Feb 2024 11:14:14 +0000 Subject: [PATCH] Ensure we only feed def ids via create_def or within eval_always queries --- compiler/rustc_middle/src/ty/context.rs | 9 ++++++++- compiler/rustc_query_system/src/dep_graph/graph.rs | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index bd86c1c284e6e..f6df8430e1756 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -62,7 +62,7 @@ use rustc_session::config::CrateType; use rustc_session::cstore::{CrateStoreDyn, Untracked}; use rustc_session::lint::Lint; use rustc_session::{Limit, MetadataKind, Session}; -use rustc_span::def_id::{DefPathHash, StableCrateId}; +use rustc_span::def_id::{DefPathHash, StableCrateId, CRATE_DEF_ID}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; use rustc_target::abi::{FieldIdx, Layout, LayoutS, TargetDataLayout, VariantIdx}; @@ -522,7 +522,14 @@ impl<'tcx> TyCtxt<'tcx> { pub fn feed_local_crate(self) -> TyCtxtFeed<'tcx, CrateNum> { TyCtxtFeed { tcx: self, key: LOCAL_CRATE } } + + /// Do not use outside the resolver, use `create_def` instead. pub fn feed_local_def_id(self, key: LocalDefId) -> TyCtxtFeed<'tcx, LocalDefId> { + if key != CRATE_DEF_ID { + // Ensure we will re-feed this query by ensuring that the feeding query is + // reexecuted. + self.dep_graph.assert_eval_always(); + } TyCtxtFeed { tcx: self, key } } diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index b6ac54a9ab59b..751ce8d73a153 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -212,6 +212,18 @@ impl DepGraph { } } + pub fn assert_eval_always(&self) { + if let Some(..) = self.data { + D::read_deps(|task_deps| { + assert_matches!( + task_deps, + TaskDepsRef::EvalAlways, + "expected an eval always query" + ); + }) + } + } + pub fn with_ignore(&self, op: OP) -> R where OP: FnOnce() -> R,