Ensure query keys are printed with reduced queries

This commit is contained in:
Michael Goulet
2025-05-31 11:48:29 +00:00
parent f7db329e81
commit cbb3a847d2
5 changed files with 15 additions and 7 deletions
@@ -2,6 +2,7 @@
use rustc_query_system::ich::StableHashingContext;
use rustc_session::Session;
use crate::ty::print::with_reduced_queries;
use crate::ty::{self, TyCtxt};
#[macro_use]
@@ -84,4 +85,8 @@ fn sess(&self) -> &Session {
fn dep_kind_info(&self, dk: DepKind) -> &DepKindStruct<'tcx> {
&self.query_kinds[dk.as_usize()]
}
fn with_reduced_queries<T>(self, f: impl FnOnce() -> T) -> T {
with_reduced_queries!(f())
}
}
+1 -1
View File
@@ -1886,7 +1886,7 @@ fn pretty_print_const_valtree(
) -> Result<(), PrintError> {
define_scoped_cx!(self);
if self.should_print_verbose() {
if with_reduced_queries() || self.should_print_verbose() {
p!(write("ValTree({:?}: ", cv.valtree), print(cv.ty), ")");
return Ok(());
}
@@ -178,9 +178,7 @@ fn to_fingerprint(&self, _: Tcx) -> Fingerprint {
panic!("Not implemented. Accidentally called on anonymous node?")
}
fn to_debug_str(&self, _: Tcx) -> String {
format!("{self:?}")
}
fn to_debug_str(&self, tcx: Tcx) -> String;
/// This method tries to recover the query key from the given `DepNode`,
/// something which is needed when forcing `DepNode`s during red-green
@@ -210,8 +208,11 @@ impl<Tcx: DepContext, T> DepNodeParams<Tcx> for T
}
#[inline(always)]
default fn to_debug_str(&self, _: Tcx) -> String {
format!("{:?}", *self)
default fn to_debug_str(&self, tcx: Tcx) -> String {
// Make sure to print dep node params with reduced queries since printing
// may themselves call queries, which may lead to (possibly untracked!)
// query cycles.
tcx.with_reduced_queries(|| format!("{self:?}"))
}
#[inline(always)]
@@ -88,6 +88,8 @@ fn try_load_from_on_disk_cache(self, dep_node: DepNode) {
f(self, dep_node)
}
}
fn with_reduced_queries<T>(self, _: impl FnOnce() -> T) -> T;
}
pub trait Deps: DynSync {
@@ -12,7 +12,7 @@ LL | struct ExplicitlyPadded(Box<ExplicitlyPadded>);
error[E0391]: cycle detected when computing layout of `should_pad_explicitly_packed_field::ExplicitlyPadded`
|
= note: ...which immediately requires computing layout of `should_pad_explicitly_packed_field::ExplicitlyPadded` again
= 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 }>`
= 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)>`
= 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
error: aborting due to 2 previous errors