@@ -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 > {
@@ -936,8 +954,9 @@ pub struct GlobalCtxt<'tcx> {
936
954
/// via `extern crate` item and not `--extern` option or compiler built-in.
937
955
pub extern_prelude : FxHashMap < Symbol , bool > ,
938
956
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 > > > ,
941
960
942
961
/// Caches the results of trait selection. This cache is used
943
962
/// for things that do not have to do with the parameters in scope.
@@ -1126,7 +1145,8 @@ impl<'tcx> TyCtxt<'tcx> {
1126
1145
definitions,
1127
1146
def_path_hash_to_def_id,
1128
1147
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 ( ) ,
1130
1150
selection_cache : Default :: default ( ) ,
1131
1151
evaluation_cache : Default :: default ( ) ,
1132
1152
crate_name : Symbol :: intern ( crate_name) ,
@@ -1623,7 +1643,7 @@ macro_rules! nop_list_lift {
1623
1643
nop_lift ! { type_; Ty <' a> => Ty <' tcx>}
1624
1644
nop_lift ! { region; Region <' a> => Region <' tcx>}
1625
1645
nop_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>}
1627
1647
1628
1648
nop_list_lift ! { type_list; Ty <' a> => Ty <' tcx>}
1629
1649
nop_list_lift ! { existential_predicates; ExistentialPredicate <' a> => ExistentialPredicate <' tcx>}
@@ -1982,6 +2002,26 @@ impl<'tcx> Borrow<TyKind<'tcx>> for Interned<'tcx, TyS<'tcx>> {
1982
2002
& self . 0 . kind
1983
2003
}
1984
2004
}
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
+ }
1985
2025
1986
2026
// N.B., an `Interned<List<T>>` compares and hashes as its elements.
1987
2027
impl < ' tcx , T : PartialEq > PartialEq for Interned < ' tcx , List < T > > {
@@ -2048,11 +2088,10 @@ macro_rules! direct_interners {
2048
2088
}
2049
2089
}
2050
2090
2051
- direct_interners ! (
2091
+ direct_interners ! {
2052
2092
region: mk_region( RegionKind ) ,
2053
2093
const_: mk_const( Const <' tcx>) ,
2054
- predicate_kind: intern_predicate_kind( PredicateKind <' tcx>) ,
2055
- ) ;
2094
+ }
2056
2095
2057
2096
macro_rules! slice_interners {
2058
2097
( $( $field: ident: $method: ident( $ty: ty) ) ,+) => (
@@ -2116,8 +2155,8 @@ impl<'tcx> TyCtxt<'tcx> {
2116
2155
2117
2156
#[ inline]
2118
2157
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 }
2121
2160
}
2122
2161
2123
2162
pub fn mk_mach_int ( self , tm : ast:: IntTy ) -> Ty < ' tcx > {
0 commit comments