@@ -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
@@ -2099,6 +2106,20 @@ impl<'tcx: 'lcx, 'lcx> Borrow<Const<'lcx>> for Interned<'tcx, Const<'tcx>> {
2099
2106
}
2100
2107
}
2101
2108
2109
+ impl < ' tcx : ' lcx , ' lcx > Borrow < [ Clause < ' lcx > ] >
2110
+ for Interned < ' tcx , Slice < Clause < ' tcx > > > {
2111
+ fn borrow < ' a > ( & ' a self ) -> & ' a [ Clause < ' lcx > ] {
2112
+ & self . 0 [ ..]
2113
+ }
2114
+ }
2115
+
2116
+ impl < ' tcx : ' lcx , ' lcx > Borrow < [ Goal < ' lcx > ] >
2117
+ for Interned < ' tcx , Slice < Goal < ' tcx > > > {
2118
+ fn borrow < ' a > ( & ' a self ) -> & ' a [ Goal < ' lcx > ] {
2119
+ & self . 0 [ ..]
2120
+ }
2121
+ }
2122
+
2102
2123
macro_rules! intern_method {
2103
2124
( $lt_tcx: tt, $name: ident: $method: ident( $alloc: ty,
2104
2125
$alloc_method: ident,
@@ -2196,7 +2217,9 @@ slice_interners!(
2196
2217
existential_predicates: _intern_existential_predicates( ExistentialPredicate ) ,
2197
2218
predicates: _intern_predicates( Predicate ) ,
2198
2219
type_list: _intern_type_list( Ty ) ,
2199
- substs: _intern_substs( Kind )
2220
+ substs: _intern_substs( Kind ) ,
2221
+ clauses: _intern_clauses( Clause ) ,
2222
+ goals: _intern_goals( Goal )
2200
2223
) ;
2201
2224
2202
2225
// This isn't a perfect fit: CanonicalVarInfo slices are always
@@ -2501,6 +2524,22 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2501
2524
}
2502
2525
}
2503
2526
2527
+ pub fn intern_clauses ( self , ts : & [ Clause < ' tcx > ] ) -> & ' tcx Slice < Clause < ' tcx > > {
2528
+ if ts. len ( ) == 0 {
2529
+ Slice :: empty ( )
2530
+ } else {
2531
+ self . _intern_clauses ( ts)
2532
+ }
2533
+ }
2534
+
2535
+ pub fn intern_goals ( self , ts : & [ Goal < ' tcx > ] ) -> & ' tcx Slice < Goal < ' tcx > > {
2536
+ if ts. len ( ) == 0 {
2537
+ Slice :: empty ( )
2538
+ } else {
2539
+ self . _intern_goals ( ts)
2540
+ }
2541
+ }
2542
+
2504
2543
pub fn mk_fn_sig < I > ( self ,
2505
2544
inputs : I ,
2506
2545
output : I :: Item ,
@@ -2547,6 +2586,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
2547
2586
self . mk_substs ( iter:: once ( s) . chain ( t. into_iter ( ) . cloned ( ) ) . map ( Kind :: from) )
2548
2587
}
2549
2588
2589
+ pub fn mk_clauses < I : InternAs < [ Clause < ' tcx > ] ,
2590
+ & ' tcx Slice < Clause < ' tcx > > > > ( self , iter : I ) -> I :: Output {
2591
+ iter. intern_with ( |xs| self . intern_clauses ( xs) )
2592
+ }
2593
+
2594
+ pub fn mk_goals < I : InternAs < [ Goal < ' tcx > ] ,
2595
+ & ' tcx Slice < Goal < ' tcx > > > > ( self , iter : I ) -> I :: Output {
2596
+ iter. intern_with ( |xs| self . intern_goals ( xs) )
2597
+ }
2598
+
2599
+ pub fn mk_goal ( self , goal : Goal < ' tcx > ) -> & ' tcx Goal {
2600
+ & self . mk_goals ( iter:: once ( goal) ) [ 0 ]
2601
+ }
2602
+
2550
2603
pub fn lint_node < S : Into < MultiSpan > > ( self ,
2551
2604
lint : & ' static Lint ,
2552
2605
id : NodeId ,
0 commit comments