diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index 83046e14f11..705300b9b7a 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -1,21 +1,12 @@ use crate::ty; use std::intrinsics::type_name; -use std::{ - fmt, - mem::{size_of, transmute_copy, MaybeUninit}, -}; +use std::mem::{size_of, transmute_copy, MaybeUninit}; #[derive(Copy, Clone)] pub struct Erased { data: MaybeUninit, } -impl fmt::Debug for Erased { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "Erased") - } -} - pub trait EraseType: Copy { type Result: Copy; } diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index 734512b4048..fa9fea72344 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -501,6 +501,7 @@ macro_rules! define_feedable { match try_get_cached(tcx, cache, &key) { Some(old) => { + let old = restore::<$V>(old); bug!( "Trying to feed an already recorded value for query {} key={key:?}:\nold value: {old:?}\nnew value: {value:?}", stringify!($name), diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index ddc86b5173f..a1dfb27c5d7 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -486,6 +486,11 @@ macro_rules! define_queries { stringify!($name) } + #[inline] + fn format_value(self) -> fn(&Self::Value) -> String { + |value| format!("{:?}", restore::>(*value)) + } + #[inline] fn cache_on_disk(self, tcx: TyCtxt<'tcx>, key: &Self::Key) -> bool { ::rustc_middle::query::cached::$name(tcx, key) @@ -819,7 +824,7 @@ macro_rules! define_queries_struct { $($(#[$attr])* #[inline(always)] - #[tracing::instrument(level = "trace", skip(self, tcx), ret)] + #[tracing::instrument(level = "trace", skip(self, tcx))] fn $name( &'tcx self, tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 2ff7de8cb9e..534d13b1ae0 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -538,7 +538,14 @@ impl DepGraph { if let Some(prev_index) = data.previous.node_to_index_opt(&node) { let dep_node_index = data.current.prev_index_to_index.lock()[prev_index]; if let Some(dep_node_index) = dep_node_index { - crate::query::incremental_verify_ich(cx, data, result, prev_index, hash_result); + crate::query::incremental_verify_ich( + cx, + data, + result, + prev_index, + hash_result, + |value| format!("{:?}", value), + ); #[cfg(debug_assertions)] if hash_result.is_some() { diff --git a/compiler/rustc_query_system/src/query/caches.rs b/compiler/rustc_query_system/src/query/caches.rs index d3efc22a194..3ac8a852a4e 100644 --- a/compiler/rustc_query_system/src/query/caches.rs +++ b/compiler/rustc_query_system/src/query/caches.rs @@ -18,7 +18,7 @@ pub trait CacheSelector<'tcx, V> { pub trait QueryCache: Sized { type Key: Hash + Eq + Copy + Debug; - type Value: Copy + Debug; + type Value: Copy; /// Checks if the query is already computed and in the cache. fn lookup(&self, key: &Self::Key) -> Option<(Self::Value, DepNodeIndex)>; @@ -52,7 +52,7 @@ impl Default for DefaultCache { impl QueryCache for DefaultCache where K: Eq + Hash + Copy + Debug, - V: Copy + Debug, + V: Copy, { type Key = K; type Value = V; @@ -120,7 +120,7 @@ impl Default for SingleCache { impl QueryCache for SingleCache where - V: Copy + Debug, + V: Copy, { type Key = (); type Value = V; @@ -164,7 +164,7 @@ impl Default for VecCache { impl QueryCache for VecCache where K: Eq + Idx + Copy + Debug, - V: Copy + Debug, + V: Copy, { type Key = K; type Value = V; diff --git a/compiler/rustc_query_system/src/query/config.rs b/compiler/rustc_query_system/src/query/config.rs index ae3b67915cb..dc981a802f3 100644 --- a/compiler/rustc_query_system/src/query/config.rs +++ b/compiler/rustc_query_system/src/query/config.rs @@ -20,10 +20,12 @@ pub trait QueryConfig: Copy { // `Key` and `Value` are `Copy` instead of `Clone` to ensure copying them stays cheap, // but it isn't necessary. type Key: DepNodeParams + Eq + Hash + Copy + Debug; - type Value: Debug + Copy; + type Value: Copy; type Cache: QueryCache; + fn format_value(self) -> fn(&Self::Value) -> String; + // Don't use this method to access query results, instead use the methods on TyCtxt fn query_state<'a>(self, tcx: Qcx) -> &'a QueryState where diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 5314d26b940..95366e1ad0b 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -411,7 +411,8 @@ where // get evaluated first, and re-feed the query. if let Some((cached_result, _)) = cache.lookup(&key) { panic!( - "fed query later has its value computed. The already cached value: {cached_result:?}" + "fed query later has its value computed. The already cached value: {}", + (query.format_value())(&cached_result) ); } } @@ -582,6 +583,7 @@ where &result, prev_dep_node_index, query.hash_result(), + query.format_value(), ); } @@ -627,19 +629,21 @@ where &result, prev_dep_node_index, query.hash_result(), + query.format_value(), ); Some((result, dep_node_index)) } #[inline] -#[instrument(skip(tcx, dep_graph_data, result, hash_result), level = "debug")] -pub(crate) fn incremental_verify_ich( +#[instrument(skip(tcx, dep_graph_data, result, hash_result, format_value), level = "debug")] +pub(crate) fn incremental_verify_ich( tcx: Tcx, dep_graph_data: &DepGraphData, result: &V, prev_index: SerializedDepNodeIndex, hash_result: Option, &V) -> Fingerprint>, + format_value: fn(&V) -> String, ) where Tcx: DepContext, { @@ -654,7 +658,7 @@ pub(crate) fn incremental_verify_ich( let old_hash = dep_graph_data.prev_fingerprint_of(prev_index); if new_hash != old_hash { - incremental_verify_ich_failed(tcx, prev_index, result); + incremental_verify_ich_failed(tcx, prev_index, &|| format_value(&result)); } } @@ -678,7 +682,7 @@ where fn incremental_verify_ich_failed( tcx: Tcx, prev_index: SerializedDepNodeIndex, - result: &dyn Debug, + result: &dyn Fn() -> String, ) where Tcx: DepContext, { @@ -708,7 +712,7 @@ fn incremental_verify_ich_failed( run_cmd, dep_node: format!("{dep_node:?}"), }); - panic!("Found unstable fingerprints for {dep_node:?}: {result:?}"); + panic!("Found unstable fingerprints for {dep_node:?}: {}", result()); } INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.set(old_in_panic));