Skip to content

Commit 050f66e

Browse files
authored
Unrolled build for rust-lang#137095
Rollup merge of rust-lang#137095 - saethlin:use-hash64-for-hashes, r=workingjubilee Replace some u64 hashes with Hash64 I introduced the Hash64 and Hash128 types in rust-lang#110083, essentially as a mechanism to prevent hashes from landing in our leb128 encoding paths. If you just have a u64 or u128 field in a struct then derive Encodable/Decodable, that number gets leb128 encoding. So if you need to store a hash or some other value which behaves very close to a hash, don't store it as a u64. This reverts part of rust-lang#117603, which turned an encoded Hash64 into a u64. Based on rust-lang#110083, I don't expect this to be perf-sensitive on its own, though I expect that it may help stabilize some of the small rmeta size fluctuations we currently see in perf reports.
2 parents 273465e + 4cf2186 commit 050f66e

File tree

51 files changed

+173
-78
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+173
-78
lines changed

Cargo.lock

+21
Original file line numberDiff line numberDiff line change
@@ -3317,6 +3317,7 @@ dependencies = [
33173317
"rand 0.8.5",
33183318
"rand_xoshiro",
33193319
"rustc_data_structures",
3320+
"rustc_hashes",
33203321
"rustc_index",
33213322
"rustc_macros",
33223323
"rustc_serialize",
@@ -3544,6 +3545,7 @@ dependencies = [
35443545
"rustc_errors",
35453546
"rustc_fluent_macro",
35463547
"rustc_fs_util",
3548+
"rustc_hashes",
35473549
"rustc_hir",
35483550
"rustc_index",
35493551
"rustc_llvm",
@@ -3586,6 +3588,7 @@ dependencies = [
35863588
"rustc_errors",
35873589
"rustc_fluent_macro",
35883590
"rustc_fs_util",
3591+
"rustc_hashes",
35893592
"rustc_hir",
35903593
"rustc_hir_pretty",
35913594
"rustc_incremental",
@@ -3658,6 +3661,7 @@ dependencies = [
36583661
"rustc-stable-hash",
36593662
"rustc_arena",
36603663
"rustc_graphviz",
3664+
"rustc_hashes",
36613665
"rustc_index",
36623666
"rustc_macros",
36633667
"rustc_serialize",
@@ -3768,6 +3772,7 @@ dependencies = [
37683772
"rustc_error_codes",
37693773
"rustc_error_messages",
37703774
"rustc_fluent_macro",
3775+
"rustc_hashes",
37713776
"rustc_hir",
37723777
"rustc_index",
37733778
"rustc_lexer",
@@ -3840,6 +3845,13 @@ version = "0.0.0"
38403845
name = "rustc_graphviz"
38413846
version = "0.0.0"
38423847

3848+
[[package]]
3849+
name = "rustc_hashes"
3850+
version = "0.0.0"
3851+
dependencies = [
3852+
"rustc-stable-hash",
3853+
]
3854+
38433855
[[package]]
38443856
name = "rustc_hir"
38453857
version = "0.0.0"
@@ -3849,6 +3861,7 @@ dependencies = [
38493861
"rustc_arena",
38503862
"rustc_ast",
38513863
"rustc_data_structures",
3864+
"rustc_hashes",
38523865
"rustc_index",
38533866
"rustc_macros",
38543867
"rustc_serialize",
@@ -4169,6 +4182,7 @@ dependencies = [
41694182
"rustc_feature",
41704183
"rustc_fluent_macro",
41714184
"rustc_graphviz",
4185+
"rustc_hashes",
41724186
"rustc_hir",
41734187
"rustc_hir_pretty",
41744188
"rustc_index",
@@ -4405,6 +4419,7 @@ dependencies = [
44054419
"measureme",
44064420
"rustc_data_structures",
44074421
"rustc_errors",
4422+
"rustc_hashes",
44084423
"rustc_hir",
44094424
"rustc_index",
44104425
"rustc_middle",
@@ -4428,6 +4443,7 @@ dependencies = [
44284443
"rustc_errors",
44294444
"rustc_feature",
44304445
"rustc_fluent_macro",
4446+
"rustc_hashes",
44314447
"rustc_hir",
44324448
"rustc_index",
44334449
"rustc_macros",
@@ -4488,6 +4504,7 @@ name = "rustc_serialize"
44884504
version = "0.0.0"
44894505
dependencies = [
44904506
"indexmap",
4507+
"rustc_hashes",
44914508
"rustc_macros",
44924509
"smallvec",
44934510
"tempfile",
@@ -4508,6 +4525,7 @@ dependencies = [
45084525
"rustc_feature",
45094526
"rustc_fluent_macro",
45104527
"rustc_fs_util",
4528+
"rustc_hashes",
45114529
"rustc_hir",
45124530
"rustc_lint_defs",
45134531
"rustc_macros",
@@ -4549,6 +4567,7 @@ dependencies = [
45494567
"md-5",
45504568
"rustc_arena",
45514569
"rustc_data_structures",
4570+
"rustc_hashes",
45524571
"rustc_index",
45534572
"rustc_macros",
45544573
"rustc_serialize",
@@ -4568,6 +4587,7 @@ dependencies = [
45684587
"rustc_abi",
45694588
"rustc_data_structures",
45704589
"rustc_errors",
4590+
"rustc_hashes",
45714591
"rustc_hir",
45724592
"rustc_middle",
45734593
"rustc_session",
@@ -4663,6 +4683,7 @@ dependencies = [
46634683
"rustc_data_structures",
46644684
"rustc_errors",
46654685
"rustc_fluent_macro",
4686+
"rustc_hashes",
46664687
"rustc_hir",
46674688
"rustc_index",
46684689
"rustc_infer",

compiler/rustc_abi/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ bitflags = "2.4.1"
99
rand = { version = "0.8.4", default-features = false, optional = true }
1010
rand_xoshiro = { version = "0.6.0", optional = true }
1111
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
12+
rustc_hashes = { path = "../rustc_hashes" }
1213
rustc_index = { path = "../rustc_index", default-features = false }
1314
rustc_macros = { path = "../rustc_macros", optional = true }
1415
rustc_serialize = { path = "../rustc_serialize", optional = true }

compiler/rustc_abi/src/layout.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::fmt::{self, Write};
22
use std::ops::{Bound, Deref};
33
use std::{cmp, iter};
44

5+
use rustc_hashes::Hash64;
56
use rustc_index::Idx;
67
use tracing::debug;
78

@@ -133,7 +134,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
133134
size,
134135
max_repr_align: None,
135136
unadjusted_abi_align: align.abi,
136-
randomization_seed: combined_seed,
137+
randomization_seed: Hash64::new(combined_seed),
137138
}
138139
}
139140

@@ -226,7 +227,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
226227
size: Size::ZERO,
227228
max_repr_align: None,
228229
unadjusted_abi_align: dl.i8_align.abi,
229-
randomization_seed: 0,
230+
randomization_seed: Hash64::ZERO,
230231
}
231232
}
232233

@@ -1058,7 +1059,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
10581059
// unsizable tail fields are excluded so that we use the same seed for the sized and unsized layouts.
10591060
let field_seed = fields_excluding_tail
10601061
.iter()
1061-
.fold(0u64, |acc, f| acc.wrapping_add(f.randomization_seed));
1062+
.fold(Hash64::ZERO, |acc, f| acc.wrapping_add(f.randomization_seed));
10621063

10631064
if optimize_field_order && fields.len() > 1 {
10641065
// If `-Z randomize-layout` was enabled for the type definition we can shuffle
@@ -1072,7 +1073,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
10721073
// `ReprOptions.field_shuffle_seed` is a deterministic seed we can use to randomize field
10731074
// ordering.
10741075
let mut rng = rand_xoshiro::Xoshiro128StarStar::seed_from_u64(
1075-
field_seed.wrapping_add(repr.field_shuffle_seed),
1076+
field_seed.wrapping_add(repr.field_shuffle_seed).as_u64(),
10761077
);
10771078

10781079
// Shuffle the ordering of the fields.

compiler/rustc_abi/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use std::str::FromStr;
5050
use bitflags::bitflags;
5151
#[cfg(feature = "nightly")]
5252
use rustc_data_structures::stable_hasher::StableOrd;
53+
use rustc_hashes::Hash64;
5354
use rustc_index::{Idx, IndexSlice, IndexVec};
5455
#[cfg(feature = "nightly")]
5556
use rustc_macros::{Decodable_Generic, Encodable_Generic, HashStable_Generic};
@@ -140,7 +141,7 @@ pub struct ReprOptions {
140141
/// hash without loss, but it does pay the price of being larger.
141142
/// Everything's a tradeoff, a 64-bit seed should be sufficient for our
142143
/// purposes (primarily `-Z randomize-layout`)
143-
pub field_shuffle_seed: u64,
144+
pub field_shuffle_seed: Hash64,
144145
}
145146

146147
impl ReprOptions {
@@ -1727,7 +1728,7 @@ pub struct LayoutData<FieldIdx: Idx, VariantIdx: Idx> {
17271728
/// transmuted to `Foo<U>` we aim to create probalistically distinct seeds so that Foo can choose
17281729
/// to reorder its fields based on that information. The current implementation is a conservative
17291730
/// approximation of this goal.
1730-
pub randomization_seed: u64,
1731+
pub randomization_seed: Hash64,
17311732
}
17321733

17331734
impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
@@ -1781,7 +1782,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
17811782
align,
17821783
max_repr_align: None,
17831784
unadjusted_abi_align: align.abi,
1784-
randomization_seed,
1785+
randomization_seed: Hash64::new(randomization_seed),
17851786
}
17861787
}
17871788
}

compiler/rustc_codegen_llvm/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ rustc_data_structures = { path = "../rustc_data_structures" }
2525
rustc_errors = { path = "../rustc_errors" }
2626
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
2727
rustc_fs_util = { path = "../rustc_fs_util" }
28+
rustc_hashes = { path = "../rustc_hashes" }
2829
rustc_hir = { path = "../rustc_hir" }
2930
rustc_index = { path = "../rustc_index" }
3031
rustc_llvm = { path = "../rustc_llvm" }

compiler/rustc_codegen_llvm/src/common.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use rustc_abi::{AddressSpace, HasDataLayout};
77
use rustc_ast::Mutability;
88
use rustc_codegen_ssa::common::TypeKind;
99
use rustc_codegen_ssa::traits::*;
10-
use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher};
10+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
11+
use rustc_hashes::Hash128;
1112
use rustc_hir::def_id::DefId;
1213
use rustc_middle::bug;
1314
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar};

compiler/rustc_codegen_ssa/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ rustc_data_structures = { path = "../rustc_data_structures" }
2525
rustc_errors = { path = "../rustc_errors" }
2626
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
2727
rustc_fs_util = { path = "../rustc_fs_util" }
28+
rustc_hashes = { path = "../rustc_hashes" }
2829
rustc_hir = { path = "../rustc_hir" }
2930
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
3031
rustc_incremental = { path = "../rustc_incremental" }

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use std::fmt::Write;
1515

1616
use rustc_abi::Integer;
1717
use rustc_data_structures::fx::FxHashSet;
18-
use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher};
18+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
19+
use rustc_hashes::Hash64;
1920
use rustc_hir::def_id::DefId;
2021
use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
2122
use rustc_hir::{CoroutineDesugaring, CoroutineKind, CoroutineSource, Mutability};

compiler/rustc_data_structures/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ rustc-rayon = { version = "0.5.1", features = ["indexmap"] }
1818
rustc-stable-hash = { version = "0.1.0", features = ["nightly"] }
1919
rustc_arena = { path = "../rustc_arena" }
2020
rustc_graphviz = { path = "../rustc_graphviz" }
21+
rustc_hashes = { path = "../rustc_hashes" }
2122
rustc_index = { path = "../rustc_index", package = "rustc_index" }
2223
rustc_macros = { path = "../rustc_macros" }
2324
rustc_serialize = { path = "../rustc_serialize" }

compiler/rustc_data_structures/src/fingerprint.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use std::hash::{Hash, Hasher};
22

3+
use rustc_hashes::Hash64;
34
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
45

5-
use crate::stable_hasher::{
6-
FromStableHash, Hash64, StableHasherHash, impl_stable_traits_for_trivial_type,
7-
};
6+
use crate::stable_hasher::{FromStableHash, StableHasherHash, impl_stable_traits_for_trivial_type};
87

98
#[cfg(test)]
109
mod tests;

compiler/rustc_data_structures/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ pub mod vec_cache;
8484
pub mod work_queue;
8585

8686
mod atomic_ref;
87-
mod hashes;
8887

8988
/// This calls the passed function while ensuring it won't be inlined into the caller.
9089
#[inline(never)]

compiler/rustc_data_structures/src/stable_hasher.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ use smallvec::SmallVec;
1010
#[cfg(test)]
1111
mod tests;
1212

13+
use rustc_hashes::{Hash64, Hash128};
1314
pub use rustc_stable_hash::{
1415
FromStableHash, SipHasher128Hash as StableHasherHash, StableSipHasher128 as StableHasher,
1516
};
1617

17-
pub use crate::hashes::{Hash64, Hash128};
18-
1918
/// Something that implements `HashStable<CTX>` can be hashed in a way that is
2019
/// stable across multiple compilation sessions.
2120
///

compiler/rustc_data_structures/src/tagged_ptr/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::ptr;
22

3+
use rustc_hashes::Hash128;
4+
35
use super::*;
4-
use crate::hashes::Hash128;
56
use crate::stable_hasher::{HashStable, StableHasher};
67

78
/// A tag type used in [`TaggedRef`] tests.

compiler/rustc_errors/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ rustc_data_structures = { path = "../rustc_data_structures" }
1414
rustc_error_codes = { path = "../rustc_error_codes" }
1515
rustc_error_messages = { path = "../rustc_error_messages" }
1616
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
17+
rustc_hashes = { path = "../rustc_hashes" }
1718
rustc_hir = { path = "../rustc_hir" }
1819
rustc_index = { path = "../rustc_index" }
1920
rustc_lexer = { path = "../rustc_lexer" }

compiler/rustc_errors/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ pub use emitter::ColorConfig;
5858
use emitter::{DynEmitter, Emitter, is_case_difference, is_different};
5959
use rustc_data_structures::AtomicRef;
6060
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
61-
use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
61+
use rustc_data_structures::stable_hasher::StableHasher;
6262
use rustc_data_structures::sync::{DynSend, Lock};
6363
pub use rustc_error_messages::{
6464
DiagMessage, FluentBundle, LanguageIdentifier, LazyFallbackBundle, MultiSpan, SpanLabel,
6565
SubdiagMessage, fallback_fluent_bundle, fluent_bundle,
6666
};
67+
use rustc_hashes::Hash128;
6768
use rustc_lint_defs::LintExpectationId;
6869
pub use rustc_lint_defs::{Applicability, listify, pluralize};
6970
use rustc_macros::{Decodable, Encodable};

compiler/rustc_hashes/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "rustc_hashes"
3+
version = "0.0.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
# tidy-alphabetical-start
8+
rustc-stable-hash = { version = "0.1.0" }
9+
# tidy-alphabetical-end

0 commit comments

Comments
 (0)