@@ -38,6 +38,7 @@ use ty::subst::{Kind, Substs};
3838use ty:: ReprOptions ;
3939use ty:: Instance ;
4040use traits;
41+ use traits:: { Clause , Goal } ;
4142use ty:: { self , Ty , TypeAndMut } ;
4243use ty:: { TyS , TypeVariants , Slice } ;
4344use ty:: { AdtKind , AdtDef , ClosureSubsts , GeneratorInterior , Region , Const } ;
@@ -125,34 +126,40 @@ impl<'tcx> GlobalArenas<'tcx> {
125126 }
126127}
127128
129+ type InternedSet < ' tcx , T > = Lock < FxHashSet < Interned < ' tcx , T > > > ;
130+
128131pub struct CtxtInterners < ' tcx > {
129132 /// The arena that types, regions, etc are allocated from
130133 arena : & ' tcx DroplessArena ,
131134
132135 /// Specifically use a speedy hash algorithm for these hash sets,
133136 /// they're accessed quite often.
134- type_ : Lock < FxHashSet < Interned < ' tcx , TyS < ' tcx > > > > ,
135- type_list : Lock < FxHashSet < Interned < ' tcx , Slice < Ty < ' tcx > > > > > ,
136- substs : Lock < FxHashSet < Interned < ' tcx , Substs < ' tcx > > > > ,
137- canonical_var_infos : Lock < FxHashSet < Interned < ' tcx , Slice < CanonicalVarInfo > > > > ,
138- region : Lock < FxHashSet < Interned < ' tcx , RegionKind > > > ,
139- existential_predicates : Lock < FxHashSet < Interned < ' tcx , Slice < ExistentialPredicate < ' tcx > > > > > ,
140- predicates : Lock < FxHashSet < Interned < ' tcx , Slice < Predicate < ' tcx > > > > > ,
141- const_ : Lock < FxHashSet < Interned < ' tcx , Const < ' tcx > > > > ,
137+ type_ : InternedSet < ' tcx , TyS < ' tcx > > ,
138+ type_list : InternedSet < ' tcx , Slice < Ty < ' tcx > > > ,
139+ substs : InternedSet < ' tcx , Substs < ' tcx > > ,
140+ canonical_var_infos : InternedSet < ' tcx , Slice < CanonicalVarInfo > > ,
141+ region : InternedSet < ' tcx , RegionKind > ,
142+ existential_predicates : InternedSet < ' tcx , Slice < ExistentialPredicate < ' tcx > > > ,
143+ predicates : InternedSet < ' tcx , Slice < Predicate < ' tcx > > > ,
144+ const_ : InternedSet < ' tcx , Const < ' tcx > > ,
145+ clauses : InternedSet < ' tcx , Slice < Clause < ' tcx > > > ,
146+ goals : InternedSet < ' tcx , Slice < Goal < ' tcx > > > ,
142147}
143148
144149impl < ' gcx : ' tcx , ' tcx > CtxtInterners < ' tcx > {
145150 fn new ( arena : & ' tcx DroplessArena ) -> CtxtInterners < ' tcx > {
146151 CtxtInterners {
147- arena : arena,
148- type_ : Lock :: new ( FxHashSet ( ) ) ,
149- type_list : Lock :: new ( FxHashSet ( ) ) ,
150- substs : Lock :: new ( FxHashSet ( ) ) ,
151- canonical_var_infos : Lock :: new ( FxHashSet ( ) ) ,
152- region : Lock :: new ( FxHashSet ( ) ) ,
153- existential_predicates : Lock :: new ( FxHashSet ( ) ) ,
154- predicates : Lock :: new ( FxHashSet ( ) ) ,
155- const_ : Lock :: new ( FxHashSet ( ) ) ,
152+ arena,
153+ type_ : Default :: default ( ) ,
154+ type_list : Default :: default ( ) ,
155+ substs : Default :: default ( ) ,
156+ region : Default :: default ( ) ,
157+ existential_predicates : Default :: default ( ) ,
158+ canonical_var_infos : Default :: default ( ) ,
159+ predicates : Default :: default ( ) ,
160+ const_ : Default :: default ( ) ,
161+ clauses : Default :: default ( ) ,
162+ goals : Default :: default ( ) ,
156163 }
157164 }
158165
@@ -2088,6 +2095,20 @@ impl<'tcx: 'lcx, 'lcx> Borrow<Const<'lcx>> for Interned<'tcx, Const<'tcx>> {
20882095 }
20892096}
20902097
2098+ impl < ' tcx : ' lcx , ' lcx > Borrow < [ Clause < ' lcx > ] >
2099+ for Interned < ' tcx , Slice < Clause < ' tcx > > > {
2100+ fn borrow < ' a > ( & ' a self ) -> & ' a [ Clause < ' lcx > ] {
2101+ & self . 0 [ ..]
2102+ }
2103+ }
2104+
2105+ impl < ' tcx : ' lcx , ' lcx > Borrow < [ Goal < ' lcx > ] >
2106+ for Interned < ' tcx , Slice < Goal < ' tcx > > > {
2107+ fn borrow < ' a > ( & ' a self ) -> & ' a [ Goal < ' lcx > ] {
2108+ & self . 0 [ ..]
2109+ }
2110+ }
2111+
20912112macro_rules! intern_method {
20922113 ( $lt_tcx: tt, $name: ident: $method: ident( $alloc: ty,
20932114 $alloc_method: ident,
@@ -2185,7 +2206,9 @@ slice_interners!(
21852206 existential_predicates: _intern_existential_predicates( ExistentialPredicate ) ,
21862207 predicates: _intern_predicates( Predicate ) ,
21872208 type_list: _intern_type_list( Ty ) ,
2188- substs: _intern_substs( Kind )
2209+ substs: _intern_substs( Kind ) ,
2210+ clauses: _intern_clauses( Clause ) ,
2211+ goals: _intern_goals( Goal )
21892212) ;
21902213
21912214// This isn't a perfect fit: CanonicalVarInfo slices are always
@@ -2490,6 +2513,22 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24902513 }
24912514 }
24922515
2516+ pub fn intern_clauses ( self , ts : & [ Clause < ' tcx > ] ) -> & ' tcx Slice < Clause < ' tcx > > {
2517+ if ts. len ( ) == 0 {
2518+ Slice :: empty ( )
2519+ } else {
2520+ self . _intern_clauses ( ts)
2521+ }
2522+ }
2523+
2524+ pub fn intern_goals ( self , ts : & [ Goal < ' tcx > ] ) -> & ' tcx Slice < Goal < ' tcx > > {
2525+ if ts. len ( ) == 0 {
2526+ Slice :: empty ( )
2527+ } else {
2528+ self . _intern_goals ( ts)
2529+ }
2530+ }
2531+
24932532 pub fn mk_fn_sig < I > ( self ,
24942533 inputs : I ,
24952534 output : I :: Item ,
@@ -2536,6 +2575,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
25362575 self . mk_substs ( iter:: once ( s) . chain ( t. into_iter ( ) . cloned ( ) ) . map ( Kind :: from) )
25372576 }
25382577
2578+ pub fn mk_clauses < I : InternAs < [ Clause < ' tcx > ] ,
2579+ & ' tcx Slice < Clause < ' tcx > > > > ( self , iter : I ) -> I :: Output {
2580+ iter. intern_with ( |xs| self . intern_clauses ( xs) )
2581+ }
2582+
2583+ pub fn mk_goals < I : InternAs < [ Goal < ' tcx > ] ,
2584+ & ' tcx Slice < Goal < ' tcx > > > > ( self , iter : I ) -> I :: Output {
2585+ iter. intern_with ( |xs| self . intern_goals ( xs) )
2586+ }
2587+
2588+ pub fn mk_goal ( self , goal : Goal < ' tcx > ) -> & ' tcx Goal {
2589+ & self . mk_goals ( iter:: once ( goal) ) [ 0 ]
2590+ }
2591+
25392592 pub fn lint_node < S : Into < MultiSpan > > ( self ,
25402593 lint : & ' static Lint ,
25412594 id : NodeId ,
0 commit comments