diff options
| author | bors <bors@rust-lang.org> | 2024-03-13 02:01:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-13 02:01:56 +0000 |
| commit | d3555f3d8e555ce488bbf8eee5eccdb66a464e14 (patch) | |
| tree | 5ef433a1bbd7118a8e4dc3ec0871903016065eab /compiler/rustc_query_impl/src | |
| parent | e61dcc7a0ac33ef054d76453307124233edcf545 (diff) | |
| parent | 55ba7a7c622fb1ac95ef05e4a652cedf923a8164 (diff) | |
| download | rust-d3555f3d8e555ce488bbf8eee5eccdb66a464e14.tar.gz rust-d3555f3d8e555ce488bbf8eee5eccdb66a464e14.zip | |
Auto merge of #122227 - Zoxc:query-hash-verify, r=michaelwoerister
Verify that query keys result in unique dep nodes This implements checking that query keys result into unique dep nodes as mentioned in https://github.com/rust-lang/rust/pull/112469. We could do a perf check to see how expensive this is. r? `@michaelwoerister`
Diffstat (limited to 'compiler/rustc_query_impl/src')
| -rw-r--r-- | compiler/rustc_query_impl/src/lib.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_query_impl/src/plumbing.rs | 50 |
2 files changed, 51 insertions, 1 deletions
diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 33116737a42..52767155532 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -41,7 +41,7 @@ use rustc_span::{ErrorGuaranteed, Span}; #[macro_use] mod plumbing; -pub use crate::plumbing::QueryCtxt; +pub use crate::plumbing::{query_key_hash_verify_all, QueryCtxt}; mod profiling_support; pub use self::profiling_support::alloc_self_profile_query_strings; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index b06d75be390..aa965779731 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -7,6 +7,7 @@ use crate::rustc_middle::ty::TyEncoder; use crate::QueryConfigRestored; use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher}; use rustc_data_structures::sync::Lock; +use rustc_data_structures::unord::UnordMap; use rustc_errors::DiagInner; use rustc_index::Idx; @@ -189,6 +190,16 @@ pub(super) fn encode_all_query_results<'tcx>( } } +pub fn query_key_hash_verify_all<'tcx>(tcx: TyCtxt<'tcx>) { + if tcx.sess().opts.unstable_opts.incremental_verify_ich || cfg!(debug_assertions) { + tcx.sess.time("query_key_hash_verify_all", || { + for verify in super::QUERY_KEY_HASH_VERIFY.iter() { + verify(tcx); + } + }) + } +} + macro_rules! handle_cycle_error { ([]) => {{ rustc_query_system::HandleCycleError::Error @@ -370,6 +381,34 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q>( }); } +pub(crate) fn query_key_hash_verify<'tcx>( + query: impl QueryConfig<QueryCtxt<'tcx>>, + qcx: QueryCtxt<'tcx>, +) { + let _timer = + qcx.profiler().generic_activity_with_arg("query_key_hash_verify_for", query.name()); + + let mut map = UnordMap::default(); + + let cache = query.query_cache(qcx); + cache.iter(&mut |key, _, _| { + let node = DepNode::construct(qcx.tcx, query.dep_kind(), key); + if let Some(other_key) = map.insert(node, *key) { + bug!( + "query key:\n\ + `{:?}`\n\ + and key:\n\ + `{:?}`\n\ + mapped to the same dep node:\n\ + {:?}", + key, + other_key, + node + ); + } + }); +} + fn try_load_from_on_disk_cache<'tcx, Q>(query: Q, tcx: TyCtxt<'tcx>, dep_node: DepNode) where Q: QueryConfig<QueryCtxt<'tcx>>, @@ -691,6 +730,13 @@ macro_rules! define_queries { ) } }} + + pub fn query_key_hash_verify<'tcx>(tcx: TyCtxt<'tcx>) { + $crate::plumbing::query_key_hash_verify( + query_impl::$name::QueryType::config(tcx), + QueryCtxt::new(tcx), + ) + } })*} pub(crate) fn engine(incremental: bool) -> QueryEngine { @@ -730,6 +776,10 @@ macro_rules! define_queries { > ] = &[$(expand_if_cached!([$($modifiers)*], query_impl::$name::encode_query_results)),*]; + const QUERY_KEY_HASH_VERIFY: &[ + for<'tcx> fn(TyCtxt<'tcx>) + ] = &[$(query_impl::$name::query_key_hash_verify),*]; + #[allow(nonstandard_style)] mod query_callbacks { use super::*; |
