Skip to content

Commit a7e5720

Browse files
authored
Unrolled build for #141985
Rollup merge of #141985 - compiler-errors:cycle-in-dep-graph-print, r=oli-obk Ensure query keys are printed with reduced queries Using `-Z query-dep-graph` and debug assertions leads to an ICE that was originally discovered in #141700: > This isn't an incremental bug per se, but instead a bug that has to do with debug printing query keys when debug assertions and `-Z query-dep-graph` is enabled. We end up printing a const (b/c we're using generic const args here) whose debug printing for -Z query-dep-graph requires invoking the same query cyclically 😃 > > I've pushed a commit which should fix this. This isn't related to the standard library changes, but instead b/c it seems to be the first usage of `feature(adt_const_params)` in the standard library that ends up being triggered in incremental tests. r? oli-obk
2 parents ff223d3 + cbb3a84 commit a7e5720

File tree

6 files changed

+40
-7
lines changed

6 files changed

+40
-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 {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ compile-flags: -Z query-dep-graph
2+
//@ revisions: rpass1
3+
4+
// Exercises a debug-assertions-only query cycle that when printing a valtree const in
5+
// a dep node's debug representation, we end up invoking a query that also has a valtree
6+
// const in its dep node's debug representation, which leads to a cycle (and ICE, since
7+
// deps are not tracked when printing dep nodes' debug representations).
8+
9+
#![feature(adt_const_params)]
10+
11+
use std::marker::ConstParamTy;
12+
13+
#[derive(Debug, ConstParamTy, PartialEq, Eq)]
14+
enum Foo {
15+
A1,
16+
}
17+
18+
#[inline(never)]
19+
fn hello<const F: Foo>() {
20+
println!("{:#?}", F);
21+
}
22+
23+
fn main() {
24+
hello::<{ Foo::A1 }>();
25+
}

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)