about summary refs log tree commit diff
path: root/compiler/rustc_query_impl/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-03-05 06:40:33 +0100
committerGitHub <noreply@github.com>2024-03-05 06:40:33 +0100
commit87dc3fc9509978b117b630916c32d14d85ba159a (patch)
tree0c438ca07eff66d67f6fabfa1bd4989c91b5f071 /compiler/rustc_query_impl/src
parent44bd2b516609933a573403a0985ff9decde314ad (diff)
parentfb9161028b8a7f276d552296811630c157471766 (diff)
downloadrust-87dc3fc9509978b117b630916c32d14d85ba159a.tar.gz
rust-87dc3fc9509978b117b630916c32d14d85ba159a.zip
Rollup merge of #121993 - Zoxc:query-stack-panic-queries, r=compiler-errors
Avoid using unnecessary queries when printing the query stack in panics

This should fix https://github.com/rust-lang/rust/issues/121974. Alternative to https://github.com/rust-lang/rust/pull/121981.
Diffstat (limited to 'compiler/rustc_query_impl/src')
-rw-r--r--compiler/rustc_query_impl/src/plumbing.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs
index 1b546bf9103..b06d75be390 100644
--- a/compiler/rustc_query_impl/src/plumbing.rs
+++ b/compiler/rustc_query_impl/src/plumbing.rs
@@ -17,6 +17,7 @@ use rustc_middle::dep_graph::{
 use rustc_middle::query::on_disk_cache::AbsoluteBytePos;
 use rustc_middle::query::on_disk_cache::{CacheDecoder, CacheEncoder, EncodedDepNodeIndex};
 use rustc_middle::query::Key;
+use rustc_middle::ty::print::with_reduced_queries;
 use rustc_middle::ty::tls::{self, ImplicitCtxt};
 use rustc_middle::ty::{self, TyCtxt};
 use rustc_query_system::dep_graph::{DepNodeParams, HasDepContext};
@@ -304,6 +305,10 @@ pub(crate) fn create_query_frame<
     kind: DepKind,
     name: &'static str,
 ) -> QueryStackFrame {
+    // If reduced queries are requested, we may be printing a query stack due
+    // to a panic. Avoid using `default_span` and `def_kind` in that case.
+    let reduce_queries = with_reduced_queries();
+
     // Avoid calling queries while formatting the description
     let description = ty::print::with_no_queries!(do_describe(tcx, key));
     let description = if tcx.sess.verbose_internals() {
@@ -311,7 +316,7 @@ pub(crate) fn create_query_frame<
     } else {
         description
     };
-    let span = if kind == dep_graph::dep_kinds::def_span {
+    let span = if kind == dep_graph::dep_kinds::def_span || reduce_queries {
         // The `def_span` query is used to calculate `default_span`,
         // so exit to avoid infinite recursion.
         None
@@ -319,7 +324,7 @@ pub(crate) fn create_query_frame<
         Some(key.default_span(tcx))
     };
     let def_id = key.key_as_def_id();
-    let def_kind = if kind == dep_graph::dep_kinds::def_kind {
+    let def_kind = if kind == dep_graph::dep_kinds::def_kind || reduce_queries {
         // Try to avoid infinite recursion.
         None
     } else {