Skip to content

Commit e49122f

Browse files
committed
Auto merge of rust-lang#110367 - saethlin:no-truncations, r=oli-obk
Remove some suspicious cast truncations These truncations were added a long time ago, and as best I can tell without a perf justification. And with rust-lang#110410 it has become perf-neutral to not truncate anymore. We worked hard for all these bits, let's use them.
2 parents bdb32bd + 84facac commit e49122f

File tree

4 files changed

+9
-33
lines changed

4 files changed

+9
-33
lines changed

compiler/rustc_data_structures/src/svh.rs

+6-28
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,30 @@
55
//! mismatches where we have two versions of the same crate that were
66
//! compiled from distinct sources.
77
8-
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
8+
use crate::fingerprint::Fingerprint;
99
use std::fmt;
10-
use std::hash::{Hash, Hasher};
1110

1211
use crate::stable_hasher;
1312

14-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
13+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable, Decodable, Hash)]
1514
pub struct Svh {
16-
hash: u64,
15+
hash: Fingerprint,
1716
}
1817

1918
impl Svh {
2019
/// Creates a new `Svh` given the hash. If you actually want to
2120
/// compute the SVH from some HIR, you want the `calculate_svh`
2221
/// function found in `rustc_incremental`.
23-
pub fn new(hash: u64) -> Svh {
22+
pub fn new(hash: Fingerprint) -> Svh {
2423
Svh { hash }
2524
}
2625

2726
pub fn as_u64(&self) -> u64 {
28-
self.hash
27+
self.hash.to_smaller_hash()
2928
}
3029

3130
pub fn to_string(&self) -> String {
32-
format!("{:016x}", self.hash)
33-
}
34-
}
35-
36-
impl Hash for Svh {
37-
fn hash<H>(&self, state: &mut H)
38-
where
39-
H: Hasher,
40-
{
41-
self.hash.to_le().hash(state);
31+
format!("{:016x}", self.hash.to_smaller_hash())
4232
}
4333
}
4434

@@ -48,18 +38,6 @@ impl fmt::Display for Svh {
4838
}
4939
}
5040

51-
impl<S: Encoder> Encodable<S> for Svh {
52-
fn encode(&self, s: &mut S) {
53-
s.emit_u64(self.as_u64().to_le());
54-
}
55-
}
56-
57-
impl<D: Decoder> Decodable<D> for Svh {
58-
fn decode(d: &mut D) -> Svh {
59-
Svh::new(u64::from_le(d.read_u64()))
60-
}
61-
}
62-
6341
impl<T> stable_hasher::HashStable<T> for Svh {
6442
#[inline]
6543
fn hash_stable(&self, ctx: &mut T, hasher: &mut stable_hasher::StableHasher) {

compiler/rustc_middle/src/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
11991199
stable_hasher.finish()
12001200
});
12011201

1202-
Svh::new(crate_hash.to_smaller_hash())
1202+
Svh::new(crate_hash)
12031203
}
12041204

12051205
fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {

compiler/rustc_query_system/src/ich/impls_syntax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
7575
ref normalized_pos,
7676
} = *self;
7777

78-
(name_hash as u64).hash_stable(hcx, hasher);
78+
name_hash.hash_stable(hcx, hasher);
7979

8080
src_hash.hash_stable(hcx, hasher);
8181

compiler/rustc_span/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2160,9 +2160,7 @@ where
21602160
};
21612161

21622162
Hash::hash(&TAG_VALID_SPAN, hasher);
2163-
// We truncate the stable ID hash and line and column numbers. The chances
2164-
// of causing a collision this way should be minimal.
2165-
Hash::hash(&(file.name_hash as u64), hasher);
2163+
Hash::hash(&file.name_hash, hasher);
21662164

21672165
// Hash both the length and the end location (line/column) of a span. If we
21682166
// hash only the length, for example, then two otherwise equal spans with

0 commit comments

Comments
 (0)