|
5 | 5 | use crate::rustc_middle::dep_graph::DepContext;
|
6 | 6 | use crate::rustc_middle::ty::TyEncoder;
|
7 | 7 | use crate::QueryConfigRestored;
|
| 8 | +use rustc_data_structures::fx::FxHashMap; |
8 | 9 | use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher};
|
9 | 10 | use rustc_data_structures::sync::Lock;
|
10 | 11 | use rustc_errors::DiagInner;
|
@@ -189,6 +190,14 @@ pub(super) fn encode_all_query_results<'tcx>(
|
189 | 190 | }
|
190 | 191 | }
|
191 | 192 |
|
| 193 | +pub fn query_key_hash_verify_all<'tcx>(tcx: TyCtxt<'tcx>) { |
| 194 | + tcx.sess.time("query_key_hash_verify_all", || { |
| 195 | + for verify in super::QUERY_KEY_HASH_VERIFY.iter() { |
| 196 | + verify(tcx); |
| 197 | + } |
| 198 | + }) |
| 199 | +} |
| 200 | + |
192 | 201 | macro_rules! handle_cycle_error {
|
193 | 202 | ([]) => {{
|
194 | 203 | rustc_query_system::HandleCycleError::Error
|
@@ -370,6 +379,34 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q>(
|
370 | 379 | });
|
371 | 380 | }
|
372 | 381 |
|
| 382 | +pub(crate) fn query_key_hash_verify<'tcx>( |
| 383 | + query: impl QueryConfig<QueryCtxt<'tcx>>, |
| 384 | + qcx: QueryCtxt<'tcx>, |
| 385 | +) { |
| 386 | + let _timer = |
| 387 | + qcx.profiler().generic_activity_with_arg("query_key_hash_verify_for", query.name()); |
| 388 | + |
| 389 | + let mut map = FxHashMap::default(); |
| 390 | + |
| 391 | + let cache = query.query_cache(qcx); |
| 392 | + cache.iter(&mut |key, _, _| { |
| 393 | + let node = DepNode::construct(qcx.tcx, query.dep_kind(), key); |
| 394 | + if let Some(other_key) = map.insert(node, *key) { |
| 395 | + bug!( |
| 396 | + "query key:\n\ |
| 397 | + `{:?}`\n\ |
| 398 | + and key:\n\ |
| 399 | + `{:?}`\n\ |
| 400 | + mapped to the same dep node:\n\ |
| 401 | + {:?}", |
| 402 | + key, |
| 403 | + other_key, |
| 404 | + node |
| 405 | + ); |
| 406 | + } |
| 407 | + }); |
| 408 | +} |
| 409 | + |
373 | 410 | fn try_load_from_on_disk_cache<'tcx, Q>(query: Q, tcx: TyCtxt<'tcx>, dep_node: DepNode)
|
374 | 411 | where
|
375 | 412 | Q: QueryConfig<QueryCtxt<'tcx>>,
|
@@ -691,6 +728,13 @@ macro_rules! define_queries {
|
691 | 728 | )
|
692 | 729 | }
|
693 | 730 | }}
|
| 731 | + |
| 732 | + pub fn query_key_hash_verify<'tcx>(tcx: TyCtxt<'tcx>) { |
| 733 | + $crate::plumbing::query_key_hash_verify( |
| 734 | + query_impl::$name::QueryType::config(tcx), |
| 735 | + QueryCtxt::new(tcx), |
| 736 | + ) |
| 737 | + } |
694 | 738 | })*}
|
695 | 739 |
|
696 | 740 | pub(crate) fn engine(incremental: bool) -> QueryEngine {
|
@@ -730,6 +774,10 @@ macro_rules! define_queries {
|
730 | 774 | >
|
731 | 775 | ] = &[$(expand_if_cached!([$($modifiers)*], query_impl::$name::encode_query_results)),*];
|
732 | 776 |
|
| 777 | + const QUERY_KEY_HASH_VERIFY: &[ |
| 778 | + for<'tcx> fn(TyCtxt<'tcx>) |
| 779 | + ] = &[$(query_impl::$name::query_key_hash_verify),*]; |
| 780 | + |
733 | 781 | #[allow(nonstandard_style)]
|
734 | 782 | mod query_callbacks {
|
735 | 783 | use super::*;
|
|
0 commit comments