Move try_print_query_stack to rustc_interface.
This commit is contained in:
parent
0e9cac40a6
commit
4dbf83a209
4 changed files with 60 additions and 52 deletions
|
@ -27,7 +27,6 @@ use rustc_interface::{interface, Queries};
|
||||||
use rustc_lint::LintStore;
|
use rustc_lint::LintStore;
|
||||||
use rustc_metadata::locator;
|
use rustc_metadata::locator;
|
||||||
use rustc_middle::middle::cstore::MetadataLoader;
|
use rustc_middle::middle::cstore::MetadataLoader;
|
||||||
use rustc_middle::ty::TyCtxt;
|
|
||||||
use rustc_save_analysis as save;
|
use rustc_save_analysis as save;
|
||||||
use rustc_save_analysis::DumpHandler;
|
use rustc_save_analysis::DumpHandler;
|
||||||
use rustc_serialize::json::{self, ToJson};
|
use rustc_serialize::json::{self, ToJson};
|
||||||
|
@ -1232,7 +1231,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
|
||||||
|
|
||||||
let num_frames = if backtrace { None } else { Some(2) };
|
let num_frames = if backtrace { None } else { Some(2) };
|
||||||
|
|
||||||
TyCtxt::try_print_query_stack(&handler, num_frames);
|
interface::try_print_query_stack(&handler, num_frames);
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -8,7 +8,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_data_structures::OnDrop;
|
use rustc_data_structures::OnDrop;
|
||||||
use rustc_errors::registry::Registry;
|
use rustc_errors::registry::Registry;
|
||||||
use rustc_errors::ErrorReported;
|
use rustc_errors::{ErrorReported, Handler};
|
||||||
use rustc_lint::LintStore;
|
use rustc_lint::LintStore;
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_parse::new_parser_from_source_str;
|
use rustc_parse::new_parser_from_source_str;
|
||||||
|
@ -213,3 +213,24 @@ pub fn run_compiler<R: Send>(mut config: Config, f: impl FnOnce(&Compiler) -> R
|
||||||
|| create_compiler_and_run(config, f),
|
|| create_compiler_and_run(config, f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn try_print_query_stack(handler: &Handler, num_frames: Option<usize>) {
|
||||||
|
eprintln!("query stack during panic:");
|
||||||
|
|
||||||
|
// 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 i = ty::tls::with_context_opt(|icx| {
|
||||||
|
if let Some(icx) = icx {
|
||||||
|
icx.tcx.queries.try_print_query_stack(icx.tcx, icx.query, handler, num_frames)
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if num_frames == None || num_frames >= Some(i) {
|
||||||
|
eprintln!("end of query stack");
|
||||||
|
} else {
|
||||||
|
eprintln!("we're just showing a limited slice of the query stack");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
//! generate the actual methods on tcx which find and execute the provider,
|
//! generate the actual methods on tcx which find and execute the provider,
|
||||||
//! manage the caches, and so forth.
|
//! manage the caches, and so forth.
|
||||||
|
|
||||||
use crate::ty::query::{on_disk_cache, Query};
|
use crate::dep_graph;
|
||||||
|
use crate::ty::query::{on_disk_cache, Queries, Query};
|
||||||
use crate::ty::tls::{self, ImplicitCtxt};
|
use crate::ty::tls::{self, ImplicitCtxt};
|
||||||
use crate::ty::{self, TyCtxt};
|
use crate::ty::{self, TyCtxt};
|
||||||
use rustc_query_system::dep_graph::HasDepContext;
|
use rustc_query_system::dep_graph::HasDepContext;
|
||||||
|
@ -170,57 +171,46 @@ impl<'tcx> QueryCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TyCtxt<'tcx> {
|
impl<'tcx> Queries<'tcx> {
|
||||||
pub fn try_print_query_stack(handler: &Handler, num_frames: Option<usize>) {
|
pub fn try_print_query_stack(
|
||||||
eprintln!("query stack during panic:");
|
&'tcx self,
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
query: Option<QueryJobId<dep_graph::DepKind>>,
|
||||||
|
handler: &Handler,
|
||||||
|
num_frames: Option<usize>,
|
||||||
|
) -> usize {
|
||||||
|
let query_map = self.try_collect_active_jobs();
|
||||||
|
|
||||||
// Be careful relying on global state here: this code is called from
|
let mut current_query = query;
|
||||||
// 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 mut i = 0;
|
||||||
ty::tls::with_context_opt(|icx| {
|
|
||||||
if let Some(icx) = icx {
|
|
||||||
let query_map = icx.tcx.queries.try_collect_active_jobs();
|
|
||||||
|
|
||||||
let mut current_query = icx.query;
|
while let Some(query) = current_query {
|
||||||
|
if Some(i) == num_frames {
|
||||||
while let Some(query) = current_query {
|
break;
|
||||||
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
|
|
||||||
.describe(QueryCtxt { tcx: icx.tcx, queries: icx.tcx.queries })
|
|
||||||
),
|
|
||||||
);
|
|
||||||
diag.span =
|
|
||||||
icx.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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
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.describe(QueryCtxt { tcx, queries: self })
|
||||||
|
),
|
||||||
|
);
|
||||||
|
diag.span = tcx.sess.source_map().guess_head_span(query_info.info.span).into();
|
||||||
|
handler.force_print_diagnostic(diag);
|
||||||
|
|
||||||
if num_frames == None || num_frames >= Some(i) {
|
current_query = query_info.job.parent;
|
||||||
eprintln!("end of query stack");
|
i += 1;
|
||||||
} else {
|
|
||||||
eprintln!("we're just showing a limited slice of the query stack");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,8 @@
|
||||||
extern crate rustc_driver;
|
extern crate rustc_driver;
|
||||||
extern crate rustc_errors;
|
extern crate rustc_errors;
|
||||||
extern crate rustc_interface;
|
extern crate rustc_interface;
|
||||||
extern crate rustc_middle;
|
|
||||||
|
|
||||||
use rustc_interface::interface;
|
use rustc_interface::interface;
|
||||||
use rustc_middle::ty::TyCtxt;
|
|
||||||
use rustc_tools_util::VersionInfo;
|
use rustc_tools_util::VersionInfo;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
@ -168,7 +166,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
|
||||||
|
|
||||||
let num_frames = if backtrace { None } else { Some(2) };
|
let num_frames = if backtrace { None } else { Some(2) };
|
||||||
|
|
||||||
TyCtxt::try_print_query_stack(&handler, num_frames);
|
interface::try_print_query_stack(&handler, num_frames);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toolchain_path(home: Option<String>, toolchain: Option<String>) -> Option<PathBuf> {
|
fn toolchain_path(home: Option<String>, toolchain: Option<String>) -> Option<PathBuf> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue