13
13
//!
14
14
15
15
use crate :: util:: is_within_packed;
16
- use rustc_index:: bit_set:: BitSet ;
17
16
use rustc_middle:: mir:: visit:: Visitor ;
18
17
use rustc_middle:: mir:: * ;
19
18
use rustc_middle:: ty:: TyCtxt ;
19
+ use rustc_mir_dataflow:: debuginfo:: debuginfo_locals;
20
20
use rustc_mir_dataflow:: impls:: {
21
21
borrowed_locals, LivenessTransferFunction , MaybeTransitiveLiveLocals ,
22
22
} ;
@@ -26,8 +26,15 @@ use rustc_mir_dataflow::Analysis;
26
26
///
27
27
/// The `borrowed` set must be a `BitSet` of all the locals that are ever borrowed in this body. It
28
28
/// can be generated via the [`borrowed_locals`] function.
29
- pub fn eliminate < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > , borrowed : & BitSet < Local > ) {
30
- let mut live = MaybeTransitiveLiveLocals :: new ( borrowed)
29
+ pub fn eliminate < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
30
+ let borrowed_locals = borrowed_locals ( body) ;
31
+
32
+ // If the user requests complete debuginfo, mark the locals that appear in it as live, so
33
+ // we don't remove assignements to them.
34
+ let mut always_live = debuginfo_locals ( body) ;
35
+ always_live. union ( & borrowed_locals) ;
36
+
37
+ let mut live = MaybeTransitiveLiveLocals :: new ( & always_live)
31
38
. into_engine ( tcx, body)
32
39
. iterate_to_fixpoint ( )
33
40
. into_results_cursor ( body) ;
@@ -48,7 +55,9 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitS
48
55
for ( index, arg) in args. iter ( ) . enumerate ( ) . rev ( ) {
49
56
if let Operand :: Copy ( place) = * arg
50
57
&& !place. is_indirect ( )
51
- && !borrowed. contains ( place. local )
58
+ // Do not skip the transformation if the local is in debuginfo, as we do
59
+ // not really lose any information for this purpose.
60
+ && !borrowed_locals. contains ( place. local )
52
61
&& !state. contains ( place. local )
53
62
// If `place` is a projection of a disaligned field in a packed ADT,
54
63
// the move may be codegened as a pointer to that field.
@@ -75,7 +84,7 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitS
75
84
StatementKind :: Assign ( box ( place, _) )
76
85
| StatementKind :: SetDiscriminant { place : box place, .. }
77
86
| StatementKind :: Deinit ( box place) => {
78
- if !place. is_indirect ( ) && !borrowed . contains ( place. local ) {
87
+ if !place. is_indirect ( ) && !always_live . contains ( place. local ) {
79
88
live. seek_before_primary_effect ( loc) ;
80
89
if !live. get ( ) . contains ( place. local ) {
81
90
patch. push ( loc) ;
@@ -126,7 +135,6 @@ impl<'tcx> MirPass<'tcx> for DeadStoreElimination {
126
135
}
127
136
128
137
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
129
- let borrowed = borrowed_locals ( body) ;
130
- eliminate ( tcx, body, & borrowed) ;
138
+ eliminate ( tcx, body) ;
131
139
}
132
140
}
0 commit comments