s/WithStableHash/WithCachedTypeInfo/
This commit is contained in:
parent
8de4b13845
commit
3d31e5c981
@ -118,33 +118,33 @@ fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
|
||||
/// This is useful if you have values that you intern but never (can?) use for stable
|
||||
/// hashing.
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct WithStableHash<T> {
|
||||
pub struct WithCachedTypeInfo<T> {
|
||||
pub internee: T,
|
||||
pub stable_hash: Fingerprint,
|
||||
}
|
||||
|
||||
impl<T: PartialEq> PartialEq for WithStableHash<T> {
|
||||
impl<T: PartialEq> PartialEq for WithCachedTypeInfo<T> {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
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> {
|
||||
fn partial_cmp(&self, other: &WithStableHash<T>) -> Option<Ordering> {
|
||||
impl<T: Ord> PartialOrd for WithCachedTypeInfo<T> {
|
||||
fn partial_cmp(&self, other: &WithCachedTypeInfo<T>) -> Option<Ordering> {
|
||||
Some(self.internee.cmp(&other.internee))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Ord> Ord for WithStableHash<T> {
|
||||
fn cmp(&self, other: &WithStableHash<T>) -> Ordering {
|
||||
impl<T: Ord> Ord for WithCachedTypeInfo<T> {
|
||||
fn cmp(&self, other: &WithCachedTypeInfo<T>) -> Ordering {
|
||||
self.internee.cmp(&other.internee)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for WithStableHash<T> {
|
||||
impl<T> Deref for WithCachedTypeInfo<T> {
|
||||
type Target = T;
|
||||
|
||||
#[inline]
|
||||
@ -153,7 +153,7 @@ fn deref(&self) -> &T {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Hash> Hash for WithStableHash<T> {
|
||||
impl<T: Hash> Hash for WithCachedTypeInfo<T> {
|
||||
#[inline]
|
||||
fn hash<H: Hasher>(&self, s: &mut H) {
|
||||
if self.stable_hash != Fingerprint::ZERO {
|
||||
@ -164,7 +164,7 @@ fn hash<H: Hasher>(&self, s: &mut H) {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) {
|
||||
// No cached hash available. This can only mean that incremental is disabled.
|
||||
|
@ -88,8 +88,8 @@ macro_rules! arena_types {
|
||||
[] hir_id_set: rustc_hir::HirIdSet,
|
||||
|
||||
// Interned types
|
||||
[] tys: rustc_data_structures::intern::WithStableHash<rustc_middle::ty::TyS<'tcx>>,
|
||||
[] predicates: rustc_data_structures::intern::WithStableHash<rustc_middle::ty::PredicateS<'tcx>>,
|
||||
[] tys: rustc_data_structures::intern::WithCachedTypeInfo<rustc_middle::ty::TyS<'tcx>>,
|
||||
[] predicates: rustc_data_structures::intern::WithCachedTypeInfo<rustc_middle::ty::PredicateS<'tcx>>,
|
||||
[] consts: rustc_middle::ty::ConstS<'tcx>,
|
||||
|
||||
// Note that this deliberately duplicates items in the `rustc_hir::arena`,
|
||||
|
@ -27,7 +27,7 @@
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
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::profiling::SelfProfilerRef;
|
||||
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
|
||||
// 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>>>,
|
||||
substs: InternedSet<'tcx, InternalSubsts<'tcx>>,
|
||||
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo<'tcx>>>,
|
||||
region: InternedSet<'tcx, RegionKind<'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>>>,
|
||||
projs: InternedSet<'tcx, List<ProjectionKind>>,
|
||||
place_elems: InternedSet<'tcx, List<PlaceElem<'tcx>>>,
|
||||
@ -200,7 +200,7 @@ fn intern_ty(
|
||||
};
|
||||
|
||||
InternedInSet(
|
||||
self.arena.alloc(WithStableHash { internee: ty_struct, stable_hash }),
|
||||
self.arena.alloc(WithCachedTypeInfo { internee: ty_struct, stable_hash }),
|
||||
)
|
||||
})
|
||||
.0,
|
||||
@ -253,7 +253,7 @@ fn intern_predicate(
|
||||
|
||||
InternedInSet(
|
||||
self.arena
|
||||
.alloc(WithStableHash { internee: predicate_struct, stable_hash }),
|
||||
.alloc(WithCachedTypeInfo { internee: predicate_struct, stable_hash }),
|
||||
)
|
||||
})
|
||||
.0,
|
||||
@ -2167,23 +2167,23 @@ fn into_pointer(&self) -> *const () {
|
||||
}
|
||||
|
||||
#[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> {
|
||||
&self.0.kind
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> PartialEq for InternedInSet<'tcx, WithStableHash<TyS<'tcx>>> {
|
||||
fn eq(&self, other: &InternedInSet<'tcx, WithStableHash<TyS<'tcx>>>) -> bool {
|
||||
impl<'tcx> PartialEq for InternedInSet<'tcx, WithCachedTypeInfo<TyS<'tcx>>> {
|
||||
fn eq(&self, other: &InternedInSet<'tcx, WithCachedTypeInfo<TyS<'tcx>>>) -> bool {
|
||||
// The `Borrow` trait requires that `x.borrow() == y.borrow()` equals
|
||||
// `x == y`.
|
||||
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) {
|
||||
// The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`.
|
||||
self.0.kind.hash(s)
|
||||
@ -2191,24 +2191,24 @@ fn hash<H: Hasher>(&self, s: &mut H) {
|
||||
}
|
||||
|
||||
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>> {
|
||||
&self.0.kind
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> PartialEq for InternedInSet<'tcx, WithStableHash<PredicateS<'tcx>>> {
|
||||
fn eq(&self, other: &InternedInSet<'tcx, WithStableHash<PredicateS<'tcx>>>) -> bool {
|
||||
impl<'tcx> PartialEq for InternedInSet<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>> {
|
||||
fn eq(&self, other: &InternedInSet<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>>) -> bool {
|
||||
// The `Borrow` trait requires that `x.borrow() == y.borrow()` equals
|
||||
// `x == y`.
|
||||
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) {
|
||||
// The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`.
|
||||
self.0.kind.hash(s)
|
||||
|
@ -32,7 +32,7 @@
|
||||
use rustc_attr as attr;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
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::tagged_ptr::CopyTaggedPtr;
|
||||
use rustc_hir as hir;
|
||||
@ -495,19 +495,20 @@ pub(crate) struct TyS<'tcx> {
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)]
|
||||
#[rustc_diagnostic_item = "Ty"]
|
||||
#[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> {
|
||||
/// A "bool" type used in rustc_mir_transform unit tests when we
|
||||
/// have not spun up a TyCtxt.
|
||||
pub const BOOL_TY_FOR_UNIT_TESTING: Ty<'tcx> = Ty(Interned::new_unchecked(&WithStableHash {
|
||||
internee: TyS {
|
||||
kind: ty::Bool,
|
||||
flags: TypeFlags::empty(),
|
||||
outer_exclusive_binder: DebruijnIndex::from_usize(0),
|
||||
},
|
||||
stable_hash: Fingerprint::ZERO,
|
||||
}));
|
||||
pub const BOOL_TY_FOR_UNIT_TESTING: Ty<'tcx> =
|
||||
Ty(Interned::new_unchecked(&WithCachedTypeInfo {
|
||||
internee: TyS {
|
||||
kind: ty::Bool,
|
||||
flags: TypeFlags::empty(),
|
||||
outer_exclusive_binder: DebruijnIndex::from_usize(0),
|
||||
},
|
||||
stable_hash: Fingerprint::ZERO,
|
||||
}));
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TyS<'tcx> {
|
||||
@ -550,7 +551,7 @@ pub(crate) struct PredicateS<'tcx> {
|
||||
/// Use this rather than `PredicateS`, whenever possible.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, HashStable)]
|
||||
#[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> {
|
||||
/// Gets the inner `Binder<'tcx, PredicateKind<'tcx>>`.
|
||||
@ -1028,7 +1029,7 @@ pub fn unpack(self) -> TermKind<'tcx> {
|
||||
unsafe {
|
||||
match ptr & TAG_MASK {
|
||||
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(
|
||||
&*((ptr & !TAG_MASK) as *const ty::ConstS<'tcx>),
|
||||
@ -1072,7 +1073,7 @@ fn pack(self) -> Term<'tcx> {
|
||||
TermKind::Ty(ty) => {
|
||||
// Ensure we can use the tag bits.
|
||||
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) => {
|
||||
// Ensure we can use the tag bits.
|
||||
@ -2694,6 +2695,6 @@ mod size_asserts {
|
||||
// tidy-alphabetical-start
|
||||
static_assert_size!(PredicateS<'_>, 48);
|
||||
static_assert_size!(TyS<'_>, 40);
|
||||
static_assert_size!(WithStableHash<TyS<'_>>, 56);
|
||||
static_assert_size!(WithCachedTypeInfo<TyS<'_>>, 56);
|
||||
// tidy-alphabetical-end
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
use crate::ty::visit::{TypeVisitable, TypeVisitor};
|
||||
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_macros::HashStable;
|
||||
use rustc_serialize::{self, Decodable, Encodable};
|
||||
@ -84,7 +84,7 @@ fn pack(self) -> GenericArg<'tcx> {
|
||||
GenericArgKind::Type(ty) => {
|
||||
// Ensure we can use the tag bits.
|
||||
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) => {
|
||||
// Ensure we can use the tag bits.
|
||||
@ -162,7 +162,7 @@ pub fn unpack(self) -> GenericArgKind<'tcx> {
|
||||
&*((ptr & !TAG_MASK) as *const ty::RegionKind<'tcx>),
|
||||
))),
|
||||
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(
|
||||
&*((ptr & !TAG_MASK) as *const ty::ConstS<'tcx>),
|
||||
|
Loading…
Reference in New Issue
Block a user