Skip to content

Commit

Permalink
Rollup merge of rust-lang#121993 - Zoxc:query-stack-panic-queries, r=…
Browse files Browse the repository at this point in the history
…compiler-errors

Avoid using unnecessary queries when printing the query stack in panics

This should fix rust-lang#121974. Alternative to rust-lang#121981.
  • Loading branch information
matthiaskrgr committed Mar 5, 2024
2 parents 9c1b0c0 + fb91610 commit 1f5b3d2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -304,22 +305,26 @@ 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() {
format!("{description} [{name:?}]")
} 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
} else {
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 {
Expand Down

0 comments on commit 1f5b3d2

Please sign in to comment.