Skip to content

Commit 57746f9

Browse files
committed
intern PredicateKind
1 parent f316479 commit 57746f9

File tree

6 files changed

+35
-14
lines changed

6 files changed

+35
-14
lines changed

src/librustc_infer/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub type TraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;
5959

6060
// `PredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
6161
#[cfg(target_arch = "x86_64")]
62-
static_assert_size!(PredicateObligation<'_>, 112);
62+
static_assert_size!(PredicateObligation<'_>, 88);
6363

6464
pub type Obligations<'tcx, O> = Vec<Obligation<'tcx, O>>;
6565
pub type PredicateObligations<'tcx> = Vec<PredicateObligation<'tcx>>;

src/librustc_middle/ty/context.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ use crate::ty::{self, DefIdTree, Ty, TypeAndMut};
2929
use crate::ty::{AdtDef, AdtKind, Const, Region};
3030
use crate::ty::{BindingMode, BoundVar};
3131
use crate::ty::{ConstVid, FloatVar, FloatVid, IntVar, IntVid, TyVar, TyVid};
32-
use crate::ty::{
33-
ExistentialPredicate, InferTy, ParamTy, PolyFnSig, Predicate, PredicateKind, ProjectionTy,
34-
};
32+
use crate::ty::{ExistentialPredicate, Predicate, PredicateKind};
3533
use crate::ty::{InferConst, ParamConst};
34+
use crate::ty::{InferTy, ParamTy, PolyFnSig, ProjectionTy};
3635
use crate::ty::{List, TyKind, TyS};
3736
use rustc_ast::ast;
3837
use rustc_ast::expand::allocator::AllocatorKind;
@@ -91,6 +90,7 @@ pub struct CtxtInterners<'tcx> {
9190
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo>>,
9291
region: InternedSet<'tcx, RegionKind>,
9392
existential_predicates: InternedSet<'tcx, List<ExistentialPredicate<'tcx>>>,
93+
predicate_kind: InternedSet<'tcx, PredicateKind<'tcx>>,
9494
predicates: InternedSet<'tcx, List<Predicate<'tcx>>>,
9595
projs: InternedSet<'tcx, List<ProjectionKind>>,
9696
place_elems: InternedSet<'tcx, List<PlaceElem<'tcx>>>,
@@ -109,6 +109,7 @@ impl<'tcx> CtxtInterners<'tcx> {
109109
region: Default::default(),
110110
existential_predicates: Default::default(),
111111
canonical_var_infos: Default::default(),
112+
predicate_kind: Default::default(),
112113
predicates: Default::default(),
113114
projs: Default::default(),
114115
place_elems: Default::default(),
@@ -1579,6 +1580,7 @@ macro_rules! nop_list_lift {
15791580
nop_lift! {type_; Ty<'a> => Ty<'tcx>}
15801581
nop_lift! {region; Region<'a> => Region<'tcx>}
15811582
nop_lift! {const_; &'a Const<'a> => &'tcx Const<'tcx>}
1583+
nop_lift! {predicate_kind; &'a PredicateKind<'a> => &'tcx PredicateKind<'tcx>}
15821584

15831585
nop_list_lift! {type_list; Ty<'a> => Ty<'tcx>}
15841586
nop_list_lift! {existential_predicates; ExistentialPredicate<'a> => ExistentialPredicate<'tcx>}
@@ -2017,8 +2019,14 @@ impl<'tcx> Borrow<[traits::ChalkEnvironmentClause<'tcx>]>
20172019
}
20182020
}
20192021

2022+
impl<'tcx> Borrow<PredicateKind<'tcx>> for Interned<'tcx, PredicateKind<'tcx>> {
2023+
fn borrow<'a>(&'a self) -> &'a PredicateKind<'tcx> {
2024+
&self.0
2025+
}
2026+
}
2027+
20202028
macro_rules! direct_interners {
2021-
($($name:ident: $method:ident($ty:ty)),+) => {
2029+
($($name:ident: $method:ident($ty:ty),)+) => {
20222030
$(impl<'tcx> PartialEq for Interned<'tcx, $ty> {
20232031
fn eq(&self, other: &Self) -> bool {
20242032
self.0 == other.0
@@ -2043,7 +2051,11 @@ macro_rules! direct_interners {
20432051
}
20442052
}
20452053

2046-
direct_interners!(region: mk_region(RegionKind), const_: mk_const(Const<'tcx>));
2054+
direct_interners!(
2055+
region: mk_region(RegionKind),
2056+
const_: mk_const(Const<'tcx>),
2057+
predicate_kind: intern_predicate_kind(PredicateKind<'tcx>),
2058+
);
20472059

20482060
macro_rules! slice_interners {
20492061
($($field:ident: $method:ident($ty:ty)),+) => (
@@ -2107,6 +2119,7 @@ impl<'tcx> TyCtxt<'tcx> {
21072119

21082120
#[inline]
21092121
pub fn mk_predicate(&self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> {
2122+
let kind = self.intern_predicate_kind(kind);
21102123
Predicate { kind }
21112124
}
21122125

src/librustc_middle/ty/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1017,14 +1017,14 @@ impl<'tcx> GenericPredicates<'tcx> {
10171017
}
10181018

10191019
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Lift)]
1020-
#[derive(HashStable, TypeFoldable)]
1020+
#[derive(HashStable)]
10211021
pub struct Predicate<'tcx> {
1022-
kind: PredicateKind<'tcx>,
1022+
kind: &'tcx PredicateKind<'tcx>,
10231023
}
10241024

10251025
impl Predicate<'tcx> {
10261026
pub fn kind(&self) -> PredicateKind<'tcx> {
1027-
self.kind
1027+
*self.kind
10281028
}
10291029
}
10301030

src/librustc_middle/ty/structural_impls.rs

+10
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,16 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
987987
}
988988
}
989989

990+
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
991+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
992+
folder.tcx().mk_predicate(ty::PredicateKind::super_fold_with(self.kind, folder))
993+
}
994+
995+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
996+
ty::PredicateKind::super_visit_with(self.kind, visitor)
997+
}
998+
}
999+
9901000
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
9911001
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
9921002
fold_list(*self, folder, |tcx, v| tcx.intern_predicates(v))

src/librustc_trait_selection/traits/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub struct PendingPredicateObligation<'tcx> {
8383

8484
// `PendingPredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
8585
#[cfg(target_arch = "x86_64")]
86-
static_assert_size!(PendingPredicateObligation<'_>, 136);
86+
static_assert_size!(PendingPredicateObligation<'_>, 112);
8787

8888
impl<'a, 'tcx> FulfillmentContext<'tcx> {
8989
/// Creates a new fulfillment context.

src/librustc_traits/type_op.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
66
use rustc_infer::traits::TraitEngineExt as _;
77
use rustc_middle::ty::query::Providers;
88
use rustc_middle::ty::subst::{GenericArg, Subst, UserSelfTy, UserSubsts};
9-
use rustc_middle::ty::{
10-
self, FnSig, Lift, ParamEnv, ParamEnvAnd, PolyFnSig, Predicate, ToPredicate, Ty, TyCtxt,
11-
TypeFoldable, Variance,
12-
};
9+
use rustc_middle::ty::{self, FnSig, Lift, PolyFnSig, Ty, TyCtxt, TypeFoldable, Variance};
10+
use rustc_middle::ty::{ParamEnv, ParamEnvAnd, Predicate, ToPredicate};
1311
use rustc_span::DUMMY_SP;
1412
use rustc_trait_selection::infer::InferCtxtBuilderExt;
1513
use rustc_trait_selection::infer::InferCtxtExt;

0 commit comments

Comments
 (0)