Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #105378

Merged
merged 25 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3d31e5c
s/WithStableHash/WithCachedTypeInfo/
oli-obk Nov 25, 2022
87a04f5
move WithCachedTypeInfo to rustc_type_ir
oli-obk Nov 25, 2022
147b854
Remove TyS
oli-obk Nov 25, 2022
46ba154
Update documentation
oli-obk Nov 28, 2022
907ef22
Remove PredicateS type
oli-obk Nov 30, 2022
14a9cf2
Generalize some InternedInSet impls
oli-obk Nov 30, 2022
0e24cee
fix #105028, Only suggest removing struct field from destructive bind…
chenyukang Nov 30, 2022
5c7278a
return when expr has error
TaKO8Ki Nov 28, 2022
3bf7d88
Add -Z maximal-hir-to-mir-coverage flag
willcrichton Dec 5, 2022
32765fb
rustdoc: simplify CSS selectors on top-doc and non-exhaustive toggles
notriddle Dec 5, 2022
d595884
Move -Z maximal-hir-to-mir-coverage implementation to new `maybe_new_…
willcrichton Dec 5, 2022
9c9c476
Point at args in associated const fn pointers
compiler-errors Dec 6, 2022
cf031a3
Replace usage of `ResumeTy` in async lowering with `Context`
Swatinem Dec 4, 2022
07fbb1b
Cleanup macro-expanded code in `rustc_type_ir`
WaffleLapkin Dec 6, 2022
e12d222
Add debug asserts to hand-implemented `Ord`/`Eq` impls
WaffleLapkin Dec 6, 2022
12ce0c2
Remove outdated syntax from trait alias pretty printing
WaffleLapkin Dec 6, 2022
db416ea
Rollup merge of #104898 - oli-obk:group_all_the_things, r=wesleywiser
matthiaskrgr Dec 6, 2022
b29a4f9
Rollup merge of #105004 - TaKO8Ki:fix-104897, r=wesleywiser
matthiaskrgr Dec 6, 2022
90d84ce
Rollup merge of #105174 - chenyukang:yukang/fix-105028-unused, r=eholk
matthiaskrgr Dec 6, 2022
967085e
Rollup merge of #105250 - Swatinem:async-rm-resumety, r=oli-obk
matthiaskrgr Dec 6, 2022
c699b05
Rollup merge of #105286 - willcrichton:maximal-hir-to-mir-coverage, r…
matthiaskrgr Dec 6, 2022
dc07e1b
Rollup merge of #105320 - notriddle:notriddle/rustdoc-toggle-hideme-2…
matthiaskrgr Dec 6, 2022
4f919e4
Rollup merge of #105349 - compiler-errors:point-at-assoc-ct-fn-ptr-ar…
matthiaskrgr Dec 6, 2022
4f527a5
Rollup merge of #105362 - WaffleLapkin:🙅, r=oli-obk
matthiaskrgr Dec 6, 2022
97008a2
Rollup merge of #105370 - WaffleLapkin:pp, r=oli-obk
matthiaskrgr Dec 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
s/WithStableHash/WithCachedTypeInfo/
  • Loading branch information
oli-obk committed Nov 30, 2022
commit 3d31e5c9810227ceb56d6d3a5228ca28b1aca890
20 changes: 10 additions & 10 deletions compiler/rustc_data_structures/src/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 {
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
30 changes: 15 additions & 15 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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>>>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -2167,48 +2167,48 @@ 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)
}
}

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)
Expand Down
29 changes: 15 additions & 14 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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>>`.
Expand Down Expand Up @@ -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>),
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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>),
Expand Down