@@ -15,7 +15,8 @@ use rustc_mir_dataflow::{Analysis, GenKill, JoinSemiLattice};
1515use tracing:: debug;
1616
1717use crate :: region_infer:: InferredRegions ;
18- use crate :: { BorrowSet , PlaceConflictBias , PlaceExt , RegionInferenceContext , places_conflict} ;
18+ use crate :: region_infer:: values:: LivenessValues ;
19+ use crate :: { BorrowSet , PlaceConflictBias , PlaceExt , places_conflict} ;
1920
2021// This analysis is different to most others. Its results aren't computed with
2122// `iterate_to_fixpoint`, but are instead composed from the results of three sub-analyses that are
@@ -183,22 +184,19 @@ struct OutOfScopePrecomputer<'a, 'tcx> {
183184 visited : DenseBitSet < mir:: BasicBlock > ,
184185 visit_stack : Vec < mir:: BasicBlock > ,
185186 body : & ' a Body < ' tcx > ,
186- regioncx : & ' a RegionInferenceContext < ' tcx > ,
187187 borrows_out_of_scope_at_location : FxIndexMap < Location , Vec < BorrowIndex > > ,
188188}
189189
190190impl < ' tcx > OutOfScopePrecomputer < ' _ , ' tcx > {
191191 fn compute (
192192 body : & Body < ' tcx > ,
193- regioncx : & RegionInferenceContext < ' tcx > ,
194193 scc_values : & InferredRegions < ' tcx > ,
195194 borrow_set : & BorrowSet < ' tcx > ,
196195 ) -> FxIndexMap < Location , Vec < BorrowIndex > > {
197196 let mut prec = OutOfScopePrecomputer {
198197 visited : DenseBitSet :: new_empty ( body. basic_blocks . len ( ) ) ,
199198 visit_stack : vec ! [ ] ,
200199 body,
201- regioncx,
202200 borrows_out_of_scope_at_location : FxIndexMap :: default ( ) ,
203201 } ;
204202 for ( borrow_index, borrow_data) in borrow_set. iter_enumerated ( ) {
@@ -225,13 +223,9 @@ impl<'tcx> OutOfScopePrecomputer<'_, 'tcx> {
225223 let first_lo = first_location. statement_index ;
226224 let first_hi = first_bb_data. statements . len ( ) ;
227225
228- if let Some ( kill_stmt) = self . regioncx . first_non_contained_inclusive (
229- scc_values,
230- borrow_region,
231- first_block,
232- first_lo,
233- first_hi,
234- ) {
226+ if let Some ( kill_stmt) =
227+ scc_values. first_non_contained_inclusive ( borrow_region, first_block, first_lo, first_hi)
228+ {
235229 let kill_location = Location { block : first_block, statement_index : kill_stmt } ;
236230 // If region does not contain a point at the location, then add to list and skip
237231 // successor locations.
@@ -258,13 +252,9 @@ impl<'tcx> OutOfScopePrecomputer<'_, 'tcx> {
258252 while let Some ( block) = self . visit_stack . pop ( ) {
259253 let bb_data = & self . body [ block] ;
260254 let num_stmts = bb_data. statements . len ( ) ;
261- if let Some ( kill_stmt) = self . regioncx . first_non_contained_inclusive (
262- scc_values,
263- borrow_region,
264- block,
265- 0 ,
266- num_stmts,
267- ) {
255+ if let Some ( kill_stmt) =
256+ scc_values. first_non_contained_inclusive ( borrow_region, block, 0 , num_stmts)
257+ {
268258 let kill_location = Location { block, statement_index : kill_stmt } ;
269259 // If region does not contain a point at the location, then add to list and skip
270260 // successor locations.
@@ -293,26 +283,24 @@ impl<'tcx> OutOfScopePrecomputer<'_, 'tcx> {
293283// This is `pub` because it's used by unstable external borrowck data users, see `consumers.rs`.
294284pub fn calculate_borrows_out_of_scope_at_location < ' tcx > (
295285 body : & Body < ' tcx > ,
296- regioncx : & RegionInferenceContext < ' tcx > ,
297286 scc_values : & InferredRegions < ' tcx > ,
298287 borrow_set : & BorrowSet < ' tcx > ,
299288) -> FxIndexMap < Location , Vec < BorrowIndex > > {
300- OutOfScopePrecomputer :: compute ( body, regioncx , scc_values, borrow_set)
289+ OutOfScopePrecomputer :: compute ( body, scc_values, borrow_set)
301290}
302291
303292struct PoloniusOutOfScopePrecomputer < ' a , ' tcx > {
304293 visited : DenseBitSet < mir:: BasicBlock > ,
305294 visit_stack : Vec < mir:: BasicBlock > ,
306295 body : & ' a Body < ' tcx > ,
307- regioncx : & ' a RegionInferenceContext < ' tcx > ,
308-
296+ liveness_values : & ' a LivenessValues ,
309297 loans_out_of_scope_at_location : FxIndexMap < Location , Vec < BorrowIndex > > ,
310298}
311299
312300impl < ' tcx > PoloniusOutOfScopePrecomputer < ' _ , ' tcx > {
313301 fn compute (
314302 body : & Body < ' tcx > ,
315- regioncx : & RegionInferenceContext < ' tcx > ,
303+ liveness_values : & LivenessValues ,
316304 borrow_set : & BorrowSet < ' tcx > ,
317305 ) -> FxIndexMap < Location , Vec < BorrowIndex > > {
318306 // The in-tree polonius analysis computes loans going out of scope using the
@@ -321,7 +309,7 @@ impl<'tcx> PoloniusOutOfScopePrecomputer<'_, 'tcx> {
321309 visited : DenseBitSet :: new_empty ( body. basic_blocks . len ( ) ) ,
322310 visit_stack : vec ! [ ] ,
323311 body,
324- regioncx ,
312+ liveness_values ,
325313 loans_out_of_scope_at_location : FxIndexMap :: default ( ) ,
326314 } ;
327315 for ( loan_idx, loan_data) in borrow_set. iter_enumerated ( ) {
@@ -421,7 +409,8 @@ impl<'tcx> PoloniusOutOfScopePrecomputer<'_, 'tcx> {
421409 // Reachability is location-insensitive, and we could take advantage of that, by jumping
422410 // to a further point than just the next statement: we can jump to the furthest point
423411 // within the block where `r` is live.
424- if self . regioncx . is_loan_live_at ( loan_idx, location) {
412+ let point = self . liveness_values . point_from_location ( location) ;
413+ if self . liveness_values . is_loan_live_at ( loan_idx, point) {
425414 continue ;
426415 }
427416
@@ -438,15 +427,15 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
438427 pub fn new (
439428 tcx : TyCtxt < ' tcx > ,
440429 body : & ' a Body < ' tcx > ,
441- regioncx : & RegionInferenceContext < ' tcx > ,
430+ liveness_values : & ' a LivenessValues ,
442431 scc_values : & InferredRegions < ' tcx > ,
443432 borrow_set : & ' a BorrowSet < ' tcx > ,
444433 ) -> Self {
445434 let borrows_out_of_scope_at_location =
446435 if !tcx. sess . opts . unstable_opts . polonius . is_next_enabled ( ) {
447- calculate_borrows_out_of_scope_at_location ( body, regioncx , scc_values, borrow_set)
436+ calculate_borrows_out_of_scope_at_location ( body, scc_values, borrow_set)
448437 } else {
449- PoloniusOutOfScopePrecomputer :: compute ( body, regioncx , borrow_set)
438+ PoloniusOutOfScopePrecomputer :: compute ( body, liveness_values , borrow_set)
450439 } ;
451440 Borrows { tcx, body, borrow_set, borrows_out_of_scope_at_location }
452441 }
0 commit comments