Skip to content

Commit 8882507

Browse files
committed
Auto merge of #112708 - flip1995:clippy-freezing-pc-with-ice, r=oli-obk
Avoid calling queries during query stack printing This has the side effect, that when Clippy should ICE (during an EarlyPass?) it will fill up the RAM with 2 GB/s and then freezes my Laptop. This is blocking the Clippy sync and might give some people really bad experiences, so this should be merged ASAP. r? `@cjgillot` cc `@Zoxc` I only commented this on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/.60try_print_query_stack.60.20has.20.60ImplicitCtx.60.20during.20.60EarlyPass.60/near/363926180). I should've left a comment on the PR as well. My bad.
2 parents 08fd6f7 + 7c15779 commit 8882507

File tree

5 files changed

+61
-9
lines changed

5 files changed

+61
-9
lines changed

compiler/rustc_interface/src/interface.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,12 @@ pub fn try_print_query_stack(handler: &Handler, num_frames: Option<usize>) {
354354
// state if it was responsible for triggering the panic.
355355
let i = ty::tls::with_context_opt(|icx| {
356356
if let Some(icx) = icx {
357-
print_query_stack(QueryCtxt::new(icx.tcx), icx.query, handler, num_frames)
357+
ty::print::with_no_queries!(print_query_stack(
358+
QueryCtxt::new(icx.tcx),
359+
icx.query,
360+
handler,
361+
num_frames
362+
))
358363
} else {
359364
0
360365
}

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

+10-5
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 {
@@ -2999,7 +3004,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
29993004
///
30003005
/// The implementation uses similar import discovery logic to that of 'use' suggestions.
30013006
///
3002-
/// See also [`DelayDm`](rustc_error_messages::DelayDm) and [`with_no_trimmed_paths`].
3007+
/// See also [`DelayDm`](rustc_error_messages::DelayDm) and [`with_no_trimmed_paths!`].
30033008
fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> FxHashMap<DefId, Symbol> {
30043009
let mut map: FxHashMap<DefId, Symbol> = FxHashMap::default();
30053010

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 {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// compile-flags: -Ztreat-err-as-bug
2+
// dont-check-failure-status
3+
// error-pattern: aborting due to `-Z treat-err-as-bug=1`
4+
// dont-check-compiler-stderr
5+
// rustc-env:RUST_BACKTRACE=0
6+
7+
fn main() {
8+
#[deny(while_true)]
9+
while true {}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: denote infinite loops with `loop { ... }`
2+
--> $DIR/panic-causes-oom-112708.rs:13:5
3+
|
4+
LL | while true {}
5+
| ^^^^^^^^^^ help: use `loop`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/panic-causes-oom-112708.rs:12:12
9+
|
10+
LL | #[deny(while_true)]
11+
| ^^^^^^^^^^
12+
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+
26+
error: the compiler unexpectedly panicked. this is a bug.
27+
28+
query stack during panic:
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)