diff --git a/compiler/rustc_data_structures/src/fingerprint.rs b/compiler/rustc_data_structures/src/fingerprint.rs index 08c3419a8421d..2fdc0644f7a49 100644 --- a/compiler/rustc_data_structures/src/fingerprint.rs +++ b/compiler/rustc_data_structures/src/fingerprint.rs @@ -159,61 +159,3 @@ impl FingerprintDecoder for opaque::Decoder<'_> { Fingerprint::decode_opaque(self) } } - -// `PackedFingerprint` wraps a `Fingerprint`. Its purpose is to, on certain -// architectures, behave like a `Fingerprint` without alignment requirements. -// This behavior is only enabled on x86 and x86_64, where the impact of -// unaligned accesses is tolerable in small doses. -// -// This may be preferable to use in large collections of structs containing -// fingerprints, as it can reduce memory consumption by preventing the padding -// that the more strictly-aligned `Fingerprint` can introduce. An application of -// this is in the query dependency graph, which contains a large collection of -// `DepNode`s. As of this writing, the size of a `DepNode` decreases by ~30% -// (from 24 bytes to 17) by using the packed representation here, which -// noticeably decreases total memory usage when compiling large crates. -// -// The wrapped `Fingerprint` is private to reduce the chance of a client -// invoking undefined behavior by taking a reference to the packed field. -#[cfg_attr(any(target_arch = "x86", target_arch = "x86_64"), repr(packed))] -#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Copy, Hash)] -pub struct PackedFingerprint(Fingerprint); - -impl std::fmt::Display for PackedFingerprint { - #[inline] - fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - // Copy to avoid taking reference to packed field. - let copy = self.0; - copy.fmt(formatter) - } -} - -impl Encodable for PackedFingerprint { - #[inline] - fn encode(&self, s: &mut E) -> Result<(), E::Error> { - // Copy to avoid taking reference to packed field. - let copy = self.0; - copy.encode(s) - } -} - -impl Decodable for PackedFingerprint { - #[inline] - fn decode(d: &mut D) -> Result { - Fingerprint::decode(d).map(PackedFingerprint) - } -} - -impl From for PackedFingerprint { - #[inline] - fn from(f: Fingerprint) -> PackedFingerprint { - PackedFingerprint(f) - } -} - -impl From for Fingerprint { - #[inline] - fn from(f: PackedFingerprint) -> Fingerprint { - f.0 - } -} diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 5880bbd3de44e..9fea4ff0ad690 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -31,7 +31,6 @@ #![feature(once_cell)] #![feature(maybe_uninit_uninit_array)] #![allow(rustc::default_hash_types)] -#![deny(unaligned_references)] #[macro_use] extern crate tracing; diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 62f2874af0493..8071e10e14f67 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -359,10 +359,6 @@ pub type DepNode = rustc_query_system::dep_graph::DepNode; // We keep a lot of `DepNode`s in memory during compilation. It's not // required that their size stay the same, but we don't want to change // it inadvertently. This assert just ensures we're aware of any change. -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -static_assert_size!(DepNode, 17); - -#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] static_assert_size!(DepNode, 24); pub trait DepNodeExt: Sized { @@ -396,7 +392,7 @@ impl DepNodeExt for DepNode { /// single DefId/DefPathHash parameter. fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> DepNode { debug_assert!(kind.can_reconstruct_query_key() && kind.has_params); - DepNode { kind, hash: def_path_hash.0.into() } + DepNode { kind, hash: def_path_hash.0 } } /// Extracts the DefId corresponding to this DepNode. This will work @@ -411,10 +407,7 @@ impl DepNodeExt for DepNode { /// has been removed. fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option { if self.kind.can_reconstruct_query_key() { - tcx.queries - .on_disk_cache - .as_ref()? - .def_path_hash_to_def_id(tcx, DefPathHash(self.hash.into())) + tcx.queries.on_disk_cache.as_ref()?.def_path_hash_to_def_id(tcx, DefPathHash(self.hash)) } else { None } diff --git a/compiler/rustc_query_system/src/dep_graph/dep_node.rs b/compiler/rustc_query_system/src/dep_graph/dep_node.rs index 64aba870502c7..7641da51e9404 100644 --- a/compiler/rustc_query_system/src/dep_graph/dep_node.rs +++ b/compiler/rustc_query_system/src/dep_graph/dep_node.rs @@ -44,7 +44,7 @@ use super::{DepContext, DepKind}; -use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint}; +use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use std::fmt; @@ -65,7 +65,7 @@ pub struct DepNode { // // FIXME: Enforce this by preventing manual construction of `DefNode` // (e.g. add a `_priv: ()` field) - pub hash: PackedFingerprint, + pub hash: Fingerprint, } impl DepNode { @@ -74,7 +74,7 @@ impl DepNode { /// does not require any parameters. pub fn new_no_params(kind: K) -> DepNode { debug_assert!(!kind.has_params()); - DepNode { kind, hash: Fingerprint::ZERO.into() } + DepNode { kind, hash: Fingerprint::ZERO } } pub fn construct(tcx: Ctxt, kind: K, arg: &Key) -> DepNode @@ -83,7 +83,7 @@ impl DepNode { Key: DepNodeParams, { let hash = arg.to_fingerprint(tcx); - let dep_node = DepNode { kind, hash: hash.into() }; + let dep_node = DepNode { kind, hash: hash }; #[cfg(debug_assertions)] { diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 4fb3a683ea225..ed181bbea8aaa 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -390,7 +390,7 @@ impl DepGraph { // Fingerprint::combine() is faster than sending Fingerprint // through the StableHasher (at least as long as StableHasher // is so slow). - hash: data.current.anon_id_seed.combine(hasher.finish()).into(), + hash: data.current.anon_id_seed.combine(hasher.finish()), }; let dep_node_index = data.current.intern_new_node(