diff options
| author | SparrowLii <liyuan179@huawei.com> | 2022-09-14 21:00:00 +0800 |
|---|---|---|
| committer | SparrowLii <liyuan179@huawei.com> | 2022-09-15 16:05:00 +0800 |
| commit | 44506f38e079caec1b6c14e05a9b86e19544757f (patch) | |
| tree | a8c4f9a28778b1afc1ade67efcb326e43c908d68 /compiler/rustc_query_system/src/query | |
| parent | c3f59295fecb9a7cb067bc4a5b50f779e159a55b (diff) | |
| download | rust-44506f38e079caec1b6c14e05a9b86e19544757f.tar.gz rust-44506f38e079caec1b6c14e05a9b86e19544757f.zip | |
add note for `layout_of` when query depth overflows
Diffstat (limited to 'compiler/rustc_query_system/src/query')
| -rw-r--r-- | compiler/rustc_query_system/src/query/job.rs | 24 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/query/mod.rs | 15 |
2 files changed, 36 insertions, 3 deletions
diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index 45b4079fb54..a5ea3a098a6 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -59,6 +59,7 @@ impl QueryJobId { } } +#[derive(Clone)] pub struct QueryJobInfo { pub query: QueryStackFrame, pub job: QueryJob, @@ -116,10 +117,10 @@ impl QueryJob { } } -#[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,27 @@ impl QueryJobId { panic!("did not find a cycle") } + + #[cold] + #[inline(never)] + pub(super) 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)] diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index 0b07bb64b6a..e29e8815331 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -123,7 +123,18 @@ pub trait QueryContext: HasDepContext { 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) { + let sess = self.dep_context().sess(); + 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) { + layout_of_depth = Some(crate::error::LayoutOfDepth { + span: info.job.span, + desc: info.query.description, + depth, + }); + } + } + sess.emit_fatal(crate::error::QueryOverflow { layout_of_depth }); } } |
