@@ -20,13 +20,13 @@ use rustc::ty::{Region, TyCtxt};
20
20
use rustc:: ty:: RegionKind ;
21
21
use rustc:: ty:: RegionKind :: ReScope ;
22
22
23
- use rustc_data_structures:: bitslice:: { BitwiseOperator } ;
24
- use rustc_data_structures:: indexed_set:: { IdxSet } ;
25
- use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
23
+ use rustc_data_structures:: bitslice:: BitwiseOperator ;
24
+ use rustc_data_structures:: indexed_set:: IdxSet ;
25
+ use rustc_data_structures:: indexed_vec:: IndexVec ;
26
26
use rustc_data_structures:: sync:: Lrc ;
27
27
28
28
use dataflow:: { BitDenotation , BlockSets , InitialFlow } ;
29
- pub use dataflow:: indexes:: { BorrowIndex , ReserveOrActivateIndex } ;
29
+ pub use dataflow:: indexes:: BorrowIndex ;
30
30
use borrow_check:: nll:: region_infer:: RegionInferenceContext ;
31
31
use borrow_check:: nll:: ToRegionVid ;
32
32
@@ -53,21 +53,6 @@ pub struct Borrows<'a, 'gcx: 'tcx, 'tcx: 'a> {
53
53
nonlexical_regioncx : Option < Rc < RegionInferenceContext < ' tcx > > > ,
54
54
}
55
55
56
- impl ReserveOrActivateIndex {
57
- fn reserved ( i : BorrowIndex ) -> Self { ReserveOrActivateIndex :: new ( i. index ( ) * 2 ) }
58
- fn active ( i : BorrowIndex ) -> Self { ReserveOrActivateIndex :: new ( ( i. index ( ) * 2 ) + 1 ) }
59
-
60
- pub ( crate ) fn is_reservation ( self ) -> bool { self . index ( ) % 2 == 0 }
61
- pub ( crate ) fn is_activation ( self ) -> bool { self . index ( ) % 2 == 1 }
62
-
63
- pub ( crate ) fn kind ( self ) -> & ' static str {
64
- if self . is_reservation ( ) { "reserved" } else { "active" }
65
- }
66
- pub ( crate ) fn borrow_index ( self ) -> BorrowIndex {
67
- BorrowIndex :: new ( self . index ( ) / 2 )
68
- }
69
- }
70
-
71
56
impl < ' a , ' gcx , ' tcx > Borrows < ' a , ' gcx , ' tcx > {
72
57
crate fn new (
73
58
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
@@ -120,7 +105,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
120
105
/// That means either they went out of either a nonlexical scope, if we care about those
121
106
/// at the moment, or the location represents a lexical EndRegion
122
107
fn kill_loans_out_of_scope_at_location ( & self ,
123
- sets : & mut BlockSets < ReserveOrActivateIndex > ,
108
+ sets : & mut BlockSets < BorrowIndex > ,
124
109
location : Location ) {
125
110
if let Some ( ref regioncx) = self . nonlexical_regioncx {
126
111
// NOTE: The state associated with a given `location`
@@ -137,22 +122,18 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
137
122
for ( borrow_index, borrow_data) in self . borrow_set . borrows . iter_enumerated ( ) {
138
123
let borrow_region = borrow_data. region . to_region_vid ( ) ;
139
124
if !regioncx. region_contains_point ( borrow_region, location) {
140
- sets. kill ( & ReserveOrActivateIndex :: reserved ( borrow_index) ) ;
141
- sets. kill ( & ReserveOrActivateIndex :: active ( borrow_index) ) ;
125
+ sets. kill ( & borrow_index) ;
142
126
}
143
127
}
144
128
}
145
129
}
146
130
147
131
fn kill_borrows_on_local ( & self ,
148
- sets : & mut BlockSets < ReserveOrActivateIndex > ,
132
+ sets : & mut BlockSets < BorrowIndex > ,
149
133
local : & rustc:: mir:: Local )
150
134
{
151
135
if let Some ( borrow_indexes) = self . borrow_set . local_map . get ( local) {
152
- sets. kill_all ( borrow_indexes. iter ( )
153
- . map ( |b| ReserveOrActivateIndex :: reserved ( * b) ) ) ;
154
- sets. kill_all ( borrow_indexes. iter ( )
155
- . map ( |b| ReserveOrActivateIndex :: active ( * b) ) ) ;
136
+ sets. kill_all ( borrow_indexes) ;
156
137
}
157
138
}
158
139
@@ -162,45 +143,29 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
162
143
. map ( |activations| & activations[ ..] )
163
144
. unwrap_or ( & [ ] )
164
145
}
165
-
166
- /// Performs the activations for a given location
167
- fn perform_activations_at_location ( & self ,
168
- sets : & mut BlockSets < ReserveOrActivateIndex > ,
169
- location : Location ) {
170
- // Handle activations
171
- match self . borrow_set . activation_map . get ( & location) {
172
- Some ( activations) => {
173
- for activated in activations {
174
- debug ! ( "activating borrow {:?}" , activated) ;
175
- sets. gen ( & ReserveOrActivateIndex :: active ( * activated) )
176
- }
177
- }
178
- None => { }
179
- }
180
- }
181
146
}
182
147
183
148
impl < ' a , ' gcx , ' tcx > BitDenotation for Borrows < ' a , ' gcx , ' tcx > {
184
- type Idx = ReserveOrActivateIndex ;
149
+ type Idx = BorrowIndex ;
185
150
fn name ( ) -> & ' static str { "borrows" }
186
151
fn bits_per_block ( & self ) -> usize {
187
152
self . borrow_set . borrows . len ( ) * 2
188
153
}
189
154
190
- fn start_block_effect ( & self , _entry_set : & mut IdxSet < ReserveOrActivateIndex > ) {
155
+ fn start_block_effect ( & self , _entry_set : & mut IdxSet < BorrowIndex > ) {
191
156
// no borrows of code region_scopes have been taken prior to
192
157
// function execution, so this method has no effect on
193
158
// `_sets`.
194
159
}
195
160
196
161
fn before_statement_effect ( & self ,
197
- sets : & mut BlockSets < ReserveOrActivateIndex > ,
162
+ sets : & mut BlockSets < BorrowIndex > ,
198
163
location : Location ) {
199
164
debug ! ( "Borrows::before_statement_effect sets: {:?} location: {:?}" , sets, location) ;
200
165
self . kill_loans_out_of_scope_at_location ( sets, location) ;
201
166
}
202
167
203
- fn statement_effect ( & self , sets : & mut BlockSets < ReserveOrActivateIndex > , location : Location ) {
168
+ fn statement_effect ( & self , sets : & mut BlockSets < BorrowIndex > , location : Location ) {
204
169
debug ! ( "Borrows::statement_effect sets: {:?} location: {:?}" , sets, location) ;
205
170
206
171
let block = & self . mir . basic_blocks ( ) . get ( location. block ) . unwrap_or_else ( || {
@@ -210,7 +175,6 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
210
175
panic ! ( "could not find statement at location {:?}" ) ;
211
176
} ) ;
212
177
213
- self . perform_activations_at_location ( sets, location) ;
214
178
self . kill_loans_out_of_scope_at_location ( sets, location) ;
215
179
216
180
match stmt. kind {
@@ -221,8 +185,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
221
185
{
222
186
assert ! ( self . nonlexical_regioncx. is_none( ) ) ;
223
187
for idx in borrow_indexes {
224
- sets. kill ( & ReserveOrActivateIndex :: reserved ( * idx) ) ;
225
- sets. kill ( & ReserveOrActivateIndex :: active ( * idx) ) ;
188
+ sets. kill ( idx) ;
226
189
}
227
190
} else {
228
191
// (if there is no entry, then there are no borrows to be tracked)
@@ -252,14 +215,14 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
252
215
if let RegionKind :: ReEmpty = region {
253
216
// If the borrowed value dies before the borrow is used, the region for
254
217
// the borrow can be empty. Don't track the borrow in that case.
255
- sets. kill ( & ReserveOrActivateIndex :: active ( * index) ) ;
218
+ sets. kill ( & index) ;
256
219
return
257
220
}
258
221
259
222
assert ! ( self . borrow_set. region_map. get( region) . unwrap_or_else( || {
260
223
panic!( "could not find BorrowIndexs for region {:?}" , region) ;
261
224
} ) . contains( & index) ) ;
262
- sets. gen ( & ReserveOrActivateIndex :: reserved ( * index) ) ;
225
+ sets. gen ( & index) ;
263
226
264
227
// Issue #46746: Two-phase borrows handles
265
228
// stmts of form `Tmp = &mut Borrow` ...
@@ -270,7 +233,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
270
233
// e.g. `box (&mut _)`. Current
271
234
// conservative solution: force
272
235
// immediate activation here.
273
- sets. gen ( & ReserveOrActivateIndex :: active ( * index) ) ;
236
+ sets. gen ( & index) ;
274
237
}
275
238
}
276
239
}
@@ -306,21 +269,20 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
306
269
}
307
270
308
271
fn before_terminator_effect ( & self ,
309
- sets : & mut BlockSets < ReserveOrActivateIndex > ,
272
+ sets : & mut BlockSets < BorrowIndex > ,
310
273
location : Location ) {
311
274
debug ! ( "Borrows::before_terminator_effect sets: {:?} location: {:?}" , sets, location) ;
312
275
self . kill_loans_out_of_scope_at_location ( sets, location) ;
313
276
}
314
277
315
- fn terminator_effect ( & self , sets : & mut BlockSets < ReserveOrActivateIndex > , location : Location ) {
278
+ fn terminator_effect ( & self , sets : & mut BlockSets < BorrowIndex > , location : Location ) {
316
279
debug ! ( "Borrows::terminator_effect sets: {:?} location: {:?}" , sets, location) ;
317
280
318
281
let block = & self . mir . basic_blocks ( ) . get ( location. block ) . unwrap_or_else ( || {
319
282
panic ! ( "could not find block at location {:?}" , location) ;
320
283
} ) ;
321
284
322
285
let term = block. terminator ( ) ;
323
- self . perform_activations_at_location ( sets, location) ;
324
286
self . kill_loans_out_of_scope_at_location ( sets, location) ;
325
287
326
288
@@ -343,8 +305,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
343
305
if * scope != root_scope &&
344
306
self . scope_tree . is_subscope_of ( * scope, root_scope)
345
307
{
346
- sets. kill ( & ReserveOrActivateIndex :: reserved ( borrow_index) ) ;
347
- sets. kill ( & ReserveOrActivateIndex :: active ( borrow_index) ) ;
308
+ sets. kill ( & borrow_index) ;
348
309
}
349
310
}
350
311
}
@@ -365,7 +326,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
365
326
}
366
327
367
328
fn propagate_call_return ( & self ,
368
- _in_out : & mut IdxSet < ReserveOrActivateIndex > ,
329
+ _in_out : & mut IdxSet < BorrowIndex > ,
369
330
_call_bb : mir:: BasicBlock ,
370
331
_dest_bb : mir:: BasicBlock ,
371
332
_dest_place : & mir:: Place ) {
0 commit comments