@@ -24,23 +24,9 @@ use bitslice::BitSlice; // adds set_bit/get_bit to &[usize] bitvector rep.
24
24
use bitslice:: { BitwiseOperator } ;
25
25
use indexed_set:: { Idx , IdxSet } ;
26
26
27
- use std:: marker:: PhantomData ;
28
-
29
27
// Dataflow analyses are built upon some interpretation of the
30
28
// bitvectors attached to each basic block, represented via a
31
29
// zero-sized structure.
32
- //
33
- // Note on PhantomData: Each interpretation will need to instantiate
34
- // the `Bit` and `Ctxt` associated types, and in this case, those
35
- // associated types need an associated lifetime `'tcx`. The
36
- // interpretive structures are zero-sized, so they all need to carry a
37
- // `PhantomData` representing how the structures relate to the `'tcx`
38
- // lifetime.
39
- //
40
- // But, since all of the uses of `'tcx` are solely via instances of
41
- // `Ctxt` that are passed into the `BitDenotation` methods, we can
42
- // consistently use a `PhantomData` that is just a function over a
43
- // `&Ctxt` (== `&MoveData<'tcx>).
44
30
45
31
/// `MaybeInitializedLvals` tracks all l-values that might be
46
32
/// initialized upon reaching a particular point in the control flow
@@ -77,10 +63,15 @@ use std::marker::PhantomData;
77
63
/// Similarly, at a given `drop` statement, the set-intersection
78
64
/// between this data and `MaybeUninitializedLvals` yields the set of
79
65
/// l-values that would require a dynamic drop-flag at that statement.
80
- #[ derive( Debug , Default ) ]
81
66
pub struct MaybeInitializedLvals < ' a , ' tcx : ' a > {
82
- // See "Note on PhantomData" above.
83
- phantom : PhantomData < Fn ( & ' a MoveData < ' tcx > , TyCtxt < ' a , ' tcx , ' tcx > , & ' a Mir < ' tcx > ) >
67
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
68
+ mir : & ' a Mir < ' tcx > ,
69
+ }
70
+
71
+ impl < ' a , ' tcx : ' a > MaybeInitializedLvals < ' a , ' tcx > {
72
+ pub fn new ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , mir : & ' a Mir < ' tcx > ) -> Self {
73
+ MaybeInitializedLvals { tcx : tcx, mir : mir }
74
+ }
84
75
}
85
76
86
77
/// `MaybeUninitializedLvals` tracks all l-values that might be
@@ -118,10 +109,15 @@ pub struct MaybeInitializedLvals<'a, 'tcx: 'a> {
118
109
/// Similarly, at a given `drop` statement, the set-intersection
119
110
/// between this data and `MaybeInitializedLvals` yields the set of
120
111
/// l-values that would require a dynamic drop-flag at that statement.
121
- #[ derive( Debug , Default ) ]
122
112
pub struct MaybeUninitializedLvals < ' a , ' tcx : ' a > {
123
- // See "Note on PhantomData" above.
124
- phantom : PhantomData < Fn ( & ' a MoveData < ' tcx > , TyCtxt < ' a , ' tcx , ' tcx > , & ' a Mir < ' tcx > ) >
113
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
114
+ mir : & ' a Mir < ' tcx > ,
115
+ }
116
+
117
+ impl < ' a , ' tcx : ' a > MaybeUninitializedLvals < ' a , ' tcx > {
118
+ pub fn new ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , mir : & ' a Mir < ' tcx > ) -> Self {
119
+ MaybeUninitializedLvals { tcx : tcx, mir : mir }
120
+ }
125
121
}
126
122
127
123
/// `DefinitelyInitializedLvals` tracks all l-values that are definitely
@@ -165,10 +161,15 @@ pub struct MaybeUninitializedLvals<'a, 'tcx: 'a> {
165
161
/// Similarly, at a given `drop` statement, the set-difference between
166
162
/// this data and `MaybeInitializedLvals` yields the set of l-values
167
163
/// that would require a dynamic drop-flag at that statement.
168
- #[ derive( Debug , Default ) ]
169
164
pub struct DefinitelyInitializedLvals < ' a , ' tcx : ' a > {
170
- // See "Note on PhantomData" above.
171
- phantom : PhantomData < Fn ( & ' a MoveData < ' tcx > , TyCtxt < ' a , ' tcx , ' tcx > , & ' a Mir < ' tcx > ) >
165
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
166
+ mir : & ' a Mir < ' tcx > ,
167
+ }
168
+
169
+ impl < ' a , ' tcx : ' a > DefinitelyInitializedLvals < ' a , ' tcx > {
170
+ pub fn new ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , mir : & ' a Mir < ' tcx > ) -> Self {
171
+ DefinitelyInitializedLvals { tcx : tcx, mir : mir }
172
+ }
172
173
}
173
174
174
175
/// `MovingOutStatements` tracks the statements that perform moves out
@@ -184,10 +185,10 @@ pub struct DefinitelyInitializedLvals<'a, 'tcx: 'a> {
184
185
/// control flow. But `MovingOutStatements` also includes the added
185
186
/// data of *which* particular statement causing the deinitialization
186
187
/// that the borrow checker's error meessage may need to report.
187
- #[ derive ( Debug , Default ) ]
188
+ #[ allow ( dead_code ) ]
188
189
pub struct MovingOutStatements < ' a , ' tcx : ' a > {
189
- // See "Note on PhantomData" above.
190
- phantom : PhantomData < Fn ( & ' a MoveData < ' tcx > , TyCtxt < ' a , ' tcx , ' tcx > , & ' a Mir < ' tcx > ) >
190
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
191
+ mir : & ' a Mir < ' tcx > ,
191
192
}
192
193
193
194
impl < ' a , ' tcx > MaybeInitializedLvals < ' a , ' tcx > {
@@ -226,18 +227,18 @@ impl<'a, 'tcx> DefinitelyInitializedLvals<'a, 'tcx> {
226
227
impl < ' a , ' tcx > BitDenotation for MaybeInitializedLvals < ' a , ' tcx > {
227
228
type Idx = MovePathIndex ;
228
229
type Bit = MovePath < ' tcx > ;
229
- type Ctxt = ( TyCtxt < ' a , ' tcx , ' tcx > , & ' a Mir < ' tcx > , MoveData < ' tcx > ) ;
230
+ type Ctxt = MoveData < ' tcx > ;
230
231
fn name ( ) -> & ' static str { "maybe_init" }
231
232
fn bits_per_block ( & self , ctxt : & Self :: Ctxt ) -> usize {
232
- ctxt. 2 . move_paths . len ( )
233
+ ctxt. move_paths . len ( )
233
234
}
234
235
fn interpret < ' c > ( & self , ctxt : & ' c Self :: Ctxt , idx : usize ) -> & ' c Self :: Bit {
235
- & ctxt. 2 . move_paths [ MovePathIndex :: new ( idx) ]
236
+ & ctxt. move_paths [ MovePathIndex :: new ( idx) ]
236
237
}
237
238
fn start_block_effect ( & self , ctxt : & Self :: Ctxt , sets : & mut BlockSets < MovePathIndex > )
238
239
{
239
240
drop_flag_effects_for_function_entry (
240
- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
241
+ self . tcx , self . mir , ctxt,
241
242
|path, s| {
242
243
assert ! ( s == DropFlagState :: Present ) ;
243
244
sets. on_entry . add ( & path) ;
@@ -251,7 +252,7 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
251
252
idx : usize )
252
253
{
253
254
drop_flag_effects_for_location (
254
- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
255
+ self . tcx , self . mir , ctxt,
255
256
Location { block : bb, index : idx } ,
256
257
|path, s| Self :: update_bits ( sets, path, s)
257
258
)
@@ -264,7 +265,7 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
264
265
statements_len : usize )
265
266
{
266
267
drop_flag_effects_for_location (
267
- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
268
+ self . tcx , self . mir , ctxt,
268
269
Location { block : bb, index : statements_len } ,
269
270
|path, s| Self :: update_bits ( sets, path, s)
270
271
)
@@ -278,9 +279,8 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
278
279
dest_lval : & repr:: Lvalue ) {
279
280
// when a call returns successfully, that means we need to set
280
281
// the bits for that dest_lval to 1 (initialized).
281
- let move_data = & ctxt. 2 ;
282
- let move_path_index = move_data. rev_lookup . find ( dest_lval) ;
283
- on_all_children_bits ( ctxt. 0 , ctxt. 1 , & ctxt. 2 ,
282
+ let move_path_index = ctxt. rev_lookup . find ( dest_lval) ;
283
+ on_all_children_bits ( self . tcx , self . mir , ctxt,
284
284
move_path_index,
285
285
|mpi| { in_out. add ( & mpi) ; } ) ;
286
286
}
@@ -289,13 +289,13 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
289
289
impl < ' a , ' tcx > BitDenotation for MaybeUninitializedLvals < ' a , ' tcx > {
290
290
type Idx = MovePathIndex ;
291
291
type Bit = MovePath < ' tcx > ;
292
- type Ctxt = ( TyCtxt < ' a , ' tcx , ' tcx > , & ' a Mir < ' tcx > , MoveData < ' tcx > ) ;
292
+ type Ctxt = MoveData < ' tcx > ;
293
293
fn name ( ) -> & ' static str { "maybe_uninit" }
294
294
fn bits_per_block ( & self , ctxt : & Self :: Ctxt ) -> usize {
295
- ctxt. 2 . move_paths . len ( )
295
+ ctxt. move_paths . len ( )
296
296
}
297
297
fn interpret < ' c > ( & self , ctxt : & ' c Self :: Ctxt , idx : usize ) -> & ' c Self :: Bit {
298
- & ctxt. 2 . move_paths [ MovePathIndex :: new ( idx) ]
298
+ & ctxt. move_paths [ MovePathIndex :: new ( idx) ]
299
299
}
300
300
301
301
// sets on_entry bits for Arg lvalues
@@ -304,7 +304,7 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
304
304
for e in sets. on_entry . words_mut ( ) { * e = !0 ; }
305
305
306
306
drop_flag_effects_for_function_entry (
307
- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
307
+ self . tcx , self . mir , ctxt,
308
308
|path, s| {
309
309
assert ! ( s == DropFlagState :: Present ) ;
310
310
sets. on_entry . remove ( & path) ;
@@ -318,7 +318,7 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
318
318
idx : usize )
319
319
{
320
320
drop_flag_effects_for_location (
321
- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
321
+ self . tcx , self . mir , ctxt,
322
322
Location { block : bb, index : idx } ,
323
323
|path, s| Self :: update_bits ( sets, path, s)
324
324
)
@@ -331,7 +331,7 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
331
331
statements_len : usize )
332
332
{
333
333
drop_flag_effects_for_location (
334
- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
334
+ self . tcx , self . mir , ctxt,
335
335
Location { block : bb, index : statements_len } ,
336
336
|path, s| Self :: update_bits ( sets, path, s)
337
337
)
@@ -345,8 +345,8 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
345
345
dest_lval : & repr:: Lvalue ) {
346
346
// when a call returns successfully, that means we need to set
347
347
// the bits for that dest_lval to 1 (initialized).
348
- let move_path_index = ctxt. 2 . rev_lookup . find ( dest_lval) ;
349
- on_all_children_bits ( ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
348
+ let move_path_index = ctxt. rev_lookup . find ( dest_lval) ;
349
+ on_all_children_bits ( self . tcx , self . mir , ctxt,
350
350
move_path_index,
351
351
|mpi| { in_out. remove ( & mpi) ; } ) ;
352
352
}
@@ -355,21 +355,21 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
355
355
impl < ' a , ' tcx > BitDenotation for DefinitelyInitializedLvals < ' a , ' tcx > {
356
356
type Idx = MovePathIndex ;
357
357
type Bit = MovePath < ' tcx > ;
358
- type Ctxt = ( TyCtxt < ' a , ' tcx , ' tcx > , & ' a Mir < ' tcx > , MoveData < ' tcx > ) ;
358
+ type Ctxt = MoveData < ' tcx > ;
359
359
fn name ( ) -> & ' static str { "definite_init" }
360
360
fn bits_per_block ( & self , ctxt : & Self :: Ctxt ) -> usize {
361
- ctxt. 2 . move_paths . len ( )
361
+ ctxt. move_paths . len ( )
362
362
}
363
363
fn interpret < ' c > ( & self , ctxt : & ' c Self :: Ctxt , idx : usize ) -> & ' c Self :: Bit {
364
- & ctxt. 2 . move_paths [ MovePathIndex :: new ( idx) ]
364
+ & ctxt. move_paths [ MovePathIndex :: new ( idx) ]
365
365
}
366
366
367
367
// sets on_entry bits for Arg lvalues
368
368
fn start_block_effect ( & self , ctxt : & Self :: Ctxt , sets : & mut BlockSets < MovePathIndex > ) {
369
369
for e in sets. on_entry . words_mut ( ) { * e = 0 ; }
370
370
371
371
drop_flag_effects_for_function_entry (
372
- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
372
+ self . tcx , self . mir , ctxt,
373
373
|path, s| {
374
374
assert ! ( s == DropFlagState :: Present ) ;
375
375
sets. on_entry . add ( & path) ;
@@ -383,7 +383,7 @@ impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
383
383
idx : usize )
384
384
{
385
385
drop_flag_effects_for_location (
386
- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
386
+ self . tcx , self . mir , ctxt,
387
387
Location { block : bb, index : idx } ,
388
388
|path, s| Self :: update_bits ( sets, path, s)
389
389
)
@@ -396,7 +396,7 @@ impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
396
396
statements_len : usize )
397
397
{
398
398
drop_flag_effects_for_location (
399
- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
399
+ self . tcx , self . mir , ctxt,
400
400
Location { block : bb, index : statements_len } ,
401
401
|path, s| Self :: update_bits ( sets, path, s)
402
402
)
@@ -410,8 +410,8 @@ impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
410
410
dest_lval : & repr:: Lvalue ) {
411
411
// when a call returns successfully, that means we need to set
412
412
// the bits for that dest_lval to 1 (initialized).
413
- let move_path_index = ctxt. 2 . rev_lookup . find ( dest_lval) ;
414
- on_all_children_bits ( ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
413
+ let move_path_index = ctxt. rev_lookup . find ( dest_lval) ;
414
+ on_all_children_bits ( self . tcx , self . mir , ctxt,
415
415
move_path_index,
416
416
|mpi| { in_out. add ( & mpi) ; } ) ;
417
417
}
@@ -420,13 +420,13 @@ impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
420
420
impl < ' a , ' tcx > BitDenotation for MovingOutStatements < ' a , ' tcx > {
421
421
type Idx = MoveOutIndex ;
422
422
type Bit = MoveOut ;
423
- type Ctxt = ( TyCtxt < ' a , ' tcx , ' tcx > , & ' a Mir < ' tcx > , MoveData < ' tcx > ) ;
423
+ type Ctxt = MoveData < ' tcx > ;
424
424
fn name ( ) -> & ' static str { "moving_out" }
425
425
fn bits_per_block ( & self , ctxt : & Self :: Ctxt ) -> usize {
426
- ctxt. 2 . moves . len ( )
426
+ ctxt. moves . len ( )
427
427
}
428
428
fn interpret < ' c > ( & self , ctxt : & ' c Self :: Ctxt , idx : usize ) -> & ' c Self :: Bit {
429
- & ctxt. 2 . moves [ idx]
429
+ & ctxt. moves [ idx]
430
430
}
431
431
fn start_block_effect ( & self , _move_data : & Self :: Ctxt , _sets : & mut BlockSets < MoveOutIndex > ) {
432
432
// no move-statements have been executed prior to function
@@ -437,7 +437,7 @@ impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> {
437
437
sets : & mut BlockSets < MoveOutIndex > ,
438
438
bb : repr:: BasicBlock ,
439
439
idx : usize ) {
440
- let & ( tcx, mir, ref move_data) = ctxt;
440
+ let ( tcx, mir, move_data) = ( self . tcx , self . mir , ctxt) ;
441
441
let stmt = & mir. basic_block_data ( bb) . statements [ idx] ;
442
442
let loc_map = & move_data. loc_map ;
443
443
let path_map = & move_data. path_map ;
@@ -477,7 +477,7 @@ impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> {
477
477
bb : repr:: BasicBlock ,
478
478
statements_len : usize )
479
479
{
480
- let & ( _tcx , mir, ref move_data) = ctxt;
480
+ let ( mir, move_data) = ( self . mir , ctxt) ;
481
481
let term = mir. basic_block_data ( bb) . terminator . as_ref ( ) . unwrap ( ) ;
482
482
let loc_map = & move_data. loc_map ;
483
483
let loc = Location { block : bb, index : statements_len } ;
@@ -496,13 +496,13 @@ impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> {
496
496
_call_bb : repr:: BasicBlock ,
497
497
_dest_bb : repr:: BasicBlock ,
498
498
dest_lval : & repr:: Lvalue ) {
499
- let move_data = & ctxt. 2 ;
499
+ let move_data = ctxt;
500
500
let move_path_index = move_data. rev_lookup . find ( dest_lval) ;
501
501
let bits_per_block = self . bits_per_block ( ctxt) ;
502
502
503
503
let path_map = & move_data. path_map ;
504
- on_all_children_bits ( ctxt . 0 ,
505
- ctxt . 1 ,
504
+ on_all_children_bits ( self . tcx ,
505
+ self . mir ,
506
506
move_data,
507
507
move_path_index,
508
508
|mpi| for moi in & path_map[ mpi] {
0 commit comments