@@ -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 > {
@@ -936,8 +954,9 @@ pub struct GlobalCtxt<'tcx> {
936954 /// via `extern crate` item and not `--extern` option or compiler built-in.
937955 pub extern_prelude : FxHashMap < Symbol , bool > ,
938956
939- // Internal cache for metadata decoding. No need to track deps on this.
940- pub rcache : Lock < FxHashMap < ty:: CReaderCacheKey , Ty < ' tcx > > > ,
957+ // Internal caches for metadata decoding. No need to track deps on this.
958+ pub ty_rcache : Lock < FxHashMap < ty:: CReaderCacheKey , Ty < ' tcx > > > ,
959+ pub pred_rcache : Lock < FxHashMap < ty:: CReaderCacheKey , Predicate < ' tcx > > > ,
941960
942961 /// Caches the results of trait selection. This cache is used
943962 /// for things that do not have to do with the parameters in scope.
@@ -1126,7 +1145,8 @@ impl<'tcx> TyCtxt<'tcx> {
11261145 definitions,
11271146 def_path_hash_to_def_id,
11281147 queries : query:: Queries :: new ( providers, extern_providers, on_disk_query_result_cache) ,
1129- rcache : Default :: default ( ) ,
1148+ ty_rcache : Default :: default ( ) ,
1149+ pred_rcache : Default :: default ( ) ,
11301150 selection_cache : Default :: default ( ) ,
11311151 evaluation_cache : Default :: default ( ) ,
11321152 crate_name : Symbol :: intern ( crate_name) ,
@@ -1623,7 +1643,7 @@ macro_rules! nop_list_lift {
16231643nop_lift ! { type_; Ty <' a> => Ty <' tcx>}
16241644nop_lift ! { region; Region <' a> => Region <' tcx>}
16251645nop_lift ! { const_; & ' a Const <' a> => & ' tcx Const <' tcx>}
1626- nop_lift ! { predicate_kind ; & ' a PredicateKind <' a> => & ' tcx PredicateKind <' tcx>}
1646+ nop_lift ! { predicate ; & ' a PredicateInner <' a> => & ' tcx PredicateInner <' tcx>}
16271647
16281648nop_list_lift ! { type_list; Ty <' a> => Ty <' tcx>}
16291649nop_list_lift ! { existential_predicates; ExistentialPredicate <' a> => ExistentialPredicate <' tcx>}
@@ -1982,6 +2002,26 @@ impl<'tcx> Borrow<TyKind<'tcx>> for Interned<'tcx, TyS<'tcx>> {
19822002 & self . 0 . kind
19832003 }
19842004}
2005+ // N.B., an `Interned<PredicateInner>` compares and hashes as a `PredicateKind`.
2006+ impl < ' tcx > PartialEq for Interned < ' tcx , PredicateInner < ' tcx > > {
2007+ fn eq ( & self , other : & Interned < ' tcx , PredicateInner < ' tcx > > ) -> bool {
2008+ self . 0 . kind == other. 0 . kind
2009+ }
2010+ }
2011+
2012+ impl < ' tcx > Eq for Interned < ' tcx , PredicateInner < ' tcx > > { }
2013+
2014+ impl < ' tcx > Hash for Interned < ' tcx , PredicateInner < ' tcx > > {
2015+ fn hash < H : Hasher > ( & self , s : & mut H ) {
2016+ self . 0 . kind . hash ( s)
2017+ }
2018+ }
2019+
2020+ impl < ' tcx > Borrow < PredicateKind < ' tcx > > for Interned < ' tcx , PredicateInner < ' tcx > > {
2021+ fn borrow < ' a > ( & ' a self ) -> & ' a PredicateKind < ' tcx > {
2022+ & self . 0 . kind
2023+ }
2024+ }
19852025
19862026// N.B., an `Interned<List<T>>` compares and hashes as its elements.
19872027impl < ' tcx , T : PartialEq > PartialEq for Interned < ' tcx , List < T > > {
@@ -2048,11 +2088,10 @@ macro_rules! direct_interners {
20482088 }
20492089}
20502090
2051- direct_interners ! (
2091+ direct_interners ! {
20522092 region: mk_region( RegionKind ) ,
20532093 const_: mk_const( Const <' tcx>) ,
2054- predicate_kind: intern_predicate_kind( PredicateKind <' tcx>) ,
2055- ) ;
2094+ }
20562095
20572096macro_rules! slice_interners {
20582097 ( $( $field: ident: $method: ident( $ty: ty) ) ,+) => (
@@ -2116,8 +2155,8 @@ impl<'tcx> TyCtxt<'tcx> {
21162155
21172156 #[ inline]
21182157 pub fn mk_predicate ( & self , kind : PredicateKind < ' tcx > ) -> Predicate < ' tcx > {
2119- let kind = self . intern_predicate_kind ( kind) ;
2120- Predicate { kind }
2158+ let inner = self . interners . intern_predicate ( kind) ;
2159+ Predicate { inner }
21212160 }
21222161
21232162 pub fn mk_mach_int ( self , tm : ast:: IntTy ) -> Ty < ' tcx > {
0 commit comments