Skip to content

Commit

Permalink
Auto merge of rust-lang#93014 - Kobzol:revert-92103-stable-hash-skip-…
Browse files Browse the repository at this point in the history
…zero-bytes, r=the8472

Revert "Do not hash leading zero bytes of i64 numbers in Sip128 hasher"

Reverts rust-lang#92103. It had a (in retrospect, obvious) correctness problem where changing the order of two adjacent values would produce identical hashes, which is problematic in stable hashing (see [this comment](rust-lang#92103 (comment))).

I'll try to send the PR again with a fix for this issue.

r? `@the8472`
  • Loading branch information
bors authored and ehuss committed Jan 25, 2022
1 parent 9f7c5dc commit e5e539c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
18 changes: 2 additions & 16 deletions compiler/rustc_data_structures/src/sip128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,20 +409,6 @@ impl SipHasher128 {
}
}

macro_rules! dispatch_value {
($target: expr, $value:expr) => {
let value = $value;
#[allow(unreachable_patterns)]
#[allow(overflowing_literals)]
match value {
0..=0xFF => $target.short_write(value as u8),
0x100..=0xFFFF => $target.short_write(value as u16),
0x10000..=0xFFFFFFFF => $target.short_write(value as u32),
_ => $target.short_write(value as u64),
}
};
}

impl Hasher for SipHasher128 {
#[inline]
fn write_u8(&mut self, i: u8) {
Expand All @@ -436,7 +422,7 @@ impl Hasher for SipHasher128 {

#[inline]
fn write_u32(&mut self, i: u32) {
dispatch_value!(self, i);
self.short_write(i);
}

#[inline]
Expand Down Expand Up @@ -466,7 +452,7 @@ impl Hasher for SipHasher128 {

#[inline]
fn write_i64(&mut self, i: i64) {
dispatch_value!(self, i as u64);
self.short_write(i as u64);
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/test/debuginfo/function-names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
// Const generic parameter
// gdb-command:info functions -q function_names::const_generic_fn.*
// gdb-check:[...]static fn function_names::const_generic_fn_bool<false>();
// gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#3fcd7c34c1555be6}>();
// gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#fe3cfa0214ac55c7}>();
// gdb-check:[...]static fn function_names::const_generic_fn_signed_int<-7>();
// gdb-check:[...]static fn function_names::const_generic_fn_unsigned_int<14>();

Expand Down Expand Up @@ -76,7 +76,7 @@
// Const generic parameter
// cdb-command:x a!function_names::const_generic_fn*
// cdb-check:[...] a!function_names::const_generic_fn_bool<false> (void)
// cdb-check:[...] a!function_names::const_generic_fn_non_int<CONST$3fcd7c34c1555be6> (void)
// cdb-check:[...] a!function_names::const_generic_fn_non_int<CONST$fe3cfa0214ac55c7> (void)
// cdb-check:[...] a!function_names::const_generic_fn_unsigned_int<14> (void)
// cdb-check:[...] a!function_names::const_generic_fn_signed_int<-7> (void)

Expand Down

0 comments on commit e5e539c

Please sign in to comment.