Skip to content

Commit d4e42af

Browse files
committed
Remove PackedFingerprint
1 parent 14265f9 commit d4e42af

File tree

5 files changed

+7
-73
lines changed

5 files changed

+7
-73
lines changed

compiler/rustc_data_structures/src/fingerprint.rs

-58
Original file line numberDiff line numberDiff line change
@@ -159,61 +159,3 @@ impl FingerprintDecoder for opaque::Decoder<'_> {
159159
Fingerprint::decode_opaque(self)
160160
}
161161
}
162-
163-
// `PackedFingerprint` wraps a `Fingerprint`. Its purpose is to, on certain
164-
// architectures, behave like a `Fingerprint` without alignment requirements.
165-
// This behavior is only enabled on x86 and x86_64, where the impact of
166-
// unaligned accesses is tolerable in small doses.
167-
//
168-
// This may be preferable to use in large collections of structs containing
169-
// fingerprints, as it can reduce memory consumption by preventing the padding
170-
// that the more strictly-aligned `Fingerprint` can introduce. An application of
171-
// this is in the query dependency graph, which contains a large collection of
172-
// `DepNode`s. As of this writing, the size of a `DepNode` decreases by ~30%
173-
// (from 24 bytes to 17) by using the packed representation here, which
174-
// noticeably decreases total memory usage when compiling large crates.
175-
//
176-
// The wrapped `Fingerprint` is private to reduce the chance of a client
177-
// invoking undefined behavior by taking a reference to the packed field.
178-
#[cfg_attr(any(target_arch = "x86", target_arch = "x86_64"), repr(packed))]
179-
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Copy, Hash)]
180-
pub struct PackedFingerprint(Fingerprint);
181-
182-
impl std::fmt::Display for PackedFingerprint {
183-
#[inline]
184-
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
185-
// Copy to avoid taking reference to packed field.
186-
let copy = self.0;
187-
copy.fmt(formatter)
188-
}
189-
}
190-
191-
impl<E: rustc_serialize::Encoder> Encodable<E> for PackedFingerprint {
192-
#[inline]
193-
fn encode(&self, s: &mut E) -> Result<(), E::Error> {
194-
// Copy to avoid taking reference to packed field.
195-
let copy = self.0;
196-
copy.encode(s)
197-
}
198-
}
199-
200-
impl<D: rustc_serialize::Decoder> Decodable<D> for PackedFingerprint {
201-
#[inline]
202-
fn decode(d: &mut D) -> Result<Self, D::Error> {
203-
Fingerprint::decode(d).map(PackedFingerprint)
204-
}
205-
}
206-
207-
impl From<Fingerprint> for PackedFingerprint {
208-
#[inline]
209-
fn from(f: Fingerprint) -> PackedFingerprint {
210-
PackedFingerprint(f)
211-
}
212-
}
213-
214-
impl From<PackedFingerprint> for Fingerprint {
215-
#[inline]
216-
fn from(f: PackedFingerprint) -> Fingerprint {
217-
f.0
218-
}
219-
}

compiler/rustc_data_structures/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#![feature(once_cell)]
3232
#![feature(maybe_uninit_uninit_array)]
3333
#![allow(rustc::default_hash_types)]
34-
#![deny(unaligned_references)]
3534

3635
#[macro_use]
3736
extern crate tracing;

compiler/rustc_middle/src/dep_graph/dep_node.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,6 @@ pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
359359
// We keep a lot of `DepNode`s in memory during compilation. It's not
360360
// required that their size stay the same, but we don't want to change
361361
// it inadvertently. This assert just ensures we're aware of any change.
362-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
363-
static_assert_size!(DepNode, 17);
364-
365-
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
366362
static_assert_size!(DepNode, 24);
367363

368364
pub trait DepNodeExt: Sized {
@@ -396,7 +392,7 @@ impl DepNodeExt for DepNode {
396392
/// single DefId/DefPathHash parameter.
397393
fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> DepNode {
398394
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params);
399-
DepNode { kind, hash: def_path_hash.0.into() }
395+
DepNode { kind, hash: def_path_hash.0 }
400396
}
401397

402398
/// Extracts the DefId corresponding to this DepNode. This will work
@@ -411,10 +407,7 @@ impl DepNodeExt for DepNode {
411407
/// has been removed.
412408
fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
413409
if self.kind.can_reconstruct_query_key() {
414-
tcx.queries
415-
.on_disk_cache
416-
.as_ref()?
417-
.def_path_hash_to_def_id(tcx, DefPathHash(self.hash.into()))
410+
tcx.queries.on_disk_cache.as_ref()?.def_path_hash_to_def_id(tcx, DefPathHash(self.hash))
418411
} else {
419412
None
420413
}

compiler/rustc_query_system/src/dep_graph/dep_node.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
4545
use super::{DepContext, DepKind};
4646

47-
use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
47+
use rustc_data_structures::fingerprint::Fingerprint;
4848
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
4949

5050
use std::fmt;
@@ -65,7 +65,7 @@ pub struct DepNode<K> {
6565
//
6666
// FIXME: Enforce this by preventing manual construction of `DefNode`
6767
// (e.g. add a `_priv: ()` field)
68-
pub hash: PackedFingerprint,
68+
pub hash: Fingerprint,
6969
}
7070

7171
impl<K: DepKind> DepNode<K> {
@@ -74,7 +74,7 @@ impl<K: DepKind> DepNode<K> {
7474
/// does not require any parameters.
7575
pub fn new_no_params(kind: K) -> DepNode<K> {
7676
debug_assert!(!kind.has_params());
77-
DepNode { kind, hash: Fingerprint::ZERO.into() }
77+
DepNode { kind, hash: Fingerprint::ZERO }
7878
}
7979

8080
pub fn construct<Ctxt, Key>(tcx: Ctxt, kind: K, arg: &Key) -> DepNode<K>
@@ -83,7 +83,7 @@ impl<K: DepKind> DepNode<K> {
8383
Key: DepNodeParams<Ctxt>,
8484
{
8585
let hash = arg.to_fingerprint(tcx);
86-
let dep_node = DepNode { kind, hash: hash.into() };
86+
let dep_node = DepNode { kind, hash: hash };
8787

8888
#[cfg(debug_assertions)]
8989
{

compiler/rustc_query_system/src/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl<K: DepKind> DepGraph<K> {
390390
// Fingerprint::combine() is faster than sending Fingerprint
391391
// through the StableHasher (at least as long as StableHasher
392392
// is so slow).
393-
hash: data.current.anon_id_seed.combine(hasher.finish()).into(),
393+
hash: data.current.anon_id_seed.combine(hasher.finish()),
394394
};
395395

396396
let dep_node_index = data.current.intern_new_node(

0 commit comments

Comments
 (0)