@@ -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} ;
@@ -129,6 +129,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
129
129
type SubtypePredicate = ty:: SubtypePredicate < ' tcx > ;
130
130
type CoercePredicate = ty:: CoercePredicate < ' tcx > ;
131
131
type ClosureKind = ty:: ClosureKind ;
132
+ type Clauses = ty:: Clauses < ' tcx > ;
132
133
133
134
fn mk_canonical_var_infos ( self , infos : & [ ty:: CanonicalVarInfo < Self > ] ) -> Self :: CanonicalVars {
134
135
self . mk_canonical_var_infos ( infos)
@@ -151,7 +152,7 @@ pub struct CtxtInterners<'tcx> {
151
152
region : InternedSet < ' tcx , RegionKind < ' tcx > > ,
152
153
poly_existential_predicates : InternedSet < ' tcx , List < PolyExistentialPredicate < ' tcx > > > ,
153
154
predicate : InternedSet < ' tcx , WithCachedTypeInfo < ty:: Binder < ' tcx , PredicateKind < ' tcx > > > > ,
154
- clauses : InternedSet < ' tcx , List < Clause < ' tcx > > > ,
155
+ clauses : InternedSet < ' tcx , ListWithCachedTypeInfo < Clause < ' tcx > > > ,
155
156
projs : InternedSet < ' tcx , List < ProjectionKind > > ,
156
157
place_elems : InternedSet < ' tcx , List < PlaceElem < ' tcx > > > ,
157
158
const_ : InternedSet < ' tcx , WithCachedTypeInfo < ConstData < ' tcx > > > ,
@@ -285,6 +286,24 @@ impl<'tcx> CtxtInterners<'tcx> {
285
286
. 0 ,
286
287
) )
287
288
}
289
+
290
+ fn intern_clauses ( & self , clauses : & [ Clause < ' tcx > ] ) -> Clauses < ' tcx > {
291
+ if clauses. is_empty ( ) {
292
+ ListWithCachedTypeInfo :: empty ( )
293
+ } else {
294
+ self . clauses
295
+ . intern_ref ( clauses, || {
296
+ let flags = super :: flags:: FlagComputation :: for_clauses ( clauses) ;
297
+
298
+ InternedInSet ( ListWithCachedTypeInfo :: from_arena (
299
+ & * self . arena ,
300
+ flags. into ( ) ,
301
+ clauses,
302
+ ) )
303
+ } )
304
+ . 0
305
+ }
306
+ }
288
307
}
289
308
290
309
// For these preinterned values, an alternative would be to have
@@ -1717,6 +1736,29 @@ impl<'tcx, T: Hash> Hash for InternedInSet<'tcx, List<T>> {
1717
1736
}
1718
1737
}
1719
1738
1739
+ impl < ' tcx , T > Borrow < [ T ] > for InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > {
1740
+ fn borrow ( & self ) -> & [ T ] {
1741
+ & self . 0 [ ..]
1742
+ }
1743
+ }
1744
+
1745
+ impl < ' tcx , T : PartialEq > PartialEq for InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > {
1746
+ fn eq ( & self , other : & InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > ) -> bool {
1747
+ // The `Borrow` trait requires that `x.borrow() == y.borrow()` equals
1748
+ // `x == y`.
1749
+ self . 0 [ ..] == other. 0 [ ..]
1750
+ }
1751
+ }
1752
+
1753
+ impl < ' tcx , T : Eq > Eq for InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > { }
1754
+
1755
+ impl < ' tcx , T : Hash > Hash for InternedInSet < ' tcx , ListWithCachedTypeInfo < T > > {
1756
+ fn hash < H : Hasher > ( & self , s : & mut H ) {
1757
+ // The `Borrow` trait requires that `x.borrow().hash(s) == x.hash(s)`.
1758
+ self . 0 [ ..] . hash ( s)
1759
+ }
1760
+ }
1761
+
1720
1762
macro_rules! direct_interners {
1721
1763
( $( $name: ident: $vis: vis $method: ident( $ty: ty) : $ret_ctor: ident -> $ret_ty: ty, ) +) => {
1722
1764
$( impl <' tcx> Borrow <$ty> for InternedInSet <' tcx, $ty> {
@@ -1792,7 +1834,6 @@ slice_interners!(
1792
1834
type_lists: pub mk_type_list( Ty <' tcx>) ,
1793
1835
canonical_var_infos: pub mk_canonical_var_infos( CanonicalVarInfo <' tcx>) ,
1794
1836
poly_existential_predicates: intern_poly_existential_predicates( PolyExistentialPredicate <' tcx>) ,
1795
- clauses: intern_clauses( Clause <' tcx>) ,
1796
1837
projs: pub mk_projs( ProjectionKind ) ,
1797
1838
place_elems: pub mk_place_elems( PlaceElem <' tcx>) ,
1798
1839
bound_variable_kinds: pub mk_bound_variable_kinds( ty:: BoundVariableKind ) ,
@@ -2026,11 +2067,11 @@ impl<'tcx> TyCtxt<'tcx> {
2026
2067
self . intern_poly_existential_predicates ( eps)
2027
2068
}
2028
2069
2029
- pub fn mk_clauses ( self , clauses : & [ Clause < ' tcx > ] ) -> & ' tcx List < Clause < ' tcx > > {
2070
+ pub fn mk_clauses ( self , clauses : & [ Clause < ' tcx > ] ) -> Clauses < ' tcx > {
2030
2071
// FIXME consider asking the input slice to be sorted to avoid
2031
2072
// re-interning permutations, in which case that would be asserted
2032
2073
// here.
2033
- self . intern_clauses ( clauses)
2074
+ self . interners . intern_clauses ( clauses)
2034
2075
}
2035
2076
2036
2077
pub fn mk_local_def_ids ( self , clauses : & [ LocalDefId ] ) -> & ' tcx List < LocalDefId > {
@@ -2094,7 +2135,7 @@ impl<'tcx> TyCtxt<'tcx> {
2094
2135
pub fn mk_clauses_from_iter < I , T > ( self , iter : I ) -> T :: Output
2095
2136
where
2096
2137
I : Iterator < Item = T > ,
2097
- T : CollectAndApply < Clause < ' tcx > , & ' tcx List < Clause < ' tcx > > > ,
2138
+ T : CollectAndApply < Clause < ' tcx > , Clauses < ' tcx > > ,
2098
2139
{
2099
2140
T :: collect_and_apply ( iter, |xs| self . mk_clauses ( xs) )
2100
2141
}
0 commit comments