From fd451dc057d7332e2e40f0625e865ea5e757d000 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Fri, 21 Feb 2025 21:36:58 -0500 Subject: [PATCH] Use StableHasher + Hash64 for dep_tracking_hash --- Cargo.lock | 1 + compiler/rustc_incremental/Cargo.toml | 1 + .../rustc_incremental/src/persist/load.rs | 3 ++- compiler/rustc_session/src/config.rs | 21 ++++++++++--------- compiler/rustc_session/src/options.rs | 10 ++++----- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6bc88fb7a6dc8..4401489813a40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3779,6 +3779,7 @@ dependencies = [ "rustc_fluent_macro", "rustc_fs_util", "rustc_graphviz", + "rustc_hashes", "rustc_hir", "rustc_macros", "rustc_middle", diff --git a/compiler/rustc_incremental/Cargo.toml b/compiler/rustc_incremental/Cargo.toml index 46a63b02e8469..83d163da4839d 100644 --- a/compiler/rustc_incremental/Cargo.toml +++ b/compiler/rustc_incremental/Cargo.toml @@ -12,6 +12,7 @@ rustc_errors = { path = "../rustc_errors" } rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_fs_util = { path = "../rustc_fs_util" } rustc_graphviz = { path = "../rustc_graphviz" } +rustc_hashes = { path = "../rustc_hashes" } rustc_hir = { path = "../rustc_hir" } rustc_macros = { path = "../rustc_macros" } rustc_middle = { path = "../rustc_middle" } diff --git a/compiler/rustc_incremental/src/persist/load.rs b/compiler/rustc_incremental/src/persist/load.rs index 7977bcc68911d..50e47533ab6ca 100644 --- a/compiler/rustc_incremental/src/persist/load.rs +++ b/compiler/rustc_incremental/src/persist/load.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use rustc_data_structures::memmap::Mmap; use rustc_data_structures::unord::UnordMap; +use rustc_hashes::Hash64; use rustc_middle::dep_graph::{DepGraph, DepsType, SerializedDepGraph, WorkProductMap}; use rustc_middle::query::on_disk_cache::OnDiskCache; use rustc_serialize::Decodable; @@ -154,7 +155,7 @@ fn load_dep_graph(sess: &Session) -> LoadResult<(Arc, WorkPr sess.dcx().emit_warn(errors::CorruptFile { path: &path }); return LoadResult::DataOutOfDate; }; - let prev_commandline_args_hash = u64::decode(&mut decoder); + let prev_commandline_args_hash = Hash64::decode(&mut decoder); if prev_commandline_args_hash != expected_hash { if sess.opts.unstable_opts.incremental_info { diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 85ef69ea2b746..6f8da1785f434 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2928,12 +2928,13 @@ pub enum WasiExecModel { /// how the hash should be calculated when adding a new command-line argument. pub(crate) mod dep_tracking { use std::collections::BTreeMap; - use std::hash::{DefaultHasher, Hash}; + use std::hash::Hash; use std::num::NonZero; use std::path::PathBuf; use rustc_abi::Align; use rustc_data_structures::fx::FxIndexMap; + use rustc_data_structures::stable_hasher::StableHasher; use rustc_errors::LanguageIdentifier; use rustc_feature::UnstableFeatures; use rustc_hashes::Hash64; @@ -2960,7 +2961,7 @@ pub(crate) mod dep_tracking { pub(crate) trait DepTrackingHash { fn hash( &self, - hasher: &mut DefaultHasher, + hasher: &mut StableHasher, error_format: ErrorOutputType, for_crate_hash: bool, ); @@ -2969,7 +2970,7 @@ pub(crate) mod dep_tracking { macro_rules! impl_dep_tracking_hash_via_hash { ($($t:ty),+ $(,)?) => {$( impl DepTrackingHash for $t { - fn hash(&self, hasher: &mut DefaultHasher, _: ErrorOutputType, _for_crate_hash: bool) { + fn hash(&self, hasher: &mut StableHasher, _: ErrorOutputType, _for_crate_hash: bool) { Hash::hash(self, hasher); } } @@ -2979,7 +2980,7 @@ pub(crate) mod dep_tracking { impl DepTrackingHash for Option { fn hash( &self, - hasher: &mut DefaultHasher, + hasher: &mut StableHasher, error_format: ErrorOutputType, for_crate_hash: bool, ) { @@ -3064,7 +3065,7 @@ pub(crate) mod dep_tracking { { fn hash( &self, - hasher: &mut DefaultHasher, + hasher: &mut StableHasher, error_format: ErrorOutputType, for_crate_hash: bool, ) { @@ -3083,7 +3084,7 @@ pub(crate) mod dep_tracking { { fn hash( &self, - hasher: &mut DefaultHasher, + hasher: &mut StableHasher, error_format: ErrorOutputType, for_crate_hash: bool, ) { @@ -3099,7 +3100,7 @@ pub(crate) mod dep_tracking { impl DepTrackingHash for Vec { fn hash( &self, - hasher: &mut DefaultHasher, + hasher: &mut StableHasher, error_format: ErrorOutputType, for_crate_hash: bool, ) { @@ -3114,7 +3115,7 @@ pub(crate) mod dep_tracking { impl DepTrackingHash for FxIndexMap { fn hash( &self, - hasher: &mut DefaultHasher, + hasher: &mut StableHasher, error_format: ErrorOutputType, for_crate_hash: bool, ) { @@ -3129,7 +3130,7 @@ pub(crate) mod dep_tracking { impl DepTrackingHash for OutputTypes { fn hash( &self, - hasher: &mut DefaultHasher, + hasher: &mut StableHasher, error_format: ErrorOutputType, for_crate_hash: bool, ) { @@ -3146,7 +3147,7 @@ pub(crate) mod dep_tracking { // This is a stable hash because BTreeMap is a sorted container pub(crate) fn stable_hash( sub_hashes: BTreeMap<&'static str, &dyn DepTrackingHash>, - hasher: &mut DefaultHasher, + hasher: &mut StableHasher, error_format: ErrorOutputType, for_crate_hash: bool, ) { diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 351dad3f3e422..ecd6ced622d66 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1,5 +1,4 @@ use std::collections::BTreeMap; -use std::hash::{DefaultHasher, Hasher}; use std::num::{IntErrorKind, NonZero}; use std::path::PathBuf; use std::str; @@ -7,6 +6,7 @@ use std::str; use rustc_abi::Align; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::profiling::TimePassesFormat; +use rustc_data_structures::stable_hasher::StableHasher; use rustc_errors::{ColorConfig, LanguageIdentifier, TerminalUrl}; use rustc_feature::UnstableFeatures; use rustc_hashes::Hash64; @@ -251,7 +251,7 @@ macro_rules! top_level_options { } impl Options { - pub fn dep_tracking_hash(&self, for_crate_hash: bool) -> u64 { + pub fn dep_tracking_hash(&self, for_crate_hash: bool) -> Hash64 { let mut sub_hashes = BTreeMap::new(); $({ hash_opt!($opt, @@ -260,7 +260,7 @@ macro_rules! top_level_options { for_crate_hash, [$dep_tracking_marker]); })* - let mut hasher = DefaultHasher::new(); + let mut hasher = StableHasher::new(); dep_tracking::stable_hash(sub_hashes, &mut hasher, self.error_format, @@ -545,7 +545,7 @@ macro_rules! options { build_options(early_dcx, matches, target_modifiers, $stat, $prefix, $outputname) } - fn dep_tracking_hash(&self, for_crate_hash: bool, error_format: ErrorOutputType) -> u64 { + fn dep_tracking_hash(&self, for_crate_hash: bool, error_format: ErrorOutputType) -> Hash64 { let mut sub_hashes = BTreeMap::new(); $({ hash_opt!($opt, @@ -554,7 +554,7 @@ macro_rules! options { for_crate_hash, [$dep_tracking_marker]); })* - let mut hasher = DefaultHasher::new(); + let mut hasher = StableHasher::new(); dep_tracking::stable_hash(sub_hashes, &mut hasher, error_format,