@@ -39,17 +39,15 @@ use crate::type_check::{NormalizeLocation, TypeChecker};
39
39
/// this respects `#[may_dangle]` annotations).
40
40
pub ( super ) fn trace < ' a , ' tcx > (
41
41
typeck : & mut TypeChecker < ' _ , ' tcx > ,
42
- body : & Body < ' tcx > ,
43
42
location_map : & DenseLocationMap ,
44
43
flow_inits : ResultsCursor < ' a , ' tcx , MaybeInitializedPlaces < ' a , ' tcx > > ,
45
44
move_data : & MoveData < ' tcx > ,
46
45
relevant_live_locals : Vec < Local > ,
47
46
boring_locals : Vec < Local > ,
48
47
) {
49
- let local_use_map = & LocalUseMap :: build ( & relevant_live_locals, location_map, body) ;
48
+ let local_use_map = & LocalUseMap :: build ( & relevant_live_locals, location_map, typeck . body ) ;
50
49
let cx = LivenessContext {
51
50
typeck,
52
- body,
53
51
flow_inits,
54
52
location_map,
55
53
local_use_map,
@@ -69,14 +67,13 @@ pub(super) fn trace<'a, 'tcx>(
69
67
/// Contextual state for the type-liveness coroutine.
70
68
struct LivenessContext < ' a , ' typeck , ' b , ' tcx > {
71
69
/// Current type-checker, giving us our inference context etc.
70
+ ///
71
+ /// This also stores the body we're currently analyzing.
72
72
typeck : & ' a mut TypeChecker < ' typeck , ' tcx > ,
73
73
74
74
/// Defines the `PointIndex` mapping
75
75
location_map : & ' a DenseLocationMap ,
76
76
77
- /// MIR we are analyzing.
78
- body : & ' a Body < ' tcx > ,
79
-
80
77
/// Mapping to/from the various indices used for initialization tracking.
81
78
move_data : & ' a MoveData < ' tcx > ,
82
79
@@ -139,7 +136,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
139
136
self . compute_use_live_points_for ( local) ;
140
137
self . compute_drop_live_points_for ( local) ;
141
138
142
- let local_ty = self . cx . body . local_decls [ local] . ty ;
139
+ let local_ty = self . cx . body ( ) . local_decls [ local] . ty ;
143
140
144
141
if !self . use_live_at . is_empty ( ) {
145
142
self . cx . add_use_live_facts_for ( local_ty, & self . use_live_at ) ;
@@ -164,16 +161,16 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
164
161
/// and can therefore safely be dropped.
165
162
fn dropck_boring_locals ( & mut self , boring_locals : Vec < Local > ) {
166
163
for local in boring_locals {
167
- let local_ty = self . cx . body . local_decls [ local] . ty ;
168
- let local_span = self . cx . body . local_decls [ local] . source_info . span ;
164
+ let local_ty = self . cx . body ( ) . local_decls [ local] . ty ;
165
+ let local_span = self . cx . body ( ) . local_decls [ local] . source_info . span ;
169
166
let drop_data = self . cx . drop_data . entry ( local_ty) . or_insert_with ( {
170
167
let typeck = & self . cx . typeck ;
171
168
move || LivenessContext :: compute_drop_data ( typeck, local_ty, local_span)
172
169
} ) ;
173
170
174
171
drop_data. dropck_result . report_overflows (
175
172
self . cx . typeck . infcx . tcx ,
176
- self . cx . body . local_decls [ local] . source_info . span ,
173
+ self . cx . typeck . body . local_decls [ local] . source_info . span ,
177
174
local_ty,
178
175
) ;
179
176
}
@@ -202,7 +199,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
202
199
. var_dropped_at
203
200
. iter ( )
204
201
. filter_map ( |& ( local, location_index) | {
205
- let local_ty = self . cx . body . local_decls [ local] . ty ;
202
+ let local_ty = self . cx . body ( ) . local_decls [ local] . ty ;
206
203
if relevant_live_locals. contains ( & local) || !local_ty. has_free_regions ( ) {
207
204
return None ;
208
205
}
@@ -278,9 +275,9 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
278
275
279
276
let block = self . cx . location_map . to_location ( block_start) . block ;
280
277
self . stack . extend (
281
- self . cx . body . basic_blocks . predecessors ( ) [ block]
278
+ self . cx . body ( ) . basic_blocks . predecessors ( ) [ block]
282
279
. iter ( )
283
- . map ( |& pred_bb| self . cx . body . terminator_loc ( pred_bb) )
280
+ . map ( |& pred_bb| self . cx . body ( ) . terminator_loc ( pred_bb) )
284
281
. map ( |pred_loc| self . cx . location_map . point_from_location ( pred_loc) ) ,
285
282
) ;
286
283
}
@@ -305,7 +302,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
305
302
// Find the drops where `local` is initialized.
306
303
for drop_point in self . cx . local_use_map . drops ( local) {
307
304
let location = self . cx . location_map . to_location ( drop_point) ;
308
- debug_assert_eq ! ( self . cx. body. terminator_loc( location. block) , location, ) ;
305
+ debug_assert_eq ! ( self . cx. body( ) . terminator_loc( location. block) , location, ) ;
309
306
310
307
if self . cx . initialized_at_terminator ( location. block , mpi)
311
308
&& self . drop_live_at . insert ( drop_point)
@@ -351,7 +348,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
351
348
// block. One of them may be either a definition or use
352
349
// live point.
353
350
let term_location = self . cx . location_map . to_location ( term_point) ;
354
- debug_assert_eq ! ( self . cx. body. terminator_loc( term_location. block) , term_location, ) ;
351
+ debug_assert_eq ! ( self . cx. body( ) . terminator_loc( term_location. block) , term_location, ) ;
355
352
let block = term_location. block ;
356
353
let entry_point = self . cx . location_map . entry_point ( term_location. block ) ;
357
354
for p in ( entry_point..term_point) . rev ( ) {
@@ -376,7 +373,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
376
373
}
377
374
}
378
375
379
- let body = self . cx . body ;
376
+ let body = self . cx . typeck . body ;
380
377
for & pred_block in body. basic_blocks . predecessors ( ) [ block] . iter ( ) {
381
378
debug ! ( "compute_drop_live_points_for_block: pred_block = {:?}" , pred_block, ) ;
382
379
@@ -403,7 +400,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
403
400
continue ;
404
401
}
405
402
406
- let pred_term_loc = self . cx . body . terminator_loc ( pred_block) ;
403
+ let pred_term_loc = self . cx . body ( ) . terminator_loc ( pred_block) ;
407
404
let pred_term_point = self . cx . location_map . point_from_location ( pred_term_loc) ;
408
405
409
406
// If the terminator of this predecessor either *assigns*
@@ -463,6 +460,9 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
463
460
}
464
461
465
462
impl < ' tcx > LivenessContext < ' _ , ' _ , ' _ , ' tcx > {
463
+ fn body ( & self ) -> & Body < ' tcx > {
464
+ self . typeck . body
465
+ }
466
466
/// Returns `true` if the local variable (or some part of it) is initialized at the current
467
467
/// cursor position. Callers should call one of the `seek` methods immediately before to point
468
468
/// the cursor to the desired location.
@@ -481,7 +481,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
481
481
/// DROP of some local variable will have an effect -- note that
482
482
/// drops, as they may unwind, are always terminators.
483
483
fn initialized_at_terminator ( & mut self , block : BasicBlock , mpi : MovePathIndex ) -> bool {
484
- self . flow_inits . seek_before_primary_effect ( self . body . terminator_loc ( block) ) ;
484
+ self . flow_inits . seek_before_primary_effect ( self . body ( ) . terminator_loc ( block) ) ;
485
485
self . initialized_at_curr_loc ( mpi)
486
486
}
487
487
@@ -491,7 +491,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
491
491
/// **Warning:** Does not account for the result of `Call`
492
492
/// instructions.
493
493
fn initialized_at_exit ( & mut self , block : BasicBlock , mpi : MovePathIndex ) -> bool {
494
- self . flow_inits . seek_after_primary_effect ( self . body . terminator_loc ( block) ) ;
494
+ self . flow_inits . seek_after_primary_effect ( self . body ( ) . terminator_loc ( block) ) ;
495
495
self . initialized_at_curr_loc ( mpi)
496
496
}
497
497
@@ -526,7 +526,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
526
526
values:: pretty_print_points( self . location_map, live_at. iter( ) ) ,
527
527
) ;
528
528
529
- let local_span = self . body . local_decls ( ) [ dropped_local] . source_info . span ;
529
+ let local_span = self . body ( ) . local_decls ( ) [ dropped_local] . source_info . span ;
530
530
let drop_data = self . drop_data . entry ( dropped_ty) . or_insert_with ( {
531
531
let typeck = & self . typeck ;
532
532
move || Self :: compute_drop_data ( typeck, dropped_ty, local_span)
@@ -544,7 +544,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
544
544
545
545
drop_data. dropck_result . report_overflows (
546
546
self . typeck . infcx . tcx ,
547
- self . body . source_info ( * drop_locations. first ( ) . unwrap ( ) ) . span ,
547
+ self . typeck . body . source_info ( * drop_locations. first ( ) . unwrap ( ) ) . span ,
548
548
dropped_ty,
549
549
) ;
550
550
0 commit comments