Skip to content

Commit 47d6703

Browse files
authored
Unrolled build for rust-lang#137410
Rollup merge of rust-lang#137410 - saethlin:stable-dep-tracking-hash, r=workingjubilee Use StableHasher + Hash64 for dep_tracking_hash This is similar to rust-lang#137095. We currently have a +/- 1 byte jitter in the size of dep graphs reported on perf.rust-lang.org. I think this fixes that jitter. When I introduced `Hash64`, I wired it through most of the compiler by making it an output of `StableHasher::finalize` then fixing the compile errors. I missed this case because the `u64` hash in this function is being produced by `DefaultHasher` instead. That seems pretty sketchy because the code seems confident that the hash needs to be stable, and we have a mechanism for stable hashing that we weren't using here.
2 parents 8dac72b + fd451dc commit 47d6703

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3779,6 +3779,7 @@ dependencies = [
37793779
"rustc_fluent_macro",
37803780
"rustc_fs_util",
37813781
"rustc_graphviz",
3782+
"rustc_hashes",
37823783
"rustc_hir",
37833784
"rustc_macros",
37843785
"rustc_middle",

compiler/rustc_incremental/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ rustc_errors = { path = "../rustc_errors" }
1212
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1313
rustc_fs_util = { path = "../rustc_fs_util" }
1414
rustc_graphviz = { path = "../rustc_graphviz" }
15+
rustc_hashes = { path = "../rustc_hashes" }
1516
rustc_hir = { path = "../rustc_hir" }
1617
rustc_macros = { path = "../rustc_macros" }
1718
rustc_middle = { path = "../rustc_middle" }

compiler/rustc_incremental/src/persist/load.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::sync::Arc;
55

66
use rustc_data_structures::memmap::Mmap;
77
use rustc_data_structures::unord::UnordMap;
8+
use rustc_hashes::Hash64;
89
use rustc_middle::dep_graph::{DepGraph, DepsType, SerializedDepGraph, WorkProductMap};
910
use rustc_middle::query::on_disk_cache::OnDiskCache;
1011
use rustc_serialize::Decodable;
@@ -154,7 +155,7 @@ fn load_dep_graph(sess: &Session) -> LoadResult<(Arc<SerializedDepGraph>, WorkPr
154155
sess.dcx().emit_warn(errors::CorruptFile { path: &path });
155156
return LoadResult::DataOutOfDate;
156157
};
157-
let prev_commandline_args_hash = u64::decode(&mut decoder);
158+
let prev_commandline_args_hash = Hash64::decode(&mut decoder);
158159

159160
if prev_commandline_args_hash != expected_hash {
160161
if sess.opts.unstable_opts.incremental_info {

compiler/rustc_session/src/config.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -2921,12 +2921,13 @@ pub enum WasiExecModel {
29212921
/// how the hash should be calculated when adding a new command-line argument.
29222922
pub(crate) mod dep_tracking {
29232923
use std::collections::BTreeMap;
2924-
use std::hash::{DefaultHasher, Hash};
2924+
use std::hash::Hash;
29252925
use std::num::NonZero;
29262926
use std::path::PathBuf;
29272927

29282928
use rustc_abi::Align;
29292929
use rustc_data_structures::fx::FxIndexMap;
2930+
use rustc_data_structures::stable_hasher::StableHasher;
29302931
use rustc_errors::LanguageIdentifier;
29312932
use rustc_feature::UnstableFeatures;
29322933
use rustc_hashes::Hash64;
@@ -2953,7 +2954,7 @@ pub(crate) mod dep_tracking {
29532954
pub(crate) trait DepTrackingHash {
29542955
fn hash(
29552956
&self,
2956-
hasher: &mut DefaultHasher,
2957+
hasher: &mut StableHasher,
29572958
error_format: ErrorOutputType,
29582959
for_crate_hash: bool,
29592960
);
@@ -2962,7 +2963,7 @@ pub(crate) mod dep_tracking {
29622963
macro_rules! impl_dep_tracking_hash_via_hash {
29632964
($($t:ty),+ $(,)?) => {$(
29642965
impl DepTrackingHash for $t {
2965-
fn hash(&self, hasher: &mut DefaultHasher, _: ErrorOutputType, _for_crate_hash: bool) {
2966+
fn hash(&self, hasher: &mut StableHasher, _: ErrorOutputType, _for_crate_hash: bool) {
29662967
Hash::hash(self, hasher);
29672968
}
29682969
}
@@ -2972,7 +2973,7 @@ pub(crate) mod dep_tracking {
29722973
impl<T: DepTrackingHash> DepTrackingHash for Option<T> {
29732974
fn hash(
29742975
&self,
2975-
hasher: &mut DefaultHasher,
2976+
hasher: &mut StableHasher,
29762977
error_format: ErrorOutputType,
29772978
for_crate_hash: bool,
29782979
) {
@@ -3057,7 +3058,7 @@ pub(crate) mod dep_tracking {
30573058
{
30583059
fn hash(
30593060
&self,
3060-
hasher: &mut DefaultHasher,
3061+
hasher: &mut StableHasher,
30613062
error_format: ErrorOutputType,
30623063
for_crate_hash: bool,
30633064
) {
@@ -3076,7 +3077,7 @@ pub(crate) mod dep_tracking {
30763077
{
30773078
fn hash(
30783079
&self,
3079-
hasher: &mut DefaultHasher,
3080+
hasher: &mut StableHasher,
30803081
error_format: ErrorOutputType,
30813082
for_crate_hash: bool,
30823083
) {
@@ -3092,7 +3093,7 @@ pub(crate) mod dep_tracking {
30923093
impl<T: DepTrackingHash> DepTrackingHash for Vec<T> {
30933094
fn hash(
30943095
&self,
3095-
hasher: &mut DefaultHasher,
3096+
hasher: &mut StableHasher,
30963097
error_format: ErrorOutputType,
30973098
for_crate_hash: bool,
30983099
) {
@@ -3107,7 +3108,7 @@ pub(crate) mod dep_tracking {
31073108
impl<T: DepTrackingHash, V: DepTrackingHash> DepTrackingHash for FxIndexMap<T, V> {
31083109
fn hash(
31093110
&self,
3110-
hasher: &mut DefaultHasher,
3111+
hasher: &mut StableHasher,
31113112
error_format: ErrorOutputType,
31123113
for_crate_hash: bool,
31133114
) {
@@ -3122,7 +3123,7 @@ pub(crate) mod dep_tracking {
31223123
impl DepTrackingHash for OutputTypes {
31233124
fn hash(
31243125
&self,
3125-
hasher: &mut DefaultHasher,
3126+
hasher: &mut StableHasher,
31263127
error_format: ErrorOutputType,
31273128
for_crate_hash: bool,
31283129
) {
@@ -3139,7 +3140,7 @@ pub(crate) mod dep_tracking {
31393140
// This is a stable hash because BTreeMap is a sorted container
31403141
pub(crate) fn stable_hash(
31413142
sub_hashes: BTreeMap<&'static str, &dyn DepTrackingHash>,
3142-
hasher: &mut DefaultHasher,
3143+
hasher: &mut StableHasher,
31433144
error_format: ErrorOutputType,
31443145
for_crate_hash: bool,
31453146
) {

compiler/rustc_session/src/options.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::collections::BTreeMap;
2-
use std::hash::{DefaultHasher, Hasher};
32
use std::num::{IntErrorKind, NonZero};
43
use std::path::PathBuf;
54
use std::str;
65

76
use rustc_abi::Align;
87
use rustc_data_structures::fx::FxIndexMap;
98
use rustc_data_structures::profiling::TimePassesFormat;
9+
use rustc_data_structures::stable_hasher::StableHasher;
1010
use rustc_errors::{ColorConfig, LanguageIdentifier, TerminalUrl};
1111
use rustc_feature::UnstableFeatures;
1212
use rustc_hashes::Hash64;
@@ -251,7 +251,7 @@ macro_rules! top_level_options {
251251
}
252252

253253
impl Options {
254-
pub fn dep_tracking_hash(&self, for_crate_hash: bool) -> u64 {
254+
pub fn dep_tracking_hash(&self, for_crate_hash: bool) -> Hash64 {
255255
let mut sub_hashes = BTreeMap::new();
256256
$({
257257
hash_opt!($opt,
@@ -260,7 +260,7 @@ macro_rules! top_level_options {
260260
for_crate_hash,
261261
[$dep_tracking_marker]);
262262
})*
263-
let mut hasher = DefaultHasher::new();
263+
let mut hasher = StableHasher::new();
264264
dep_tracking::stable_hash(sub_hashes,
265265
&mut hasher,
266266
self.error_format,
@@ -545,7 +545,7 @@ macro_rules! options {
545545
build_options(early_dcx, matches, target_modifiers, $stat, $prefix, $outputname)
546546
}
547547

548-
fn dep_tracking_hash(&self, for_crate_hash: bool, error_format: ErrorOutputType) -> u64 {
548+
fn dep_tracking_hash(&self, for_crate_hash: bool, error_format: ErrorOutputType) -> Hash64 {
549549
let mut sub_hashes = BTreeMap::new();
550550
$({
551551
hash_opt!($opt,
@@ -554,7 +554,7 @@ macro_rules! options {
554554
for_crate_hash,
555555
[$dep_tracking_marker]);
556556
})*
557-
let mut hasher = DefaultHasher::new();
557+
let mut hasher = StableHasher::new();
558558
dep_tracking::stable_hash(sub_hashes,
559559
&mut hasher,
560560
error_format,

0 commit comments

Comments
 (0)