diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2020-04-08 20:47:36 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-02-19 17:51:55 +0100 |
| commit | 4dbf83a2091bea4027f0e6eae43c991f06ff46b9 (patch) | |
| tree | 203145a808e17a163792b2c137ba3e58a855b371 | |
| parent | 0e9cac40a66ad8c18409890673150d8a4eacf039 (diff) | |
| download | rust-4dbf83a2091bea4027f0e6eae43c991f06ff46b9.tar.gz rust-4dbf83a2091bea4027f0e6eae43c991f06ff46b9.zip | |
Move try_print_query_stack to rustc_interface.
| -rw-r--r-- | compiler/rustc_driver/src/lib.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/interface.rs | 23 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/query/plumbing.rs | 86 | ||||
| -rw-r--r-- | src/tools/clippy/src/driver.rs | 4 |
4 files changed, 62 insertions, 54 deletions
diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index cad5a87bb13..07c7278a2f4 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -27,7 +27,6 @@ use rustc_interface::{interface, Queries}; use rustc_lint::LintStore; use rustc_metadata::locator; use rustc_middle::middle::cstore::MetadataLoader; -use rustc_middle::ty::TyCtxt; use rustc_save_analysis as save; use rustc_save_analysis::DumpHandler; 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) }; - TyCtxt::try_print_query_stack(&handler, num_frames); + interface::try_print_query_stack(&handler, num_frames); #[cfg(windows)] unsafe { diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 28eb1fed6a0..502e7155c2e 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -8,7 +8,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::Lrc; use rustc_data_structures::OnDrop; use rustc_errors::registry::Registry; -use rustc_errors::ErrorReported; +use rustc_errors::{ErrorReported, Handler}; use rustc_lint::LintStore; use rustc_middle::ty; 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), ) } + +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"); + } +} diff --git a/compiler/rustc_middle/src/ty/query/plumbing.rs b/compiler/rustc_middle/src/ty/query/plumbing.rs index a17fc71fd5c..6aa9d88798f 100644 --- a/compiler/rustc_middle/src/ty/query/plumbing.rs +++ b/compiler/rustc_middle/src/ty/query/plumbing.rs @@ -2,7 +2,8 @@ //! generate the actual methods on tcx which find and execute the provider, //! 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::{self, TyCtxt}; use rustc_query_system::dep_graph::HasDepContext; @@ -170,57 +171,46 @@ impl<'tcx> QueryCtxt<'tcx> { } } -impl<'tcx> TyCtxt<'tcx> { - 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. +impl<'tcx> Queries<'tcx> { + pub fn try_print_query_stack( + &'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(); + + let mut current_query = query; 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 { - 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; - } + + 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.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) { - eprintln!("end of query stack"); - } else { - eprintln!("we're just showing a limited slice of the query stack"); + current_query = query_info.job.parent; + i += 1; } + + i } } diff --git a/src/tools/clippy/src/driver.rs b/src/tools/clippy/src/driver.rs index f5f6c09ed8e..d5143e1438e 100644 --- a/src/tools/clippy/src/driver.rs +++ b/src/tools/clippy/src/driver.rs @@ -11,10 +11,8 @@ extern crate rustc_driver; extern crate rustc_errors; extern crate rustc_interface; -extern crate rustc_middle; use rustc_interface::interface; -use rustc_middle::ty::TyCtxt; use rustc_tools_util::VersionInfo; 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) }; - 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> { |
