Remove DepContext.

It's no longer needed now that we can access `TyCtxt` directly.
This commit is contained in:
Nicholas Nethercote 2026-02-12 11:25:32 +11:00
parent 414be2e6ff
commit 7c877d994b
12 changed files with 138 additions and 207 deletions

View file

@ -13,7 +13,7 @@ use std::fmt;
use rustc_errors::{DiagInner, TRACK_DIAGNOSTIC};
use rustc_middle::dep_graph::dep_node::default_dep_kind_debug;
use rustc_middle::dep_graph::{DepContext, DepKind, DepNode, TaskDepsRef};
use rustc_middle::dep_graph::{DepKind, DepNode, TaskDepsRef};
use rustc_middle::ty::tls;
fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) {

View file

@ -67,7 +67,7 @@ use rustc_macros::{Decodable, Encodable};
use rustc_query_system::ich::StableHashingContext;
use rustc_span::Symbol;
use super::{DepContext, FingerprintStyle, SerializedDepNodeIndex};
use super::{FingerprintStyle, SerializedDepNodeIndex};
use crate::mir::mono::MonoItem;
use crate::ty::TyCtxt;
@ -117,18 +117,14 @@ impl DepNode {
/// Creates a new, parameterless DepNode. This method will assert
/// that the DepNode corresponding to the given DepKind actually
/// does not require any parameters.
pub fn new_no_params<Tcx>(tcx: Tcx, kind: DepKind) -> DepNode
where
Tcx: super::DepContext,
{
pub fn new_no_params<'tcx>(tcx: TyCtxt<'tcx>, kind: DepKind) -> DepNode {
debug_assert_eq!(tcx.fingerprint_style(kind), FingerprintStyle::Unit);
DepNode { kind, hash: Fingerprint::ZERO.into() }
}
pub fn construct<Tcx, Key>(tcx: Tcx, kind: DepKind, arg: &Key) -> DepNode
pub fn construct<'tcx, Key>(tcx: TyCtxt<'tcx>, kind: DepKind, arg: &Key) -> DepNode
where
Tcx: super::DepContext,
Key: DepNodeKey<Tcx>,
Key: DepNodeKey<'tcx>,
{
let hash = arg.to_fingerprint(tcx);
let dep_node = DepNode { kind, hash: hash.into() };
@ -136,10 +132,10 @@ impl DepNode {
#[cfg(debug_assertions)]
{
if !tcx.fingerprint_style(kind).reconstructible()
&& (tcx.sess().opts.unstable_opts.incremental_info
|| tcx.sess().opts.unstable_opts.query_dep_graph)
&& (tcx.sess.opts.unstable_opts.incremental_info
|| tcx.sess.opts.unstable_opts.query_dep_graph)
{
tcx.dep_graph().register_dep_node_debug_str(dep_node, || arg.to_debug_str(tcx));
tcx.dep_graph.register_dep_node_debug_str(dep_node, || arg.to_debug_str(tcx));
}
}
@ -149,10 +145,11 @@ impl DepNode {
/// Construct a DepNode from the given DepKind and DefPathHash. This
/// method will assert that the given DepKind actually requires a
/// single DefId/DefPathHash parameter.
pub fn from_def_path_hash<Tcx>(tcx: Tcx, def_path_hash: DefPathHash, kind: DepKind) -> Self
where
Tcx: super::DepContext,
{
pub fn from_def_path_hash<'tcx>(
tcx: TyCtxt<'tcx>,
def_path_hash: DefPathHash,
kind: DepKind,
) -> Self {
debug_assert!(tcx.fingerprint_style(kind) == FingerprintStyle::DefPathHash);
DepNode { kind, hash: def_path_hash.0.into() }
}
@ -172,14 +169,14 @@ impl fmt::Debug for DepNode {
}
/// Trait for query keys as seen by dependency-node tracking.
pub trait DepNodeKey<Tcx: DepContext>: fmt::Debug + Sized {
pub trait DepNodeKey<'tcx>: fmt::Debug + Sized {
fn fingerprint_style() -> FingerprintStyle;
/// This method turns a query key into an opaque `Fingerprint` to be used
/// in `DepNode`.
fn to_fingerprint(&self, _: Tcx) -> Fingerprint;
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint;
fn to_debug_str(&self, tcx: Tcx) -> String;
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String;
/// This method tries to recover the query key from the given `DepNode`,
/// something which is needed when forcing `DepNode`s during red-green
@ -187,11 +184,11 @@ pub trait DepNodeKey<Tcx: DepContext>: fmt::Debug + Sized {
/// `fingerprint_style()` is not `FingerprintStyle::Opaque`.
/// It is always valid to return `None` here, in which case incremental
/// compilation will treat the query as having changed instead of forcing it.
fn recover(tcx: Tcx, dep_node: &DepNode) -> Option<Self>;
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self>;
}
// Blanket impl of `DepNodeKey`, which is specialized by other impls elsewhere.
impl<Tcx: DepContext, T> DepNodeKey<Tcx> for T
impl<'tcx, T> DepNodeKey<'tcx> for T
where
T: for<'a> HashStable<StableHashingContext<'a>> + fmt::Debug,
{
@ -201,7 +198,7 @@ where
}
#[inline(always)]
default fn to_fingerprint(&self, tcx: Tcx) -> Fingerprint {
default fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
tcx.with_stable_hashing_context(|mut hcx| {
let mut hasher = StableHasher::new();
self.hash_stable(&mut hcx, &mut hasher);
@ -210,7 +207,7 @@ where
}
#[inline(always)]
default fn to_debug_str(&self, tcx: Tcx) -> String {
default fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
// Make sure to print dep node params with reduced queries since printing
// may themselves call queries, which may lead to (possibly untracked!)
// query cycles.
@ -218,7 +215,7 @@ where
}
#[inline(always)]
default fn recover(_: Tcx, _: &DepNode) -> Option<Self> {
default fn recover(_: TyCtxt<'tcx>, _: &DepNode) -> Option<Self> {
None
}
}
@ -228,7 +225,7 @@ where
/// Information is retrieved by indexing the `DEP_KINDS` array using the integer value
/// of the `DepKind`. Overall, this allows to implement `DepContext` using this manual
/// jump table instead of large matches.
pub struct DepKindVTable<Tcx: DepContext> {
pub struct DepKindVTable<'tcx> {
/// Anonymous queries cannot be replayed from one compiler invocation to the next.
/// When their result is needed, it is recomputed. They are useful for fine-grained
/// dependency tracking, and caching within one compiler invocation.
@ -279,11 +276,12 @@ pub struct DepKindVTable<Tcx: DepContext> {
/// with kind `MirValidated`, we know that the GUID/fingerprint of the `DepNode`
/// is actually a `DefPathHash`, and can therefore just look up the corresponding
/// `DefId` in `tcx.def_path_hash_to_def_id`.
pub force_from_dep_node:
Option<fn(tcx: Tcx, dep_node: DepNode, prev_index: SerializedDepNodeIndex) -> bool>,
pub force_from_dep_node: Option<
fn(tcx: TyCtxt<'tcx>, dep_node: DepNode, prev_index: SerializedDepNodeIndex) -> bool,
>,
/// Invoke a query to put the on-disk cached value in memory.
pub try_load_from_on_disk_cache: Option<fn(Tcx, DepNode)>,
pub try_load_from_on_disk_cache: Option<fn(TyCtxt<'tcx>, DepNode)>,
/// The name of this dep kind.
pub name: &'static &'static str,

View file

@ -3,10 +3,10 @@ use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId,
use rustc_hir::definitions::DefPathHash;
use rustc_hir::{HirId, ItemLocalId, OwnerId};
use crate::dep_graph::{DepContext, DepNode, DepNodeKey, FingerprintStyle};
use crate::dep_graph::{DepNode, DepNodeKey, FingerprintStyle};
use crate::ty::TyCtxt;
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for () {
impl<'tcx> DepNodeKey<'tcx> for () {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::Unit
@ -23,7 +23,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for () {
}
}
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for DefId {
impl<'tcx> DepNodeKey<'tcx> for DefId {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::DefPathHash
@ -45,7 +45,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for DefId {
}
}
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for LocalDefId {
impl<'tcx> DepNodeKey<'tcx> for LocalDefId {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::DefPathHash
@ -67,7 +67,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for LocalDefId {
}
}
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for OwnerId {
impl<'tcx> DepNodeKey<'tcx> for OwnerId {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::DefPathHash
@ -89,7 +89,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for OwnerId {
}
}
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for CrateNum {
impl<'tcx> DepNodeKey<'tcx> for CrateNum {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::DefPathHash
@ -112,7 +112,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for CrateNum {
}
}
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for (DefId, DefId) {
impl<'tcx> DepNodeKey<'tcx> for (DefId, DefId) {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::Opaque
@ -139,7 +139,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for (DefId, DefId) {
}
}
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for HirId {
impl<'tcx> DepNodeKey<'tcx> for HirId {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::HirId
@ -182,7 +182,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for HirId {
}
}
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for ModDefId {
impl<'tcx> DepNodeKey<'tcx> for ModDefId {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::DefPathHash
@ -204,7 +204,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for ModDefId {
}
}
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for LocalModDefId {
impl<'tcx> DepNodeKey<'tcx> for LocalModDefId {
#[inline(always)]
fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::DefPathHash

View file

@ -25,7 +25,7 @@ use {super::debug::EdgeFilter, std::env};
use super::query::DepGraphQuery;
use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex};
use super::{DepContext, DepKind, DepNode, DepsType, HasDepContext, WorkProductId};
use super::{DepKind, DepNode, DepsType, HasDepContext, WorkProductId};
use crate::dep_graph::edges::EdgesVec;
use crate::ty::TyCtxt;
use crate::verify_ich::incremental_verify_ich;
@ -62,7 +62,7 @@ impl From<DepNodeIndex> for QueryInvocationId {
}
}
pub struct MarkFrame<'a> {
pub(crate) struct MarkFrame<'a> {
index: SerializedDepNodeIndex,
parent: Option<&'a MarkFrame<'a>>,
}
@ -252,7 +252,7 @@ impl DepGraph {
}
#[inline(always)]
pub fn with_task<Ctxt: HasDepContext, A: Debug, R>(
pub fn with_task<'tcx, Ctxt: HasDepContext<'tcx>, A: Debug, R>(
&self,
key: DepNode,
cx: Ctxt,
@ -266,9 +266,9 @@ impl DepGraph {
}
}
pub fn with_anon_task<Tcx: DepContext, OP, R>(
pub fn with_anon_task<'tcx, OP, R>(
&self,
cx: Tcx,
cx: TyCtxt<'tcx>,
dep_kind: DepKind,
op: OP,
) -> (R, DepNodeIndex)
@ -315,7 +315,7 @@ impl DepGraphData {
///
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html
#[inline(always)]
pub fn with_task<Ctxt: HasDepContext, A: Debug, R>(
pub fn with_task<'tcx, Ctxt: HasDepContext<'tcx>, A: Debug, R>(
&self,
key: DepNode,
cx: Ctxt,
@ -329,7 +329,7 @@ impl DepGraphData {
// 2. Two distinct query keys get mapped to the same `DepNode`
// (see for example #48923).
self.assert_dep_node_not_yet_allocated_in_current_session(
cx.dep_context().sess(),
cx.dep_context().sess,
&key,
|| {
format!(
@ -352,8 +352,8 @@ impl DepGraphData {
(with_deps(TaskDepsRef::Allow(&task_deps)), task_deps.into_inner().reads)
};
let dcx = cx.dep_context();
let dep_node_index = self.hash_result_and_alloc_node(dcx, key, edges, &result, hash_result);
let dep_node_index =
self.hash_result_and_alloc_node(cx.dep_context(), key, edges, &result, hash_result);
(result, dep_node_index)
}
@ -369,9 +369,9 @@ impl DepGraphData {
/// FIXME: This could perhaps return a `WithDepNode` to ensure that the
/// user of this function actually performs the read; we'll have to see
/// how to make that work with `anon` in `execute_job_incr`, though.
pub fn with_anon_task_inner<Tcx: DepContext, OP, R>(
pub fn with_anon_task_inner<'tcx, OP, R>(
&self,
cx: Tcx,
cx: TyCtxt<'tcx>,
dep_kind: DepKind,
op: OP,
) -> (R, DepNodeIndex)
@ -438,17 +438,17 @@ impl DepGraphData {
}
/// Intern the new `DepNode` with the dependencies up-to-now.
fn hash_result_and_alloc_node<Ctxt: DepContext, R>(
fn hash_result_and_alloc_node<'tcx, R>(
&self,
cx: &Ctxt,
tcx: TyCtxt<'tcx>,
node: DepNode,
edges: EdgesVec,
result: &R,
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
) -> DepNodeIndex {
let hashing_timer = cx.profiler().incr_result_hashing();
let hashing_timer = tcx.prof.incr_result_hashing();
let current_fingerprint = hash_result.map(|hash_result| {
cx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result))
tcx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result))
});
let dep_node_index = self.alloc_and_color_node(node, edges, current_fingerprint);
hashing_timer.finish_with_query_invocation_id(dep_node_index.into());
@ -553,10 +553,10 @@ impl DepGraph {
/// FIXME: If the code is changed enough for this node to be marked before requiring the
/// caller's node, we suppose that those changes will be enough to mark this node red and
/// force a recomputation using the "normal" way.
pub fn with_feed_task<Ctxt: DepContext, R>(
pub fn with_feed_task<'tcx, R>(
&self,
node: DepNode,
cx: Ctxt,
tcx: TyCtxt<'tcx>,
result: &R,
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
format_value_fn: fn(&R) -> String,
@ -572,7 +572,7 @@ impl DepGraph {
let dep_node_index = data.colors.current(prev_index);
if let Some(dep_node_index) = dep_node_index {
incremental_verify_ich(
cx,
tcx,
data,
result,
prev_index,
@ -605,7 +605,7 @@ impl DepGraph {
}
});
data.hash_result_and_alloc_node(&cx, node, edges, result, hash_result)
data.hash_result_and_alloc_node(tcx, node, edges, result, hash_result)
} else {
// Incremental compilation is turned off. We just execute the task
// without tracking. We still provide a dep-node index that uniquely
@ -1051,8 +1051,8 @@ impl DepGraph {
///
/// This method will only load queries that will end up in the disk cache.
/// Other queries will not be executed.
pub fn exec_cache_promotions<Tcx: DepContext>(&self, tcx: Tcx) {
let _prof_timer = tcx.profiler().generic_activity("incr_comp_query_cache_promotion");
pub fn exec_cache_promotions<'tcx>(&self, tcx: TyCtxt<'tcx>) {
let _prof_timer = tcx.prof.generic_activity("incr_comp_query_cache_promotion");
let data = self.data.as_ref().unwrap();
for prev_index in data.colors.values.indices() {

View file

@ -1,12 +1,10 @@
use std::panic;
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_query_system::ich::StableHashingContext;
use rustc_session::Session;
use tracing::instrument;
pub use self::dep_node::{
DepKind, DepNode, DepNodeKey, WorkProductId, dep_kind_from_label, dep_kinds, label_strs,
DepKind, DepKindVTable, DepNode, DepNodeKey, WorkProductId, dep_kind_from_label, dep_kinds,
label_strs,
};
pub use self::graph::{
DepGraph, DepGraphData, DepNodeIndex, TaskDepsRef, WorkProduct, WorkProductMap, hash_result,
@ -26,91 +24,18 @@ mod graph;
mod query;
mod serialized;
pub trait DepContext: Copy {
/// Create a hashing context for hashing new results.
fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R;
/// Access the DepGraph.
fn dep_graph(&self) -> &DepGraph;
/// Access the profiler.
fn profiler(&self) -> &SelfProfilerRef;
/// Access the compiler session.
fn sess(&self) -> &Session;
fn dep_kind_vtable(&self, dep_node: DepKind) -> &dep_node::DepKindVTable<Self>;
#[inline(always)]
fn fingerprint_style(self, kind: DepKind) -> FingerprintStyle {
self.dep_kind_vtable(kind).fingerprint_style
}
#[inline(always)]
/// Return whether this kind always require evaluation.
// FIXME: remove this in favour of the version on `TyCtxt`.
fn is_eval_always(self, kind: DepKind) -> bool {
self.dep_kind_vtable(kind).is_eval_always
}
/// Try to force a dep node to execute and see if it's green.
///
/// Returns true if the query has actually been forced. It is valid that a query
/// fails to be forced, e.g. when the query key cannot be reconstructed from the
/// dep-node or when the query kind outright does not support it.
#[inline]
#[instrument(skip(self, frame), level = "debug")]
fn try_force_from_dep_node(
self,
dep_node: DepNode,
prev_index: SerializedDepNodeIndex,
frame: &MarkFrame<'_>,
) -> bool {
if let Some(force_fn) = self.dep_kind_vtable(dep_node.kind).force_from_dep_node {
match panic::catch_unwind(panic::AssertUnwindSafe(|| {
force_fn(self, dep_node, prev_index)
})) {
Err(value) => {
if !value.is::<rustc_errors::FatalErrorMarker>() {
print_markframe_trace(self.dep_graph(), frame);
}
panic::resume_unwind(value)
}
Ok(query_has_been_forced) => query_has_been_forced,
}
} else {
false
}
}
/// Load data from the on-disk cache.
fn try_load_from_on_disk_cache(self, dep_node: &DepNode) {
if let Some(try_load_fn) = self.dep_kind_vtable(dep_node.kind).try_load_from_on_disk_cache {
try_load_fn(self, *dep_node)
}
}
fn with_reduced_queries<T>(self, _: impl FnOnce() -> T) -> T;
pub trait HasDepContext<'tcx>: Copy {
fn dep_context(&self) -> TyCtxt<'tcx>;
}
pub trait HasDepContext: Copy {
type DepContext: self::DepContext;
fn dep_context(&self) -> &Self::DepContext;
}
impl<T: DepContext> HasDepContext for T {
type DepContext = Self;
fn dep_context(&self) -> &Self::DepContext {
self
impl<'tcx> HasDepContext<'tcx> for TyCtxt<'tcx> {
fn dep_context(&self) -> TyCtxt<'tcx> {
*self
}
}
impl<T: HasDepContext, Q: Copy> HasDepContext for (T, Q) {
type DepContext = T::DepContext;
fn dep_context(&self) -> &Self::DepContext {
impl<'tcx, T: HasDepContext<'tcx>, Q: Copy> HasDepContext<'tcx> for (T, Q) {
fn dep_context(&self) -> TyCtxt<'tcx> {
self.0.dep_context()
}
}
@ -143,8 +68,6 @@ impl FingerprintStyle {
}
}
pub type DepKindVTable<'tcx> = dep_node::DepKindVTable<TyCtxt<'tcx>>;
pub struct DepsType;
impl DepsType {
@ -192,33 +115,55 @@ impl DepsType {
const DEP_KIND_MAX: u16 = dep_node::DEP_KIND_VARIANTS - 1;
}
impl<'tcx> DepContext for TyCtxt<'tcx> {
impl<'tcx> TyCtxt<'tcx> {
#[inline]
fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R {
TyCtxt::with_stable_hashing_context(self, f)
}
#[inline]
fn dep_graph(&self) -> &DepGraph {
&self.dep_graph
}
#[inline(always)]
fn profiler(&self) -> &SelfProfilerRef {
&self.prof
}
#[inline(always)]
fn sess(&self) -> &Session {
self.sess
}
#[inline]
fn dep_kind_vtable(&self, dk: DepKind) -> &DepKindVTable<'tcx> {
pub fn dep_kind_vtable(self, dk: DepKind) -> &'tcx DepKindVTable<'tcx> {
&self.dep_kind_vtables[dk.as_usize()]
}
fn with_reduced_queries<T>(self, f: impl FnOnce() -> T) -> T {
with_reduced_queries!(f())
}
#[inline(always)]
pub fn fingerprint_style(self, kind: DepKind) -> FingerprintStyle {
self.dep_kind_vtable(kind).fingerprint_style
}
/// Try to force a dep node to execute and see if it's green.
///
/// Returns true if the query has actually been forced. It is valid that a query
/// fails to be forced, e.g. when the query key cannot be reconstructed from the
/// dep-node or when the query kind outright does not support it.
#[inline]
#[instrument(skip(self, frame), level = "debug")]
fn try_force_from_dep_node(
self,
dep_node: DepNode,
prev_index: SerializedDepNodeIndex,
frame: &MarkFrame<'_>,
) -> bool {
if let Some(force_fn) = self.dep_kind_vtable(dep_node.kind).force_from_dep_node {
match panic::catch_unwind(panic::AssertUnwindSafe(|| {
force_fn(self, dep_node, prev_index)
})) {
Err(value) => {
if !value.is::<rustc_errors::FatalErrorMarker>() {
print_markframe_trace(&self.dep_graph, frame);
}
panic::resume_unwind(value)
}
Ok(query_has_been_forced) => query_has_been_forced,
}
} else {
false
}
}
/// Load data from the on-disk cache.
fn try_load_from_on_disk_cache(self, dep_node: &DepNode) {
if let Some(try_load_fn) = self.dep_kind_vtable(dep_node.kind).try_load_from_on_disk_cache {
try_load_fn(self, *dep_node)
}
}
}

View file

@ -105,7 +105,7 @@ pub(crate) fn query_feed<'tcx, Cache>(
value: Cache::Value,
) where
Cache: QueryCache,
Cache::Key: DepNodeKey<TyCtxt<'tcx>>,
Cache::Key: DepNodeKey<'tcx>,
{
let format_value = query_vtable.format_value;

View file

@ -4,20 +4,19 @@ use rustc_data_structures::fingerprint::Fingerprint;
use rustc_query_system::ich::StableHashingContext;
use tracing::instrument;
use crate::dep_graph::{DepContext, DepGraphData, SerializedDepNodeIndex};
use crate::dep_graph::{DepGraphData, SerializedDepNodeIndex};
use crate::ty::TyCtxt;
#[inline]
#[instrument(skip(tcx, dep_graph_data, result, hash_result, format_value), level = "debug")]
pub fn incremental_verify_ich<Tcx, V>(
tcx: Tcx,
pub fn incremental_verify_ich<'tcx, V>(
tcx: TyCtxt<'tcx>,
dep_graph_data: &DepGraphData,
result: &V,
prev_index: SerializedDepNodeIndex,
hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
format_value: fn(&V) -> String,
) where
Tcx: DepContext,
{
) {
if !dep_graph_data.is_index_green(prev_index) {
incremental_verify_ich_not_green(tcx, prev_index)
}
@ -35,13 +34,10 @@ pub fn incremental_verify_ich<Tcx, V>(
#[cold]
#[inline(never)]
fn incremental_verify_ich_not_green<Tcx>(tcx: Tcx, prev_index: SerializedDepNodeIndex)
where
Tcx: DepContext,
{
fn incremental_verify_ich_not_green<'tcx>(tcx: TyCtxt<'tcx>, prev_index: SerializedDepNodeIndex) {
panic!(
"fingerprint for green query instance not loaded from cache: {:?}",
tcx.dep_graph().data().unwrap().prev_node_of(prev_index)
tcx.dep_graph.data().unwrap().prev_node_of(prev_index)
)
}
@ -50,13 +46,11 @@ where
// chew on (and filling up the final binary, too).
#[cold]
#[inline(never)]
fn incremental_verify_ich_failed<Tcx>(
tcx: Tcx,
fn incremental_verify_ich_failed<'tcx>(
tcx: TyCtxt<'tcx>,
prev_index: SerializedDepNodeIndex,
result: &dyn Fn() -> String,
) where
Tcx: DepContext,
{
) {
// When we emit an error message and panic, we try to debug-print the `DepNode`
// and query result. Unfortunately, this can cause us to run additional queries,
// which may result in another fingerprint mismatch while we're in the middle
@ -70,16 +64,16 @@ fn incremental_verify_ich_failed<Tcx>(
let old_in_panic = INSIDE_VERIFY_PANIC.replace(true);
if old_in_panic {
tcx.sess().dcx().emit_err(crate::error::Reentrant);
tcx.dcx().emit_err(crate::error::Reentrant);
} else {
let run_cmd = if let Some(crate_name) = &tcx.sess().opts.crate_name {
let run_cmd = if let Some(crate_name) = &tcx.sess.opts.crate_name {
format!("`cargo clean -p {crate_name}` or `cargo clean`")
} else {
"`cargo clean`".to_string()
};
let dep_node = tcx.dep_graph().data().unwrap().prev_node_of(prev_index);
tcx.sess().dcx().emit_err(crate::error::IncrementCompilation {
let dep_node = tcx.dep_graph.data().unwrap().prev_node_of(prev_index);
tcx.dcx().emit_err(crate::error::IncrementCompilation {
run_cmd,
dep_node: format!("{dep_node:?}"),
});

View file

@ -1,7 +1,6 @@
use rustc_middle::bug;
use rustc_middle::dep_graph::{DepKindVTable, DepNodeKey, FingerprintStyle};
use rustc_middle::query::QueryCache;
use rustc_middle::ty::TyCtxt;
use crate::plumbing::{force_from_dep_node_inner, try_load_from_on_disk_cache_inner};
use crate::{QueryDispatcherUnerased, QueryFlags};
@ -122,7 +121,7 @@ where
let fingerprint_style = if is_anon {
FingerprintStyle::Opaque
} else {
<Cache::Key as DepNodeKey<TyCtxt<'tcx>>>::fingerprint_style()
<Cache::Key as DepNodeKey<'tcx>>::fingerprint_style()
};
if is_anon || !fingerprint_style.reconstructible() {

View file

@ -14,7 +14,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_middle::verify_ich::incremental_verify_ich;
use rustc_span::{DUMMY_SP, Span};
use crate::dep_graph::{DepContext, DepNode, DepNodeIndex};
use crate::dep_graph::{DepNode, DepNodeIndex};
use crate::job::{QueryJobInfo, QueryJobMap, find_cycle_in_stack, report_cycle};
use crate::{QueryCtxt, QueryFlags, SemiDynamicQueryDispatcher};
@ -535,7 +535,7 @@ fn try_load_from_disk_and_cache_in_memory<'tcx, C: QueryCache, const FLAGS: Quer
// can be forced from `DepNode`.
debug_assert!(
!query.will_cache_on_disk_for_key(qcx.tcx, key)
|| !qcx.dep_context().fingerprint_style(dep_node.kind).reconstructible(),
|| !qcx.tcx.fingerprint_style(dep_node.kind).reconstructible(),
"missing on-disk cache entry for {dep_node:?}"
);

View file

@ -13,7 +13,6 @@ use rustc_session::Session;
use rustc_span::{DUMMY_SP, Span};
use crate::QueryCtxt;
use crate::dep_graph::DepContext;
/// Map from query job IDs to job information collected by
/// `collect_active_jobs_from_all_queries`.

View file

@ -15,8 +15,7 @@ use rustc_middle::bug;
#[expect(unused_imports, reason = "used by doc comments")]
use rustc_middle::dep_graph::DepKindVTable;
use rustc_middle::dep_graph::{
self, DepContext, DepNode, DepNodeIndex, DepNodeKey, HasDepContext, SerializedDepNodeIndex,
dep_kinds,
self, DepNode, DepNodeIndex, DepNodeKey, HasDepContext, SerializedDepNodeIndex, dep_kinds,
};
use rustc_middle::query::on_disk_cache::{
AbsoluteBytePos, CacheDecoder, CacheEncoder, EncodedDepNodeIndex,
@ -141,12 +140,10 @@ impl<'tcx> QueryCtxt<'tcx> {
}
}
impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
type DepContext = TyCtxt<'tcx>;
impl<'tcx> HasDepContext<'tcx> for QueryCtxt<'tcx> {
#[inline]
fn dep_context(&self) -> &Self::DepContext {
&self.tcx
fn dep_context(&self) -> TyCtxt<'tcx> {
self.tcx
}
}
@ -165,7 +162,7 @@ pub(super) fn encode_all_query_results<'tcx>(
}
pub fn query_key_hash_verify_all<'tcx>(tcx: TyCtxt<'tcx>) {
if tcx.sess().opts.unstable_opts.incremental_verify_ich || cfg!(debug_assertions) {
if tcx.sess.opts.unstable_opts.incremental_verify_ich || cfg!(debug_assertions) {
tcx.sess.time("query_key_hash_verify_all", || {
for verify in super::QUERY_KEY_HASH_VERIFY.iter() {
verify(tcx);

View file

@ -60,7 +60,6 @@ use rustc_hir::lang_items::LangItem;
use rustc_hir::{self as hir};
use rustc_macros::extension;
use rustc_middle::bug;
use rustc_middle::dep_graph::DepContext;
use rustc_middle::traits::PatternOriginExpr;
use rustc_middle::ty::error::{ExpectedFound, TypeError, TypeErrorToStringExt};
use rustc_middle::ty::print::{PrintTraitRefExt as _, WrapBinderMode, with_forced_trimmed_paths};
@ -1757,7 +1756,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// containing a single ASCII character, perhaps the user meant to write `b'c'` to
// specify a byte literal
(ty::Uint(ty::UintTy::U8), ty::Char) => {
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span)
if let Ok(code) = self.tcx.sess.source_map().span_to_snippet(span)
&& let Some(code) = code.strip_circumfix('\'', '\'')
// forbid all Unicode escapes
&& !code.starts_with("\\u")
@ -1774,7 +1773,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// containing a single character, perhaps the user meant to write `'c'` to
// specify a character literal (issue #92479)
(ty::Char, ty::Ref(_, r, _)) if r.is_str() => {
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span)
if let Ok(code) = self.tcx.sess.source_map().span_to_snippet(span)
&& let Some(code) = code.strip_circumfix('"', '"')
&& code.chars().count() == 1
{
@ -1787,7 +1786,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// If a string was expected and the found expression is a character literal,
// perhaps the user meant to write `"s"` to specify a string literal.
(ty::Ref(_, r, _), ty::Char) if r.is_str() => {
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span)
if let Ok(code) = self.tcx.sess.source_map().span_to_snippet(span)
&& code.starts_with("'")
&& code.ends_with("'")
{
@ -1928,7 +1927,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
return None;
}
let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span) else { return None };
let Ok(code) = self.tcx.sess.source_map().span_to_snippet(span) else { return None };
let sugg = if code.starts_with('(') && code.ends_with(')') {
let before_close = span.hi() - BytePos::from_u32(1);
@ -2005,7 +2004,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// Use the terminal width as the basis to determine when to compress the printed
// out type, but give ourselves some leeway to avoid ending up creating a file for
// a type that is somewhat shorter than the path we'd write to.
let len = self.tcx.sess().diagnostic_width() + 40;
let len = self.tcx.sess.diagnostic_width() + 40;
let exp_s = exp.content();
let fnd_s = fnd.content();
if exp_s.len() > len {