@@ -24,23 +24,9 @@ use bitslice::BitSlice; // adds set_bit/get_bit to &[usize] bitvector rep.
2424use bitslice:: { BitwiseOperator } ;
2525use indexed_set:: { Idx , IdxSet } ;
2626
27- use std:: marker:: PhantomData ;
28-
2927// Dataflow analyses are built upon some interpretation of the
3028// bitvectors attached to each basic block, represented via a
3129// 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>).
4430
4531/// `MaybeInitializedLvals` tracks all l-values that might be
4632/// initialized upon reaching a particular point in the control flow
@@ -77,10 +63,15 @@ use std::marker::PhantomData;
7763/// Similarly, at a given `drop` statement, the set-intersection
7864/// between this data and `MaybeUninitializedLvals` yields the set of
7965/// l-values that would require a dynamic drop-flag at that statement.
80- #[ derive( Debug , Default ) ]
8166pub 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+ }
8475}
8576
8677/// `MaybeUninitializedLvals` tracks all l-values that might be
@@ -118,10 +109,15 @@ pub struct MaybeInitializedLvals<'a, 'tcx: 'a> {
118109/// Similarly, at a given `drop` statement, the set-intersection
119110/// between this data and `MaybeInitializedLvals` yields the set of
120111/// l-values that would require a dynamic drop-flag at that statement.
121- #[ derive( Debug , Default ) ]
122112pub 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+ }
125121}
126122
127123/// `DefinitelyInitializedLvals` tracks all l-values that are definitely
@@ -165,10 +161,15 @@ pub struct MaybeUninitializedLvals<'a, 'tcx: 'a> {
165161/// Similarly, at a given `drop` statement, the set-difference between
166162/// this data and `MaybeInitializedLvals` yields the set of l-values
167163/// that would require a dynamic drop-flag at that statement.
168- #[ derive( Debug , Default ) ]
169164pub 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+ }
172173}
173174
174175/// `MovingOutStatements` tracks the statements that perform moves out
@@ -184,10 +185,10 @@ pub struct DefinitelyInitializedLvals<'a, 'tcx: 'a> {
184185/// control flow. But `MovingOutStatements` also includes the added
185186/// data of *which* particular statement causing the deinitialization
186187/// that the borrow checker's error meessage may need to report.
187- #[ derive ( Debug , Default ) ]
188+ #[ allow ( dead_code ) ]
188189pub 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 > ,
191192}
192193
193194impl < ' a , ' tcx > MaybeInitializedLvals < ' a , ' tcx > {
@@ -226,18 +227,18 @@ impl<'a, 'tcx> DefinitelyInitializedLvals<'a, 'tcx> {
226227impl < ' a , ' tcx > BitDenotation for MaybeInitializedLvals < ' a , ' tcx > {
227228 type Idx = MovePathIndex ;
228229 type Bit = MovePath < ' tcx > ;
229- type Ctxt = ( TyCtxt < ' a , ' tcx , ' tcx > , & ' a Mir < ' tcx > , MoveData < ' tcx > ) ;
230+ type Ctxt = MoveData < ' tcx > ;
230231 fn name ( ) -> & ' static str { "maybe_init" }
231232 fn bits_per_block ( & self , ctxt : & Self :: Ctxt ) -> usize {
232- ctxt. 2 . move_paths . len ( )
233+ ctxt. move_paths . len ( )
233234 }
234235 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) ]
236237 }
237238 fn start_block_effect ( & self , ctxt : & Self :: Ctxt , sets : & mut BlockSets < MovePathIndex > )
238239 {
239240 drop_flag_effects_for_function_entry (
240- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
241+ self . tcx , self . mir , ctxt,
241242 |path, s| {
242243 assert ! ( s == DropFlagState :: Present ) ;
243244 sets. on_entry . add ( & path) ;
@@ -251,7 +252,7 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
251252 idx : usize )
252253 {
253254 drop_flag_effects_for_location (
254- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
255+ self . tcx , self . mir , ctxt,
255256 Location { block : bb, index : idx } ,
256257 |path, s| Self :: update_bits ( sets, path, s)
257258 )
@@ -264,7 +265,7 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
264265 statements_len : usize )
265266 {
266267 drop_flag_effects_for_location (
267- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
268+ self . tcx , self . mir , ctxt,
268269 Location { block : bb, index : statements_len } ,
269270 |path, s| Self :: update_bits ( sets, path, s)
270271 )
@@ -278,9 +279,8 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
278279 dest_lval : & repr:: Lvalue ) {
279280 // when a call returns successfully, that means we need to set
280281 // 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,
284284 move_path_index,
285285 |mpi| { in_out. add ( & mpi) ; } ) ;
286286 }
@@ -289,13 +289,13 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
289289impl < ' a , ' tcx > BitDenotation for MaybeUninitializedLvals < ' a , ' tcx > {
290290 type Idx = MovePathIndex ;
291291 type Bit = MovePath < ' tcx > ;
292- type Ctxt = ( TyCtxt < ' a , ' tcx , ' tcx > , & ' a Mir < ' tcx > , MoveData < ' tcx > ) ;
292+ type Ctxt = MoveData < ' tcx > ;
293293 fn name ( ) -> & ' static str { "maybe_uninit" }
294294 fn bits_per_block ( & self , ctxt : & Self :: Ctxt ) -> usize {
295- ctxt. 2 . move_paths . len ( )
295+ ctxt. move_paths . len ( )
296296 }
297297 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) ]
299299 }
300300
301301 // sets on_entry bits for Arg lvalues
@@ -304,7 +304,7 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
304304 for e in sets. on_entry . words_mut ( ) { * e = !0 ; }
305305
306306 drop_flag_effects_for_function_entry (
307- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
307+ self . tcx , self . mir , ctxt,
308308 |path, s| {
309309 assert ! ( s == DropFlagState :: Present ) ;
310310 sets. on_entry . remove ( & path) ;
@@ -318,7 +318,7 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
318318 idx : usize )
319319 {
320320 drop_flag_effects_for_location (
321- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
321+ self . tcx , self . mir , ctxt,
322322 Location { block : bb, index : idx } ,
323323 |path, s| Self :: update_bits ( sets, path, s)
324324 )
@@ -331,7 +331,7 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
331331 statements_len : usize )
332332 {
333333 drop_flag_effects_for_location (
334- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
334+ self . tcx , self . mir , ctxt,
335335 Location { block : bb, index : statements_len } ,
336336 |path, s| Self :: update_bits ( sets, path, s)
337337 )
@@ -345,8 +345,8 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
345345 dest_lval : & repr:: Lvalue ) {
346346 // when a call returns successfully, that means we need to set
347347 // 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,
350350 move_path_index,
351351 |mpi| { in_out. remove ( & mpi) ; } ) ;
352352 }
@@ -355,21 +355,21 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
355355impl < ' a , ' tcx > BitDenotation for DefinitelyInitializedLvals < ' a , ' tcx > {
356356 type Idx = MovePathIndex ;
357357 type Bit = MovePath < ' tcx > ;
358- type Ctxt = ( TyCtxt < ' a , ' tcx , ' tcx > , & ' a Mir < ' tcx > , MoveData < ' tcx > ) ;
358+ type Ctxt = MoveData < ' tcx > ;
359359 fn name ( ) -> & ' static str { "definite_init" }
360360 fn bits_per_block ( & self , ctxt : & Self :: Ctxt ) -> usize {
361- ctxt. 2 . move_paths . len ( )
361+ ctxt. move_paths . len ( )
362362 }
363363 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) ]
365365 }
366366
367367 // sets on_entry bits for Arg lvalues
368368 fn start_block_effect ( & self , ctxt : & Self :: Ctxt , sets : & mut BlockSets < MovePathIndex > ) {
369369 for e in sets. on_entry . words_mut ( ) { * e = 0 ; }
370370
371371 drop_flag_effects_for_function_entry (
372- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
372+ self . tcx , self . mir , ctxt,
373373 |path, s| {
374374 assert ! ( s == DropFlagState :: Present ) ;
375375 sets. on_entry . add ( & path) ;
@@ -383,7 +383,7 @@ impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
383383 idx : usize )
384384 {
385385 drop_flag_effects_for_location (
386- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
386+ self . tcx , self . mir , ctxt,
387387 Location { block : bb, index : idx } ,
388388 |path, s| Self :: update_bits ( sets, path, s)
389389 )
@@ -396,7 +396,7 @@ impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
396396 statements_len : usize )
397397 {
398398 drop_flag_effects_for_location (
399- ctxt . 0 , ctxt . 1 , & ctxt. 2 ,
399+ self . tcx , self . mir , ctxt,
400400 Location { block : bb, index : statements_len } ,
401401 |path, s| Self :: update_bits ( sets, path, s)
402402 )
@@ -410,8 +410,8 @@ impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
410410 dest_lval : & repr:: Lvalue ) {
411411 // when a call returns successfully, that means we need to set
412412 // 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,
415415 move_path_index,
416416 |mpi| { in_out. add ( & mpi) ; } ) ;
417417 }
@@ -420,13 +420,13 @@ impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
420420impl < ' a , ' tcx > BitDenotation for MovingOutStatements < ' a , ' tcx > {
421421 type Idx = MoveOutIndex ;
422422 type Bit = MoveOut ;
423- type Ctxt = ( TyCtxt < ' a , ' tcx , ' tcx > , & ' a Mir < ' tcx > , MoveData < ' tcx > ) ;
423+ type Ctxt = MoveData < ' tcx > ;
424424 fn name ( ) -> & ' static str { "moving_out" }
425425 fn bits_per_block ( & self , ctxt : & Self :: Ctxt ) -> usize {
426- ctxt. 2 . moves . len ( )
426+ ctxt. moves . len ( )
427427 }
428428 fn interpret < ' c > ( & self , ctxt : & ' c Self :: Ctxt , idx : usize ) -> & ' c Self :: Bit {
429- & ctxt. 2 . moves [ idx]
429+ & ctxt. moves [ idx]
430430 }
431431 fn start_block_effect ( & self , _move_data : & Self :: Ctxt , _sets : & mut BlockSets < MoveOutIndex > ) {
432432 // no move-statements have been executed prior to function
@@ -437,7 +437,7 @@ impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> {
437437 sets : & mut BlockSets < MoveOutIndex > ,
438438 bb : repr:: BasicBlock ,
439439 idx : usize ) {
440- let & ( tcx, mir, ref move_data) = ctxt;
440+ let ( tcx, mir, move_data) = ( self . tcx , self . mir , ctxt) ;
441441 let stmt = & mir. basic_block_data ( bb) . statements [ idx] ;
442442 let loc_map = & move_data. loc_map ;
443443 let path_map = & move_data. path_map ;
@@ -477,7 +477,7 @@ impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> {
477477 bb : repr:: BasicBlock ,
478478 statements_len : usize )
479479 {
480- let & ( _tcx , mir, ref move_data) = ctxt;
480+ let ( mir, move_data) = ( self . mir , ctxt) ;
481481 let term = mir. basic_block_data ( bb) . terminator . as_ref ( ) . unwrap ( ) ;
482482 let loc_map = & move_data. loc_map ;
483483 let loc = Location { block : bb, index : statements_len } ;
@@ -496,13 +496,13 @@ impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> {
496496 _call_bb : repr:: BasicBlock ,
497497 _dest_bb : repr:: BasicBlock ,
498498 dest_lval : & repr:: Lvalue ) {
499- let move_data = & ctxt. 2 ;
499+ let move_data = ctxt;
500500 let move_path_index = move_data. rev_lookup . find ( dest_lval) ;
501501 let bits_per_block = self . bits_per_block ( ctxt) ;
502502
503503 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 ,
506506 move_data,
507507 move_path_index,
508508 |mpi| for moi in & path_map[ mpi] {
0 commit comments