Skip to content

Commit fb91610

Browse files
committed
Avoid using unnecessary queries when printing the query stack in panics
1 parent 7606c13 commit fb91610

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

compiler/rustc_query_impl/src/plumbing.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_middle::dep_graph::{
1717
use rustc_middle::query::on_disk_cache::AbsoluteBytePos;
1818
use rustc_middle::query::on_disk_cache::{CacheDecoder, CacheEncoder, EncodedDepNodeIndex};
1919
use rustc_middle::query::Key;
20+
use rustc_middle::ty::print::with_reduced_queries;
2021
use rustc_middle::ty::tls::{self, ImplicitCtxt};
2122
use rustc_middle::ty::{self, TyCtxt};
2223
use rustc_query_system::dep_graph::{DepNodeParams, HasDepContext};
@@ -304,22 +305,26 @@ pub(crate) fn create_query_frame<
304305
kind: DepKind,
305306
name: &'static str,
306307
) -> QueryStackFrame {
308+
// If reduced queries are requested, we may be printing a query stack due
309+
// to a panic. Avoid using `default_span` and `def_kind` in that case.
310+
let reduce_queries = with_reduced_queries();
311+
307312
// Avoid calling queries while formatting the description
308313
let description = ty::print::with_no_queries!(do_describe(tcx, key));
309314
let description = if tcx.sess.verbose_internals() {
310315
format!("{description} [{name:?}]")
311316
} else {
312317
description
313318
};
314-
let span = if kind == dep_graph::dep_kinds::def_span {
319+
let span = if kind == dep_graph::dep_kinds::def_span || reduce_queries {
315320
// The `def_span` query is used to calculate `default_span`,
316321
// so exit to avoid infinite recursion.
317322
None
318323
} else {
319324
Some(key.default_span(tcx))
320325
};
321326
let def_id = key.key_as_def_id();
322-
let def_kind = if kind == dep_graph::dep_kinds::def_kind {
327+
let def_kind = if kind == dep_graph::dep_kinds::def_kind || reduce_queries {
323328
// Try to avoid infinite recursion.
324329
None
325330
} else {

0 commit comments

Comments
 (0)