Skip to content

Commit 907ef22

Browse files
committed
Remove PredicateS type
1 parent 46ba154 commit 907ef22

File tree

3 files changed

+28
-52
lines changed

3 files changed

+28
-52
lines changed

compiler/rustc_middle/src/arena.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ macro_rules! arena_types {
9191

9292
// Interned types
9393
[] tys: rustc_type_ir::WithCachedTypeInfo<rustc_middle::ty::TyKind<'tcx>>,
94-
[] predicates: rustc_type_ir::WithCachedTypeInfo<rustc_middle::ty::PredicateS<'tcx>>,
94+
[] predicates: rustc_type_ir::WithCachedTypeInfo<rustc_middle::ty::PredicateKind<'tcx>>,
9595
[] consts: rustc_middle::ty::ConstS<'tcx>,
9696

9797
// Note that this deliberately duplicates items in the `rustc_hir::arena`,

compiler/rustc_middle/src/ty/context.rs

+21-20
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ use crate::ty::{
2121
self, AdtDef, AdtDefData, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig,
2222
ClosureSizeProfileData, Const, ConstS, DefIdTree, FloatTy, FloatVar, FloatVid,
2323
GenericParamDefKind, InferTy, IntTy, IntVar, IntVid, List, ParamConst, ParamTy,
24-
PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, PredicateS, ProjectionTy,
25-
Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVar, TyVid, TypeAndMut,
26-
UintTy, Visibility,
24+
PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, ProjectionTy, Region,
25+
RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVar, TyVid, TypeAndMut, UintTy,
26+
Visibility,
2727
};
2828
use crate::ty::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef, UserSubsts};
2929
use rustc_ast as ast;
@@ -145,7 +145,7 @@ pub struct CtxtInterners<'tcx> {
145145
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo<'tcx>>>,
146146
region: InternedSet<'tcx, RegionKind<'tcx>>,
147147
poly_existential_predicates: InternedSet<'tcx, List<PolyExistentialPredicate<'tcx>>>,
148-
predicate: InternedSet<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>>,
148+
predicate: InternedSet<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>,
149149
predicates: InternedSet<'tcx, List<Predicate<'tcx>>>,
150150
projs: InternedSet<'tcx, List<ProjectionKind>>,
151151
place_elems: InternedSet<'tcx, List<PlaceElem<'tcx>>>,
@@ -245,16 +245,12 @@ impl<'tcx> CtxtInterners<'tcx> {
245245
let stable_hash =
246246
self.stable_hash(&flags, sess, definitions, cstore, source_span, &kind);
247247

248-
let predicate_struct = PredicateS {
249-
kind,
248+
InternedInSet(self.arena.alloc(WithCachedTypeInfo {
249+
internee: kind,
250+
stable_hash,
250251
flags: flags.flags,
251252
outer_exclusive_binder: flags.outer_exclusive_binder,
252-
};
253-
254-
InternedInSet(
255-
self.arena
256-
.alloc(WithCachedTypeInfo { internee: predicate_struct, stable_hash }),
257-
)
253+
}))
258254
})
259255
.0,
260256
))
@@ -2191,27 +2187,32 @@ impl<'tcx> Hash for InternedInSet<'tcx, WithCachedTypeInfo<TyKind<'tcx>>> {
21912187
}
21922188

21932189
impl<'tcx> Borrow<Binder<'tcx, PredicateKind<'tcx>>>
2194-
for InternedInSet<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>>
2190+
for InternedInSet<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>
21952191
{
21962192
fn borrow<'a>(&'a self) -> &'a Binder<'tcx, PredicateKind<'tcx>> {
2197-
&self.0.kind
2193+
&self.0.internee
21982194
}
21992195
}
22002196

