Skip to content

Commit d80f60c

Browse files
committed
Auto merge of #128324 - aDotInTheVoid:defid-derive-hash, r=<try>
Defid derive hash r? `@ghost` Built on-top of #128323, to see if using new fxhash lets us eliminate DefId custom hashing. (prediction: this kills perf, as we'll hash 2 u32's instead of 1 u64)
2 parents 2cbbe8b + 5a8ccff commit d80f60c

File tree

6 files changed

+20
-48
lines changed

6 files changed

+20
-48
lines changed

Cargo.lock

+15-9
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ dependencies = [
13091309
"fluent-syntax",
13101310
"intl-memoizer",
13111311
"intl_pluralrules",
1312-
"rustc-hash",
1312+
"rustc-hash 1.1.0",
13131313
"self_cell 0.10.3",
13141314
"smallvec",
13151315
"unic-langid",
@@ -2019,7 +2019,7 @@ dependencies = [
20192019
"anyhow",
20202020
"clap",
20212021
"fs-err",
2022-
"rustc-hash",
2022+
"rustc-hash 2.0.0",
20232023
"rustdoc-json-types",
20242024
"serde",
20252025
"serde_json",
@@ -2290,7 +2290,7 @@ dependencies = [
22902290
"memmap2",
22912291
"parking_lot",
22922292
"perf-event-open-sys",
2293-
"rustc-hash",
2293+
"rustc-hash 1.1.0",
22942294
"smallvec",
22952295
]
22962296

@@ -2934,7 +2934,7 @@ checksum = "c4e8e505342045d397d0b6674dcb82d6faf5cf40484d30eeb88fc82ef14e903f"
29342934
dependencies = [
29352935
"datafrog",
29362936
"log",
2937-
"rustc-hash",
2937+
"rustc-hash 1.1.0",
29382938
]
29392939

29402940
[[package]]
@@ -3372,6 +3372,12 @@ version = "1.1.0"
33723372
source = "registry+https://github.com/rust-lang/crates.io-index"
33733373
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
33743374

3375+
[[package]]
3376+
name = "rustc-hash"
3377+
version = "2.0.0"
3378+
source = "registry+https://github.com/rust-lang/crates.io-index"
3379+
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
3380+
33753381
[[package]]
33763382
name = "rustc-main"
33773383
version = "0.0.0"
@@ -3761,7 +3767,7 @@ dependencies = [
37613767
"memmap2",
37623768
"parking_lot",
37633769
"portable-atomic",
3764-
"rustc-hash",
3770+
"rustc-hash 2.0.0",
37653771
"rustc-rayon",
37663772
"rustc-stable-hash",
37673773
"rustc_arena",
@@ -4452,7 +4458,7 @@ dependencies = [
44524458
name = "rustc_pattern_analysis"
44534459
version = "0.0.0"
44544460
dependencies = [
4455-
"rustc-hash",
4461+
"rustc-hash 2.0.0",
44564462
"rustc_apfloat",
44574463
"rustc_arena",
44584464
"rustc_data_structures",
@@ -4843,7 +4849,7 @@ name = "rustdoc-json-types"
48434849
version = "0.1.0"
48444850
dependencies = [
48454851
"bincode",
4846-
"rustc-hash",
4852+
"rustc-hash 2.0.0",
48474853
"serde",
48484854
"serde_json",
48494855
]
@@ -5557,7 +5563,7 @@ dependencies = [
55575563
"ignore",
55585564
"miropt-test-tools",
55595565
"regex",
5560-
"rustc-hash",
5566+
"rustc-hash 1.1.0",
55615567
"semver",
55625568
"similar",
55635569
"termcolor",
@@ -5786,7 +5792,7 @@ version = "0.5.0"
57865792
source = "registry+https://github.com/rust-lang/crates.io-index"
57875793
checksum = "deb68604048ff8fa93347f02441e4487594adc20bb8a084f9e564d2b827a0a9f"
57885794
dependencies = [
5789-
"rustc-hash",
5795+
"rustc-hash 1.1.0",
57905796
]
57915797

57925798
[[package]]

compiler/rustc_data_structures/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ena = "0.14.3"
1313
indexmap = { version = "2.0.0" }
1414
jobserver_crate = { version = "0.1.28", package = "jobserver" }
1515
measureme = "11"
16-
rustc-hash = "1.1.0"
16+
rustc-hash = "2.0.0"
1717
rustc-rayon = { version = "0.5.0", optional = true }
1818
rustc-stable-hash = { version = "0.1.0", features = ["nightly"] }
1919
rustc_arena = { path = "../rustc_arena" }

compiler/rustc_pattern_analysis/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
rustc-hash = "1.1.0"
8+
rustc-hash = "2.0.0"
99
rustc_apfloat = "0.2.0"
1010
rustc_arena = { path = "../rustc_arena", optional = true }
1111
rustc_data_structures = { path = "../rustc_data_structures", optional = true }

compiler/rustc_span/src/def_id.rs

+1-35
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,12 @@ rustc_index::newtype_index! {
219219
/// index and a def index.
220220
///
221221
/// You can create a `DefId` from a `LocalDefId` using `local_def_id.to_def_id()`.
222-
#[derive(Clone, PartialEq, Eq, Copy)]
223-
// On below-64 bit systems we can simply use the derived `Hash` impl
224-
#[cfg_attr(not(target_pointer_width = "64"), derive(Hash))]
222+
#[derive(Clone, PartialEq, Eq, Copy, Hash)]
225223
#[repr(C)]
226224
#[rustc_pass_by_value]
227-
// We guarantee field order. Note that the order is essential here, see below why.
228225
pub struct DefId {
229-
// cfg-ing the order of fields so that the `DefIndex` which is high entropy always ends up in
230-
// the lower bits no matter the endianness. This allows the compiler to turn that `Hash` impl
231-
// into a direct call to `u64::hash(_)`.
232-
#[cfg(not(all(target_pointer_width = "64", target_endian = "big")))]
233226
pub index: DefIndex,
234227
pub krate: CrateNum,
235-
#[cfg(all(target_pointer_width = "64", target_endian = "big"))]
236-
pub index: DefIndex,
237228
}
238229

239230
// To ensure correctness of incremental compilation,
@@ -242,31 +233,6 @@ pub struct DefId {
242233
impl !Ord for DefId {}
243234
impl !PartialOrd for DefId {}
244235

245-
// On 64-bit systems, we can hash the whole `DefId` as one `u64` instead of two `u32`s. This
246-
// improves performance without impairing `FxHash` quality. So the below code gets compiled to a
247-
// noop on little endian systems because the memory layout of `DefId` is as follows:
248-
//
249-
// ```
250-
// +-1--------------31-+-32-------------63-+
251-
// ! index ! krate !
252-
// +-------------------+-------------------+
253-
// ```
254-
//
255-
// The order here has direct impact on `FxHash` quality because we have far more `DefIndex` per
256-
// crate than we have `Crate`s within one compilation. Or in other words, this arrangement puts
257-
// more entropy in the low bits than the high bits. The reason this matters is that `FxHash`, which
258-
// is used throughout rustc, has problems distributing the entropy from the high bits, so reversing
259-
// the order would lead to a large number of collisions and thus far worse performance.
260-
//
261-
// On 64-bit big-endian systems, this compiles to a 64-bit rotation by 32 bits, which is still
262-
// faster than another `FxHash` round.
263-
#[cfg(target_pointer_width = "64")]
264-
impl Hash for DefId {
265-
fn hash<H: Hasher>(&self, h: &mut H) {
266-
(((self.krate.as_u32() as u64) << 32) | (self.index.as_u32() as u64)).hash(h)
267-
}
268-
}
269-
270236
impl DefId {
271237
/// Makes a local `DefId` from the given `DefIndex`.
272238
#[inline]

src/rustdoc-json-types/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ path = "lib.rs"
88

99
[dependencies]
1010
serde = { version = "1.0", features = ["derive"] }
11-
rustc-hash = "1.1.0"
11+
rustc-hash = "2.0.0"
1212

1313
[dev-dependencies]
1414
serde_json = "1.0"

src/tools/jsondoclint/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ edition = "2021"
99
anyhow = "1.0.62"
1010
clap = { version = "4.0.15", features = ["derive"] }
1111
fs-err = "2.8.1"
12-
rustc-hash = "1.1.0"
12+
rustc-hash = "2.0.0"
1313
rustdoc-json-types = { version = "0.1.0", path = "../../rustdoc-json-types" }
1414
serde = { version = "1.0", features = ["derive"] }
1515
serde_json = "1.0.85"

0 commit comments

Comments
 (0)