@@ -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
@@ -1775,6 +1794,29 @@ impl<'tcx, T: Hash> Hash for InternedInSet<'tcx, List<T>> {
1775
1794
}
1776
1795
}
1777
1796
1797
+ impl < ' tcx , T > Borrow < [ T ] > for InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > {
1798
+ fn borrow ( & self ) -> & [ T ] {
1799
+ & self . 0 [ ..]
1800
+ }
1801
+ }
1802
+
1803
+ impl < ' tcx , T : PartialEq > PartialEq for InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > {
1804
+ fn eq ( & self , other : & InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > ) -> bool {
1805
+ // The `Borrow` trait requires that `x.borrow() == y.borrow()` equals
1806
+ // `x == y`.
1807
+ self . 0 [ ..] == other. 0 [ ..]
1808
+ }
1809
+ }
1810
+
1811
+ impl < ' tcx , T : Eq > Eq for InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > { }
1812
+
1813
+ impl < ' tcx , T : Hash > Hash for InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > {
1814
+ fn hash < H : Hasher > ( & self , s : & mut H ) {
1815
+ // The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`.
1816
+ self . 0 [ ..] . hash ( s)
1817
+ }
1818
+ }
1819
+
1778
1820
macro_rules! direct_interners {
1779
1821
( $( $name: ident: $vis: vis $method: ident( $ty: ty) : $ret_ctor: ident -> $ret_ty: ty, ) +) => {
1780
1822
$( impl <' tcx> Borrow <$ty> for InternedInSet <' tcx, $ty> {
@@ -1850,7 +1892,6 @@ slice_interners!(
1850
1892
type_lists: pub mk_type_list( Ty <' tcx>) ,
1851
1893
canonical_var_infos: pub mk_canonical_var_infos( CanonicalVarInfo <' tcx>) ,
1852
1894
poly_existential_predicates: intern_poly_existential_predicates( PolyExistentialPredicate <' tcx>) ,
1853
- clauses: intern_clauses( Clause <' tcx>) ,
1854
1895
projs: pub mk_projs( ProjectionKind ) ,
1855
1896
place_elems: pub mk_place_elems( PlaceElem <' tcx>) ,
1856
1897
bound_variable_kinds: pub mk_bound_variable_kinds( ty:: BoundVariableKind ) ,
@@ -2155,11 +2196,11 @@ impl<'tcx> TyCtxt<'tcx> {
2155
2196
self . intern_poly_existential_predicates ( eps)
2156
2197
}
2157
2198
2158
- pub fn mk_clauses ( self , clauses : & [ Clause < ' tcx > ] ) -> & ' tcx List < Clause < ' tcx > > {
2199
+ pub fn mk_clauses ( self , clauses : & [ Clause < ' tcx > ] ) -> Clauses < ' tcx > {
2159
2200
// FIXME consider asking the input slice to be sorted to avoid
2160
2201
// re-interning permutations, in which case that would be asserted
2161
2202
// here.
2162
- self . intern_clauses ( clauses)
2203
+ self . interners . intern_clauses ( clauses)
2163
2204
}
2164
2205
2165
2206
pub fn mk_local_def_ids ( self , clauses : & [ LocalDefId ] ) -> & ' tcx List < LocalDefId > {
@@ -2223,7 +2264,7 @@ impl<'tcx> TyCtxt<'tcx> {
2223
2264
pub fn mk_clauses_from_iter < I , T > ( self , iter : I ) -> T :: Output
2224
2265
where
2225
2266
I : Iterator < Item = T > ,
2226
- T : CollectAndApply < Clause < ' tcx > , & ' tcx List < Clause < ' tcx > > > ,
2267
+ T : CollectAndApply < Clause < ' tcx > , Clauses < ' tcx > > ,
2227
2268
{
2228
2269
T :: collect_and_apply ( iter, |xs| self . mk_clauses ( xs) )
2229
2270
}
0 commit comments