diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2020-11-29 00:39:34 +0100 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-02-20 23:40:56 +0100 |
| commit | a87de890fd1a797952ab49459aeca4ce598d8f15 (patch) | |
| tree | 5be960f5c6ce24faeef7c70752222ea8746fc8fe /compiler/rustc_query_system | |
| parent | c26d965714e38d62b1610780f67bec14dafe25c3 (diff) | |
| download | rust-a87de890fd1a797952ab49459aeca4ce598d8f15.tar.gz rust-a87de890fd1a797952ab49459aeca4ce598d8f15.zip | |
Move print_query_stack to rustc_query_system.
Diffstat (limited to 'compiler/rustc_query_system')
| -rw-r--r-- | compiler/rustc_query_system/src/query/job.rs | 46 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/query/mod.rs | 2 |
2 files changed, 43 insertions, 5 deletions
diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index a30cd078d6c..30dce1e5018 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -1,8 +1,9 @@ +use crate::dep_graph::DepContext; use crate::query::plumbing::CycleError; -use crate::query::QueryStackFrame; +use crate::query::{QueryContext, QueryStackFrame}; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{struct_span_err, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, Handler, Level}; use rustc_session::Session; use rustc_span::Span; @@ -13,8 +14,6 @@ use std::num::NonZeroU32; #[cfg(parallel_compiler)] use { - crate::dep_graph::DepContext, - crate::query::QueryContext, parking_lot::{Condvar, Mutex}, rustc_data_structures::fx::FxHashSet, rustc_data_structures::stable_hasher::{HashStable, StableHasher}, @@ -626,3 +625,42 @@ pub(crate) fn report_cycle<'a>( err } + +pub fn print_query_stack<CTX: QueryContext>( + tcx: CTX, + mut current_query: Option<QueryJobId<CTX::DepKind>>, + handler: &Handler, + num_frames: Option<usize>, +) -> usize { + // Be careful relying on global state here: this code is called from + // a panic hook, which means that the global `Handler` may be in a weird + // state if it was responsible for triggering the panic. + let mut i = 0; + let query_map = tcx.try_collect_active_jobs(); + + while let Some(query) = current_query { + if Some(i) == num_frames { + break; + } + let query_info = if let Some(info) = query_map.as_ref().and_then(|map| map.get(&query)) { + info + } else { + break; + }; + let mut diag = Diagnostic::new( + Level::FailureNote, + &format!( + "#{} [{}] {}", + i, query_info.info.query.name, query_info.info.query.description + ), + ); + diag.span = + tcx.dep_context().sess().source_map().guess_head_span(query_info.info.span).into(); + handler.force_print_diagnostic(diag); + + current_query = query_info.job.parent; + i += 1; + } + + i +} diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index 7b46674c743..81e2b4877fd 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -4,7 +4,7 @@ pub use self::plumbing::*; mod job; #[cfg(parallel_compiler)] pub use self::job::deadlock; -pub use self::job::{QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryMap}; +pub use self::job::{print_query_stack, QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryMap}; mod caches; pub use self::caches::{ |
