Make PackedFingerprint's Fingerprint private
This commit is contained in:
parent
f09d474836
commit
05dde137ca
|
@ -170,9 +170,12 @@ impl FingerprintDecoder for opaque::Decoder<'_> {
|
|||
// `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(pub Fingerprint);
|
||||
pub struct PackedFingerprint(Fingerprint);
|
||||
|
||||
impl std::fmt::Display for PackedFingerprint {
|
||||
#[inline]
|
||||
|
@ -198,3 +201,17 @@ impl<D: rustc_serialize::Decoder> Decodable<D> for PackedFingerprint {
|
|||
Fingerprint::decode(d).map(|f| PackedFingerprint(f))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Fingerprint> for PackedFingerprint {
|
||||
#[inline]
|
||||
fn from(f: Fingerprint) -> PackedFingerprint {
|
||||
PackedFingerprint(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PackedFingerprint> for Fingerprint {
|
||||
#[inline]
|
||||
fn from(f: PackedFingerprint) -> Fingerprint {
|
||||
f.0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ use crate::traits::query::{
|
|||
use crate::ty::subst::{GenericArg, SubstsRef};
|
||||
use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
|
||||
|
||||
use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
|
||||
use rustc_hir::definitions::DefPathHash;
|
||||
use rustc_hir::HirId;
|
||||
|
@ -236,7 +236,7 @@ macro_rules! define_dep_nodes {
|
|||
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
|
||||
DepNode {
|
||||
kind,
|
||||
hash: PackedFingerprint(def_path_hash.0),
|
||||
hash: def_path_hash.0.into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,7 +252,7 @@ macro_rules! define_dep_nodes {
|
|||
/// has been removed.
|
||||
fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
|
||||
if self.kind.can_reconstruct_query_key() {
|
||||
let def_path_hash = DefPathHash(self.hash.0);
|
||||
let def_path_hash = DefPathHash(self.hash.into());
|
||||
tcx.def_path_hash_to_def_id.as_ref()?.get(&def_path_hash).cloned()
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -62,7 +62,7 @@ impl<K: DepKind> DepNode<K> {
|
|||
/// does not require any parameters.
|
||||
pub fn new_no_params(kind: K) -> DepNode<K> {
|
||||
debug_assert!(!kind.has_params());
|
||||
DepNode { kind, hash: PackedFingerprint(Fingerprint::ZERO) }
|
||||
DepNode { kind, hash: Fingerprint::ZERO.into() }
|
||||
}
|
||||
|
||||
pub fn construct<Ctxt, Key>(tcx: Ctxt, kind: K, arg: &Key) -> DepNode<K>
|
||||
|
@ -71,7 +71,7 @@ impl<K: DepKind> DepNode<K> {
|
|||
Key: DepNodeParams<Ctxt>,
|
||||
{
|
||||
let hash = arg.to_fingerprint(tcx);
|
||||
let dep_node = DepNode { kind, hash: PackedFingerprint(hash) };
|
||||
let dep_node = DepNode { kind, hash: hash.into() };
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::profiling::QueryInvocationId;
|
||||
use rustc_data_structures::sharded::{self, Sharded};
|
||||
|
@ -976,7 +976,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
|
|||
// Fingerprint::combine() is faster than sending Fingerprint
|
||||
// through the StableHasher (at least as long as StableHasher
|
||||
// is so slow).
|
||||
hash: PackedFingerprint(self.anon_id_seed.combine(hasher.finish())),
|
||||
hash: self.anon_id_seed.combine(hasher.finish()).into(),
|
||||
};
|
||||
|
||||
self.intern_node(target_dep_node, task_deps.reads, Fingerprint::ZERO)
|
||||
|
|
Loading…
Reference in a new issue