Skip to content

Commit b0142f6

Browse files
oli-obkflip1995
authored andcommittedJun 27, 2023
Avoid calling queries during query stack printing
1 parent 5d3377d commit b0142f6

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed
 

‎compiler/rustc_interface/src/interface.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,12 @@ pub fn try_print_query_stack(handler: &Handler, num_frames: Option<usize>) {
349349
// state if it was responsible for triggering the panic.
350350
let i = ty::tls::with_context_opt(|icx| {
351351
if let Some(icx) = icx {
352-
print_query_stack(QueryCtxt::new(icx.tcx), icx.query, handler, num_frames)
352+
ty::print::with_no_queries!(print_query_stack(
353+
QueryCtxt::new(icx.tcx),
354+
icx.query,
355+
handler,
356+
num_frames
357+
))
353358
} else {
354359
0
355360
}

‎compiler/rustc_middle/src/ty/print/pretty.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ macro_rules! define_helper {
9494
$tl.with(|c| c.set(self.0))
9595
}
9696
}
97+
98+
pub fn $name() -> bool {
99+
$tl.with(|c| c.get())
100+
}
97101
)+
98102
}
99103
}
@@ -676,7 +680,7 @@ pub trait PrettyPrinter<'tcx>:
676680
p!(")")
677681
}
678682
ty::FnDef(def_id, substs) => {
679-
if NO_QUERIES.with(|q| q.get()) {
683+
if with_no_queries() {
680684
p!(print_def_path(def_id, substs));
681685
} else {
682686
let sig = self.tcx().fn_sig(def_id).subst(self.tcx(), substs);
@@ -732,7 +736,7 @@ pub trait PrettyPrinter<'tcx>:
732736
p!(print_def_path(def_id, &[]));
733737
}
734738
ty::Alias(ty::Projection | ty::Inherent | ty::Weak, ref data) => {
735-
if !(self.should_print_verbose() || NO_QUERIES.with(|q| q.get()))
739+
if !(self.should_print_verbose() || with_no_queries())
736740
&& self.tcx().is_impl_trait_in_trait(data.def_id)
737741
{
738742
return self.pretty_print_opaque_impl_type(data.def_id, data.substs);
@@ -779,7 +783,7 @@ pub trait PrettyPrinter<'tcx>:
779783
return Ok(self);
780784
}
781785
_ => {
782-
if NO_QUERIES.with(|q| q.get()) {
786+
if with_no_queries() {
783787
p!(print_def_path(def_id, &[]));
784788
return Ok(self);
785789
} else {
@@ -1746,7 +1750,8 @@ impl DerefMut for FmtPrinter<'_, '_> {
17461750

17471751
impl<'a, 'tcx> FmtPrinter<'a, 'tcx> {
17481752
pub fn new(tcx: TyCtxt<'tcx>, ns: Namespace) -> Self {
1749-
Self::new_with_limit(tcx, ns, tcx.type_length_limit())
1753+
let limit = if with_no_queries() { Limit::new(1048576) } else { tcx.type_length_limit() };
1754+
Self::new_with_limit(tcx, ns, limit)
17501755
}
17511756

17521757
pub fn new_with_limit(tcx: TyCtxt<'tcx>, ns: Namespace, type_length_limit: Limit) -> Self {

‎compiler/rustc_query_impl/src/plumbing.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::query::on_disk_cache::AbsoluteBytePos;
1616
use rustc_middle::query::on_disk_cache::{CacheDecoder, CacheEncoder, EncodedDepNodeIndex};
1717
use rustc_middle::query::Key;
1818
use rustc_middle::ty::tls::{self, ImplicitCtxt};
19-
use rustc_middle::ty::{self, TyCtxt};
19+
use rustc_middle::ty::{self, print::with_no_queries, TyCtxt};
2020
use rustc_query_system::dep_graph::{DepNodeParams, HasDepContext};
2121
use rustc_query_system::ich::StableHashingContext;
2222
use rustc_query_system::query::{
@@ -312,15 +312,15 @@ pub(crate) fn create_query_frame<
312312
);
313313
let description =
314314
if tcx.sess.verbose() { format!("{description} [{name:?}]") } else { description };
315-
let span = if kind == dep_graph::DepKind::def_span {
315+
let span = if kind == dep_graph::DepKind::def_span || with_no_queries() {
316316
// The `def_span` query is used to calculate `default_span`,
317317
// so exit to avoid infinite recursion.
318318
None
319319
} else {
320320
Some(key.default_span(tcx))
321321
};
322322
let def_id = key.key_as_def_id();
323-
let def_kind = if kind == dep_graph::DepKind::opt_def_kind {
323+
let def_kind = if kind == dep_graph::DepKind::opt_def_kind || with_no_queries() {
324324
// Try to avoid infinite recursion.
325325
None
326326
} else {

‎tests/ui/treat-err-as-bug/panic-causes-oom-112708.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// compile-flags: -Ztreat-err-as-bug
22
// dont-check-failure-status
33
// error-pattern: aborting due to `-Z treat-err-as-bug=1`
4-
// normalize-stderr-test "note: .*\n\n" -> ""
5-
// normalize-stderr-test "thread 'rustc' panicked.*\n" -> ""
4+
// dont-check-compiler-stderr
65
// rustc-env:RUST_BACKTRACE=0
76

87
fn main() {
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
error: denote infinite loops with `loop { ... }`
2-
--> $DIR/panic-causes-oom-112708.rs:10:5
2+
--> $DIR/panic-causes-oom-112708.rs:13:5
33
|
44
LL | while true {}
55
| ^^^^^^^^^^ help: use `loop`
66
|
77
note: the lint level is defined here
8-
--> $DIR/panic-causes-oom-112708.rs:9:12
8+
--> $DIR/panic-causes-oom-112708.rs:12:12
99
|
1010
LL | #[deny(while_true)]
1111
| ^^^^^^^^^^
1212

13+
14+
query stack during panic:
15+
#0 [early_lint_checks] perform lints prior to macro expansion
16+
#1 [hir_crate] getting the crate HIR
17+
end of query stack
18+
19+
error: the compiler unexpectedly panicked. this is a bug.
20+
21+
query stack during panic:
22+
#0 [early_lint_checks] perform lints prior to macro expansion
23+
#1 [hir_crate] getting the crate HIR
24+
end of query stack
25+
1326
error: the compiler unexpectedly panicked. this is a bug.
1427

1528
query stack during panic:
16-
thread panicked while processing panic. aborting.
29+
#0 [early_lint_checks] perform lints prior to macro expansion
30+
#1 [hir_crate] getting the crate HIR
31+
end of query stack
32+
thread caused non-unwinding panic. aborting.

0 commit comments

Comments
 (0)