Rollup merge of #101801 - SparrowLii:query_depth_note, r=estebank
add note for `layout_of` when query depth overflows Fixes #101747 Added `try_find_layout_root` function to add a note for `layout_of` when query depth overflows. This would make the error in #101747 look like this: ``` error: queries overflow the depth limit! | note: Query depth increased by 66 when computing layout of `core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<alloc::boxed::Box<alloc::string::String>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`! --> D:\rust-backup\parallel_rust\query_depth.rs:40:1 | 40 | fn main() { | ^^^^^^^^^ error: aborting due to previous error ``` cc ``@semicoleon``
This commit is contained in:
commit
4757d2d57e
@ -23,3 +23,6 @@ query_system_cycle_recursive_trait_alias = trait aliases cannot be recursive
|
||||
query_system_cycle_which_requires = ...which requires {$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}`)
|
||||
|
||||
query_system_layout_of_depth = query depth increased by {$depth} when {$desc}
|
||||
|
@ -19,8 +19,10 @@
|
||||
force_query, QueryConfig, QueryContext, QueryDescription, QueryJobId, QueryMap,
|
||||
QuerySideEffects, QueryStackFrame,
|
||||
};
|
||||
use rustc_query_system::Value;
|
||||
use rustc_query_system::{LayoutOfDepth, QueryOverflow, Value};
|
||||
use rustc_serialize::Decodable;
|
||||
use rustc_session::Limit;
|
||||
use rustc_span::def_id::LOCAL_CRATE;
|
||||
use std::any::Any;
|
||||
use std::num::NonZeroU64;
|
||||
use thin_vec::ThinVec;
|
||||
@ -109,7 +111,7 @@ fn start_query<R>(
|
||||
// when accessing the `ImplicitCtxt`.
|
||||
tls::with_related_context(**self, move |current_icx| {
|
||||
if depth_limit && !self.recursion_limit().value_within_limit(current_icx.query_depth) {
|
||||
self.depth_limit_error();
|
||||
self.depth_limit_error(token);
|
||||
}
|
||||
|
||||
// Update the `ImplicitCtxt` to point to our new query job.
|
||||
@ -127,6 +129,29 @@ fn start_query<R>(
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn depth_limit_error(&self, job: QueryJobId) {
|
||||
let mut span = None;
|
||||
let mut layout_of_depth = None;
|
||||
if let Some(map) = self.try_collect_active_jobs() {
|
||||
if let Some((info, depth)) = job.try_find_layout_root(map) {
|
||||
span = Some(info.job.span);
|
||||
layout_of_depth = Some(LayoutOfDepth { desc: info.query.description, depth });
|
||||
}
|
||||
}
|
||||
|
||||
let suggested_limit = match self.recursion_limit() {
|
||||
Limit(0) => Limit(2),
|
||||
limit => limit * 2,
|
||||
};
|
||||
|
||||
self.sess.emit_fatal(QueryOverflow {
|
||||
span,
|
||||
layout_of_depth,
|
||||
suggested_limit,
|
||||
crate_name: self.crate_name(LOCAL_CRATE),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> QueryCtxt<'tcx> {
|
||||
|
@ -1,5 +1,6 @@
|
||||
use rustc_errors::AddSubdiagnostic;
|
||||
use rustc_span::Span;
|
||||
use rustc_session::Limit;
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
||||
pub struct CycleStack {
|
||||
pub span: Span,
|
||||
@ -76,5 +77,20 @@ pub struct IncrementCompilation {
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[help]
|
||||
#[diag(query_system::query_overflow)]
|
||||
pub struct QueryOverflow;
|
||||
pub struct QueryOverflow {
|
||||
#[primary_span]
|
||||
pub span: Option<Span>,
|
||||
#[subdiagnostic]
|
||||
pub layout_of_depth: Option<LayoutOfDepth>,
|
||||
pub suggested_limit: Limit,
|
||||
pub crate_name: Symbol,
|
||||
}
|
||||
|
||||
#[derive(SessionSubdiagnostic)]
|
||||
#[note(query_system::layout_of_depth)]
|
||||
pub struct LayoutOfDepth {
|
||||
pub desc: String,
|
||||
pub depth: usize,
|
||||
}
|
||||
|
@ -23,4 +23,6 @@
|
||||
mod values;
|
||||
|
||||
pub use error::HandleCycleError;
|
||||
pub use error::LayoutOfDepth;
|
||||
pub use error::QueryOverflow;
|
||||
pub use values::Value;
|
||||
|
@ -59,6 +59,7 @@ fn latch<'a>(self, map: &'a QueryMap) -> Option<&'a QueryLatch> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct QueryJobInfo {
|
||||
pub query: QueryStackFrame,
|
||||
pub job: QueryJob,
|
||||
@ -116,10 +117,10 @@ pub fn signal_complete(self) {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(parallel_compiler))]
|
||||
impl QueryJobId {
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
#[cfg(not(parallel_compiler))]
|
||||
pub(super) fn find_cycle_in_stack(
|
||||
&self,
|
||||
query_map: QueryMap,
|
||||
@ -156,6 +157,24 @@ pub(super) fn find_cycle_in_stack(
|
||||
|
||||
panic!("did not find a cycle")
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub fn try_find_layout_root(&self, query_map: QueryMap) -> Option<(QueryJobInfo, usize)> {
|
||||
let mut last_layout = None;
|
||||
let mut current_id = Some(*self);
|
||||
let mut depth = 0;
|
||||
|
||||
while let Some(id) = current_id {
|
||||
let info = query_map.get(&id).unwrap();
|
||||
if info.query.name == "layout_of" {
|
||||
depth += 1;
|
||||
last_layout = Some((info.clone(), depth));
|
||||
}
|
||||
current_id = info.job.parent;
|
||||
}
|
||||
last_layout
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(parallel_compiler)]
|
||||
|
@ -14,7 +14,7 @@
|
||||
mod config;
|
||||
pub use self::config::{QueryConfig, QueryDescription, QueryVTable};
|
||||
|
||||
use crate::dep_graph::{DepContext, DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
|
||||
use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
|
||||
use rustc_data_structures::sync::Lock;
|
||||
use rustc_errors::Diagnostic;
|
||||
use rustc_hir::def::DefKind;
|
||||
@ -123,7 +123,5 @@ fn start_query<R>(
|
||||
compute: impl FnOnce() -> R,
|
||||
) -> R;
|
||||
|
||||
fn depth_limit_error(&self) {
|
||||
self.dep_context().sess().emit_fatal(crate::error::QueryOverflow);
|
||||
}
|
||||
fn depth_limit_error(&self, job: QueryJobId);
|
||||
}
|
||||
|
31
src/test/ui/query-system/query_depth.rs
Normal file
31
src/test/ui/query-system/query_depth.rs
Normal file
@ -0,0 +1,31 @@
|
||||
// build-fail
|
||||
|
||||
#![recursion_limit = "64"]
|
||||
type Byte = Option<Option<Option<Option< Option<Option<Option<Option<
|
||||
Option<Option<Option<Option< Option<Option<Option<Option<
|
||||
Option<Option<Option<Option< Option<Option<Option<Option<
|
||||
Option<Option<Option<Option< Option<Option<Option<Option<
|
||||
Option<Option<Option<Option< Option<Option<Option<Option<
|
||||
Option<Option<Option<Option< Option<Option<Option<Option<
|
||||
Option<Option<Option<Option< Option<Option<Option<Option<
|
||||
Option<Option<Option<Option< Option<Option<Option<Option<
|
||||
Option<Option<Option<Option< Option<Option<Option<Option<
|
||||
Option<Option<Option<Option< Option<Option<Option<Option<
|
||||
Option<Option<Option<Option< Option<Option<Option<Option<
|
||||
Box<String>
|
||||
>>>> >>>>
|
||||
>>>> >>>>
|
||||
>>>> >>>>
|
||||
>>>> >>>>
|
||||
>>>> >>>>
|
||||
>>>> >>>>
|
||||
>>>> >>>>
|
||||
>>>> >>>>
|
||||
>>>> >>>>
|
||||
>>>> >>>>
|
||||
>>>> >>>>;
|
||||
|
||||
fn main() {
|
||||
//~^ ERROR: queries overflow the depth limit!
|
||||
println!("{}", std::mem::size_of::<Byte>());
|
||||
}
|
11
src/test/ui/query-system/query_depth.stderr
Normal file
11
src/test/ui/query-system/query_depth.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error: queries overflow the depth limit!
|
||||
--> $DIR/query_depth.rs:28:1
|
||||
|
|
||||
LL | fn main() {
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "128"]` attribute to your crate (`query_depth`)
|
||||
= note: query depth increased by 66 when computing layout of `core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<alloc::boxed::Box<alloc::string::String>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user