1
Fork 0

improve diagnostics for const eval query overflow

This commit is contained in:
Martin Zacho 2025-01-06 09:04:22 +01:00
parent 83853ccdc3
commit 38e10e5619
7 changed files with 32 additions and 26 deletions

View file

@ -27,7 +27,7 @@ use rustc_query_system::query::{
QueryCache, QueryConfig, QueryContext, QueryJobId, QueryMap, QuerySideEffects, QueryStackFrame, QueryCache, QueryConfig, QueryContext, QueryJobId, QueryMap, QuerySideEffects, QueryStackFrame,
force_query, force_query,
}; };
use rustc_query_system::{LayoutOfDepth, QueryOverflow}; use rustc_query_system::{QueryOverflow, QueryOverflowNote};
use rustc_serialize::{Decodable, Encodable}; use rustc_serialize::{Decodable, Encodable};
use rustc_session::Limit; use rustc_session::Limit;
use rustc_span::def_id::LOCAL_CRATE; use rustc_span::def_id::LOCAL_CRATE;
@ -154,12 +154,10 @@ impl QueryContext for QueryCtxt<'_> {
fn depth_limit_error(self, job: QueryJobId) { fn depth_limit_error(self, job: QueryJobId) {
let mut span = None; let mut span = None;
let mut layout_of_depth = None; let mut note = None;
if let Some((info, depth)) = if let Some((info, depth)) = job.try_find_dep_kind_root(self.collect_active_jobs()) {
job.try_find_layout_root(self.collect_active_jobs(), dep_kinds::layout_of)
{
span = Some(info.job.span); 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() { let suggested_limit = match self.recursion_limit() {
@ -169,7 +167,7 @@ impl QueryContext for QueryCtxt<'_> {
self.sess.dcx().emit_fatal(QueryOverflow { self.sess.dcx().emit_fatal(QueryOverflow {
span, span,
layout_of_depth, note,
suggested_limit, suggested_limit,
crate_name: self.crate_name(LOCAL_CRATE), crate_name: self.crate_name(LOCAL_CRATE),
}); });

View file

@ -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_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_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! 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}`) .help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)

View file

@ -84,14 +84,14 @@ pub struct QueryOverflow {
#[primary_span] #[primary_span]
pub span: Option<Span>, pub span: Option<Span>,
#[subdiagnostic] #[subdiagnostic]
pub layout_of_depth: Option<LayoutOfDepth>, pub note: Option<QueryOverflowNote>,
pub suggested_limit: Limit, pub suggested_limit: Limit,
pub crate_name: Symbol, pub crate_name: Symbol,
} }
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[note(query_system_layout_of_depth)] #[note(query_system_overflow_note)]
pub struct LayoutOfDepth { pub struct QueryOverflowNote {
pub desc: String, pub desc: String,
pub depth: usize, pub depth: usize,
} }

View file

@ -16,7 +16,7 @@ pub mod ich;
pub mod query; pub mod query;
mod values; mod values;
pub use error::{HandleCycleError, LayoutOfDepth, QueryOverflow}; pub use error::{HandleCycleError, QueryOverflow, QueryOverflowNote};
pub use values::Value; pub use values::Value;
rustc_fluent_macro::fluent_messages! { "../messages.ftl" } rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

View file

@ -15,7 +15,7 @@ use rustc_span::{DUMMY_SP, Span};
use crate::dep_graph::DepContext; use crate::dep_graph::DepContext;
use crate::error::CycleStack; use crate::error::CycleStack;
use crate::query::plumbing::CycleError; use crate::query::plumbing::CycleError;
use crate::query::{DepKind, QueryContext, QueryStackFrame}; use crate::query::{QueryContext, QueryStackFrame};
/// Represents a span and a query key. /// Represents a span and a query key.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -136,18 +136,16 @@ impl QueryJobId {
#[cold] #[cold]
#[inline(never)] #[inline(never)]
pub fn try_find_layout_root( pub fn try_find_dep_kind_root(&self, query_map: QueryMap) -> Option<(QueryJobInfo, usize)> {
&self, let mut depth = 1;
query_map: QueryMap, let info = query_map.get(&self).unwrap();
layout_of_kind: DepKind, let dep_kind = info.query.dep_kind;
) -> Option<(QueryJobInfo, usize)> { let mut current_id = info.job.parent;
let mut last_layout = None; let mut last_layout = Some((info.clone(), depth));
let mut current_id = Some(*self);
let mut depth = 0;
while let Some(id) = current_id { while let Some(id) = current_id {
let info = query_map.get(&id).unwrap(); let info = query_map.get(&id).unwrap();
if info.query.dep_kind == layout_of_kind { if info.query.dep_kind == dep_kind {
depth += 1; depth += 1;
last_layout = Some((info.clone(), depth)); last_layout = Some((info.clone(), depth));
} }

View file

@ -1,12 +1,11 @@
// FIXME(generic_const_items): This leads to a stack overflow in the compiler! //@ build-fail
//@ known-bug: unknown
//@ ignore-test
#![feature(generic_const_items)] #![feature(generic_const_items)]
#![allow(incomplete_features)] #![allow(incomplete_features)]
#![recursion_limit = "15"]
const RECUR<T>: () = RECUR::<(T,)>; const RECUR<T>: () = RECUR::<(T,)>;
fn main() { fn main() {
let _ = RECUR::<()>; let _ = RECUR::<()>; //~ ERROR: queries overflow the depth limit!
} }

View file

@ -0,0 +1,11 @@
error: queries overflow the depth limit!
--> $DIR/recursive.rs:10:13
|
LL | let _ = RECUR::<()>;
| ^^^^^^^^^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "30"]` attribute to your crate (`recursive`)
= note: query depth increased by 17 when simplifying constant for the type system `RECUR`
error: aborting due to 1 previous error