Move print_query_stack to rustc_query_system.
This commit is contained in:
parent
c26d965714
commit
a87de890fd
@ -18,7 +18,7 @@ extern crate tracing;
|
|||||||
|
|
||||||
use rustc_data_structures::fingerprint::Fingerprint;
|
use rustc_data_structures::fingerprint::Fingerprint;
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_errors::{Diagnostic, DiagnosticBuilder, Handler, Level};
|
use rustc_errors::{DiagnosticBuilder, Handler};
|
||||||
use rustc_hir::def_id::CrateNum;
|
use rustc_hir::def_id::CrateNum;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_middle::dep_graph;
|
use rustc_middle::dep_graph;
|
||||||
|
@ -584,38 +584,8 @@ macro_rules! define_queries_struct {
|
|||||||
handler: &Handler,
|
handler: &Handler,
|
||||||
num_frames: Option<usize>,
|
num_frames: Option<usize>,
|
||||||
) -> usize {
|
) -> usize {
|
||||||
let query_map = self.try_collect_active_jobs(tcx);
|
let qcx = QueryCtxt { tcx, queries: self };
|
||||||
|
rustc_query_system::query::print_query_stack(qcx, query, handler, num_frames)
|
||||||
let mut current_query = query;
|
|
||||||
let mut i = 0;
|
|
||||||
|
|
||||||
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.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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$($(#[$attr])*
|
$($(#[$attr])*
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
use crate::dep_graph::DepContext;
|
||||||
use crate::query::plumbing::CycleError;
|
use crate::query::plumbing::CycleError;
|
||||||
use crate::query::QueryStackFrame;
|
use crate::query::{QueryContext, QueryStackFrame};
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
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_session::Session;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
@ -13,8 +14,6 @@ use std::num::NonZeroU32;
|
|||||||
|
|
||||||
#[cfg(parallel_compiler)]
|
#[cfg(parallel_compiler)]
|
||||||
use {
|
use {
|
||||||
crate::dep_graph::DepContext,
|
|
||||||
crate::query::QueryContext,
|
|
||||||
parking_lot::{Condvar, Mutex},
|
parking_lot::{Condvar, Mutex},
|
||||||
rustc_data_structures::fx::FxHashSet,
|
rustc_data_structures::fx::FxHashSet,
|
||||||
rustc_data_structures::stable_hasher::{HashStable, StableHasher},
|
rustc_data_structures::stable_hasher::{HashStable, StableHasher},
|
||||||
@ -626,3 +625,42 @@ pub(crate) fn report_cycle<'a>(
|
|||||||
|
|
||||||
err
|
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
|
||||||
|
}
|
||||||
|
@ -4,7 +4,7 @@ pub use self::plumbing::*;
|
|||||||
mod job;
|
mod job;
|
||||||
#[cfg(parallel_compiler)]
|
#[cfg(parallel_compiler)]
|
||||||
pub use self::job::deadlock;
|
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;
|
mod caches;
|
||||||
pub use self::caches::{
|
pub use self::caches::{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user