Skip to content

Commit

Permalink
Auto merge of #127479 - Urgau:rustc-stable-hash, r=michaelwoerister
Browse files Browse the repository at this point in the history
Use rustc-stable-hash in the compiler

Following rust-lang/compiler-team#755 and the release of the crate on crates.io, let's now use it in the compiler and remove the old implementation.

cc `@michaelwoerister`
r? ghost
  • Loading branch information
bors committed Jul 12, 2024
2 parents b286722 + 977439d commit 05eac57
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 1,049 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3514,6 +3514,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5be1bdc7edf596692617627bbfeaba522131b18e06ca4df2b6b689e3c5d5ce84"

[[package]]
name = "rustc-stable-hash"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5c9f15eec8235d7cb775ee6f81891db79b98fd54ba1ad8fae565b88ef1ae4e2"

[[package]]
name = "rustc-std-workspace-alloc"
version = "1.99.0"
Expand Down Expand Up @@ -3852,6 +3858,7 @@ dependencies = [
"portable-atomic",
"rustc-hash",
"rustc-rayon",
"rustc-stable-hash",
"rustc_arena",
"rustc_graphviz",
"rustc_index",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobserver_crate = { version = "0.1.28", package = "jobserver" }
measureme = "11"
rustc-hash = "1.1.0"
rustc-rayon = { version = "0.5.0", optional = true }
rustc-stable-hash = { version = "0.1.0", features = ["nightly"] }
rustc_arena = { path = "../rustc_arena" }
rustc_graphviz = { path = "../rustc_graphviz" }
rustc_index = { path = "../rustc_index", package = "rustc_index" }
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_data_structures/src/fingerprint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::stable_hasher::impl_stable_traits_for_trivial_type;
use crate::stable_hasher::{Hash64, StableHasher, StableHasherResult};
use crate::stable_hasher::{FromStableHash, Hash64, StableHasherHash};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use std::hash::{Hash, Hasher};

Expand Down Expand Up @@ -154,10 +154,11 @@ impl FingerprintHasher for crate::unhash::Unhasher {
}
}

impl StableHasherResult for Fingerprint {
impl FromStableHash for Fingerprint {
type Hash = StableHasherHash;

#[inline]
fn finish(hasher: StableHasher) -> Self {
let (_0, _1) = hasher.finalize();
fn from(StableHasherHash([_0, _1]): Self::Hash) -> Self {
Fingerprint(_0, _1)
}
}
Expand Down
17 changes: 10 additions & 7 deletions compiler/rustc_data_structures/src/hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! connect the fact that they can only be produced by a `StableHasher` to their
//! `Encode`/`Decode` impls.

use crate::stable_hasher::{StableHasher, StableHasherResult};
use crate::stable_hasher::{FromStableHash, StableHasherHash};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use std::fmt;
use std::ops::BitXorAssign;
Expand Down Expand Up @@ -56,10 +56,12 @@ impl<D: Decoder> Decodable<D> for Hash64 {
}
}

impl StableHasherResult for Hash64 {
impl FromStableHash for Hash64 {
type Hash = StableHasherHash;

#[inline]
fn finish(hasher: StableHasher) -> Self {
Self { inner: hasher.finalize().0 }
fn from(StableHasherHash([_0, __1]): Self::Hash) -> Self {
Self { inner: _0 }
}
}

Expand Down Expand Up @@ -121,10 +123,11 @@ impl<D: Decoder> Decodable<D> for Hash128 {
}
}

impl StableHasherResult for Hash128 {
impl FromStableHash for Hash128 {
type Hash = StableHasherHash;

#[inline]
fn finish(hasher: StableHasher) -> Self {
let (_0, _1) = hasher.finalize();
fn from(StableHasherHash([_0, _1]): Self::Hash) -> Self {
Self { inner: u128::from(_0) | (u128::from(_1) << 64) }
}
}
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#![feature(core_intrinsics)]
#![feature(extend_one)]
#![feature(hash_raw_entry)]
#![feature(hasher_prefixfree_extras)]
#![feature(macro_metavar_expr)]
#![feature(map_try_insert)]
#![feature(min_specialization)]
Expand Down Expand Up @@ -67,7 +66,6 @@ pub mod owned_slice;
pub mod packed;
pub mod profiling;
pub mod sharded;
pub mod sip128;
pub mod small_c_str;
pub mod snapshot_map;
pub mod sorted_map;
Expand Down
Loading

0 comments on commit 05eac57

Please sign in to comment.