2201-
impl<'tcx> PartialEq for InternedInSet<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>> {
2202-
fn eq(&self, other: &InternedInSet<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>>) -> bool {
2197+
impl<'tcx> PartialEq
2198+
for InternedInSet<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>
2199+
{
2200+
fn eq(
2201+
&self,
2202+
other: &InternedInSet<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>,
2203+
) -> bool {
22032204
// The `Borrow` trait requires that `x.borrow() == y.borrow()` equals
22042205
// `x == y`.
2205-
self.0.kind == other.0.kind
2206+
self.0.internee == other.0.internee
22062207
}
22072208
}
22082209

2209-
impl<'tcx> Eq for InternedInSet<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>> {}
2210+
impl<'tcx> Eq for InternedInSet<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>> {}
22102211

2211-
impl<'tcx> Hash for InternedInSet<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>> {
2212+
impl<'tcx> Hash for InternedInSet<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>> {
22122213
fn hash<H: Hasher>(&self, s: &mut H) {
22132214
// The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`.
2214-
self.0.kind.hash(s)
2215+
self.0.internee.hash(s)
22152216
}
22162217
}
22172218

compiler/rustc_middle/src/ty/mod.rs

+6-31
Original file line numberDiff line numberDiff line change
@@ -474,28 +474,18 @@ impl ty::EarlyBoundRegion {
474474
}
475475
}
476476

477-
/// Represents a predicate.
478-
///
479-
/// See comments on `WithCachedTypeInfo`, which apply here too (albeit for
480-
/// `PredicateS`/`Predicate` rather than `TyKind`/`Ty`).
481-
#[derive(Debug)]
482-
pub(crate) struct PredicateS<'tcx> {
483-
kind: Binder<'tcx, PredicateKind<'tcx>>,
484-
flags: TypeFlags,
485-
/// See the comment for the corresponding field of [WithCachedTypeInfo].
486-
outer_exclusive_binder: ty::DebruijnIndex,
487-
}
488-
489-
/// Use this rather than `PredicateS`, whenever possible.
477+
/// Use this rather than `PredicateKind`, whenever possible.
490478
#[derive(Clone, Copy, PartialEq, Eq, Hash, HashStable)]
491479
#[rustc_pass_by_value]
492-
pub struct Predicate<'tcx>(Interned<'tcx, WithCachedTypeInfo<PredicateS<'tcx>>>);
480+
pub struct Predicate<'tcx>(
481+
Interned<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>,
482+
);
493483

494484
impl<'tcx> Predicate<'tcx> {
495485
/// Gets the inner `Binder<'tcx, PredicateKind<'tcx>>`.
496486
#[inline]
497487
pub fn kind(self) -> Binder<'tcx, PredicateKind<'tcx>> {
498-
self.0.kind
488+
self.0.internee
499489
}
500490

501491
#[inline(always)]
@@ -570,21 +560,6 @@ impl<'tcx> Predicate<'tcx> {
570560
}
571561
}
572562

573-
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for PredicateS<'tcx> {
574-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
575-
let PredicateS {
576-
ref kind,
577-
578-
// The other fields just provide fast access to information that is
579-
// also contained in `kind`, so no need to hash them.
580-
flags: _,
581-
outer_exclusive_binder: _,
582-
} = self;
583-
584-
kind.hash_stable(hcx, hasher);
585-
}
586-
}
587-
588563
impl rustc_errors::IntoDiagnosticArg for Predicate<'_> {
589564
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
590565
rustc_errors::DiagnosticArgValue::Str(std::borrow::Cow::Owned(self.to_string()))
@@ -2631,7 +2606,7 @@ mod size_asserts {
26312606
use super::*;
26322607
use rustc_data_structures::static_assert_size;
26332608
// tidy-alphabetical-start
2634-
static_assert_size!(PredicateS<'_>, 48);
2609+
static_assert_size!(PredicateKind<'_>, 32);
26352610
static_assert_size!(WithCachedTypeInfo<TyKind<'_>>, 56);
26362611
// tidy-alphabetical-end
26372612
}

0 commit comments

Comments
 (0)