@@ -5,7 +5,7 @@ use super::FunctionCx;
55use crate :: traits:: * ;
66use rustc_data_structures:: graph:: dominators:: Dominators ;
77use rustc_index:: bit_set:: BitSet ;
8- use rustc_index:: vec:: { Idx , IndexVec } ;
8+ use rustc_index:: vec:: IndexVec ;
99use rustc_middle:: mir:: traversal;
1010use rustc_middle:: mir:: visit:: {
1111 MutatingUseContext , NonMutatingUseContext , NonUseContext , PlaceContext , Visitor ,
@@ -40,37 +40,31 @@ struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
4040 fx : & ' mir FunctionCx < ' a , ' tcx , Bx > ,
4141 dominators : Dominators < mir:: BasicBlock > ,
4242 non_ssa_locals : BitSet < mir:: Local > ,
43- // The location of the first visited direct assignment to each
44- // local, or an invalid location (out of bounds `block` index) .
45- first_assignment : IndexVec < mir:: Local , Location > ,
43+
44+ /// The location of the first visited direct assignment to each local .
45+ first_assignment : IndexVec < mir:: Local , Option < Location > > ,
4646}
4747
4848impl < Bx : BuilderMethods < ' a , ' tcx > > LocalAnalyzer < ' mir , ' a , ' tcx , Bx > {
4949 fn new ( fx : & ' mir FunctionCx < ' a , ' tcx , Bx > ) -> Self {
50- let invalid_location = mir:: BasicBlock :: new ( fx. mir . basic_blocks ( ) . len ( ) ) . start_location ( ) ;
5150 let dominators = fx. mir . dominators ( ) ;
5251 let mut analyzer = LocalAnalyzer {
5352 fx,
5453 dominators,
5554 non_ssa_locals : BitSet :: new_empty ( fx. mir . local_decls . len ( ) ) ,
56- first_assignment : IndexVec :: from_elem ( invalid_location , & fx. mir . local_decls ) ,
55+ first_assignment : IndexVec :: from_elem ( None , & fx. mir . local_decls ) ,
5756 } ;
5857
5958 // Arguments get assigned to by means of the function being called
6059 for arg in fx. mir . args_iter ( ) {
61- analyzer. first_assignment [ arg] = mir:: START_BLOCK . start_location ( ) ;
60+ analyzer. assign ( arg, mir:: START_BLOCK . start_location ( ) ) ;
6261 }
6362
6463 analyzer
6564 }
6665
6766 fn first_assignment ( & self , local : mir:: Local ) -> Option < Location > {
68- let location = self . first_assignment [ local] ;
69- if location. block . index ( ) < self . fx . mir . basic_blocks ( ) . len ( ) {
70- Some ( location)
71- } else {
72- None
73- }
67+ self . first_assignment [ local]
7468 }
7569
7670 fn not_ssa ( & mut self , local : mir:: Local ) {
@@ -79,10 +73,10 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
7973 }
8074
8175 fn assign ( & mut self , local : mir:: Local , location : Location ) {
82- if self . first_assignment ( local) . is_some ( ) {
76+ if self . first_assignment [ local] . is_some ( ) {
8377 self . not_ssa ( local) ;
8478 } else {
85- self . first_assignment [ local] = location;
79+ self . first_assignment [ local] = Some ( location) ;
8680 }
8781 }
8882
0 commit comments