Inline DepNodeParams methods.

This commit is contained in:
Camille GILLOT 2021-10-17 11:49:30 +02:00
parent df71d0874a
commit 8785b70774
2 changed files with 18 additions and 1 deletions

View File

@ -308,10 +308,12 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for () {
FingerprintStyle::Unit FingerprintStyle::Unit
} }
#[inline(always)]
fn to_fingerprint(&self, _: TyCtxt<'tcx>) -> Fingerprint { fn to_fingerprint(&self, _: TyCtxt<'tcx>) -> Fingerprint {
Fingerprint::ZERO Fingerprint::ZERO
} }
#[inline(always)]
fn recover(_: TyCtxt<'tcx>, _: &DepNode) -> Option<Self> { fn recover(_: TyCtxt<'tcx>, _: &DepNode) -> Option<Self> {
Some(()) Some(())
} }
@ -323,14 +325,17 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId {
FingerprintStyle::DefPathHash FingerprintStyle::DefPathHash
} }
#[inline(always)]
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint { fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
tcx.def_path_hash(*self).0 tcx.def_path_hash(*self).0
} }
#[inline(always)]
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String { fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
tcx.def_path_str(*self) tcx.def_path_str(*self)
} }
#[inline(always)]
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> { fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
dep_node.extract_def_id(tcx) dep_node.extract_def_id(tcx)
} }
@ -342,14 +347,17 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for LocalDefId {
FingerprintStyle::DefPathHash FingerprintStyle::DefPathHash
} }
#[inline(always)]
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint { fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
self.to_def_id().to_fingerprint(tcx) self.to_def_id().to_fingerprint(tcx)
} }
#[inline(always)]
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String { fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
self.to_def_id().to_debug_str(tcx) self.to_def_id().to_debug_str(tcx)
} }
#[inline(always)]
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> { fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
dep_node.extract_def_id(tcx).map(|id| id.expect_local()) dep_node.extract_def_id(tcx).map(|id| id.expect_local())
} }
@ -361,15 +369,18 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for CrateNum {
FingerprintStyle::DefPathHash FingerprintStyle::DefPathHash
} }
#[inline(always)]
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint { fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
let def_id = DefId { krate: *self, index: CRATE_DEF_INDEX }; let def_id = DefId { krate: *self, index: CRATE_DEF_INDEX };
def_id.to_fingerprint(tcx) def_id.to_fingerprint(tcx)
} }
#[inline(always)]
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String { fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
tcx.crate_name(*self).to_string() tcx.crate_name(*self).to_string()
} }
#[inline(always)]
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> { fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
dep_node.extract_def_id(tcx).map(|id| id.krate) dep_node.extract_def_id(tcx).map(|id| id.krate)
} }
@ -384,6 +395,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for (DefId, DefId) {
// We actually would not need to specialize the implementation of this // We actually would not need to specialize the implementation of this
// method but it's faster to combine the hashes than to instantiate a full // method but it's faster to combine the hashes than to instantiate a full
// hashing context and stable-hashing state. // hashing context and stable-hashing state.
#[inline(always)]
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint { fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
let (def_id_0, def_id_1) = *self; let (def_id_0, def_id_1) = *self;
@ -393,6 +405,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for (DefId, DefId) {
def_path_hash_0.0.combine(def_path_hash_1.0) def_path_hash_0.0.combine(def_path_hash_1.0)
} }
#[inline(always)]
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String { fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
let (def_id_0, def_id_1) = *self; let (def_id_0, def_id_1) = *self;
@ -409,6 +422,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
// We actually would not need to specialize the implementation of this // We actually would not need to specialize the implementation of this
// method but it's faster to combine the hashes than to instantiate a full // method but it's faster to combine the hashes than to instantiate a full
// hashing context and stable-hashing state. // hashing context and stable-hashing state.
#[inline(always)]
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint { fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
let HirId { owner, local_id } = *self; let HirId { owner, local_id } = *self;

View File

@ -124,11 +124,12 @@ impl<Ctxt: DepContext, T> DepNodeParams<Ctxt> for T
where where
T: for<'a> HashStable<StableHashingContext<'a>> + fmt::Debug, T: for<'a> HashStable<StableHashingContext<'a>> + fmt::Debug,
{ {
#[inline] #[inline(always)]
default fn fingerprint_style() -> FingerprintStyle { default fn fingerprint_style() -> FingerprintStyle {
FingerprintStyle::Opaque FingerprintStyle::Opaque
} }
#[inline(always)]
default fn to_fingerprint(&self, tcx: Ctxt) -> Fingerprint { default fn to_fingerprint(&self, tcx: Ctxt) -> Fingerprint {
let mut hcx = tcx.create_stable_hashing_context(); let mut hcx = tcx.create_stable_hashing_context();
let mut hasher = StableHasher::new(); let mut hasher = StableHasher::new();
@ -138,10 +139,12 @@ where
hasher.finish() hasher.finish()
} }
#[inline(always)]
default fn to_debug_str(&self, _: Ctxt) -> String { default fn to_debug_str(&self, _: Ctxt) -> String {
format!("{:?}", *self) format!("{:?}", *self)
} }
#[inline(always)]
default fn recover(_: Ctxt, _: &DepNode<Ctxt::DepKind>) -> Option<Self> { default fn recover(_: Ctxt, _: &DepNode<Ctxt::DepKind>) -> Option<Self> {
None None
} }