@@ -25,10 +25,10 @@ use crate::traits::solve::{
25
25
ExternalConstraints , ExternalConstraintsData , PredefinedOpaques , PredefinedOpaquesData ,
26
26
} ;
27
27
use crate :: ty:: {
28
- self , AdtDef , AdtDefData , AdtKind , Binder , Clause , Const , ConstData , GenericParamDefKind ,
29
- ImplPolarity , List , ParamConst , ParamTy , PolyExistentialPredicate , PolyFnSig , Predicate ,
30
- PredicateKind , PredicatePolarity , Region , RegionKind , ReprOptions , TraitObjectVisitor , Ty ,
31
- TyKind , TyVid , TypeVisitable , Visibility ,
28
+ self , AdtDef , AdtDefData , AdtKind , Binder , Clause , Clauses , Const , ConstData ,
29
+ GenericParamDefKind , ImplPolarity , List , ListWithCachedTypeInfo , ParamConst , ParamTy ,
30
+ PolyExistentialPredicate , PolyFnSig , Predicate , PredicateKind , PredicatePolarity , Region ,
31
+ RegionKind , ReprOptions , TraitObjectVisitor , Ty , TyKind , TyVid , TypeVisitable , Visibility ,
32
32
} ;
33
33
use crate :: ty:: { GenericArg , GenericArgs , GenericArgsRef } ;
34
34
use rustc_ast:: { self as ast, attr} ;
@@ -130,6 +130,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
130
130
type SubtypePredicate = ty:: SubtypePredicate < ' tcx > ;
131
131
type CoercePredicate = ty:: CoercePredicate < ' tcx > ;
132
132
type ClosureKind = ty:: ClosureKind ;
133
+ type Clauses = ty:: Clauses < ' tcx > ;
133
134
134
135
fn mk_canonical_var_infos ( self , infos : & [ ty:: CanonicalVarInfo < Self > ] ) -> Self :: CanonicalVars {
135
136
self . mk_canonical_var_infos ( infos)
@@ -152,7 +153,7 @@ pub struct CtxtInterners<'tcx> {
152
153
region : InternedSet < ' tcx , RegionKind < ' tcx > > ,
153
154
poly_existential_predicates : InternedSet < ' tcx , List < PolyExistentialPredicate < ' tcx > > > ,
154
155
predicate : InternedSet < ' tcx , WithCachedTypeInfo < ty:: Binder < ' tcx , PredicateKind < ' tcx > > > > ,
155
- clauses : InternedSet < ' tcx , List < Clause < ' tcx > > > ,
156
+ clauses : InternedSet < ' tcx , ListWithCachedTypeInfo < Clause < ' tcx > > > ,
156
157
projs : InternedSet < ' tcx , List < ProjectionKind > > ,
157
158
place_elems : InternedSet < ' tcx , List < PlaceElem < ' tcx > > > ,
158
159
const_ : InternedSet < ' tcx , WithCachedTypeInfo < ConstData < ' tcx > > > ,
@@ -286,6 +287,24 @@ impl<'tcx> CtxtInterners<'tcx> {
286
287
. 0 ,
287
288
) )
288
289
}
290
+
291
+ fn intern_clauses ( & self , clauses : & [ Clause < ' tcx > ] ) -> Clauses < ' tcx > {
292
+ if clauses. is_empty ( ) {
293
+ ListWithCachedTypeInfo :: empty ( )
294
+ } else {
295
+ self . clauses
296
+ . intern_ref ( clauses, || {
297
+ let flags = super :: flags:: FlagComputation :: for_clauses ( clauses) ;
298
+
299
+ InternedInSet ( ListWithCachedTypeInfo :: from_arena (
300
+ & * self . arena ,
301
+ flags. into ( ) ,
302
+ clauses,
303
+ ) )
304
+ } )
305
+ . 0
306
+ }
307
+ }
289
308
}
290
309
291
310
// For these preinterned values, an alternative would be to have
@@ -1783,6 +1802,29 @@ impl<'tcx, T: Hash> Hash for InternedInSet<'tcx, List<T>> {
1783
1802
}
1784
1803
}
1785
1804
1805
+ impl < ' tcx , T > Borrow < [ T ] > for InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > {
1806
+ fn borrow ( & self ) -> & [ T ] {
1807
+ & self . 0 [ ..]
1808
+ }
1809
+ }
1810
+
1811
+ impl < ' tcx , T : PartialEq > PartialEq for InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > {
1812
+ fn eq ( & self , other : & InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > ) -> bool {
1813
+ // The `Borrow` trait requires that `x.borrow() == y.borrow()` equals
1814
+ // `x == y`.
1815
+ self . 0 [ ..] == other. 0 [ ..]
1816
+ }
1817
+ }
1818
+
1819
+ impl < ' tcx , T : Eq > Eq for InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > { }
1820
+
1821
+ impl < ' tcx , T : Hash > Hash for InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > {
1822
+ fn hash < H : Hasher > ( & self , s : & mut H ) {
1823
+ // The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`.
1824
+ self . 0 [ ..] . hash ( s)
1825
+ }
1826
+ }
1827
+
1786
1828
macro_rules! direct_interners {
1787
1829
( $( $name: ident: $vis: vis $method: ident( $ty: ty) : $ret_ctor: ident -> $ret_ty: ty, ) +) => {
1788
1830
$( impl <' tcx> Borrow <$ty> for InternedInSet <' tcx, $ty> {
@@ -1841,7 +1883,7 @@ macro_rules! slice_interners {
1841
1883
List :: empty( )
1842
1884
} else {
1843
1885
self . interners. $field. intern_ref( v, || {
1844
- InternedInSet ( List :: from_arena( & * self . arena, v) )
1886
+ InternedInSet ( List :: from_arena( & * self . arena, ( ) , v) )
1845
1887
} ) . 0
1846
1888
}
1847
1889
} ) +
@@ -1858,7 +1900,6 @@ slice_interners!(
1858
1900
type_lists: pub mk_type_list( Ty <' tcx>) ,
1859
1901
canonical_var_infos: pub mk_canonical_var_infos( CanonicalVarInfo <' tcx>) ,
1860
1902
poly_existential_predicates: intern_poly_existential_predicates( PolyExistentialPredicate <' tcx>) ,
1861
- clauses: intern_clauses( Clause <' tcx>) ,
1862
1903
projs: pub mk_projs( ProjectionKind ) ,
1863
1904
place_elems: pub mk_place_elems( PlaceElem <' tcx>) ,
1864
1905
bound_variable_kinds: pub mk_bound_variable_kinds( ty:: BoundVariableKind ) ,
@@ -2163,11 +2204,11 @@ impl<'tcx> TyCtxt<'tcx> {
2163
2204
self . intern_poly_existential_predicates ( eps)
2164
2205
}
2165
2206
2166
- pub fn mk_clauses ( self , clauses : & [ Clause < ' tcx > ] ) -> & ' tcx List < Clause < ' tcx > > {
2207
+ pub fn mk_clauses ( self , clauses : & [ Clause < ' tcx > ] ) -> Clauses < ' tcx > {
2167
2208
// FIXME consider asking the input slice to be sorted to avoid
2168
2209
// re-interning permutations, in which case that would be asserted
2169
2210
// here.
2170
- self . intern_clauses ( clauses)
2211
+ self . interners . intern_clauses ( clauses)
2171
2212
}
2172
2213
2173
2214
pub fn mk_local_def_ids ( self , clauses : & [ LocalDefId ] ) -> & ' tcx List < LocalDefId > {
@@ -2231,7 +2272,7 @@ impl<'tcx> TyCtxt<'tcx> {
2231
2272
pub fn mk_clauses_from_iter < I , T > ( self , iter : I ) -> T :: Output
2232
2273
where
2233
2274
I : Iterator < Item = T > ,
2234
- T : CollectAndApply < Clause < ' tcx > , & ' tcx List < Clause < ' tcx > > > ,
2275
+ T : CollectAndApply < Clause < ' tcx > , Clauses < ' tcx > > ,
2235
2276
{
2236
2277
T :: collect_and_apply ( iter, |xs| self . mk_clauses ( xs) )
2237
2278
}
0 commit comments