@@ -28,7 +28,8 @@ impl<'tcx> MirPass<'tcx> for SingleUseConsts {
28
28
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
29
29
let mut finder = SingleUseConstsFinder {
30
30
ineligible_locals : BitSet :: new_empty ( body. local_decls . len ( ) ) ,
31
- locations : IndexVec :: new ( ) ,
31
+ locations : IndexVec :: from_elem ( LocationPair :: new ( ) , & body. local_decls ) ,
32
+ locals_in_debug_info : BitSet :: new_empty ( body. local_decls . len ( ) ) ,
32
33
} ;
33
34
34
35
finder. ineligible_locals . insert_range ( ..=Local :: from_usize ( body. arg_count ) ) ;
@@ -57,8 +58,10 @@ impl<'tcx> MirPass<'tcx> for SingleUseConsts {
57
58
58
59
let mut replacer = LocalReplacer { tcx, local, operand : Some ( operand) } ;
59
60
60
- for var_debug_info in & mut body. var_debug_info {
61
- replacer. visit_var_debug_info ( var_debug_info) ;
61
+ if finder. locals_in_debug_info . contains ( local) {
62
+ for var_debug_info in & mut body. var_debug_info {
63
+ replacer. visit_var_debug_info ( var_debug_info) ;
64
+ }
62
65
}
63
66
64
67
let Some ( use_loc) = locations. use_loc else { continue } ;
@@ -94,6 +97,7 @@ impl LocationPair {
94
97
struct SingleUseConstsFinder {
95
98
ineligible_locals : BitSet < Local > ,
96
99
locations : IndexVec < Local , LocationPair > ,
100
+ locals_in_debug_info : BitSet < Local > ,
97
101
}
98
102
99
103
impl < ' tcx > Visitor < ' tcx > for SingleUseConstsFinder {
@@ -102,7 +106,7 @@ impl<'tcx> Visitor<'tcx> for SingleUseConstsFinder {
102
106
&& let Rvalue :: Use ( operand) = rvalue
103
107
&& let Operand :: Constant ( _) = operand
104
108
{
105
- let locations = self . locations . ensure_contains_elem ( local, LocationPair :: new ) ;
109
+ let locations = & mut self . locations [ local] ;
106
110
if locations. init_loc . is_some ( ) {
107
111
self . ineligible_locals . insert ( local) ;
108
112
} else {
@@ -117,7 +121,7 @@ impl<'tcx> Visitor<'tcx> for SingleUseConstsFinder {
117
121
if let Some ( place) = operand. place ( )
118
122
&& let Some ( local) = place. as_local ( )
119
123
{
120
- let locations = self . locations . ensure_contains_elem ( local, LocationPair :: new ) ;
124
+ let locations = & mut self . locations [ local] ;
121
125
if locations. use_loc . is_some ( ) {
122
126
self . ineligible_locals . insert ( local) ;
123
127
} else {
@@ -138,9 +142,9 @@ impl<'tcx> Visitor<'tcx> for SingleUseConstsFinder {
138
142
139
143
fn visit_var_debug_info ( & mut self , var_debug_info : & VarDebugInfo < ' tcx > ) {
140
144
if let VarDebugInfoContents :: Place ( place) = & var_debug_info. value
141
- && let Some ( _local ) = place. as_local ( )
145
+ && let Some ( local ) = place. as_local ( )
142
146
{
143
- // It's a simple one that we can easily update
147
+ self . locals_in_debug_info . insert ( local ) ;
144
148
} else {
145
149
self . super_var_debug_info ( var_debug_info) ;
146
150
}
0 commit comments