diff options
| author | Martin Zacho <hi@martinzacho.net> | 2025-01-06 09:04:22 +0100 |
|---|---|---|
| committer | Martin Zacho <hi@martinzacho.net> | 2025-01-06 09:43:05 +0100 |
| commit | 38e10e56198759b37595c48c43441a3cafa390a4 (patch) | |
| tree | 1b7562710d76deb2052c356ccf375c44f0003a7f /compiler | |
| parent | 83853ccdc3ac840c26aed112f854a3264f9cb614 (diff) | |
| download | rust-38e10e56198759b37595c48c43441a3cafa390a4.tar.gz rust-38e10e56198759b37595c48c43441a3cafa390a4.zip | |
improve diagnostics for const eval query overflow
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_query_impl/src/plumbing.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_query_system/messages.ftl | 2 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/error.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/lib.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/query/job.rs | 18 |
5 files changed, 18 insertions, 22 deletions
diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 1b12af62ea5..a74457a8118 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -27,7 +27,7 @@ use rustc_query_system::query::{ QueryCache, QueryConfig, QueryContext, QueryJobId, QueryMap, QuerySideEffects, QueryStackFrame, force_query, }; -use rustc_query_system::{LayoutOfDepth, QueryOverflow}; +use rustc_query_system::{QueryOverflow, QueryOverflowNote}; use rustc_serialize::{Decodable, Encodable}; use rustc_session::Limit; use rustc_span::def_id::LOCAL_CRATE; @@ -154,12 +154,10 @@ impl QueryContext for QueryCtxt<'_> { fn depth_limit_error(self, job: QueryJobId) { let mut span = None; - let mut layout_of_depth = None; - if let Some((info, depth)) = - job.try_find_layout_root(self.collect_active_jobs(), dep_kinds::layout_of) - { + let mut note = None; + if let Some((info, depth)) = job.try_find_dep_kind_root(self.collect_active_jobs()) { span = Some(info.job.span); - layout_of_depth = Some(LayoutOfDepth { desc: info.query.description, depth }); + note = Some(QueryOverflowNote { desc: info.query.description, depth }); } let suggested_limit = match self.recursion_limit() { @@ -169,7 +167,7 @@ impl QueryContext for QueryCtxt<'_> { self.sess.dcx().emit_fatal(QueryOverflow { span, - layout_of_depth, + note, suggested_limit, crate_name: self.crate_name(LOCAL_CRATE), }); diff --git a/compiler/rustc_query_system/messages.ftl b/compiler/rustc_query_system/messages.ftl index d7ab7557511..f48dc60afa0 100644 --- a/compiler/rustc_query_system/messages.ftl +++ b/compiler/rustc_query_system/messages.ftl @@ -21,7 +21,7 @@ query_system_increment_compilation = internal compiler error: encountered increm query_system_increment_compilation_note1 = Please follow the instructions below to create a bug report with the provided information query_system_increment_compilation_note2 = See <https://github.com/rust-lang/rust/issues/84970> for more information -query_system_layout_of_depth = query depth increased by {$depth} when {$desc} +query_system_overflow_note = query depth increased by {$depth} when {$desc} query_system_query_overflow = queries overflow the depth limit! .help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`) diff --git a/compiler/rustc_query_system/src/error.rs b/compiler/rustc_query_system/src/error.rs index 860f2e66915..4d5a944b179 100644 --- a/compiler/rustc_query_system/src/error.rs +++ b/compiler/rustc_query_system/src/error.rs @@ -84,14 +84,14 @@ pub struct QueryOverflow { #[primary_span] pub span: Option<Span>, #[subdiagnostic] - pub layout_of_depth: Option<LayoutOfDepth>, + pub note: Option<QueryOverflowNote>, pub suggested_limit: Limit, pub crate_name: Symbol, } #[derive(Subdiagnostic)] -#[note(query_system_layout_of_depth)] -pub struct LayoutOfDepth { +#[note(query_system_overflow_note)] +pub struct QueryOverflowNote { pub desc: String, pub depth: usize, } diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs index a85e8a55a21..ee984095ad8 100644 --- a/compiler/rustc_query_system/src/lib.rs +++ b/compiler/rustc_query_system/src/lib.rs @@ -16,7 +16,7 @@ pub mod ich; pub mod query; mod values; -pub use error::{HandleCycleError, LayoutOfDepth, QueryOverflow}; +pub use error::{HandleCycleError, QueryOverflow, QueryOverflowNote}; pub use values::Value; rustc_fluent_macro::fluent_messages! { "../messages.ftl" } diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index 2a7d759ab35..95fa63c11f6 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -15,7 +15,7 @@ use rustc_span::{DUMMY_SP, Span}; use crate::dep_graph::DepContext; use crate::error::CycleStack; use crate::query::plumbing::CycleError; -use crate::query::{DepKind, QueryContext, QueryStackFrame}; +use crate::query::{QueryContext, QueryStackFrame}; /// Represents a span and a query key. #[derive(Clone, Debug)] @@ -136,18 +136,16 @@ impl QueryJobId { #[cold] #[inline(never)] - pub fn try_find_layout_root( - &self, - query_map: QueryMap, - layout_of_kind: DepKind, - ) -> Option<(QueryJobInfo, usize)> { - let mut last_layout = None; - let mut current_id = Some(*self); - let mut depth = 0; + pub fn try_find_dep_kind_root(&self, query_map: QueryMap) -> Option<(QueryJobInfo, usize)> { + let mut depth = 1; + let info = query_map.get(&self).unwrap(); + let dep_kind = info.query.dep_kind; + let mut current_id = info.job.parent; + let mut last_layout = Some((info.clone(), depth)); while let Some(id) = current_id { let info = query_map.get(&id).unwrap(); - if info.query.dep_kind == layout_of_kind { + if info.query.dep_kind == dep_kind { depth += 1; last_layout = Some((info.clone(), depth)); } |
