|
1 | 1 | use std::hash::Hash; |
2 | 2 | use std::mem::ManuallyDrop; |
3 | 3 |
|
4 | | -use rustc_data_structures::fingerprint::Fingerprint; |
| 4 | +use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint}; |
5 | 5 | use rustc_data_structures::hash_table::{Entry, HashTable}; |
6 | 6 | use rustc_data_structures::stack::ensure_sufficient_stack; |
7 | 7 | use rustc_data_structures::sync::{DynSend, DynSync}; |
@@ -490,12 +490,21 @@ fn execute_job_incr<'tcx, C: QueryCache>( |
490 | 490 | /// specified, re-hash results from the cache and make sure that they have the |
491 | 491 | /// expected fingerprint. |
492 | 492 | /// |
493 | | -/// If not, we still seek to verify a subset of fingerprints loaded from disk. |
494 | | -/// Re-hashing results is fairly expensive, so we can't currently afford to |
495 | | -/// verify every hash. This subset should still give us some coverage of |
496 | | -/// potential bugs. |
497 | | -pub(crate) fn should_verify_loaded_value(tcx: TyCtxt<'_>, prev_fingerprint: Fingerprint) -> bool { |
498 | | - prev_fingerprint.split().1.as_u64().is_multiple_of(32) |
| 493 | +/// If not, we still verify a subset: re-hashing is too expensive to do for |
| 494 | +/// every value. The subset rotates with the session count, covering the whole |
| 495 | +/// cache every 32 sessions, and is deterministic so that a verification |
| 496 | +/// failure reproduces on retry. |
| 497 | +/// |
| 498 | +/// `to_smaller_hash` mixes both fingerprint halves because neither half is |
| 499 | +/// evenly distributed on its own (`DefPathHash` keys share the |
| 500 | +/// `StableCrateId`, `HirId` keys contain a sequential id). |
| 501 | +pub(crate) fn should_verify_loaded_value( |
| 502 | + tcx: TyCtxt<'_>, |
| 503 | + dep_graph_data: &DepGraphData, |
| 504 | + key_fingerprint: PackedFingerprint, |
| 505 | +) -> bool { |
| 506 | + let hash = Fingerprint::from(key_fingerprint).to_smaller_hash().as_u64(); |
| 507 | + hash % 32 == dep_graph_data.session_count() % 32 |
499 | 508 | || tcx.sess.opts.unstable_opts.incremental_verify_ich |
500 | 509 | } |
501 | 510 |
|
@@ -532,8 +541,7 @@ fn load_from_disk_or_invoke_provider_green<'tcx, C: QueryCache>( |
532 | 541 | dep_graph_data.mark_debug_loaded_from_disk(*dep_node) |
533 | 542 | } |
534 | 543 |
|
535 | | - let prev_fingerprint = dep_graph_data.prev_value_fingerprint_of(prev_index); |
536 | | - let verify = should_verify_loaded_value(tcx, prev_fingerprint); |
| 544 | + let verify = should_verify_loaded_value(tcx, dep_graph_data, dep_node.key_fingerprint); |
537 | 545 |
|
538 | 546 | (value, verify) |
539 | 547 | } |
|
0 commit comments