@@ -131,104 +131,6 @@ struct StackEntry {
131131 lo : usize ,
132132 hi : usize ,
133133}
134-
135- struct OutOfScopePrecomputer < ' a , ' tcx > {
136- visited : BitSet < mir:: BasicBlock > ,
137- visit_stack : Vec < StackEntry > ,
138- body : & ' a Body < ' tcx > ,
139- regioncx : & ' a RegionInferenceContext < ' tcx > ,
140- borrows_out_of_scope_at_location : FxIndexMap < Location , Vec < BorrowIndex > > ,
141- }
142-
143- impl < ' a , ' tcx > OutOfScopePrecomputer < ' a , ' tcx > {
144- fn new ( body : & ' a Body < ' tcx > , regioncx : & ' a RegionInferenceContext < ' tcx > ) -> Self {
145- OutOfScopePrecomputer {
146- visited : BitSet :: new_empty ( body. basic_blocks . len ( ) ) ,
147- visit_stack : vec ! [ ] ,
148- body,
149- regioncx,
150- borrows_out_of_scope_at_location : FxIndexMap :: default ( ) ,
151- }
152- }
153- }
154-
155- impl < ' tcx > OutOfScopePrecomputer < ' _ , ' tcx > {
156- fn precompute_borrows_out_of_scope (
157- & mut self ,
158- borrow_index : BorrowIndex ,
159- borrow_region : RegionVid ,
160- first_location : Location ,
161- ) {
162- // We visit one BB at a time. The complication is that we may start in the
163- // middle of the first BB visited (the one containing `first_location`), in which
164- // case we may have to later on process the first part of that BB if there
165- // is a path back to its start.
166-
167- // For visited BBs, we record the index of the first statement processed.
168- // (In fully processed BBs this index is 0.) Note also that we add BBs to
169- // `visited` once they are added to `stack`, before they are actually
170- // processed, because this avoids the need to look them up again on
171- // completion.
172- self . visited . insert ( first_location. block ) ;
173-
174- let first_block = first_location. block ;
175- let mut first_lo = first_location. statement_index ;
176- let first_hi = self . body [ first_block] . statements . len ( ) ;
177-
178- self . visit_stack . push ( StackEntry { bb : first_block, lo : first_lo, hi : first_hi } ) ;
179-
180- ' preorder: while let Some ( StackEntry { bb, lo, hi } ) = self . visit_stack . pop ( ) {
181- if let Some ( kill_stmt) =
182- self . regioncx . first_non_contained_inclusive ( borrow_region, bb, lo, hi)
183- {
184- let kill_location = Location { block : bb, statement_index : kill_stmt } ;
185- // If region does not contain a point at the location, then add to list and skip
186- // successor locations.
187- debug ! ( "borrow {:?} gets killed at {:?}" , borrow_index, kill_location) ;
188- self . borrows_out_of_scope_at_location
189- . entry ( kill_location)
190- . or_default ( )
191- . push ( borrow_index) ;
192- continue ' preorder;
193- }
194-
195- // If we process the first part of the first basic block (i.e. we encounter that block
196- // for the second time), we no longer have to visit its successors again.
197- if bb == first_block && hi != first_hi {
198- continue ;
199- }
200-
201- // Add successor BBs to the work list, if necessary.
202- let bb_data = & self . body [ bb] ;
203- debug_assert ! ( hi == bb_data. statements. len( ) ) ;
204- for succ_bb in bb_data. terminator ( ) . successors ( ) {
205- if !self . visited . insert ( succ_bb) {
206- if succ_bb == first_block && first_lo > 0 {
207- // `succ_bb` has been seen before. If it wasn't
208- // fully processed, add its first part to `stack`
209- // for processing.
210- self . visit_stack . push ( StackEntry { bb : succ_bb, lo : 0 , hi : first_lo - 1 } ) ;
211-
212- // And update this entry with 0, to represent the
213- // whole BB being processed.
214- first_lo = 0 ;
215- }
216- } else {
217- // succ_bb hasn't been seen before. Add it to
218- // `stack` for processing.
219- self . visit_stack . push ( StackEntry {
220- bb : succ_bb,
221- lo : 0 ,
222- hi : self . body [ succ_bb] . statements . len ( ) ,
223- } ) ;
224- }
225- }
226- }
227-
228- self . visited . clear ( ) ;
229- }
230- }
231-
232134struct PoloniusOutOfScopePrecomputer < ' a , ' tcx > {
233135 visited : BitSet < mir:: BasicBlock > ,
234136 visit_stack : Vec < StackEntry > ,
@@ -455,31 +357,15 @@ pub fn calculate_borrows_out_of_scope_at_location<'tcx>(
455357 regioncx : & RegionInferenceContext < ' tcx > ,
456358 borrow_set : & BorrowSet < ' tcx > ,
457359) -> FxIndexMap < Location , Vec < BorrowIndex > > {
458- let mut prec = OutOfScopePrecomputer :: new ( body, regioncx) ;
459- for ( borrow_index , borrow_data) in borrow_set. iter_enumerated ( ) {
460- let borrow_region = borrow_data. region ;
461- let location = borrow_data. reserve_location ;
360+ let mut polonius_prec = PoloniusOutOfScopePrecomputer :: new ( body, regioncx) ;
361+ for ( loan_idx , borrow_data) in borrow_set. iter_enumerated ( ) {
362+ let issuing_region = borrow_data. region ;
363+ let issued_location = borrow_data. reserve_location ;
462364
463- prec . precompute_borrows_out_of_scope ( borrow_index , borrow_region , location ) ;
365+ polonius_prec . precompute_loans_out_of_scope ( loan_idx , issuing_region , issued_location ) ;
464366 }
465367
466- if std:: env:: var ( "POLONIUS2" ) . is_ok ( ) {
467- let mut polonius_prec = PoloniusOutOfScopePrecomputer :: new ( body, regioncx) ;
468- for ( loan_idx, borrow_data) in borrow_set. iter_enumerated ( ) {
469- let issuing_region = borrow_data. region ;
470- let issued_location = borrow_data. reserve_location ;
471-
472- polonius_prec. precompute_loans_out_of_scope ( loan_idx, issuing_region, issued_location) ;
473- }
474-
475- assert_eq ! (
476- prec. borrows_out_of_scope_at_location, polonius_prec. borrows_out_of_scope_at_location,
477- "out of scope borrows and loans differ between polonius and non-polonius mode"
478- ) ;
479- polonius_prec. borrows_out_of_scope_at_location
480- } else {
481- prec. borrows_out_of_scope_at_location
482- }
368+ polonius_prec. borrows_out_of_scope_at_location
483369}
484370
485371impl < ' a , ' tcx > Borrows < ' a , ' tcx > {
0 commit comments