Don't rely on Debug
impl for Erased
This commit is contained in:
parent
785459d630
commit
36b4199a8e
7 changed files with 33 additions and 23 deletions
|
@ -1,21 +1,12 @@
|
||||||
use crate::ty;
|
use crate::ty;
|
||||||
use std::intrinsics::type_name;
|
use std::intrinsics::type_name;
|
||||||
use std::{
|
use std::mem::{size_of, transmute_copy, MaybeUninit};
|
||||||
fmt,
|
|
||||||
mem::{size_of, transmute_copy, MaybeUninit},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct Erased<T: Copy> {
|
pub struct Erased<T: Copy> {
|
||||||
data: MaybeUninit<T>,
|
data: MaybeUninit<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Copy> fmt::Debug for Erased<T> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "Erased")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait EraseType: Copy {
|
pub trait EraseType: Copy {
|
||||||
type Result: Copy;
|
type Result: Copy;
|
||||||
}
|
}
|
||||||
|
|
|
@ -501,6 +501,7 @@ macro_rules! define_feedable {
|
||||||
|
|
||||||
match try_get_cached(tcx, cache, &key) {
|
match try_get_cached(tcx, cache, &key) {
|
||||||
Some(old) => {
|
Some(old) => {
|
||||||
|
let old = restore::<$V>(old);
|
||||||
bug!(
|
bug!(
|
||||||
"Trying to feed an already recorded value for query {} key={key:?}:\nold value: {old:?}\nnew value: {value:?}",
|
"Trying to feed an already recorded value for query {} key={key:?}:\nold value: {old:?}\nnew value: {value:?}",
|
||||||
stringify!($name),
|
stringify!($name),
|
||||||
|
|
|
@ -486,6 +486,11 @@ macro_rules! define_queries {
|
||||||
stringify!($name)
|
stringify!($name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn format_value(self) -> fn(&Self::Value) -> String {
|
||||||
|
|value| format!("{:?}", restore::<query_values::$name<'tcx>>(*value))
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cache_on_disk(self, tcx: TyCtxt<'tcx>, key: &Self::Key) -> bool {
|
fn cache_on_disk(self, tcx: TyCtxt<'tcx>, key: &Self::Key) -> bool {
|
||||||
::rustc_middle::query::cached::$name(tcx, key)
|
::rustc_middle::query::cached::$name(tcx, key)
|
||||||
|
@ -819,7 +824,7 @@ macro_rules! define_queries_struct {
|
||||||
|
|
||||||
$($(#[$attr])*
|
$($(#[$attr])*
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[tracing::instrument(level = "trace", skip(self, tcx), ret)]
|
#[tracing::instrument(level = "trace", skip(self, tcx))]
|
||||||
fn $name(
|
fn $name(
|
||||||
&'tcx self,
|
&'tcx self,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
|
|
@ -538,7 +538,14 @@ impl<K: DepKind> DepGraph<K> {
|
||||||
if let Some(prev_index) = data.previous.node_to_index_opt(&node) {
|
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];
|
let dep_node_index = data.current.prev_index_to_index.lock()[prev_index];
|
||||||
if let Some(dep_node_index) = dep_node_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)]
|
#[cfg(debug_assertions)]
|
||||||
if hash_result.is_some() {
|
if hash_result.is_some() {
|
||||||
|
|
|
@ -18,7 +18,7 @@ pub trait CacheSelector<'tcx, V> {
|
||||||
|
|
||||||
pub trait QueryCache: Sized {
|
pub trait QueryCache: Sized {
|
||||||
type Key: Hash + Eq + Copy + Debug;
|
type Key: Hash + Eq + Copy + Debug;
|
||||||
type Value: Copy + Debug;
|
type Value: Copy;
|
||||||
|
|
||||||
/// Checks if the query is already computed and in the cache.
|
/// Checks if the query is already computed and in the cache.
|
||||||
fn lookup(&self, key: &Self::Key) -> Option<(Self::Value, DepNodeIndex)>;
|
fn lookup(&self, key: &Self::Key) -> Option<(Self::Value, DepNodeIndex)>;
|
||||||
|
@ -52,7 +52,7 @@ impl<K, V> Default for DefaultCache<K, V> {
|
||||||
impl<K, V> QueryCache for DefaultCache<K, V>
|
impl<K, V> QueryCache for DefaultCache<K, V>
|
||||||
where
|
where
|
||||||
K: Eq + Hash + Copy + Debug,
|
K: Eq + Hash + Copy + Debug,
|
||||||
V: Copy + Debug,
|
V: Copy,
|
||||||
{
|
{
|
||||||
type Key = K;
|
type Key = K;
|
||||||
type Value = V;
|
type Value = V;
|
||||||
|
@ -120,7 +120,7 @@ impl<V> Default for SingleCache<V> {
|
||||||
|
|
||||||
impl<V> QueryCache for SingleCache<V>
|
impl<V> QueryCache for SingleCache<V>
|
||||||
where
|
where
|
||||||
V: Copy + Debug,
|
V: Copy,
|
||||||
{
|
{
|
||||||
type Key = ();
|
type Key = ();
|
||||||
type Value = V;
|
type Value = V;
|
||||||
|
@ -164,7 +164,7 @@ impl<K: Idx, V> Default for VecCache<K, V> {
|
||||||
impl<K, V> QueryCache for VecCache<K, V>
|
impl<K, V> QueryCache for VecCache<K, V>
|
||||||
where
|
where
|
||||||
K: Eq + Idx + Copy + Debug,
|
K: Eq + Idx + Copy + Debug,
|
||||||
V: Copy + Debug,
|
V: Copy,
|
||||||
{
|
{
|
||||||
type Key = K;
|
type Key = K;
|
||||||
type Value = V;
|
type Value = V;
|
||||||
|
|
|
@ -20,10 +20,12 @@ pub trait QueryConfig<Qcx: QueryContext>: Copy {
|
||||||
// `Key` and `Value` are `Copy` instead of `Clone` to ensure copying them stays cheap,
|
// `Key` and `Value` are `Copy` instead of `Clone` to ensure copying them stays cheap,
|
||||||
// but it isn't necessary.
|
// but it isn't necessary.
|
||||||
type Key: DepNodeParams<Qcx::DepContext> + Eq + Hash + Copy + Debug;
|
type Key: DepNodeParams<Qcx::DepContext> + Eq + Hash + Copy + Debug;
|
||||||
type Value: Debug + Copy;
|
type Value: Copy;
|
||||||
|
|
||||||
type Cache: QueryCache<Key = Self::Key, Value = Self::Value>;
|
type Cache: QueryCache<Key = Self::Key, Value = Self::Value>;
|
||||||
|
|
||||||
|
fn format_value(self) -> fn(&Self::Value) -> String;
|
||||||
|
|
||||||
// Don't use this method to access query results, instead use the methods on TyCtxt
|
// Don't use this method to access query results, instead use the methods on TyCtxt
|
||||||
fn query_state<'a>(self, tcx: Qcx) -> &'a QueryState<Self::Key, Qcx::DepKind>
|
fn query_state<'a>(self, tcx: Qcx) -> &'a QueryState<Self::Key, Qcx::DepKind>
|
||||||
where
|
where
|
||||||
|
|
|
@ -411,7 +411,8 @@ where
|
||||||
// get evaluated first, and re-feed the query.
|
// get evaluated first, and re-feed the query.
|
||||||
if let Some((cached_result, _)) = cache.lookup(&key) {
|
if let Some((cached_result, _)) = cache.lookup(&key) {
|
||||||
panic!(
|
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,
|
&result,
|
||||||
prev_dep_node_index,
|
prev_dep_node_index,
|
||||||
query.hash_result(),
|
query.hash_result(),
|
||||||
|
query.format_value(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -627,19 +629,21 @@ where
|
||||||
&result,
|
&result,
|
||||||
prev_dep_node_index,
|
prev_dep_node_index,
|
||||||
query.hash_result(),
|
query.hash_result(),
|
||||||
|
query.format_value(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Some((result, dep_node_index))
|
Some((result, dep_node_index))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[instrument(skip(tcx, dep_graph_data, result, hash_result), level = "debug")]
|
#[instrument(skip(tcx, dep_graph_data, result, hash_result, format_value), level = "debug")]
|
||||||
pub(crate) fn incremental_verify_ich<Tcx, V: Debug>(
|
pub(crate) fn incremental_verify_ich<Tcx, V>(
|
||||||
tcx: Tcx,
|
tcx: Tcx,
|
||||||
dep_graph_data: &DepGraphData<Tcx::DepKind>,
|
dep_graph_data: &DepGraphData<Tcx::DepKind>,
|
||||||
result: &V,
|
result: &V,
|
||||||
prev_index: SerializedDepNodeIndex,
|
prev_index: SerializedDepNodeIndex,
|
||||||
hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
|
hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
|
||||||
|
format_value: fn(&V) -> String,
|
||||||
) where
|
) where
|
||||||
Tcx: DepContext,
|
Tcx: DepContext,
|
||||||
{
|
{
|
||||||
|
@ -654,7 +658,7 @@ pub(crate) fn incremental_verify_ich<Tcx, V: Debug>(
|
||||||
let old_hash = dep_graph_data.prev_fingerprint_of(prev_index);
|
let old_hash = dep_graph_data.prev_fingerprint_of(prev_index);
|
||||||
|
|
||||||
if new_hash != old_hash {
|
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>(
|
fn incremental_verify_ich_failed<Tcx>(
|
||||||
tcx: Tcx,
|
tcx: Tcx,
|
||||||
prev_index: SerializedDepNodeIndex,
|
prev_index: SerializedDepNodeIndex,
|
||||||
result: &dyn Debug,
|
result: &dyn Fn() -> String,
|
||||||
) where
|
) where
|
||||||
Tcx: DepContext,
|
Tcx: DepContext,
|
||||||
{
|
{
|
||||||
|
@ -708,7 +712,7 @@ fn incremental_verify_ich_failed<Tcx>(
|
||||||
run_cmd,
|
run_cmd,
|
||||||
dep_node: format!("{dep_node:?}"),
|
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));
|
INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.set(old_in_panic));
|
||||||
|
|
Loading…
Add table
Reference in a new issue