From 1d410c58312119c1418346bec21ef5fe8e96d77e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 17 Feb 2026 12:14:37 +1100 Subject: [PATCH 1/5] Fix a typo. --- compiler/rustc_incremental/src/persist/clean.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_incremental/src/persist/clean.rs b/compiler/rustc_incremental/src/persist/clean.rs index 9e974e432c399..ca41f4ec58ce1 100644 --- a/compiler/rustc_incremental/src/persist/clean.rs +++ b/compiler/rustc_incremental/src/persist/clean.rs @@ -9,7 +9,7 @@ //! - `#[rustc_clean(cfg="rev2")]` same as above, except that the //! fingerprints must be the SAME (along with all other fingerprints). //! -//! - `#[rustc_clean(cfg="rev2", loaded_from_disk='typeck")]` asserts that +//! - `#[rustc_clean(cfg="rev2", loaded_from_disk="typeck")]` asserts that //! the query result for `DepNode::typeck(X)` was actually //! loaded from disk (not just marked green). This can be useful //! to ensure that a test is actually exercising the deserialization From 90b994b8832e913f08930dfc5f40b001856595ca Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 17 Feb 2026 11:37:01 +1100 Subject: [PATCH 2/5] Rename query `dep_kind`. The next commit will bring back `enum DepKind` and there would be a variant `DepKind::dep_kind`. This makes it impossible to have a variable named `dep_kind`, because the `bindings_with_variant_name` lint is overzealous. For this code: ``` let dep_kind = DepKind::dep_kind; ``` the lint will give this error: ``` pattern binding `dep_kind` is named the same as one of the variants of the type `DepKind` ``` This is arguably a bug in the lint. To work around it, this commit renames the `dep_kind` query as `crate_dep_kind`. It is a better name anyway given that `DepKind` and `CrateDepKind` are different things. --- compiler/rustc_codegen_ssa/src/base.rs | 2 +- compiler/rustc_metadata/src/dependency_format.rs | 10 +++++----- .../rustc_metadata/src/rmeta/decoder/cstore_impl.rs | 2 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- compiler/rustc_middle/src/queries.rs | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 85c8890d661c5..61e08c0f9323e 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -911,7 +911,7 @@ impl CrateInfo { .rev() .copied() .filter(|&cnum| { - let link = !tcx.dep_kind(cnum).macros_only(); + let link = !tcx.crate_dep_kind(cnum).macros_only(); if link && tcx.is_compiler_builtins(cnum) { compiler_builtins = Some(cnum); return false; diff --git a/compiler/rustc_metadata/src/dependency_format.rs b/compiler/rustc_metadata/src/dependency_format.rs index a74d387ad5a4a..30721784ad65e 100644 --- a/compiler/rustc_metadata/src/dependency_format.rs +++ b/compiler/rustc_metadata/src/dependency_format.rs @@ -146,7 +146,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList { && !sess.target.crt_static_allows_dylibs) { for &cnum in tcx.crates(()).iter() { - if tcx.dep_kind(cnum).macros_only() { + if tcx.crate_dep_kind(cnum).macros_only() { continue; } let src = tcx.used_crate_source(cnum); @@ -163,7 +163,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList { let all_dylibs = || { tcx.crates(()).iter().filter(|&&cnum| { - !tcx.dep_kind(cnum).macros_only() + !tcx.crate_dep_kind(cnum).macros_only() && (tcx.used_crate_source(cnum).dylib.is_some() || tcx.used_crate_source(cnum).sdylib_interface.is_some()) }) @@ -241,7 +241,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList { let src = tcx.used_crate_source(cnum); if src.dylib.is_none() && !formats.contains_key(&cnum) - && tcx.dep_kind(cnum) == CrateDepKind::Unconditional + && tcx.crate_dep_kind(cnum) == CrateDepKind::Unconditional { assert!(src.rlib.is_some() || src.rmeta.is_some()); info!("adding staticlib: {}", tcx.crate_name(cnum)); @@ -333,7 +333,7 @@ fn attempt_static(tcx: TyCtxt<'_>, unavailable: &mut Vec) -> Option, unavailable: &mut Vec) -> Option Linkage::Static, CrateDepKind::MacrosOnly | CrateDepKind::Conditional => Linkage::NotLinked, }), diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 6ea9a28528042..3c14fd859b984 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -382,7 +382,7 @@ provide! { tcx, def_id, other, cdata, implementations_of_trait => { cdata.get_implementations_of_trait(tcx, other) } crate_incoherent_impls => { cdata.get_incoherent_impls(tcx, other) } - dep_kind => { cdata.dep_kind } + crate_dep_kind => { cdata.dep_kind } module_children => { tcx.arena.alloc_from_iter(cdata.get_module_children(tcx, def_id.index)) } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index a3d8b07fb1d9a..758a7f6fcc042 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2072,7 +2072,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { name: self.tcx.crate_name(cnum), hash: self.tcx.crate_hash(cnum), host_hash: self.tcx.crate_host_hash(cnum), - kind: self.tcx.dep_kind(cnum), + kind: self.tcx.crate_dep_kind(cnum), extra_filename: self.tcx.extra_filename(cnum).clone(), is_private: self.tcx.is_private_dep(cnum), }; diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index 59171f2da4f20..cb922a2ad90bd 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -2179,7 +2179,7 @@ rustc_queries! { desc { "computing the uninhabited predicate of `{}`", key } } - query dep_kind(_: CrateNum) -> CrateDepKind { + query crate_dep_kind(_: CrateNum) -> CrateDepKind { eval_always desc { "fetching what a dependency looks like" } separate_provide_extern From c4a69d4712effc7f51c05ce01a882e69f178784a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 17 Feb 2026 11:36:48 +1100 Subject: [PATCH 3/5] Bring back `enum DepKind`. It was removed in #115920 to enable it being moved to `rustc_query_system`, a move that has recently been reversed. It's much simpler as an enum. Also: - Remove the overly complicated `Debug` impl for `DepKind`. - Remove the trivial `DepKind` associated constants (`NULL` et al.) - Add an assertion to ensure that the number of `DepKinds` fits within a `u16`. - Rename `DEP_KIND_VARIANTS` as `DEP_KIND_NUM_VARIANTS`, to make it clearer that it's a count, not a collection. - Use `stringify!` in one place to make the code clearer. --- .../rustc_incremental/src/assert_dep_graph.rs | 6 +- .../src/rmeta/decoder/cstore_impl.rs | 4 +- .../rustc_middle/src/dep_graph/dep_node.rs | 82 ++++++------------- compiler/rustc_middle/src/dep_graph/graph.rs | 8 +- compiler/rustc_middle/src/dep_graph/mod.rs | 3 +- .../rustc_middle/src/dep_graph/serialized.rs | 12 +-- compiler/rustc_middle/src/query/plumbing.rs | 4 +- .../src/ty/context/impl_interner.rs | 4 +- compiler/rustc_query_impl/src/plumbing.rs | 14 ++-- compiler/rustc_query_impl/src/values.rs | 14 ++-- .../src/traits/select/mod.rs | 4 +- 11 files changed, 59 insertions(+), 96 deletions(-) diff --git a/compiler/rustc_incremental/src/assert_dep_graph.rs b/compiler/rustc_incremental/src/assert_dep_graph.rs index a51b86eb72bfc..945f1ab797e76 100644 --- a/compiler/rustc_incremental/src/assert_dep_graph.rs +++ b/compiler/rustc_incremental/src/assert_dep_graph.rs @@ -44,9 +44,7 @@ use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId}; use rustc_hir::intravisit::{self, Visitor}; use rustc_middle::bug; -use rustc_middle::dep_graph::{ - DepGraphQuery, DepKind, DepNode, DepNodeFilter, EdgeFilter, dep_kinds, -}; +use rustc_middle::dep_graph::{DepGraphQuery, DepKind, DepNode, DepNodeFilter, EdgeFilter}; use rustc_middle::hir::nested_filter; use rustc_middle::ty::TyCtxt; use rustc_span::{Span, Symbol, sym}; @@ -117,7 +115,7 @@ impl<'tcx> IfThisChanged<'tcx> { None => DepNode::from_def_path_hash( self.tcx, def_path_hash, - dep_kinds::opt_hir_owner_nodes, + DepKind::opt_hir_owner_nodes, ), Some(n) => { match DepNode::from_label_string(self.tcx, n.as_str(), def_path_hash) { diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 3c14fd859b984..8c4f2e4a36b12 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -147,8 +147,8 @@ macro_rules! provide_one { // External query providers call `crate_hash` in order to register a dependency // on the crate metadata. The exception is `crate_hash` itself, which obviously // doesn't need to do this (and can't, as it would cause a query cycle). - use rustc_middle::dep_graph::dep_kinds; - if dep_kinds::$name != dep_kinds::crate_hash && $tcx.dep_graph.is_fully_enabled() { + use rustc_middle::dep_graph::DepKind; + if DepKind::$name != DepKind::crate_hash && $tcx.dep_graph.is_fully_enabled() { $tcx.ensure_ok().crate_hash($def_id.krate); } diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 52faebcba025c..2f637dfe0cbd2 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -62,59 +62,34 @@ use crate::ich::StableHashingContext; use crate::mir::mono::MonoItem; use crate::ty::{TyCtxt, tls}; -/// This serves as an index into arrays built by `make_dep_kind_array`. -#[derive(Clone, Copy, PartialEq, Eq, Hash)] -pub struct DepKind { - variant: u16, -} - +// `enum DepKind` is generated by `define_dep_nodes!` below. impl DepKind { #[inline] - pub const fn new(variant: u16) -> Self { - Self { variant } + pub(crate) fn from_u16(u: u16) -> Self { + if u > Self::MAX { + panic!("Invalid DepKind {u}"); + } + // SAFETY: See comment on DEP_KIND_NUM_VARIANTS + unsafe { std::mem::transmute(u) } } #[inline] - pub const fn as_inner(&self) -> u16 { - self.variant + pub(crate) const fn as_u16(&self) -> u16 { + *self as u16 } #[inline] pub const fn as_usize(&self) -> usize { - self.variant as usize + *self as usize } pub(crate) fn name(self) -> &'static str { DEP_KIND_NAMES[self.as_usize()] } - /// We use this for most things when incr. comp. is turned off. - pub(crate) const NULL: DepKind = dep_kinds::Null; - - /// We use this to create a forever-red node. - pub(crate) const RED: DepKind = dep_kinds::Red; - - /// We use this to create a side effect node. - pub(crate) const SIDE_EFFECT: DepKind = dep_kinds::SideEffect; - - /// We use this to create the anon node with zero dependencies. - pub(crate) const ANON_ZERO_DEPS: DepKind = dep_kinds::AnonZeroDeps; - /// This is the highest value a `DepKind` can have. It's used during encoding to /// pack information into the unused bits. - pub(crate) const MAX: u16 = DEP_KIND_VARIANTS - 1; -} - -impl fmt::Debug for DepKind { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - tls::with_opt(|opt_tcx| { - if let Some(tcx) = opt_tcx { - write!(f, "{}", tcx.dep_kind_vtable(*self).name) - } else { - f.debug_struct("DepKind").field("variant", &self.variant).finish() - } - }) - } + pub(crate) const MAX: u16 = DEP_KIND_NUM_VARIANTS - 1; } /// Combination of a [`DepKind`] and a key fingerprint that uniquely identifies @@ -374,26 +349,18 @@ macro_rules! define_dep_nodes { // encoding. The derived Encodable/Decodable uses leb128 encoding which is // dense when only considering this enum. But DepKind is encoded in a larger // struct, and there we can take advantage of the unused bits in the u16. + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[allow(non_camel_case_types)] - #[repr(u16)] // Must be kept in sync with the inner type of `DepKind`. - enum DepKindDefs { + #[repr(u16)] // Must be kept in sync with the rest of `DepKind`. + pub enum DepKind { $( $( #[$attr] )* $variant),* } - #[allow(non_upper_case_globals)] - pub mod dep_kinds { - use super::*; - - $( - // The `as u16` cast must be kept in sync with the inner type of `DepKind`. - pub const $variant: DepKind = DepKind::new(DepKindDefs::$variant as u16); - )* - } - - // This checks that the discriminants of the variants have been assigned consecutively - // from 0 so that they can be used as a dense index. - pub(crate) const DEP_KIND_VARIANTS: u16 = { - let deps = &[$(dep_kinds::$variant,)*]; + // This computes the number of dep kind variants. Along the way, it sanity-checks that the + // discriminants of the variants have been assigned consecutively from 0 so that they can + // be used as a dense index, and that all discriminants fit in a `u16`. + pub(crate) const DEP_KIND_NUM_VARIANTS: u16 = { + let deps = &[$(DepKind::$variant,)*]; let mut i = 0; while i < deps.len() { if i != deps[i].as_usize() { @@ -401,6 +368,7 @@ macro_rules! define_dep_nodes { } i += 1; } + assert!(deps.len() <= u16::MAX as usize); deps.len() as u16 }; @@ -412,7 +380,7 @@ macro_rules! define_dep_nodes { pub(super) fn dep_kind_from_label_string(label: &str) -> Result { match label { - $( self::label_strs::$variant => Ok(self::dep_kinds::$variant), )* + $( stringify!($variant) => Ok(self::DepKind::$variant), )* _ => Err(()), } } @@ -433,7 +401,9 @@ rustc_with_all_queries!(define_dep_nodes![ [] fn Null() -> (), /// We use this to create a forever-red node. [] fn Red() -> (), + /// We use this to create a side effect node. [] fn SideEffect() -> (), + /// We use this to create the anon node with zero dependencies. [] fn AnonZeroDeps() -> (), [] fn TraitSelect() -> (), [] fn CompileCodegenUnit() -> (), @@ -444,7 +414,7 @@ rustc_with_all_queries!(define_dep_nodes![ // WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys. // Be very careful changing this type signature! pub(crate) fn make_compile_codegen_unit(tcx: TyCtxt<'_>, name: Symbol) -> DepNode { - DepNode::construct(tcx, dep_kinds::CompileCodegenUnit, &name) + DepNode::construct(tcx, DepKind::CompileCodegenUnit, &name) } // WARNING: `construct` is generic and does not know that `CompileMonoItem` takes `MonoItem`s as keys. @@ -453,13 +423,13 @@ pub(crate) fn make_compile_mono_item<'tcx>( tcx: TyCtxt<'tcx>, mono_item: &MonoItem<'tcx>, ) -> DepNode { - DepNode::construct(tcx, dep_kinds::CompileMonoItem, mono_item) + DepNode::construct(tcx, DepKind::CompileMonoItem, mono_item) } // WARNING: `construct` is generic and does not know that `Metadata` takes `()`s as keys. // Be very careful changing this type signature! pub(crate) fn make_metadata(tcx: TyCtxt<'_>) -> DepNode { - DepNode::construct(tcx, dep_kinds::Metadata, &()) + DepNode::construct(tcx, DepKind::Metadata, &()) } impl DepNode { diff --git a/compiler/rustc_middle/src/dep_graph/graph.rs b/compiler/rustc_middle/src/dep_graph/graph.rs index f5787716a94e0..f54cd3c85fb4e 100644 --- a/compiler/rustc_middle/src/dep_graph/graph.rs +++ b/compiler/rustc_middle/src/dep_graph/graph.rs @@ -142,7 +142,7 @@ impl DepGraph { // Instantiate a node with zero dependencies only once for anonymous queries. let _green_node_index = current.alloc_new_node( - DepNode { kind: DepKind::ANON_ZERO_DEPS, key_fingerprint: current.anon_id_seed.into() }, + DepNode { kind: DepKind::AnonZeroDeps, key_fingerprint: current.anon_id_seed.into() }, EdgesVec::new(), Fingerprint::ZERO, ); @@ -152,7 +152,7 @@ impl DepGraph { // Other nodes can use the always-red node as a fake dependency, to // ensure that their dependency list will never be all-green. let red_node_index = current.alloc_new_node( - DepNode { kind: DepKind::RED, key_fingerprint: Fingerprint::ZERO.into() }, + DepNode { kind: DepKind::Red, key_fingerprint: Fingerprint::ZERO.into() }, EdgesVec::new(), Fingerprint::ZERO, ); @@ -680,7 +680,7 @@ impl DepGraphData { // Use `send_new` so we get an unique index, even though the dep node is not. let dep_node_index = self.current.encoder.send_new( DepNode { - kind: DepKind::SIDE_EFFECT, + kind: DepKind::SideEffect, key_fingerprint: PackedFingerprint::from(Fingerprint::ZERO), }, Fingerprint::ZERO, @@ -713,7 +713,7 @@ impl DepGraphData { prev_index, &self.colors, DepNode { - kind: DepKind::SIDE_EFFECT, + kind: DepKind::SideEffect, key_fingerprint: PackedFingerprint::from(Fingerprint::ZERO), }, Fingerprint::ZERO, diff --git a/compiler/rustc_middle/src/dep_graph/mod.rs b/compiler/rustc_middle/src/dep_graph/mod.rs index dda336fcd0b09..5df877a7eff03 100644 --- a/compiler/rustc_middle/src/dep_graph/mod.rs +++ b/compiler/rustc_middle/src/dep_graph/mod.rs @@ -3,8 +3,7 @@ use std::panic; use tracing::instrument; pub use self::dep_node::{ - DepKind, DepKindVTable, DepNode, DepNodeKey, WorkProductId, dep_kind_from_label, dep_kinds, - label_strs, + DepKind, DepKindVTable, DepNode, DepNodeKey, WorkProductId, dep_kind_from_label, label_strs, }; pub use self::graph::{ DepGraph, DepGraphData, DepNodeIndex, QuerySideEffect, TaskDepsRef, WorkProduct, diff --git a/compiler/rustc_middle/src/dep_graph/serialized.rs b/compiler/rustc_middle/src/dep_graph/serialized.rs index 4da96c5c99336..a22af8a296dd7 100644 --- a/compiler/rustc_middle/src/dep_graph/serialized.rs +++ b/compiler/rustc_middle/src/dep_graph/serialized.rs @@ -84,7 +84,7 @@ const DEP_NODE_WIDTH_BITS: usize = DEP_NODE_SIZE / 2; /// Data for use when recompiling the **current crate**. /// -/// There may be unused indices with DEP_KIND_NULL in this graph due to batch allocation of +/// There may be unused indices with DepKind::Null in this graph due to batch allocation of /// indices to threads. #[derive(Debug, Default)] pub struct SerializedDepGraph { @@ -220,7 +220,7 @@ impl SerializedDepGraph { let mut nodes = IndexVec::from_elem_n( DepNode { - kind: DepKind::NULL, + kind: DepKind::Null, key_fingerprint: PackedFingerprint::from(Fingerprint::ZERO), }, node_max, @@ -250,7 +250,7 @@ impl SerializedDepGraph { let node = &mut nodes[index]; // Make sure there's no duplicate indices in the dep graph. - assert!(node_header.node().kind != DepKind::NULL && node.kind == DepKind::NULL); + assert!(node_header.node().kind != DepKind::Null && node.kind == DepKind::Null); *node = node_header.node(); value_fingerprints[index] = node_header.value_fingerprint(); @@ -287,7 +287,7 @@ impl SerializedDepGraph { for (idx, node) in nodes.iter_enumerated() { if index[node.kind.as_usize()].insert(node.key_fingerprint, idx).is_some() { // Empty nodes and side effect nodes can have duplicates - if node.kind != DepKind::NULL && node.kind != DepKind::SIDE_EFFECT { + if node.kind != DepKind::Null && node.kind != DepKind::SideEffect { let name = node.kind.name(); panic!( "Error: A dep graph node ({name}) does not have an unique index. \ @@ -361,7 +361,7 @@ impl SerializedNodeHeader { ) -> Self { debug_assert_eq!(Self::TOTAL_BITS, Self::LEN_BITS + Self::WIDTH_BITS + Self::KIND_BITS); - let mut head = node.kind.as_inner(); + let mut head = node.kind.as_u16(); let free_bytes = edge_max_index.leading_zeros() as usize / 8; let bytes_per_index = (DEP_NODE_SIZE - free_bytes).saturating_sub(1); @@ -408,7 +408,7 @@ impl SerializedNodeHeader { Unpacked { len: len.checked_sub(1), bytes_per_index: bytes_per_index as usize + 1, - kind: DepKind::new(kind), + kind: DepKind::from_u16(kind), index: SerializedDepNodeIndex::from_u32(index), key_fingerprint: Fingerprint::from_le_bytes(key_fingerprint).into(), value_fingerprint: Fingerprint::from_le_bytes(value_fingerprint), diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs index 47b6aea077d17..03618ee6acd46 100644 --- a/compiler/rustc_middle/src/query/plumbing.rs +++ b/compiler/rustc_middle/src/query/plumbing.rs @@ -588,11 +588,9 @@ macro_rules! define_feedable { let tcx = self.tcx; let erased_value = $name::provided_to_erased(tcx, value); - let dep_kind: dep_graph::DepKind = dep_graph::dep_kinds::$name; - $crate::query::inner::query_feed( tcx, - dep_kind, + dep_graph::DepKind::$name, &tcx.query_system.query_vtables.$name, &tcx.query_system.caches.$name, key, diff --git a/compiler/rustc_middle/src/ty/context/impl_interner.rs b/compiler/rustc_middle/src/ty/context/impl_interner.rs index 7580cc65d530a..a4aeaacbf05db 100644 --- a/compiler/rustc_middle/src/ty/context/impl_interner.rs +++ b/compiler/rustc_middle/src/ty/context/impl_interner.rs @@ -13,7 +13,7 @@ use rustc_span::{DUMMY_SP, Span, Symbol}; use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem}; use rustc_type_ir::{CollectAndApply, Interner, TypeFoldable, search_graph}; -use crate::dep_graph::DepNodeIndex; +use crate::dep_graph::{DepKind, DepNodeIndex}; use crate::infer::canonical::CanonicalVarKinds; use crate::query::IntoQueryParam; use crate::traits::cache::WithDepNode; @@ -77,7 +77,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { } type DepNodeIndex = DepNodeIndex; fn with_cached_task(self, task: impl FnOnce() -> T) -> (T, DepNodeIndex) { - self.dep_graph.with_anon_task(self, crate::dep_graph::dep_kinds::TraitSelect, task) + self.dep_graph.with_anon_task(self, DepKind::TraitSelect, task) } type Ty = Ty<'tcx>; type Tys = &'tcx List>; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 5981e7e0f5269..31f27efdb43f1 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -14,9 +14,7 @@ use rustc_index::Idx; use rustc_middle::bug; #[expect(unused_imports, reason = "used by doc comments")] use rustc_middle::dep_graph::DepKindVTable; -use rustc_middle::dep_graph::{ - self, DepNode, DepNodeIndex, DepNodeKey, SerializedDepNodeIndex, dep_kinds, -}; +use rustc_middle::dep_graph::{DepKind, DepNode, DepNodeIndex, DepNodeKey, SerializedDepNodeIndex}; use rustc_middle::query::on_disk_cache::{ AbsoluteBytePos, CacheDecoder, CacheEncoder, EncodedDepNodeIndex, }; @@ -123,7 +121,7 @@ pub fn collect_active_jobs_from_all_queries<'tcx>( if complete { Ok(job_map_out) } else { Err(job_map_out) } } -pub(super) fn try_mark_green<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &dep_graph::DepNode) -> bool { +pub(super) fn try_mark_green<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> bool { tcx.dep_graph.try_mark_green(tcx, dep_node).is_some() } @@ -293,7 +291,7 @@ where } else { description }; - let span = if vtable.dep_kind == dep_graph::dep_kinds::def_span || reduce_queries { + let span = if vtable.dep_kind == DepKind::def_span || reduce_queries { // The `def_span` query is used to calculate `default_span`, // so exit to avoid infinite recursion. None @@ -301,7 +299,7 @@ where Some(key.default_span(tcx)) }; - let def_kind = if vtable.dep_kind == dep_graph::dep_kinds::def_kind || reduce_queries { + let def_kind = if vtable.dep_kind == DepKind::def_kind || reduce_queries { // Try to avoid infinite recursion. None } else { @@ -461,7 +459,7 @@ pub(crate) fn force_from_dep_node_inner<'tcx, C: QueryCache, const FLAGS: QueryF // hit the cache instead of having to go through `force_from_dep_node`. // This assertion makes sure, we actually keep applying the solution above. debug_assert!( - dep_node.kind != dep_kinds::codegen_unit, + dep_node.kind != DepKind::codegen_unit, "calling force_from_dep_node() on dep_kinds::codegen_unit" ); @@ -567,7 +565,7 @@ macro_rules! define_queries { QueryVTable { name: stringify!($name), eval_always: is_eval_always!([$($modifiers)*]), - dep_kind: dep_graph::dep_kinds::$name, + dep_kind: dep_graph::DepKind::$name, cycle_error_handling: cycle_error_handling!([$($modifiers)*]), query_state: std::mem::offset_of!(QueryStates<'tcx>, $name), query_cache: std::mem::offset_of!(QueryCaches<'tcx>, $name), diff --git a/compiler/rustc_query_impl/src/values.rs b/compiler/rustc_query_impl/src/values.rs index 67bc6893a320d..8f55e98df867e 100644 --- a/compiler/rustc_query_impl/src/values.rs +++ b/compiler/rustc_query_impl/src/values.rs @@ -7,7 +7,7 @@ use rustc_errors::codes::*; use rustc_errors::{Applicability, MultiSpan, pluralize, struct_span_code_err}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; -use rustc_middle::dep_graph::dep_kinds; +use rustc_middle::dep_graph::DepKind; use rustc_middle::query::CycleError; use rustc_middle::query::plumbing::CyclePlaceholder; use rustc_middle::ty::{self, Representability, Ty, TyCtxt}; @@ -72,7 +72,7 @@ impl<'tcx> Value<'tcx> for ty::Binder<'_, ty::FnSig<'_>> { let err = Ty::new_error(tcx, guar); let arity = if let Some(info) = cycle_error.cycle.get(0) - && info.frame.dep_kind == dep_kinds::fn_sig + && info.frame.dep_kind == DepKind::fn_sig && let Some(def_id) = info.frame.def_id && let Some(node) = tcx.hir_get_if_local(def_id) && let Some(sig) = node.fn_sig() @@ -106,7 +106,7 @@ impl<'tcx> Value<'tcx> for Representability { let mut item_and_field_ids = Vec::new(); let mut representable_ids = FxHashSet::default(); for info in &cycle_error.cycle { - if info.frame.dep_kind == dep_kinds::representability + if info.frame.dep_kind == DepKind::representability && let Some(field_id) = info.frame.def_id && let Some(field_id) = field_id.as_local() && let Some(DefKind::Field) = info.frame.info.def_kind @@ -120,7 +120,7 @@ impl<'tcx> Value<'tcx> for Representability { } } for info in &cycle_error.cycle { - if info.frame.dep_kind == dep_kinds::representability_adt_ty + if info.frame.dep_kind == DepKind::representability_adt_ty && let Some(def_id) = info.frame.def_id_for_ty_in_cycle && let Some(def_id) = def_id.as_local() && !item_and_field_ids.iter().any(|&(id, _)| id == def_id) @@ -163,7 +163,7 @@ impl<'tcx> Value<'tcx> for &[ty::Variance] { &cycle_error.cycle, |cycle| { if let Some(info) = cycle.get(0) - && info.frame.dep_kind == dep_kinds::variances_of + && info.frame.dep_kind == DepKind::variances_of && let Some(def_id) = info.frame.def_id { let n = tcx.generics_of(def_id).own_params.len(); @@ -210,7 +210,7 @@ impl<'tcx, T> Value<'tcx> for Result> { let diag = search_for_cycle_permutation( &cycle_error.cycle, |cycle| { - if cycle[0].frame.dep_kind == dep_kinds::layout_of + if cycle[0].frame.dep_kind == DepKind::layout_of && let Some(def_id) = cycle[0].frame.def_id_for_ty_in_cycle && let Some(def_id) = def_id.as_local() && let def_kind = tcx.def_kind(def_id) @@ -235,7 +235,7 @@ impl<'tcx, T> Value<'tcx> for Result> { tcx.def_kind_descr(def_kind, def_id.to_def_id()), ); for (i, info) in cycle.iter().enumerate() { - if info.frame.dep_kind != dep_kinds::layout_of { + if info.frame.dep_kind != DepKind::layout_of { continue; } let Some(frame_def_id) = info.frame.def_id_for_ty_in_cycle else { diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 3c3160bc533e2..c5a96fa963f88 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -22,7 +22,7 @@ use rustc_infer::infer::relate::TypeRelation; use rustc_infer::traits::{PredicateObligations, TraitObligation}; use rustc_macros::{TypeFoldable, TypeVisitable}; use rustc_middle::bug; -use rustc_middle::dep_graph::{DepNodeIndex, dep_kinds}; +use rustc_middle::dep_graph::{DepKind, DepNodeIndex}; pub use rustc_middle::traits::select::*; use rustc_middle::ty::abstract_const::NotConstEvaluatable; use rustc_middle::ty::error::TypeErrorToStringExt; @@ -1399,7 +1399,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { where OP: FnOnce(&mut Self) -> R, { - self.tcx().dep_graph.with_anon_task(self.tcx(), dep_kinds::TraitSelect, || op(self)) + self.tcx().dep_graph.with_anon_task(self.tcx(), DepKind::TraitSelect, || op(self)) } /// filter_impls filters candidates that have a positive impl for a negative From baa74a85ee2e901f28576cd81429d18da99875df Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 17 Feb 2026 12:55:14 +1100 Subject: [PATCH 4/5] Remove `DepKind` name plumbing. There is a bunch of plumbing to record the string `"foo"` for each variant `DepKind::foo`. But that's what the `Debug `impl` now produces. So this commit removes the plumbing. --- compiler/rustc_middle/src/dep_graph/dep_node.rs | 13 ------------- compiler/rustc_middle/src/dep_graph/serialized.rs | 13 +++++++------ compiler/rustc_query_impl/src/dep_kind_vtables.rs | 10 ---------- compiler/rustc_query_impl/src/job.rs | 6 ++---- compiler/rustc_query_impl/src/lib.rs | 2 -- compiler/rustc_query_impl/src/plumbing.rs | 2 -- 6 files changed, 9 insertions(+), 37 deletions(-) diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 2f637dfe0cbd2..1ffbdfbf11875 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -83,10 +83,6 @@ impl DepKind { *self as usize } - pub(crate) fn name(self) -> &'static str { - DEP_KIND_NAMES[self.as_usize()] - } - /// This is the highest value a `DepKind` can have. It's used during encoding to /// pack information into the unused bits. pub(crate) const MAX: u16 = DEP_KIND_NUM_VARIANTS - 1; @@ -287,9 +283,6 @@ pub struct DepKindVTable<'tcx> { /// Invoke a query to put the on-disk cached value in memory. pub try_load_from_on_disk_cache: Option, DepNode)>, - - /// The name of this dep kind. - pub name: &'static &'static str, } /// A "work product" corresponds to a `.o` (or other) file that we @@ -372,12 +365,6 @@ macro_rules! define_dep_nodes { deps.len() as u16 }; - /// List containing the name of each dep kind as a static string, - /// indexable by `DepKind`. - pub(crate) const DEP_KIND_NAMES: &[&str] = &[ - $( self::label_strs::$variant, )* - ]; - pub(super) fn dep_kind_from_label_string(label: &str) -> Result { match label { $( stringify!($variant) => Ok(self::DepKind::$variant), )* diff --git a/compiler/rustc_middle/src/dep_graph/serialized.rs b/compiler/rustc_middle/src/dep_graph/serialized.rs index a22af8a296dd7..7885b43535446 100644 --- a/compiler/rustc_middle/src/dep_graph/serialized.rs +++ b/compiler/rustc_middle/src/dep_graph/serialized.rs @@ -288,13 +288,14 @@ impl SerializedDepGraph { if index[node.kind.as_usize()].insert(node.key_fingerprint, idx).is_some() { // Empty nodes and side effect nodes can have duplicates if node.kind != DepKind::Null && node.kind != DepKind::SideEffect { - let name = node.kind.name(); + let kind = node.kind; panic!( - "Error: A dep graph node ({name}) does not have an unique index. \ - Running a clean build on a nightly compiler with `-Z incremental-verify-ich` \ - can help narrow down the issue for reporting. A clean build may also work around the issue.\n - DepNode: {node:?}" - ) + "Error: A dep graph node ({kind:?}) does not have an unique index. \ + Running a clean build on a nightly compiler with \ + `-Z incremental-verify-ich` can help narrow down the issue for reporting. \ + A clean build may also work around the issue.\n + DepNode: {node:?}" + ) } } } diff --git a/compiler/rustc_query_impl/src/dep_kind_vtables.rs b/compiler/rustc_query_impl/src/dep_kind_vtables.rs index 39bd2569ef468..a180ea8327fd1 100644 --- a/compiler/rustc_query_impl/src/dep_kind_vtables.rs +++ b/compiler/rustc_query_impl/src/dep_kind_vtables.rs @@ -20,7 +20,6 @@ mod non_query { bug!("force_from_dep_node: encountered {dep_node:?}") }), try_load_from_on_disk_cache: None, - name: &"Null", } } @@ -34,7 +33,6 @@ mod non_query { bug!("force_from_dep_node: encountered {dep_node:?}") }), try_load_from_on_disk_cache: None, - name: &"Red", } } @@ -48,7 +46,6 @@ mod non_query { true }), try_load_from_on_disk_cache: None, - name: &"SideEffect", } } @@ -59,7 +56,6 @@ mod non_query { key_fingerprint_style: KeyFingerprintStyle::Opaque, force_from_dep_node: Some(|_, _, _| bug!("cannot force an anon node")), try_load_from_on_disk_cache: None, - name: &"AnonZeroDeps", } } @@ -70,7 +66,6 @@ mod non_query { key_fingerprint_style: KeyFingerprintStyle::Unit, force_from_dep_node: None, try_load_from_on_disk_cache: None, - name: &"TraitSelect", } } @@ -81,7 +76,6 @@ mod non_query { key_fingerprint_style: KeyFingerprintStyle::Opaque, force_from_dep_node: None, try_load_from_on_disk_cache: None, - name: &"CompileCodegenUnit", } } @@ -92,7 +86,6 @@ mod non_query { key_fingerprint_style: KeyFingerprintStyle::Opaque, force_from_dep_node: None, try_load_from_on_disk_cache: None, - name: &"CompileMonoItem", } } @@ -103,7 +96,6 @@ mod non_query { key_fingerprint_style: KeyFingerprintStyle::Unit, force_from_dep_node: None, try_load_from_on_disk_cache: None, - name: &"Metadata", } } } @@ -131,7 +123,6 @@ where key_fingerprint_style, force_from_dep_node: None, try_load_from_on_disk_cache: None, - name: Q::NAME, }; } @@ -145,7 +136,6 @@ where try_load_from_on_disk_cache: Some(|tcx, dep_node| { try_load_from_on_disk_cache_inner(Q::query_dispatcher(tcx), tcx, dep_node) }), - name: Q::NAME, } } diff --git a/compiler/rustc_query_impl/src/job.rs b/compiler/rustc_query_impl/src/job.rs index 1256b514edb5c..5f728fec83c3b 100644 --- a/compiler/rustc_query_impl/src/job.rs +++ b/compiler/rustc_query_impl/src/job.rs @@ -423,10 +423,8 @@ pub fn print_query_stack<'tcx>( if let Some(ref mut file) = file { let _ = writeln!( file, - "#{} [{}] {}", - count_total, - tcx.dep_kind_vtable(query_info.frame.dep_kind).name, - query_extra.description + "#{} [{:?}] {}", + count_total, query_info.frame.dep_kind, query_extra.description ); } diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index b4a64686728f1..2804f5cfa055d 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -231,8 +231,6 @@ impl<'tcx, C: QueryCache, const FLAGS: QueryFlags> SemiDynamicQueryDispatcher<'t trait QueryDispatcherUnerased<'tcx, C: QueryCache, const FLAGS: QueryFlags> { type UnerasedValue; - const NAME: &'static &'static str; - fn query_dispatcher(tcx: TyCtxt<'tcx>) -> SemiDynamicQueryDispatcher<'tcx, C, FLAGS>; fn restore_val(value: C::Value) -> Self::UnerasedValue; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 31f27efdb43f1..1ed601aae3562 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -630,8 +630,6 @@ macro_rules! define_queries { { type UnerasedValue = queries::$name::Value<'tcx>; - const NAME: &'static &'static str = &stringify!($name); - #[inline(always)] fn query_dispatcher(tcx: TyCtxt<'tcx>) -> SemiDynamicQueryDispatcher<'tcx, queries::$name::Storage<'tcx>, FLAGS> From 1c8abe6d26f3ab935c688310731c66e37a38908a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 17 Feb 2026 13:33:23 +1100 Subject: [PATCH 5/5] Adjust a module visibility. --- compiler/rustc_middle/src/dep_graph/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/dep_graph/mod.rs b/compiler/rustc_middle/src/dep_graph/mod.rs index 5df877a7eff03..0f08a66caeeb0 100644 --- a/compiler/rustc_middle/src/dep_graph/mod.rs +++ b/compiler/rustc_middle/src/dep_graph/mod.rs @@ -17,7 +17,7 @@ use crate::ty::print::with_reduced_queries; use crate::ty::{self, TyCtxt}; mod debug; -pub mod dep_node; +pub(crate) mod dep_node; mod dep_node_key; mod edges; mod graph;