@@ -19,8 +19,9 @@ use crate::ty::TyKind::*;
1919use crate :: ty:: {
2020 self , query, AdtDef , AdtKind , BindingMode , BoundVar , CanonicalPolyFnSig , Const , ConstVid ,
2121 DefIdTree , ExistentialPredicate , FloatVar , FloatVid , GenericParamDefKind , InferConst , InferTy ,
22- IntVar , IntVid , List , ParamConst , ParamTy , PolyFnSig , Predicate , PredicateKind , ProjectionTy ,
23- Region , RegionKind , ReprOptions , TraitObjectVisitor , Ty , TyKind , TyS , TyVar , TyVid , TypeAndMut ,
22+ IntVar , IntVid , List , ParamConst , ParamTy , PolyFnSig , Predicate , PredicateInner , PredicateKind ,
23+ ProjectionTy , Region , RegionKind , ReprOptions , TraitObjectVisitor , Ty , TyKind , TyS , TyVar ,
24+ TyVid , TypeAndMut ,
2425} ;
2526use rustc_ast:: ast;
2627use rustc_ast:: expand:: allocator:: AllocatorKind ;
@@ -76,7 +77,7 @@ pub struct CtxtInterners<'tcx> {
7677 canonical_var_infos : InternedSet < ' tcx , List < CanonicalVarInfo > > ,
7778 region : InternedSet < ' tcx , RegionKind > ,
7879 existential_predicates : InternedSet < ' tcx , List < ExistentialPredicate < ' tcx > > > ,
79- predicate_kind : InternedSet < ' tcx , PredicateKind < ' tcx > > ,
80+ predicate : InternedSet < ' tcx , PredicateInner < ' tcx > > ,
8081 predicates : InternedSet < ' tcx , List < Predicate < ' tcx > > > ,
8182 projs : InternedSet < ' tcx , List < ProjectionKind > > ,
8283 place_elems : InternedSet < ' tcx , List < PlaceElem < ' tcx > > > ,
@@ -95,7 +96,7 @@ impl<'tcx> CtxtInterners<'tcx> {
9596 region : Default :: default ( ) ,
9697 existential_predicates : Default :: default ( ) ,
9798 canonical_var_infos : Default :: default ( ) ,
98- predicate_kind : Default :: default ( ) ,
99+ predicate : Default :: default ( ) ,
99100 predicates : Default :: default ( ) ,
100101 projs : Default :: default ( ) ,
101102 place_elems : Default :: default ( ) ,
@@ -123,6 +124,23 @@ impl<'tcx> CtxtInterners<'tcx> {
123124 } )
124125 . 0
125126 }
127+
128+ #[ inline( never) ]
129+ fn intern_predicate ( & self , kind : PredicateKind < ' tcx > ) -> & ' tcx PredicateInner < ' tcx > {
130+ self . predicate
131+ . intern ( kind, |kind| {
132+ let flags = super :: flags:: FlagComputation :: for_predicate ( & kind) ;
133+
134+ let predicate_struct = PredicateInner {
135+ kind,
136+ flags : flags. flags ,
137+ outer_exclusive_binder : flags. outer_exclusive_binder ,
138+ } ;
139+
140+ Interned ( self . arena . alloc ( predicate_struct) )
141+ } )
142+ . 0
143+ }
126144}
127145
128146pub struct CommonTypes < ' tcx > {
@@ -938,8 +956,9 @@ pub struct GlobalCtxt<'tcx> {
938956 /// via `extern crate` item and not `--extern` option or compiler built-in.
939957 pub extern_prelude : FxHashMap < Symbol , bool > ,
940958
941- // Internal cache for metadata decoding. No need to track deps on this.
942- pub rcache : Lock < FxHashMap < ty:: CReaderCacheKey , Ty < ' tcx > > > ,
959+ // Internal caches for metadata decoding. No need to track deps on this.
960+ pub ty_rcache : Lock < FxHashMap < ty:: CReaderCacheKey , Ty < ' tcx > > > ,
961+ pub pred_rcache : Lock < FxHashMap < ty:: CReaderCacheKey , Predicate < ' tcx > > > ,
943962
944963 /// Caches the results of trait selection. This cache is used
945964 /// for things that do not have to do with the parameters in scope.
@@ -1128,7 +1147,8 @@ impl<'tcx> TyCtxt<'tcx> {
11281147 definitions,
11291148 def_path_hash_to_def_id,
11301149 queries : query:: Queries :: new ( providers, extern_providers, on_disk_query_result_cache) ,
1131- rcache : Default :: default ( ) ,
1150+ ty_rcache : Default :: default ( ) ,
1151+ pred_rcache : Default :: default ( ) ,
11321152 selection_cache : Default :: default ( ) ,
11331153 evaluation_cache : Default :: default ( ) ,
11341154 crate_name : Symbol :: intern ( crate_name) ,
@@ -1625,7 +1645,7 @@ macro_rules! nop_list_lift {
16251645nop_lift ! { type_; Ty <' a> => Ty <' tcx>}
16261646nop_lift ! { region; Region <' a> => Region <' tcx>}
16271647nop_lift ! { const_; & ' a Const <' a> => & ' tcx Const <' tcx>}
1628- nop_lift ! { predicate_kind ; & ' a PredicateKind <' a> => & ' tcx PredicateKind <' tcx>}
1648+ nop_lift ! { predicate ; & ' a PredicateInner <' a> => & ' tcx PredicateInner <' tcx>}
16291649
16301650nop_list_lift ! { type_list; Ty <' a> => Ty <' tcx>}
16311651nop_list_lift ! { existential_predicates; ExistentialPredicate <' a> => ExistentialPredicate <' tcx>}
@@ -1984,6 +2004,26 @@ impl<'tcx> Borrow<TyKind<'tcx>> for Interned<'tcx, TyS<'tcx>> {
19842004 & self . 0 . kind
19852005 }
19862006}
2007+ // N.B., an `Interned<PredicateInner>` compares and hashes as a `PredicateKind`.
2008+ impl < ' tcx > PartialEq for Interned < ' tcx , PredicateInner < ' tcx > > {
2009+ fn eq ( & self , other : & Interned < ' tcx , PredicateInner < ' tcx > > ) -> bool {
2010+ self . 0 . kind == other. 0 . kind
2011+ }
2012+ }
2013+
2014+ impl < ' tcx > Eq for Interned < ' tcx , PredicateInner < ' tcx > > { }
2015+
2016+ impl < ' tcx > Hash for Interned < ' tcx , PredicateInner < ' tcx > > {
2017+ fn hash < H : Hasher > ( & self , s : & mut H ) {
2018+ self . 0 . kind . hash ( s)
2019+ }
2020+ }
2021+
2022+ impl < ' tcx > Borrow < PredicateKind < ' tcx > > for Interned < ' tcx , PredicateInner < ' tcx > > {
2023+ fn borrow < ' a > ( & ' a self ) -> & ' a PredicateKind < ' tcx > {
2024+ & self . 0 . kind
2025+ }
2026+ }
19872027
19882028// N.B., an `Interned<List<T>>` compares and hashes as its elements.
19892029impl < ' tcx , T : PartialEq > PartialEq for Interned < ' tcx , List < T > > {
@@ -2050,11 +2090,10 @@ macro_rules! direct_interners {
20502090 }
20512091}
20522092
2053- direct_interners ! (
2093+ direct_interners ! {
20542094 region: mk_region( RegionKind ) ,
20552095 const_: mk_const( Const <' tcx>) ,
2056- predicate_kind: intern_predicate_kind( PredicateKind <' tcx>) ,
2057- ) ;
2096+ }
20582097
20592098macro_rules! slice_interners {
20602099 ( $( $field: ident: $method: ident( $ty: ty) ) ,+) => (
@@ -2125,8 +2164,8 @@ impl<'tcx> TyCtxt<'tcx> {
21252164
21262165 #[ inline]
21272166 pub fn mk_predicate ( & self , kind : PredicateKind < ' tcx > ) -> Predicate < ' tcx > {
2128- let kind = self . intern_predicate_kind ( kind) ;
2129- Predicate { kind }
2167+ let inner = self . interners . intern_predicate ( kind) ;
2168+ Predicate { inner }
21302169 }
21312170
21322171 pub fn mk_mach_int ( self , tm : ast:: IntTy ) -> Ty < ' tcx > {
0 commit comments