Skip to content

Commit cbb3a84

Browse files
Ensure query keys are printed with reduced queries
1 parent f7db329 commit cbb3a84

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

compiler/rustc_middle/src/dep_graph/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc_data_structures::profiling::SelfProfilerRef;
22
use rustc_query_system::ich::StableHashingContext;
33
use rustc_session::Session;
44

5+
use crate::ty::print::with_reduced_queries;
56
use crate::ty::{self, TyCtxt};
67

78
#[macro_use]
@@ -84,4 +85,8 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
8485
fn dep_kind_info(&self, dk: DepKind) -> &DepKindStruct<'tcx> {
8586
&self.query_kinds[dk.as_usize()]
8687
}
88+
89+
fn with_reduced_queries<T>(self, f: impl FnOnce() -> T) -> T {
90+
with_reduced_queries!(f())
91+
}
8792
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
18861886
) -> Result<(), PrintError> {
18871887
define_scoped_cx!(self);
18881888

1889-
if self.should_print_verbose() {
1889+
if with_reduced_queries() || self.should_print_verbose() {
18901890
p!(write("ValTree({:?}: ", cv.valtree), print(cv.ty), ")");
18911891
return Ok(());
18921892
}

compiler/rustc_query_system/src/dep_graph/dep_node.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ pub trait DepNodeParams<Tcx: DepContext>: fmt::Debug + Sized {
178178
panic!("Not implemented. Accidentally called on anonymous node?")
179179
}
180180

181-
fn to_debug_str(&self, _: Tcx) -> String {
182-
format!("{self:?}")
183-
}
181+
fn to_debug_str(&self, tcx: Tcx) -> String;
184182

185183
/// This method tries to recover the query key from the given `DepNode`,
186184
/// something which is needed when forcing `DepNode`s during red-green
@@ -210,8 +208,11 @@ where
210208
}
211209

212210
#[inline(always)]
213-
default fn to_debug_str(&self, _: Tcx) -> String {
214-
format!("{:?}", *self)
211+
default fn to_debug_str(&self, tcx: Tcx) -> String {
212+
// Make sure to print dep node params with reduced queries since printing
213+
// may themselves call queries, which may lead to (possibly untracked!)
214+
// query cycles.
215+
tcx.with_reduced_queries(|| format!("{self:?}"))
215216
}
216217

217218
#[inline(always)]

compiler/rustc_query_system/src/dep_graph/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ pub trait DepContext: Copy {
8888
f(self, dep_node)
8989
}
9090
}
91+
92+
fn with_reduced_queries<T>(self, _: impl FnOnce() -> T) -> T;
9193
}
9294

9395
pub trait Deps: DynSync {

tests/ui/transmutability/structs/repr/transmute_infinitely_recursive_type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | struct ExplicitlyPadded(Box<ExplicitlyPadded>);
1212
error[E0391]: cycle detected when computing layout of `should_pad_explicitly_packed_field::ExplicitlyPadded`
1313
|
1414
= note: ...which immediately requires computing layout of `should_pad_explicitly_packed_field::ExplicitlyPadded` again
15-
= note: cycle used when evaluating trait selection obligation `(): core::mem::transmutability::TransmuteFrom<should_pad_explicitly_packed_field::ExplicitlyPadded, core::mem::transmutability::Assume { alignment: false, lifetimes: false, safety: false, validity: false }>`
15+
= note: cycle used when evaluating trait selection obligation `(): core::mem::transmutability::TransmuteFrom<should_pad_explicitly_packed_field::ExplicitlyPadded, ValTree(Branch([Leaf(0x00), Leaf(0x00), Leaf(0x00), Leaf(0x00)]): core::mem::transmutability::Assume)>`
1616
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
1717

1818
error: aborting due to 2 previous errors

0 commit comments

Comments
 (0)