@@ -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 , ConstraintCategory , Local , Location , ReadOnlyBodyAndCache } ;
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 : ReadOnlyBodyAndCache < ' _ , ' 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.
@@ -390,23 +391,26 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
390
391
}
391
392
392
393
impl LivenessContext < ' _ , ' _ , ' _ , ' tcx > {
394
+ /// Returns `true` if the local variable (or some part of it) is initialized at the current
395
+ /// cursor position. Callers should call one of the `seek` methods immediately before to point
396
+ /// the cursor to the desired location.
397
+ fn initialized_at_curr_loc ( & self , mpi : MovePathIndex ) -> bool {
398
+ let state = self . flow_inits . get ( ) ;
399
+ if state. contains ( mpi) {
400
+ return true ;
401
+ }
402
+
403
+ let move_paths = & self . flow_inits . analysis ( ) . move_data ( ) . move_paths ;
404
+ move_paths[ mpi] . find_child ( & move_paths, |mpi| state. contains ( mpi) ) . is_some ( )
405
+ }
406
+
393
407
/// Returns `true` if the local variable (or some part of it) is initialized in
394
408
/// the terminator of `block`. We need to check this to determine if a
395
409
/// DROP of some local variable will have an effect -- note that
396
410
/// drops, as they may unwind, are always terminators.
397
411
fn initialized_at_terminator ( & mut self , block : BasicBlock , mpi : MovePathIndex ) -> bool {
398
- // Compute the set of initialized paths at terminator of block
399
- // by resetting to the start of the block and then applying
400
- // the effects of all statements. This is the only way to get
401
- // "just ahead" of a terminator.
402
- self . flow_inits . reset_to_entry_of ( block) ;
403
- for statement_index in 0 ..self . body [ block] . statements . len ( ) {
404
- let location = Location { block, statement_index } ;
405
- self . flow_inits . reconstruct_statement_effect ( location) ;
406
- self . flow_inits . apply_local_effect ( location) ;
407
- }
408
-
409
- self . flow_inits . has_any_child_of ( mpi) . is_some ( )
412
+ self . flow_inits . seek_before ( self . body . terminator_loc ( block) ) ;
413
+ self . initialized_at_curr_loc ( mpi)
410
414
}
411
415
412
416
/// Returns `true` if the path `mpi` (or some part of it) is initialized at
@@ -415,8 +419,8 @@ impl LivenessContext<'_, '_, '_, 'tcx> {
415
419
/// **Warning:** Does not account for the result of `Call`
416
420
/// instructions.
417
421
fn initialized_at_exit ( & mut self , block : BasicBlock , mpi : MovePathIndex ) -> bool {
418
- self . flow_inits . reset_to_exit_of ( block) ;
419
- self . flow_inits . has_any_child_of ( mpi) . is_some ( )
422
+ self . flow_inits . seek_after ( self . body . terminator_loc ( block) ) ;
423
+ self . initialized_at_curr_loc ( mpi)
420
424
}
421
425
422
426
/// Stores the result that all regions in `value` are live for the
0 commit comments