intern PredicateKind
This commit is contained in:
parent
f3164790bd
commit
57746f943b
6 changed files with 35 additions and 14 deletions
|
|
@ -59,7 +59,7 @@ pub type TraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;
|
|||
|
||||
// `PredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
static_assert_size!(PredicateObligation<'_>, 112);
|
||||
static_assert_size!(PredicateObligation<'_>, 88);
|
||||
|
||||
pub type Obligations<'tcx, O> = Vec<Obligation<'tcx, O>>;
|
||||
pub type PredicateObligations<'tcx> = Vec<PredicateObligation<'tcx>>;
|
||||
|
|
|
|||
|
|
@ -29,10 +29,9 @@ use crate::ty::{self, DefIdTree, Ty, TypeAndMut};
|
|||
use crate::ty::{AdtDef, AdtKind, Const, Region};
|
||||
use crate::ty::{BindingMode, BoundVar};
|
||||
use crate::ty::{ConstVid, FloatVar, FloatVid, IntVar, IntVid, TyVar, TyVid};
|
||||
use crate::ty::{
|
||||
ExistentialPredicate, InferTy, ParamTy, PolyFnSig, Predicate, PredicateKind, ProjectionTy,
|
||||
};
|
||||
use crate::ty::{ExistentialPredicate, Predicate, PredicateKind};
|
||||
use crate::ty::{InferConst, ParamConst};
|
||||
use crate::ty::{InferTy, ParamTy, PolyFnSig, ProjectionTy};
|
||||
use crate::ty::{List, TyKind, TyS};
|
||||
use rustc_ast::ast;
|
||||
use rustc_ast::expand::allocator::AllocatorKind;
|
||||
|
|
@ -91,6 +90,7 @@ pub struct CtxtInterners<'tcx> {
|
|||
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo>>,
|
||||
region: InternedSet<'tcx, RegionKind>,
|
||||
existential_predicates: InternedSet<'tcx, List<ExistentialPredicate<'tcx>>>,
|
||||
predicate_kind: InternedSet<'tcx, PredicateKind<'tcx>>,
|
||||
predicates: InternedSet<'tcx, List<Predicate<'tcx>>>,
|
||||
projs: InternedSet<'tcx, List<ProjectionKind>>,
|
||||
place_elems: InternedSet<'tcx, List<PlaceElem<'tcx>>>,
|
||||
|
|
@ -109,6 +109,7 @@ impl<'tcx> CtxtInterners<'tcx> {
|
|||
region: Default::default(),
|
||||
existential_predicates: Default::default(),
|
||||
canonical_var_infos: Default::default(),
|
||||
predicate_kind: Default::default(),
|
||||
predicates: Default::default(),
|
||||
projs: Default::default(),
|
||||
place_elems: Default::default(),
|
||||
|
|
@ -1579,6 +1580,7 @@ macro_rules! nop_list_lift {
|
|||
nop_lift! {type_; Ty<'a> => Ty<'tcx>}
|
||||
nop_lift! {region; Region<'a> => Region<'tcx>}
|
||||
nop_lift! {const_; &'a Const<'a> => &'tcx Const<'tcx>}
|
||||
nop_lift! {predicate_kind; &'a PredicateKind<'a> => &'tcx PredicateKind<'tcx>}
|
||||
|
||||
nop_list_lift! {type_list; Ty<'a> => Ty<'tcx>}
|
||||
nop_list_lift! {existential_predicates; ExistentialPredicate<'a> => ExistentialPredicate<'tcx>}
|
||||
|
|
@ -2017,8 +2019,14 @@ impl<'tcx> Borrow<[traits::ChalkEnvironmentClause<'tcx>]>
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Borrow<PredicateKind<'tcx>> for Interned<'tcx, PredicateKind<'tcx>> {
|
||||
fn borrow<'a>(&'a self) -> &'a PredicateKind<'tcx> {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! direct_interners {
|
||||
($($name:ident: $method:ident($ty:ty)),+) => {
|
||||
($($name:ident: $method:ident($ty:ty),)+) => {
|
||||
$(impl<'tcx> PartialEq for Interned<'tcx, $ty> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0 == other.0
|
||||
|
|
@ -2043,7 +2051,11 @@ macro_rules! direct_interners {
|
|||
}
|
||||
}
|
||||
|
||||
direct_interners!(region: mk_region(RegionKind), const_: mk_const(Const<'tcx>));
|
||||
direct_interners!(
|
||||
region: mk_region(RegionKind),
|
||||
const_: mk_const(Const<'tcx>),
|
||||
predicate_kind: intern_predicate_kind(PredicateKind<'tcx>),
|
||||
);
|
||||
|
||||
macro_rules! slice_interners {
|
||||
($($field:ident: $method:ident($ty:ty)),+) => (
|
||||
|
|
@ -2107,6 +2119,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
#[inline]
|
||||
pub fn mk_predicate(&self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> {
|
||||
let kind = self.intern_predicate_kind(kind);
|
||||
Predicate { kind }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1017,14 +1017,14 @@ impl<'tcx> GenericPredicates<'tcx> {
|
|||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Lift)]
|
||||
#[derive(HashStable, TypeFoldable)]
|
||||
#[derive(HashStable)]
|
||||
pub struct Predicate<'tcx> {
|
||||
kind: PredicateKind<'tcx>,
|
||||
kind: &'tcx PredicateKind<'tcx>,
|
||||
}
|
||||
|
||||
impl Predicate<'tcx> {
|
||||
pub fn kind(&self) -> PredicateKind<'tcx> {
|
||||
self.kind
|
||||
*self.kind
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -987,6 +987,16 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
folder.tcx().mk_predicate(ty::PredicateKind::super_fold_with(self.kind, folder))
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
||||
ty::PredicateKind::super_visit_with(self.kind, visitor)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
fold_list(*self, folder, |tcx, v| tcx.intern_predicates(v))
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ pub struct PendingPredicateObligation<'tcx> {
|
|||
|
||||
// `PendingPredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
static_assert_size!(PendingPredicateObligation<'_>, 136);
|
||||
static_assert_size!(PendingPredicateObligation<'_>, 112);
|
||||
|
||||
impl<'a, 'tcx> FulfillmentContext<'tcx> {
|
||||
/// Creates a new fulfillment context.
|
||||
|
|
|
|||
|
|
@ -6,10 +6,8 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
|||
use rustc_infer::traits::TraitEngineExt as _;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::subst::{GenericArg, Subst, UserSelfTy, UserSubsts};
|
||||
use rustc_middle::ty::{
|
||||
self, FnSig, Lift, ParamEnv, ParamEnvAnd, PolyFnSig, Predicate, ToPredicate, Ty, TyCtxt,
|
||||
TypeFoldable, Variance,
|
||||
};
|
||||
use rustc_middle::ty::{self, FnSig, Lift, PolyFnSig, Ty, TyCtxt, TypeFoldable, Variance};
|
||||
use rustc_middle::ty::{ParamEnv, ParamEnvAnd, Predicate, ToPredicate};
|
||||
use rustc_span::DUMMY_SP;
|
||||
use rustc_trait_selection::infer::InferCtxtBuilderExt;
|
||||
use rustc_trait_selection::infer::InferCtxtExt;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue