Skip to content

Commit

Permalink
Move print_query_stack to rustc_query_system.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Feb 20, 2021
1 parent c26d965 commit a87de89
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 38 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_query_impl/src/lib.rs
Expand Up @@ -18,7 +18,7 @@ extern crate tracing;

use rustc_data_structures::fingerprint::Fingerprint;
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_index::vec::IndexVec;
use rustc_middle::dep_graph;
Expand Down
34 changes: 2 additions & 32 deletions compiler/rustc_query_impl/src/plumbing.rs
Expand Up @@ -584,38 +584,8 @@ macro_rules! define_queries_struct {
handler: &Handler,
num_frames: Option<usize>,
) -> usize {
let query_map = self.try_collect_active_jobs(tcx);

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
let qcx = QueryCtxt { tcx, queries: self };
rustc_query_system::query::print_query_stack(qcx, query, handler, num_frames)
}

$($(#[$attr])*
Expand Down
46 changes: 42 additions & 4 deletions 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;

Expand All @@ -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},
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/query/mod.rs
Expand Up @@ -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::{
Expand Down

0 comments on commit a87de89

Please sign in to comment.