Skip to content

Commit 4dbf83a

Browse files
committed
Move try_print_query_stack to rustc_interface.
1 parent 0e9cac4 commit 4dbf83a

File tree

4 files changed

+62
-54
lines changed

4 files changed

+62
-54
lines changed

compiler/rustc_driver/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use rustc_interface::{interface, Queries};
2727
use rustc_lint::LintStore;
2828
use rustc_metadata::locator;
2929
use rustc_middle::middle::cstore::MetadataLoader;
30-
use rustc_middle::ty::TyCtxt;
3130
use rustc_save_analysis as save;
3231
use rustc_save_analysis::DumpHandler;
3332
use rustc_serialize::json::{self, ToJson};
@@ -1232,7 +1231,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12321231

12331232
let num_frames = if backtrace { None } else { Some(2) };
12341233

1235-
TyCtxt::try_print_query_stack(&handler, num_frames);
1234+
interface::try_print_query_stack(&handler, num_frames);
12361235

12371236
#[cfg(windows)]
12381237
unsafe {

compiler/rustc_interface/src/interface.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
88
use rustc_data_structures::sync::Lrc;
99
use rustc_data_structures::OnDrop;
1010
use rustc_errors::registry::Registry;
11-
use rustc_errors::ErrorReported;
11+
use rustc_errors::{ErrorReported, Handler};
1212
use rustc_lint::LintStore;
1313
use rustc_middle::ty;
1414
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
213213
|| create_compiler_and_run(config, f),
214214
)
215215
}
216+
217+
pub fn try_print_query_stack(handler: &Handler, num_frames: Option<usize>) {
218+
eprintln!("query stack during panic:");
219+
220+
// Be careful relying on global state here: this code is called from
221+
// a panic hook, which means that the global `Handler` may be in a weird
222+
// state if it was responsible for triggering the panic.
223+
let i = ty::tls::with_context_opt(|icx| {
224+
if let Some(icx) = icx {
225+
icx.tcx.queries.try_print_query_stack(icx.tcx, icx.query, handler, num_frames)
226+
} else {
227+
0
228+
}
229+
});
230+
231+
if num_frames == None || num_frames >= Some(i) {
232+
eprintln!("end of query stack");
233+
} else {
234+
eprintln!("we're just showing a limited slice of the query stack");
235+
}
236+
}

compiler/rustc_middle/src/ty/query/plumbing.rs

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
//! generate the actual methods on tcx which find and execute the provider,
33
//! manage the caches, and so forth.
44
5-
use crate::ty::query::{on_disk_cache, Query};
5+
use crate::dep_graph;
6+
use crate::ty::query::{on_disk_cache, Queries, Query};
67
use crate::ty::tls::{self, ImplicitCtxt};
78
use crate::ty::{self, TyCtxt};
89
use rustc_query_system::dep_graph::HasDepContext;
@@ -170,57 +171,46 @@ impl<'tcx> QueryCtxt<'tcx> {
170171
}
171172
}
172173

173-
impl<'tcx> TyCtxt<'tcx> {
174-
pub fn try_print_query_stack(handler: &Handler, num_frames: Option<usize>) {
175-
eprintln!("query stack during panic:");
176-
177-
// Be careful relying on global state here: this code is called from
178-
// a panic hook, which means that the global `Handler` may be in a weird
179-
// state if it was responsible for triggering the panic.
174+
impl<'tcx> Queries<'tcx> {
175+
pub fn try_print_query_stack(
176+
&'tcx self,
177+
tcx: TyCtxt<'tcx>,
178+
query: Option<QueryJobId<dep_graph::DepKind>>,
179+
handler: &Handler,
180+
num_frames: Option<usize>,
181+
) -> usize {
182+
let query_map = self.try_collect_active_jobs();
183+
184+
let mut current_query = query;
180185
let mut i = 0;
181-
ty::tls::with_context_opt(|icx| {
182-
if let Some(icx) = icx {
183-
let query_map = icx.tcx.queries.try_collect_active_jobs();
184-
185-
let mut current_query = icx.query;
186-
187-
while let Some(query) = current_query {
188-
if Some(i) == num_frames {
189-
break;
190-
}
191-
let query_info =
192-
if let Some(info) = query_map.as_ref().and_then(|map| map.get(&query)) {
193-
info
194-
} else {
195-
break;
196-
};
197-
let mut diag = Diagnostic::new(
198-
Level::FailureNote,
199-
&format!(
200-
"#{} [{}] {}",
201-
i,
202-
query_info.info.query.name(),
203-
query_info
204-
.info
205-
.query
206-
.describe(QueryCtxt { tcx: icx.tcx, queries: icx.tcx.queries })
207-
),
208-
);
209-
diag.span =
210-
icx.tcx.sess.source_map().guess_head_span(query_info.info.span).into();
211-
handler.force_print_diagnostic(diag);
212-
213-
current_query = query_info.job.parent;
214-
i += 1;
215-
}
186+
187+
while let Some(query) = current_query {
188+
if Some(i) == num_frames {
189+
break;
216190
}
217-
});
191+
let query_info = if let Some(info) = query_map.as_ref().and_then(|map| map.get(&query))
192+
{
193+
info
194+
} else {
195+
break;
196+
};
197+
let mut diag = Diagnostic::new(
198+
Level::FailureNote,
199+
&format!(
200+
"#{} [{}] {}",
201+
i,
202+
query_info.info.query.name(),
203+
query_info.info.query.describe(QueryCtxt { tcx, queries: self })
204+
),
205+
);
206+
diag.span = tcx.sess.source_map().guess_head_span(query_info.info.span).into();
207+
handler.force_print_diagnostic(diag);
218208

219-
if num_frames == None || num_frames >= Some(i) {
220-
eprintln!("end of query stack");
221-
} else {
222-
eprintln!("we're just showing a limited slice of the query stack");
209+
current_query = query_info.job.parent;
210+
i += 1;
223211
}
212+
213+
i
224214
}
225215
}
226216

src/tools/clippy/src/driver.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
extern crate rustc_driver;
1212
extern crate rustc_errors;
1313
extern crate rustc_interface;
14-
extern crate rustc_middle;
1514

1615
use rustc_interface::interface;
17-
use rustc_middle::ty::TyCtxt;
1816
use rustc_tools_util::VersionInfo;
1917

2018
use std::borrow::Cow;
@@ -168,7 +166,7 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
168166

169167
let num_frames = if backtrace { None } else { Some(2) };
170168

171-
TyCtxt::try_print_query_stack(&handler, num_frames);
169+
interface::try_print_query_stack(&handler, num_frames);
172170
}
173171

174172
fn toolchain_path(home: Option<String>, toolchain: Option<String>) -> Option<PathBuf> {

0 commit comments

Comments
 (0)