@@ -38,6 +38,7 @@ use ty::subst::{Kind, Substs};
38
38
use ty:: ReprOptions ;
39
39
use ty:: Instance ;
40
40
use traits;
41
+ use traits:: { Clause , Goal } ;
41
42
use ty:: { self , Ty , TypeAndMut } ;
42
43
use ty:: { TyS , TypeVariants , Slice } ;
43
44
use ty:: { AdtKind , AdtDef , ClosureSubsts , GeneratorInterior , Region , Const } ;
@@ -125,34 +126,40 @@ impl<'tcx> GlobalArenas<'tcx> {
125
126
}
126
127
}
127
128
129
+ type InternedSet < ' tcx , T > = Lock < FxHashSet < Interned < ' tcx , T > > > ;
130
+
128
131
pub struct CtxtInterners < ' tcx > {
129
132
/// The arena that types, regions, etc are allocated from
130
133
arena : & ' tcx DroplessArena ,
131
134
132
135
/// Specifically use a speedy hash algorithm for these hash sets,
133
136
/// 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 > > > ,
142
147
}
143
148
144
149
impl < ' gcx : ' tcx , ' tcx > CtxtInterners < ' tcx > {
145
150
fn new ( arena : & ' tcx DroplessArena ) -> CtxtInterners < ' tcx > {
146
151
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 ( ) ,
156
163
}
157
164
}
158
165
@@ -2088,6 +2095,20 @@ impl<'tcx: 'lcx, 'lcx> Borrow<Const<'lcx>> for Interned<'tcx, Const<'tcx>> {
2088
2095
}
2089
2096
}
2090
2097
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
+
2091
2112
macro_rules! intern_method {
2092
2113
( $lt_tcx: tt, $name: ident: $method: ident( $alloc: ty,
2093
2114
$alloc_method: ident,
@@ -2185,7 +2206,9 @@ slice_interners!(
2185
2206
existential_predicates: _intern_existential_predicates( ExistentialPredicate ) ,
2186
2207
predicates: _intern_predicates( Predicate ) ,
2187
2208
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 )
2189
2212
) ;
2190
2213
2191
2214
// This isn't a perfect fit: CanonicalVarInfo slices are always
@@ -2490,6 +2513,22 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2490
2513
}
2491
2514
}
2492
2515
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
+
2493
2532
pub fn mk_fn_sig < I > ( self ,
2494
2533
inputs : I ,
2495
2534
output : I :: Item ,
@@ -2536,6 +2575,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2536
2575
self . mk_substs ( iter:: once ( s) . chain ( t. into_iter ( ) . cloned ( ) ) . map ( Kind :: from) )
2537
2576
}
2538
2577
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
+
2539
2592
pub fn lint_node < S : Into < MultiSpan > > ( self ,
2540
2593
lint : & ' static Lint ,
2541
2594
id : NodeId ,
0 commit comments