rustc_middle/
verify_ich.rs1use std::cell::Cell;
2
3use rustc_data_structures::fingerprint::Fingerprint;
4use rustc_hir::def_id::LOCAL_CRATE;
5use rustc_session::utils::was_invoked_from_cargo;
6use tracing::instrument;
7
8use crate::dep_graph::{DepGraphData, SerializedDepNodeIndex};
9use crate::ich::StableHashingContext;
10use crate::ty::TyCtxt;
11
12#[inline]
13#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("incremental_verify_ich",
"rustc_middle::verify_ich", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/verify_ich.rs"),
::tracing_core::__macro_support::Option::Some(13u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::verify_ich"),
::tracing_core::field::FieldSet::new(&["prev_index"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&prev_index)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if !dep_graph_data.is_index_green(prev_index) {
incremental_verify_ich_not_green(tcx, prev_index)
}
let new_hash =
hash_result.map_or(Fingerprint::ZERO,
|f|
{
tcx.with_stable_hashing_context(|mut hcx|
f(&mut hcx, result))
});
let old_hash =
dep_graph_data.prev_value_fingerprint_of(prev_index);
if new_hash != old_hash {
incremental_verify_ich_failed(tcx, prev_index,
&|| format_value(result));
}
}
}
}#[instrument(skip(tcx, dep_graph_data, result, hash_result, format_value), level = "debug")]
14pub fn incremental_verify_ich<'tcx, V>(
15 tcx: TyCtxt<'tcx>,
16 dep_graph_data: &DepGraphData,
17 result: &V,
18 prev_index: SerializedDepNodeIndex,
19 hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
20 format_value: fn(&V) -> String,
21) {
22 if !dep_graph_data.is_index_green(prev_index) {
23 incremental_verify_ich_not_green(tcx, prev_index)
24 }
25
26 let new_hash = hash_result.map_or(Fingerprint::ZERO, |f| {
27 tcx.with_stable_hashing_context(|mut hcx| f(&mut hcx, result))
28 });
29
30 let old_hash = dep_graph_data.prev_value_fingerprint_of(prev_index);
31
32 if new_hash != old_hash {
33 incremental_verify_ich_failed(tcx, prev_index, &|| format_value(result));
34 }
35}
36
37#[cold]
38#[inline(never)]
39fn incremental_verify_ich_not_green<'tcx>(tcx: TyCtxt<'tcx>, prev_index: SerializedDepNodeIndex) {
40 {
::core::panicking::panic_fmt(format_args!("fingerprint for green query instance not loaded from cache: {0:?}",
tcx.dep_graph.data().unwrap().prev_node_of(prev_index)));
}panic!(
41 "fingerprint for green query instance not loaded from cache: {:?}",
42 tcx.dep_graph.data().unwrap().prev_node_of(prev_index)
43 )
44}
45
46#[cold]
50#[inline(never)]
51fn incremental_verify_ich_failed<'tcx>(
52 tcx: TyCtxt<'tcx>,
53 prev_index: SerializedDepNodeIndex,
54 result: &dyn Fn() -> String,
55) {
56 const INSIDE_VERIFY_PANIC: ::std::thread::LocalKey<Cell<bool>> =
{
const __RUST_STD_INTERNAL_INIT: Cell<bool> = { Cell::new(false) };
unsafe {
::std::thread::LocalKey::new(const {
if ::std::mem::needs_drop::<Cell<bool>>() {
|_|
{
#[thread_local]
static __RUST_STD_INTERNAL_VAL:
::std::thread::local_impl::EagerStorage<Cell<bool>> =
::std::thread::local_impl::EagerStorage::new(__RUST_STD_INTERNAL_INIT);
__RUST_STD_INTERNAL_VAL.get()
}
} else {
|_|
{
#[thread_local]
static __RUST_STD_INTERNAL_VAL: Cell<bool> =
__RUST_STD_INTERNAL_INIT;
&__RUST_STD_INTERNAL_VAL
}
}
})
}
};thread_local! {
63 static INSIDE_VERIFY_PANIC: Cell<bool> = const { Cell::new(false) };
64 };
65
66 let old_in_panic = INSIDE_VERIFY_PANIC.replace(true);
67
68 if old_in_panic {
69 tcx.dcx().emit_err(crate::error::Reentrant);
70 } else {
71 let run_cmd = if was_invoked_from_cargo() {
72 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("run `cargo clean -p {0}` or `cargo clean`",
tcx.crate_name(LOCAL_CRATE)))
})format!("run `cargo clean -p {}` or `cargo clean`", tcx.crate_name(LOCAL_CRATE))
73 } else {
74 "clean your build cache".to_owned()
75 };
76
77 let dep_node = tcx.dep_graph.data().unwrap().prev_node_of(prev_index);
78 tcx.dcx().emit_err(crate::error::IncrementCompilation {
79 run_cmd,
80 dep_node: ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:?}", dep_node))
})format!("{dep_node:?}"),
81 });
82 {
::core::panicking::panic_fmt(format_args!("Found unstable fingerprints for {1:?}: {0}",
result(), dep_node));
};panic!("Found unstable fingerprints for {dep_node:?}: {}", result());
83 }
84
85 INSIDE_VERIFY_PANIC.set(old_in_panic);
86}