@@ -3,9 +3,10 @@ use crate::borrow_check::nll::type_check::liveness::local_use_map::LocalUseMap;
3
3
use crate :: borrow_check:: nll:: type_check:: liveness:: polonius;
4
4
use crate :: borrow_check:: nll:: type_check:: NormalizeLocation ;
5
5
use crate :: borrow_check:: nll:: type_check:: TypeChecker ;
6
+ use crate :: dataflow:: generic:: ResultsCursor ;
6
7
use crate :: dataflow:: indexes:: MovePathIndex ;
7
- use crate :: dataflow:: move_paths:: MoveData ;
8
- use crate :: dataflow:: { FlowAtLocation , FlowsAtLocation , MaybeInitializedPlaces } ;
8
+ use crate :: dataflow:: move_paths:: { HasMoveData , MoveData } ;
9
+ use crate :: dataflow:: MaybeInitializedPlaces ;
9
10
use rustc:: infer:: canonical:: QueryRegionConstraints ;
10
11
use rustc:: mir:: { BasicBlock , Body , ConstraintCategory , Local , Location } ;
11
12
use rustc:: traits:: query:: dropck_outlives:: DropckOutlivesResult ;
@@ -34,7 +35,7 @@ pub(super) fn trace(
34
35
typeck : & mut TypeChecker < ' _ , ' tcx > ,
35
36
body : & Body < ' tcx > ,
36
37
elements : & Rc < RegionValueElements > ,
37
- flow_inits : & mut FlowAtLocation < ' tcx , MaybeInitializedPlaces < ' _ , ' tcx > > ,
38
+ flow_inits : & mut ResultsCursor < ' mir , ' tcx , MaybeInitializedPlaces < ' mir , ' tcx > > ,
38
39
move_data : & MoveData < ' tcx > ,
39
40
live_locals : Vec < Local > ,
40
41
polonius_drop_used : Option < Vec < ( Local , Location ) > > ,
@@ -81,7 +82,7 @@ struct LivenessContext<'me, 'typeck, 'flow, 'tcx> {
81
82
82
83
/// Results of dataflow tracking which variables (and paths) have been
83
84
/// initialized.
84
- flow_inits : & ' me mut FlowAtLocation < ' tcx , MaybeInitializedPlaces < ' flow , ' tcx > > ,
85
+ flow_inits : & ' me mut ResultsCursor < ' flow , ' tcx , MaybeInitializedPlaces < ' flow , ' tcx > > ,
85
86
86
87
/// Index indicating where each variable is assigned, used, or
87
88
/// dropped.
@@ -389,23 +390,26 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
389
390
}
390
391
391
392
impl LivenessContext < ' _ , ' _ , ' _ , ' tcx > {
393
+ /// Returns `true` if the local variable (or some part of it) is initialized at the current
394
+ /// cursor position. Callers should call one of the `seek` methods immediately before to point
395
+ /// the cursor to the desired location.
396
+ fn initialized_at_curr_loc ( & self , mpi : MovePathIndex ) -> bool {
397
+ let state = self . flow_inits . get ( ) ;
398
+ if state. contains ( mpi) {
399
+ return true ;
400
+ }
401
+
402
+ let move_paths = & self . flow_inits . analysis ( ) . move_data ( ) . move_paths ;
403
+ move_paths[ mpi] . find_child ( & move_paths, |mpi| state. contains ( mpi) ) . is_some ( )
404
+ }
405
+
392
406
/// Returns `true` if the local variable (or some part of it) is initialized in
393
407
/// the terminator of `block`. We need to check this to determine if a
394
408
/// DROP of some local variable will have an effect -- note that
395
409
/// drops, as they may unwind, are always terminators.
396
410
fn initialized_at_terminator ( & mut self , block : BasicBlock , mpi : MovePathIndex ) -> bool {
397
- // Compute the set of initialized paths at terminator of block
398
- // by resetting to the start of the block and then applying
399
- // the effects of all statements. This is the only way to get
400
- // "just ahead" of a terminator.
401
- self . flow_inits . reset_to_entry_of ( block) ;
402
- for statement_index in 0 ..self . body [ block] . statements . len ( ) {
403
- let location = Location { block, statement_index } ;
404
- self . flow_inits . reconstruct_statement_effect ( location) ;
405
- self . flow_inits . apply_local_effect ( location) ;
406
- }
407
-
408
- self . flow_inits . has_any_child_of ( mpi) . is_some ( )
411
+ self . flow_inits . seek_before ( self . body . terminator_loc ( block) ) ;
412
+ self . initialized_at_curr_loc ( mpi)
409
413
}
410
414
411
415
/// Returns `true` if the path `mpi` (or some part of it) is initialized at
@@ -414,8 +418,8 @@ impl LivenessContext<'_, '_, '_, 'tcx> {
414
418
/// **Warning:** Does not account for the result of `Call`
415
419
/// instructions.
416
420
fn initialized_at_exit ( & mut self , block : BasicBlock , mpi : MovePathIndex ) -> bool {
417
- self . flow_inits . reset_to_exit_of ( block) ;
418
- self . flow_inits . has_any_child_of ( mpi) . is_some ( )
421
+ self . flow_inits . seek_after ( self . body . terminator_loc ( block) ) ;
422
+ self . initialized_at_curr_loc ( mpi)
419
423
}
420
424
421
425
/// Stores the result that all regions in `value` are live for the
0 commit comments