Auto merge of #94487 - oli-obk:stable_hash_ty, r=fee1-dead

Also cache the stable hash of interned Predicates

continuation of https://github.com/rust-lang/rust/pull/94299

This is a small perf improvement and shares more code between `Ty` and `Predicate`
This commit is contained in:
bors
2022-11-29 21:35:02 +00:00
3 changed files with 59 additions and 28 deletions

View File

@@ -548,9 +548,9 @@ pub(crate) struct PredicateS<'tcx> {
}
/// Use this rather than `PredicateS`, whenever possible.
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, HashStable)]
#[rustc_pass_by_value]
pub struct Predicate<'tcx>(Interned<'tcx, PredicateS<'tcx>>);
pub struct Predicate<'tcx>(Interned<'tcx, WithStableHash<PredicateS<'tcx>>>);
impl<'tcx> Predicate<'tcx> {
/// Gets the inner `Binder<'tcx, PredicateKind<'tcx>>`.
@@ -631,7 +631,7 @@ impl<'tcx> Predicate<'tcx> {
}
}
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for PredicateS<'tcx> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let PredicateS {
ref kind,
@@ -640,7 +640,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
// also contained in `kind`, so no need to hash them.
flags: _,
outer_exclusive_binder: _,
} = self.0.0;
} = self;
kind.hash_stable(hcx, hasher);
}