From ff331d2cc8ba48224fff04a4cbcb2bc5b6afe2c1 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Fri, 23 Jan 2026 11:42:45 +1100 Subject: [PATCH] Rename `HandleCycleError` to `CycleErrorHandling` --- compiler/rustc_middle/src/query/plumbing.rs | 6 +++--- compiler/rustc_query_impl/src/lib.rs | 10 +++++----- compiler/rustc_query_impl/src/plumbing.rs | 14 +++++++------- compiler/rustc_query_system/src/error.rs | 8 -------- compiler/rustc_query_system/src/lib.rs | 2 +- compiler/rustc_query_system/src/query/config.rs | 5 ++--- compiler/rustc_query_system/src/query/mod.rs | 12 ++++++++++++ .../rustc_query_system/src/query/plumbing.rs | 16 ++++++++-------- 8 files changed, 38 insertions(+), 35 deletions(-) diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs index 16121c38d1a9..17330f4e14be 100644 --- a/compiler/rustc_middle/src/query/plumbing.rs +++ b/compiler/rustc_middle/src/query/plumbing.rs @@ -4,10 +4,9 @@ use rustc_data_structures::sync::{AtomicU64, WorkerLocal}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::hir_id::OwnerId; use rustc_macros::HashStable; -use rustc_query_system::HandleCycleError; use rustc_query_system::dep_graph::{DepNodeIndex, SerializedDepNodeIndex}; pub(crate) use rustc_query_system::query::QueryJobId; -use rustc_query_system::query::*; +use rustc_query_system::query::{CycleError, CycleErrorHandling, HashResult, QueryCache}; use rustc_span::{ErrorGuaranteed, Span}; pub use sealed::IntoQueryParam; @@ -23,7 +22,8 @@ pub struct DynamicQuery<'tcx, C: QueryCache> { pub name: &'static str, pub eval_always: bool, pub dep_kind: DepKind, - pub handle_cycle_error: HandleCycleError, + /// How this query deals with query cycle errors. + pub cycle_error_handling: CycleErrorHandling, // Offset of this query's state field in the QueryStates struct pub query_state: usize, // Offset of this query's cache field in the QueryCaches struct diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index f763b707aa23..c9abc4bdcdfc 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -18,13 +18,13 @@ use rustc_middle::query::{ queries, }; use rustc_middle::ty::TyCtxt; +use rustc_query_system::Value; use rustc_query_system::dep_graph::SerializedDepNodeIndex; use rustc_query_system::ich::StableHashingContext; use rustc_query_system::query::{ - CycleError, HashResult, QueryCache, QueryConfig, QueryMap, QueryMode, QueryState, - get_query_incr, get_query_non_incr, + CycleError, CycleErrorHandling, HashResult, QueryCache, QueryConfig, QueryMap, QueryMode, + QueryState, get_query_incr, get_query_non_incr, }; -use rustc_query_system::{HandleCycleError, Value}; use rustc_span::{ErrorGuaranteed, Span}; use crate::plumbing::{__rust_begin_short_backtrace, encode_all_query_results, try_mark_green}; @@ -181,8 +181,8 @@ where } #[inline(always)] - fn handle_cycle_error(self) -> HandleCycleError { - self.dynamic.handle_cycle_error + fn cycle_error_handling(self) -> CycleErrorHandling { + self.dynamic.cycle_error_handling } #[inline(always)] diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index d6d1dc781f3e..7479a992e297 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -199,21 +199,21 @@ pub fn query_key_hash_verify_all<'tcx>(tcx: TyCtxt<'tcx>) { } } -macro_rules! handle_cycle_error { +macro_rules! cycle_error_handling { ([]) => {{ - rustc_query_system::HandleCycleError::Error + rustc_query_system::query::CycleErrorHandling::Error }}; ([(cycle_fatal) $($rest:tt)*]) => {{ - rustc_query_system::HandleCycleError::Fatal + rustc_query_system::query::CycleErrorHandling::Fatal }}; ([(cycle_stash) $($rest:tt)*]) => {{ - rustc_query_system::HandleCycleError::Stash + rustc_query_system::query::CycleErrorHandling::Stash }}; ([(cycle_delay_bug) $($rest:tt)*]) => {{ - rustc_query_system::HandleCycleError::DelayBug + rustc_query_system::query::CycleErrorHandling::DelayBug }}; ([$other:tt $($modifiers:tt)*]) => { - handle_cycle_error!([$($modifiers)*]) + cycle_error_handling!([$($modifiers)*]) }; } @@ -618,7 +618,7 @@ macro_rules! define_queries { name: stringify!($name), eval_always: is_eval_always!([$($modifiers)*]), dep_kind: dep_graph::dep_kinds::$name, - handle_cycle_error: handle_cycle_error!([$($modifiers)*]), + 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), cache_on_disk: |tcx, key| ::rustc_middle::query::cached::$name(tcx, key), diff --git a/compiler/rustc_query_system/src/error.rs b/compiler/rustc_query_system/src/error.rs index 96998c798689..4b1effe2b33d 100644 --- a/compiler/rustc_query_system/src/error.rs +++ b/compiler/rustc_query_system/src/error.rs @@ -11,14 +11,6 @@ pub(crate) struct CycleStack { pub desc: String, } -#[derive(Copy, Clone)] -pub enum HandleCycleError { - Error, - Fatal, - DelayBug, - Stash, -} - #[derive(Subdiagnostic)] pub(crate) enum StackCount { #[note(query_system_cycle_stack_single)] diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs index 7fa643d91aa3..cdfe3454061c 100644 --- a/compiler/rustc_query_system/src/lib.rs +++ b/compiler/rustc_query_system/src/lib.rs @@ -12,7 +12,7 @@ pub mod ich; pub mod query; mod values; -pub use error::{HandleCycleError, QueryOverflow, QueryOverflowNote}; +pub use error::{QueryOverflow, QueryOverflowNote}; pub use values::Value; rustc_fluent_macro::fluent_messages! { "../messages.ftl" } diff --git a/compiler/rustc_query_system/src/query/config.rs b/compiler/rustc_query_system/src/query/config.rs index 371b896400a5..739e8e3a8f26 100644 --- a/compiler/rustc_query_system/src/query/config.rs +++ b/compiler/rustc_query_system/src/query/config.rs @@ -7,10 +7,9 @@ use rustc_data_structures::fingerprint::Fingerprint; use rustc_span::ErrorGuaranteed; use crate::dep_graph::{DepKind, DepNode, DepNodeParams, SerializedDepNodeIndex}; -use crate::error::HandleCycleError; use crate::ich::StableHashingContext; use crate::query::caches::QueryCache; -use crate::query::{CycleError, DepNodeIndex, QueryContext, QueryState}; +use crate::query::{CycleError, CycleErrorHandling, DepNodeIndex, QueryContext, QueryState}; pub type HashResult = Option, &V) -> Fingerprint>; @@ -67,7 +66,7 @@ pub trait QueryConfig: Copy { fn feedable(self) -> bool; fn dep_kind(self) -> DepKind; - fn handle_cycle_error(self) -> HandleCycleError; + fn cycle_error_handling(self) -> CycleErrorHandling; fn hash_result(self) -> HashResult; // Just here for convenience and checking that the key matches the kind, don't override this. diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index b524756d81b6..796f41d41efa 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -20,6 +20,18 @@ mod config; mod job; mod plumbing; +/// How a particular query deals with query cycle errors. +/// +/// Inspected by the code that actually handles cycle errors, to decide what +/// approach to use. +#[derive(Copy, Clone)] +pub enum CycleErrorHandling { + Error, + Fatal, + DelayBug, + Stash, +} + /// Description of a frame in the query stack. /// /// This is mostly used in case of cycles for error reporting. diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index fa5a94d65188..150ad238dad9 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -19,12 +19,13 @@ use rustc_span::{DUMMY_SP, Span}; use tracing::instrument; use super::QueryConfig; -use crate::HandleCycleError; use crate::dep_graph::{DepContext, DepGraphData, DepNode, DepNodeIndex, DepNodeParams}; use crate::ich::StableHashingContext; use crate::query::caches::QueryCache; use crate::query::job::{QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryLatch, report_cycle}; -use crate::query::{QueryContext, QueryMap, QueryStackFrame, SerializedDepNodeIndex}; +use crate::query::{ + CycleErrorHandling, QueryContext, QueryMap, QueryStackFrame, SerializedDepNodeIndex, +}; #[inline] fn equivalent_key(k: &K) -> impl Fn(&(K, V)) -> bool + '_ { @@ -142,22 +143,21 @@ where Q: QueryConfig, Qcx: QueryContext, { - use HandleCycleError::*; - match query.handle_cycle_error() { - Error => { + match query.cycle_error_handling() { + CycleErrorHandling::Error => { let guar = error.emit(); query.value_from_cycle_error(*qcx.dep_context(), cycle_error, guar) } - Fatal => { + CycleErrorHandling::Fatal => { error.emit(); qcx.dep_context().sess().dcx().abort_if_errors(); unreachable!() } - DelayBug => { + CycleErrorHandling::DelayBug => { let guar = error.delay_as_bug(); query.value_from_cycle_error(*qcx.dep_context(), cycle_error, guar) } - Stash => { + CycleErrorHandling::Stash => { let guar = if let Some(root) = cycle_error.cycle.first() && let Some(span) = root.query.span {