1
Fork 0

s/WithStableHash/WithCachedTypeInfo/

This commit is contained in:
Oli Scherer 2022-11-25 16:30:23 +00:00
parent 8de4b13845
commit 3d31e5c981
5 changed files with 45 additions and 44 deletions

View file

@ -118,33 +118,33 @@ where
/// This is useful if you have values that you intern but never (can?) use for stable /// This is useful if you have values that you intern but never (can?) use for stable
/// hashing. /// hashing.
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct WithStableHash<T> { pub struct WithCachedTypeInfo<T> {
pub internee: T, pub internee: T,
pub stable_hash: Fingerprint, pub stable_hash: Fingerprint,
} }
impl<T: PartialEq> PartialEq for WithStableHash<T> { impl<T: PartialEq> PartialEq for WithCachedTypeInfo<T> {
#[inline] #[inline]
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.internee.eq(&other.internee) self.internee.eq(&other.internee)
} }
} }
impl<T: Eq> Eq for WithStableHash<T> {} impl<T: Eq> Eq for WithCachedTypeInfo<T> {}
impl<T: Ord> PartialOrd for WithStableHash<T> { impl<T: Ord> PartialOrd for WithCachedTypeInfo<T> {
fn partial_cmp(&self, other: &WithStableHash<T>) -> Option<Ordering> { fn partial_cmp(&self, other: &WithCachedTypeInfo<T>) -> Option<Ordering> {
Some(self.internee.cmp(&other.internee)) Some(self.internee.cmp(&other.internee))
} }
} }
impl<T: Ord> Ord for WithStableHash<T> { impl<T: Ord> Ord for WithCachedTypeInfo<T> {
fn cmp(&self, other: &WithStableHash<T>) -> Ordering { fn cmp(&self, other: &WithCachedTypeInfo<T>) -> Ordering {
self.internee.cmp(&other.internee) self.internee.cmp(&other.internee)
} }
} }
impl<T> Deref for WithStableHash<T> { impl<T> Deref for WithCachedTypeInfo<T> {
type Target = T; type Target = T;
#[inline] #[inline]
@ -153,7 +153,7 @@ impl<T> Deref for WithStableHash<T> {
} }
} }
impl<T: Hash> Hash for WithStableHash<T> { impl<T: Hash> Hash for WithCachedTypeInfo<T> {
#[inline] #[inline]
fn hash<H: Hasher>(&self, s: &mut H) { fn hash<H: Hasher>(&self, s: &mut H) {
if self.stable_hash != Fingerprint::ZERO { if self.stable_hash != Fingerprint::ZERO {
@ -164,7 +164,7 @@ impl<T: Hash> Hash for WithStableHash<T> {
} }
} }
impl<T: HashStable<CTX>, CTX> HashStable<CTX> for WithStableHash<T> { impl<T: HashStable<CTX>, CTX> HashStable<CTX> for WithCachedTypeInfo<T> {
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) { if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) {
// No cached hash available. This can only mean that incremental is disabled. // No cached hash available. This can only mean that incremental is disabled.

View file

@ -88,8 +88,8 @@ macro_rules! arena_types {
[] hir_id_set: rustc_hir::HirIdSet, [] hir_id_set: rustc_hir::HirIdSet,
// Interned types // Interned types
[] tys: rustc_data_structures::intern::WithStableHash<rustc_middle::ty::TyS<'tcx>>, [] tys: rustc_data_structures::intern::WithCachedTypeInfo<rustc_middle::ty::TyS<'tcx>>,
[] predicates: rustc_data_structures::intern::WithStableHash<rustc_middle::ty::PredicateS<'tcx>>, [] predicates: rustc_data_structures::intern::WithCachedTypeInfo<rustc_middle::ty::PredicateS<'tcx>>,
[] consts: rustc_middle::ty::ConstS<'tcx>, [] consts: rustc_middle::ty::ConstS<'tcx>,
// Note that this deliberately duplicates items in the `rustc_hir::arena`, // Note that this deliberately duplicates items in the `rustc_hir::arena`,

View file

@ -27,7 +27,7 @@ use crate::ty::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef, UserSubst
use rustc_ast as ast; use rustc_ast as ast;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::intern::{Interned, WithStableHash}; use rustc_data_structures::intern::{Interned, WithCachedTypeInfo};
use rustc_data_structures::memmap::Mmap; use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap}; use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
@ -136,13 +136,13 @@ pub struct CtxtInterners<'tcx> {
// Specifically use a speedy hash algorithm for these hash sets, since // Specifically use a speedy hash algorithm for these hash sets, since
// they're accessed quite often. // they're accessed quite often.
type_: InternedSet<'tcx, WithStableHash<TyS<'tcx>>>, type_: InternedSet<'tcx, WithCachedTypeInfo<TyS<'tcx>>>,
const_lists: InternedSet<'tcx, List<ty::Const<'tcx>>>, const_lists: InternedSet<'tcx, List<ty::Const<'tcx>>>,
substs: InternedSet<'tcx, InternalSubsts<'tcx>>, substs: InternedSet<'tcx, InternalSubsts<'tcx>>,
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo<'tcx>>>, canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo<'tcx>>>,
region: InternedSet<'tcx, RegionKind<'tcx>>, region: InternedSet<'tcx, RegionKind<'tcx>>,
poly_existential_predicates: InternedSet<'tcx, List<PolyExistentialPredicate<'tcx>>>, poly_existential_predicates: InternedSet<'tcx, List<PolyExistentialPredicate<'tcx>>>,
predicate: InternedSet<'tcx, WithStableHash<PredicateS<'tcx>>>, predicate: InternedSet<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>>,
predicates: InternedSet<'tcx, List<Predicate<'tcx>>>, predicates: InternedSet<'tcx, List<Predicate<'tcx>>>,
projs: InternedSet<'tcx, List<ProjectionKind>>, projs: InternedSet<'tcx, List<ProjectionKind>>,
place_elems: InternedSet<'tcx, List<PlaceElem<'tcx>>>, place_elems: InternedSet<'tcx, List<PlaceElem<'tcx>>>,
@ -200,7 +200,7 @@ impl<'tcx> CtxtInterners<'tcx> {
}; };
InternedInSet( InternedInSet(
self.arena.alloc(WithStableHash { internee: ty_struct, stable_hash }), self.arena.alloc(WithCachedTypeInfo { internee: ty_struct, stable_hash }),
) )
}) })
.0, .0,
@ -253,7 +253,7 @@ impl<'tcx> CtxtInterners<'tcx> {
InternedInSet( InternedInSet(
self.arena self.arena
.alloc(WithStableHash { internee: predicate_struct, stable_hash }), .alloc(WithCachedTypeInfo { internee: predicate_struct, stable_hash }),
) )
}) })
.0, .0,
@ -2167,23 +2167,23 @@ impl<'tcx, T: 'tcx + ?Sized> IntoPointer for InternedInSet<'tcx, T> {
} }
#[allow(rustc::usage_of_ty_tykind)] #[allow(rustc::usage_of_ty_tykind)]
impl<'tcx> Borrow<TyKind<'tcx>> for InternedInSet<'tcx, WithStableHash<TyS<'tcx>>> { impl<'tcx> Borrow<TyKind<'tcx>> for InternedInSet<'tcx, WithCachedTypeInfo<TyS<'tcx>>> {
fn borrow<'a>(&'a self) -> &'a TyKind<'tcx> { fn borrow<'a>(&'a self) -> &'a TyKind<'tcx> {
&self.0.kind &self.0.kind
} }
} }
impl<'tcx> PartialEq for InternedInSet<'tcx, WithStableHash<TyS<'tcx>>> { impl<'tcx> PartialEq for InternedInSet<'tcx, WithCachedTypeInfo<TyS<'tcx>>> {
fn eq(&self, other: &InternedInSet<'tcx, WithStableHash<TyS<'tcx>>>) -> bool { fn eq(&self, other: &InternedInSet<'tcx, WithCachedTypeInfo<TyS<'tcx>>>) -> bool {
// The `Borrow` trait requires that `x.borrow() == y.borrow()` equals // The `Borrow` trait requires that `x.borrow() == y.borrow()` equals
// `x == y`. // `x == y`.
self.0.kind == other.0.kind self.0.kind == other.0.kind
} }
} }
impl<'tcx> Eq for InternedInSet<'tcx, WithStableHash<TyS<'tcx>>> {} impl<'tcx> Eq for InternedInSet<'tcx, WithCachedTypeInfo<TyS<'tcx>>> {}
impl<'tcx> Hash for InternedInSet<'tcx, WithStableHash<TyS<'tcx>>> { impl<'tcx> Hash for InternedInSet<'tcx, WithCachedTypeInfo<TyS<'tcx>>> {
fn hash<H: Hasher>(&self, s: &mut H) { fn hash<H: Hasher>(&self, s: &mut H) {
// The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`. // The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`.
self.0.kind.hash(s) self.0.kind.hash(s)
@ -2191,24 +2191,24 @@ impl<'tcx> Hash for InternedInSet<'tcx, WithStableHash<TyS<'tcx>>> {
} }
impl<'tcx> Borrow<Binder<'tcx, PredicateKind<'tcx>>> impl<'tcx> Borrow<Binder<'tcx, PredicateKind<'tcx>>>
for InternedInSet<'tcx, WithStableHash<PredicateS<'tcx>>> for InternedInSet<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>>
{ {
fn borrow<'a>(&'a self) -> &'a Binder<'tcx, PredicateKind<'tcx>> { fn borrow<'a>(&'a self) -> &'a Binder<'tcx, PredicateKind<'tcx>> {
&self.0.kind &self.0.kind
} }
} }
impl<'tcx> PartialEq for InternedInSet<'tcx, WithStableHash<PredicateS<'tcx>>> { impl<'tcx> PartialEq for InternedInSet<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>> {
fn eq(&self, other: &InternedInSet<'tcx, WithStableHash<PredicateS<'tcx>>>) -> bool { fn eq(&self, other: &InternedInSet<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>>) -> bool {
// The `Borrow` trait requires that `x.borrow() == y.borrow()` equals // The `Borrow` trait requires that `x.borrow() == y.borrow()` equals
// `x == y`. // `x == y`.
self.0.kind == other.0.kind self.0.kind == other.0.kind
} }
} }
impl<'tcx> Eq for InternedInSet<'tcx, WithStableHash<PredicateS<'tcx>>> {} impl<'tcx> Eq for InternedInSet<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>> {}
impl<'tcx> Hash for InternedInSet<'tcx, WithStableHash<PredicateS<'tcx>>> { impl<'tcx> Hash for InternedInSet<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>> {
fn hash<H: Hasher>(&self, s: &mut H) { fn hash<H: Hasher>(&self, s: &mut H) {
// The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`. // The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`.
self.0.kind.hash(s) self.0.kind.hash(s)

View file

@ -32,7 +32,7 @@ use rustc_ast::node_id::NodeMap;
use rustc_attr as attr; use rustc_attr as attr;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
use rustc_data_structures::intern::{Interned, WithStableHash}; use rustc_data_structures::intern::{Interned, WithCachedTypeInfo};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::tagged_ptr::CopyTaggedPtr; use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
use rustc_hir as hir; use rustc_hir as hir;
@ -495,12 +495,13 @@ pub(crate) struct TyS<'tcx> {
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)]
#[rustc_diagnostic_item = "Ty"] #[rustc_diagnostic_item = "Ty"]
#[rustc_pass_by_value] #[rustc_pass_by_value]
pub struct Ty<'tcx>(Interned<'tcx, WithStableHash<TyS<'tcx>>>); pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo<TyS<'tcx>>>);
impl<'tcx> TyCtxt<'tcx> { impl<'tcx> TyCtxt<'tcx> {
/// A "bool" type used in rustc_mir_transform unit tests when we /// A "bool" type used in rustc_mir_transform unit tests when we
/// have not spun up a TyCtxt. /// have not spun up a TyCtxt.
pub const BOOL_TY_FOR_UNIT_TESTING: Ty<'tcx> = Ty(Interned::new_unchecked(&WithStableHash { pub const BOOL_TY_FOR_UNIT_TESTING: Ty<'tcx> =
Ty(Interned::new_unchecked(&WithCachedTypeInfo {
internee: TyS { internee: TyS {
kind: ty::Bool, kind: ty::Bool,
flags: TypeFlags::empty(), flags: TypeFlags::empty(),
@ -550,7 +551,7 @@ pub(crate) struct PredicateS<'tcx> {
/// Use this rather than `PredicateS`, whenever possible. /// Use this rather than `PredicateS`, whenever possible.
#[derive(Clone, Copy, PartialEq, Eq, Hash, HashStable)] #[derive(Clone, Copy, PartialEq, Eq, Hash, HashStable)]
#[rustc_pass_by_value] #[rustc_pass_by_value]
pub struct Predicate<'tcx>(Interned<'tcx, WithStableHash<PredicateS<'tcx>>>); pub struct Predicate<'tcx>(Interned<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>>);
impl<'tcx> Predicate<'tcx> { impl<'tcx> Predicate<'tcx> {
/// Gets the inner `Binder<'tcx, PredicateKind<'tcx>>`. /// Gets the inner `Binder<'tcx, PredicateKind<'tcx>>`.
@ -1028,7 +1029,7 @@ impl<'tcx> Term<'tcx> {
unsafe { unsafe {
match ptr & TAG_MASK { match ptr & TAG_MASK {
TYPE_TAG => TermKind::Ty(Ty(Interned::new_unchecked( TYPE_TAG => TermKind::Ty(Ty(Interned::new_unchecked(
&*((ptr & !TAG_MASK) as *const WithStableHash<ty::TyS<'tcx>>), &*((ptr & !TAG_MASK) as *const WithCachedTypeInfo<ty::TyS<'tcx>>),
))), ))),
CONST_TAG => TermKind::Const(ty::Const(Interned::new_unchecked( CONST_TAG => TermKind::Const(ty::Const(Interned::new_unchecked(
&*((ptr & !TAG_MASK) as *const ty::ConstS<'tcx>), &*((ptr & !TAG_MASK) as *const ty::ConstS<'tcx>),
@ -1072,7 +1073,7 @@ impl<'tcx> TermKind<'tcx> {
TermKind::Ty(ty) => { TermKind::Ty(ty) => {
// Ensure we can use the tag bits. // Ensure we can use the tag bits.
assert_eq!(mem::align_of_val(&*ty.0.0) & TAG_MASK, 0); assert_eq!(mem::align_of_val(&*ty.0.0) & TAG_MASK, 0);
(TYPE_TAG, ty.0.0 as *const WithStableHash<ty::TyS<'tcx>> as usize) (TYPE_TAG, ty.0.0 as *const WithCachedTypeInfo<ty::TyS<'tcx>> as usize)
} }
TermKind::Const(ct) => { TermKind::Const(ct) => {
// Ensure we can use the tag bits. // Ensure we can use the tag bits.
@ -2694,6 +2695,6 @@ mod size_asserts {
// tidy-alphabetical-start // tidy-alphabetical-start
static_assert_size!(PredicateS<'_>, 48); static_assert_size!(PredicateS<'_>, 48);
static_assert_size!(TyS<'_>, 40); static_assert_size!(TyS<'_>, 40);
static_assert_size!(WithStableHash<TyS<'_>>, 56); static_assert_size!(WithCachedTypeInfo<TyS<'_>>, 56);
// tidy-alphabetical-end // tidy-alphabetical-end
} }

View file

@ -6,7 +6,7 @@ use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts};
use crate::ty::visit::{TypeVisitable, TypeVisitor}; use crate::ty::visit::{TypeVisitable, TypeVisitor};
use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt}; use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt};
use rustc_data_structures::intern::{Interned, WithStableHash}; use rustc_data_structures::intern::{Interned, WithCachedTypeInfo};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_macros::HashStable; use rustc_macros::HashStable;
use rustc_serialize::{self, Decodable, Encodable}; use rustc_serialize::{self, Decodable, Encodable};
@ -84,7 +84,7 @@ impl<'tcx> GenericArgKind<'tcx> {
GenericArgKind::Type(ty) => { GenericArgKind::Type(ty) => {
// Ensure we can use the tag bits. // Ensure we can use the tag bits.
assert_eq!(mem::align_of_val(&*ty.0.0) & TAG_MASK, 0); assert_eq!(mem::align_of_val(&*ty.0.0) & TAG_MASK, 0);
(TYPE_TAG, ty.0.0 as *const WithStableHash<ty::TyS<'tcx>> as usize) (TYPE_TAG, ty.0.0 as *const WithCachedTypeInfo<ty::TyS<'tcx>> as usize)
} }
GenericArgKind::Const(ct) => { GenericArgKind::Const(ct) => {
// Ensure we can use the tag bits. // Ensure we can use the tag bits.
@ -162,7 +162,7 @@ impl<'tcx> GenericArg<'tcx> {
&*((ptr & !TAG_MASK) as *const ty::RegionKind<'tcx>), &*((ptr & !TAG_MASK) as *const ty::RegionKind<'tcx>),
))), ))),
TYPE_TAG => GenericArgKind::Type(Ty(Interned::new_unchecked( TYPE_TAG => GenericArgKind::Type(Ty(Interned::new_unchecked(
&*((ptr & !TAG_MASK) as *const WithStableHash<ty::TyS<'tcx>>), &*((ptr & !TAG_MASK) as *const WithCachedTypeInfo<ty::TyS<'tcx>>),
))), ))),
CONST_TAG => GenericArgKind::Const(ty::Const(Interned::new_unchecked( CONST_TAG => GenericArgKind::Const(ty::Const(Interned::new_unchecked(
&*((ptr & !TAG_MASK) as *const ty::ConstS<'tcx>), &*((ptr & !TAG_MASK) as *const ty::ConstS<'tcx>),