diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-11-25 16:30:23 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-11-30 12:11:19 +0000 |
| commit | 3d31e5c9810227ceb56d6d3a5228ca28b1aca890 (patch) | |
| tree | 4394b120584c2394dd8b8e9356816701f90789ed | |
| parent | 8de4b138455add55bde6de5553a933a2ab79b71f (diff) | |
| download | rust-3d31e5c9810227ceb56d6d3a5228ca28b1aca890.tar.gz rust-3d31e5c9810227ceb56d6d3a5228ca28b1aca890.zip | |
s/WithStableHash/WithCachedTypeInfo/
| -rw-r--r-- | compiler/rustc_data_structures/src/intern.rs | 20 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/arena.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 30 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 29 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/subst.rs | 6 |
5 files changed, 45 insertions, 44 deletions
diff --git a/compiler/rustc_data_structures/src/intern.rs b/compiler/rustc_data_structures/src/intern.rs index 11cbff8ea6a..9985aeaab57 100644 --- a/compiler/rustc_data_structures/src/intern.rs +++ b/compiler/rustc_data_structures/src/intern.rs @@ -118,33 +118,33 @@ where /// 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 @@ impl<T> Deref for WithStableHash<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 @@ 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) { if self.stable_hash == Fingerprint::ZERO || cfg!(debug_assertions) { // No cached hash available. This can only mean that incremental is disabled. diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index e83106b1ee5..3f3d92d68e3 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -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`, diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index a1acca3097d..3af3444b86c 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -27,7 +27,7 @@ use crate::ty::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef, UserSubst 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 @@ impl<'tcx> CtxtInterners<'tcx> { }; InternedInSet( - self.arena.alloc(WithStableHash { internee: ty_struct, stable_hash }), + self.arena.alloc(WithCachedTypeInfo { internee: ty_struct, stable_hash }), ) }) .0, @@ -253,7 +253,7 @@ impl<'tcx> CtxtInterners<'tcx> { InternedInSet( self.arena - .alloc(WithStableHash { internee: predicate_struct, stable_hash }), + .alloc(WithCachedTypeInfo { internee: predicate_struct, stable_hash }), ) }) .0, @@ -2167,23 +2167,23 @@ impl<'tcx, T: 'tcx + ?Sized> IntoPointer for InternedInSet<'tcx, T> { } #[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 @@ impl<'tcx> Hash for InternedInSet<'tcx, WithStableHash<TyS<'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>> { &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) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index dd4ab3e8d30..d3cbd2e03cf 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -32,7 +32,7 @@ use rustc_ast::node_id::NodeMap; 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 @@ impl<'tcx> Term<'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 @@ impl<'tcx> TermKind<'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 } diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index 141c8354c18..f69035f619f 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -6,7 +6,7 @@ use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts}; 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 @@ impl<'tcx> GenericArgKind<'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 @@ impl<'tcx> GenericArg<'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>), |
