-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import
StableHasher
, StableHasherResult
and SipHasher128
as well as the `DebugStrictAdd` and `DebugStrictSub` from rustc.
- Loading branch information
Showing
9 changed files
with
1,204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "rustc-stable-hash" | ||
version = "0.1.0" | ||
authors = ["The Rust Project Developers"] | ||
description = "A stable hashing algorithm used by rustc" | ||
license = "Apache-2.0 OR MIT" | ||
readme = "README.md" | ||
repository = "https://github.com/rust-lang/rustc-stable-hash" | ||
edition = "2021" | ||
|
||
[features] | ||
nightly = [] # for feature(hasher_prefixfree_extras) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Weaker version of `-Coverflow-checks`. | ||
|
||
/// Addition, but only overflow checked when `cfg(debug_assertions)` is set | ||
/// instead of respecting `-Coverflow-checks`. | ||
/// | ||
/// This exists for performance reasons, as we ship rustc with overflow checks. | ||
/// While overflow checks are perf neutral in almost all of the compiler, there | ||
/// are a few particularly hot areas where we don't want overflow checks in our | ||
/// dist builds. Overflow is still a bug there, so we want overflow check for | ||
/// builds with debug assertions. | ||
/// | ||
/// That's a long way to say that this should be used in areas where overflow | ||
/// is a bug but overflow checking is too slow. | ||
pub trait DebugStrictAdd { | ||
/// See [`DebugStrictAdd`]. | ||
fn debug_strict_add(self, other: Self) -> Self; | ||
} | ||
|
||
macro_rules! impl_debug_strict_add { | ||
($( $ty:ty )*) => { | ||
$( | ||
impl DebugStrictAdd for $ty { | ||
fn debug_strict_add(self, other: Self) -> Self { | ||
if cfg!(debug_assertions) { | ||
self + other | ||
} else { | ||
self.wrapping_add(other) | ||
} | ||
} | ||
} | ||
)* | ||
}; | ||
} | ||
|
||
/// See [`DebugStrictAdd`]. | ||
pub trait DebugStrictSub { | ||
/// See [`DebugStrictAdd`]. | ||
fn debug_strict_sub(self, other: Self) -> Self; | ||
} | ||
|
||
macro_rules! impl_debug_strict_sub { | ||
($( $ty:ty )*) => { | ||
$( | ||
impl DebugStrictSub for $ty { | ||
fn debug_strict_sub(self, other: Self) -> Self { | ||
if cfg!(debug_assertions) { | ||
self - other | ||
} else { | ||
self.wrapping_sub(other) | ||
} | ||
} | ||
} | ||
)* | ||
}; | ||
} | ||
|
||
impl_debug_strict_add! { | ||
usize | ||
} | ||
|
||
/* | ||
impl_debug_strict_add! { | ||
u8 u16 u32 u64 u128 usize | ||
i8 i16 i32 i64 i128 isize | ||
} | ||
*/ | ||
|
||
impl_debug_strict_sub! { | ||
usize | ||
} | ||
|
||
/* | ||
impl_debug_strict_sub! { | ||
u8 u16 u32 u64 u128 usize | ||
i8 i16 i32 i64 i128 isize | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//! A stable hashing algorithm used by rustc | ||
|
||
#![cfg_attr(feature = "nightly", feature(hasher_prefixfree_extras))] | ||
|
||
mod int_overflow; | ||
mod sip128; | ||
mod stable_hasher; | ||
|
||
#[doc(inline)] | ||
pub use stable_hasher::StableHasher; | ||
|
||
#[doc(inline)] | ||
pub use stable_hasher::StableHasherResult; |
Oops, something went wrong.