@@ -19,8 +19,9 @@ use crate::ty::TyKind::*;
19
19
use crate :: ty:: {
20
20
self , query, AdtDef , AdtKind , BindingMode , BoundVar , CanonicalPolyFnSig , Const , ConstVid ,
21
21
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 ,
24
25
} ;
25
26
use rustc_ast:: ast;
26
27
use rustc_ast:: expand:: allocator:: AllocatorKind ;
@@ -76,7 +77,7 @@ pub struct CtxtInterners<'tcx> {
76
77
canonical_var_infos : InternedSet < ' tcx , List < CanonicalVarInfo > > ,
77
78
region : InternedSet < ' tcx , RegionKind > ,
78
79
existential_predicates : InternedSet < ' tcx , List < ExistentialPredicate < ' tcx > > > ,
79
- predicate_kind : InternedSet < ' tcx , PredicateKind < ' tcx > > ,
80
+ predicate : InternedSet < ' tcx , PredicateInner < ' tcx > > ,
80
81
predicates : InternedSet < ' tcx , List < Predicate < ' tcx > > > ,
81
82
projs : InternedSet < ' tcx , List < ProjectionKind > > ,
82
83
place_elems : InternedSet < ' tcx , List < PlaceElem < ' tcx > > > ,
@@ -95,7 +96,7 @@ impl<'tcx> CtxtInterners<'tcx> {
95
96
region : Default :: default ( ) ,
96
97
existential_predicates : Default :: default ( ) ,
97
98
canonical_var_infos : Default :: default ( ) ,
98
- predicate_kind : Default :: default ( ) ,
99
+ predicate : Default :: default ( ) ,
99
100
predicates : Default :: default ( ) ,
100
101
projs : Default :: default ( ) ,
101
102
place_elems : Default :: default ( ) ,
@@ -123,6 +124,23 @@ impl<'tcx> CtxtInterners<'tcx> {
123
124
} )
124
125
. 0
125
126
}
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
+ }
126
144
}
127
145
128
146
pub struct CommonTypes < ' tcx > {
@@ -938,8 +956,9 @@ pub struct GlobalCtxt<'tcx> {
938
956
/// via `extern crate` item and not `--extern` option or compiler built-in.
939
957
pub extern_prelude : FxHashMap < Symbol , bool > ,
940
958
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 > > > ,
943
962
944
963
/// Caches the results of trait selection. This cache is used
945
964
/// for things that do not have to do with the parameters in scope.
@@ -1128,7 +1147,8 @@ impl<'tcx> TyCtxt<'tcx> {
1128
1147
definitions,
1129
1148
def_path_hash_to_def_id,
1130
1149
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 ( ) ,
1132
1152
selection_cache : Default :: default ( ) ,
1133
1153
evaluation_cache : Default :: default ( ) ,
1134
1154
crate_name : Symbol :: intern ( crate_name) ,
@@ -1625,7 +1645,7 @@ macro_rules! nop_list_lift {
1625
1645
nop_lift ! { type_; Ty <' a> => Ty <' tcx>}
1626
1646
nop_lift ! { region; Region <' a> => Region <' tcx>}
1627
1647
nop_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>}
1629
1649
1630
1650
nop_list_lift ! { type_list; Ty <' a> => Ty <' tcx>}
1631
1651
nop_list_lift ! { existential_predicates; ExistentialPredicate <' a> => ExistentialPredicate <' tcx>}
@@ -1984,6 +2004,26 @@ impl<'tcx> Borrow<TyKind<'tcx>> for Interned<'tcx, TyS<'tcx>> {
1984
2004
& self . 0 . kind
1985
2005
}
1986
2006
}
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
+ }
1987
2027
1988
2028
// N.B., an `Interned<List<T>>` compares and hashes as its elements.
1989
2029
impl < ' tcx , T : PartialEq > PartialEq for Interned < ' tcx , List < T > > {
@@ -2050,11 +2090,10 @@ macro_rules! direct_interners {
2050
2090
}
2051
2091
}
2052
2092
2053
- direct_interners ! (
2093
+ direct_interners ! {
2054
2094
region: mk_region( RegionKind ) ,
2055
2095
const_: mk_const( Const <' tcx>) ,
2056
- predicate_kind: intern_predicate_kind( PredicateKind <' tcx>) ,
2057
- ) ;
2096
+ }
2058
2097
2059
2098
macro_rules! slice_interners {
2060
2099
( $( $field: ident: $method: ident( $ty: ty) ) ,+) => (
@@ -2125,8 +2164,8 @@ impl<'tcx> TyCtxt<'tcx> {
2125
2164
2126
2165
#[ inline]
2127
2166
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 }
2130
2169
}
2131
2170
2132
2171
pub fn mk_mach_int ( self , tm : ast:: IntTy ) -> Ty < ' tcx > {
0 commit comments