@@ -5,7 +5,7 @@ use super::FunctionCx;
5
5
use crate :: traits:: * ;
6
6
use rustc_data_structures:: graph:: dominators:: Dominators ;
7
7
use rustc_index:: bit_set:: BitSet ;
8
- use rustc_index:: vec:: { Idx , IndexVec } ;
8
+ use rustc_index:: vec:: IndexVec ;
9
9
use rustc_middle:: mir:: traversal;
10
10
use rustc_middle:: mir:: visit:: {
11
11
MutatingUseContext , NonMutatingUseContext , NonUseContext , PlaceContext , Visitor ,
@@ -40,37 +40,31 @@ struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
40
40
fx : & ' mir FunctionCx < ' a , ' tcx , Bx > ,
41
41
dominators : Dominators < mir:: BasicBlock > ,
42
42
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 > > ,
46
46
}
47
47
48
48
impl < Bx : BuilderMethods < ' a , ' tcx > > LocalAnalyzer < ' mir , ' a , ' tcx , Bx > {
49
49
fn new ( fx : & ' mir FunctionCx < ' a , ' tcx , Bx > ) -> Self {
50
- let invalid_location = mir:: BasicBlock :: new ( fx. mir . basic_blocks ( ) . len ( ) ) . start_location ( ) ;
51
50
let dominators = fx. mir . dominators ( ) ;
52
51
let mut analyzer = LocalAnalyzer {
53
52
fx,
54
53
dominators,
55
54
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 ) ,
57
56
} ;
58
57
59
58
// Arguments get assigned to by means of the function being called
60
59
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 ( ) ) ;
62
61
}
63
62
64
63
analyzer
65
64
}
66
65
67
66
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]
74
68
}
75
69
76
70
fn not_ssa ( & mut self , local : mir:: Local ) {
@@ -79,10 +73,10 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
79
73
}
80
74
81
75
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 ( ) {
83
77
self . not_ssa ( local) ;
84
78
} else {
85
- self . first_assignment [ local] = location;
79
+ self . first_assignment [ local] = Some ( location) ;
86
80
}
87
81
}
88
82
0 commit comments