Skip to content

Commit 107bd38

Browse files
committed
Only account for debuginfo if the user requests it.
1 parent 8cf135e commit 107bd38

File tree

33 files changed

+243
-174
lines changed

33 files changed

+243
-174
lines changed

compiler/rustc_mir_transform/src/dead_store_elimination.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//! will still not cause any further changes.
1313
//!
1414
15+
use crate::simplify::preserve_debug_even_if_never_generated;
1516
use crate::util::is_within_packed;
1617
use rustc_middle::mir::visit::Visitor;
1718
use rustc_middle::mir::*;
@@ -31,10 +32,16 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
3132

3233
// If the user requests complete debuginfo, mark the locals that appear in it as live, so
3334
// 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)
35+
let mut always_live;
36+
let always_live = if preserve_debug_even_if_never_generated(tcx) {
37+
always_live = debuginfo_locals(body);
38+
always_live.union(&borrowed_locals);
39+
&always_live
40+
} else {
41+
&borrowed_locals
42+
};
43+
44+
let mut live = MaybeTransitiveLiveLocals::new(always_live)
3845
.into_engine(tcx, body)
3946
.iterate_to_fixpoint()
4047
.into_results_cursor(body);

compiler/rustc_mir_transform/src/inline.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ use rustc_middle::mir::visit::*;
1111
use rustc_middle::mir::*;
1212
use rustc_middle::ty::TypeVisitableExt;
1313
use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
14-
use rustc_session::config::{DebugInfo, OptLevel};
14+
use rustc_session::config::OptLevel;
1515
use rustc_span::source_map::Spanned;
1616
use rustc_span::sym;
1717
use rustc_target::abi::FieldIdx;
1818
use rustc_target::spec::abi::Abi;
1919

2020
use crate::cost_checker::CostChecker;
21-
use crate::simplify::simplify_cfg;
21+
use crate::simplify::{preserve_debug_even_if_never_generated, simplify_cfg};
2222
use crate::util;
2323
use std::iter;
2424
use std::ops::{Range, RangeFrom};
@@ -699,14 +699,7 @@ impl<'tcx> Inliner<'tcx> {
699699
// Insert all of the (mapped) parts of the callee body into the caller.
700700
caller_body.local_decls.extend(callee_body.drain_vars_and_temps());
701701
caller_body.source_scopes.extend(&mut callee_body.source_scopes.drain(..));
702-
if self
703-
.tcx
704-
.sess
705-
.opts
706-
.unstable_opts
707-
.inline_mir_preserve_debug
708-
.unwrap_or(self.tcx.sess.opts.debuginfo != DebugInfo::None)
709-
{
702+
if preserve_debug_even_if_never_generated(self.tcx) {
710703
// Note that we need to preserve these in the standard library so that
711704
// people working on rust can build with or without debuginfo while
712705
// still getting consistent results from the mir-opt tests.

compiler/rustc_mir_transform/src/simplify.rs

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use rustc_index::{Idx, IndexSlice, IndexVec};
3131
use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor};
3232
use rustc_middle::mir::*;
3333
use rustc_middle::ty::TyCtxt;
34+
use rustc_session::config::DebugInfo;
3435
use smallvec::SmallVec;
3536

3637
pub enum SimplifyCfg {
@@ -581,3 +582,12 @@ impl<'tcx> MutVisitor<'tcx> for LocalUpdater<'tcx> {
581582
*l = self.map[*l].unwrap();
582583
}
583584
}
585+
586+
pub(crate) fn preserve_debug_even_if_never_generated(tcx: TyCtxt<'_>) -> bool {
587+
tcx.sess.opts.unstable_opts.inline_mir_preserve_debug.unwrap_or_else(|| {
588+
match tcx.sess.opts.debuginfo {
589+
DebugInfo::None | DebugInfo::LineDirectivesOnly | DebugInfo::LineTablesOnly => false,
590+
DebugInfo::Limited | DebugInfo::Full => true,
591+
}
592+
})
593+
}

tests/codegen/slice-ref-equality.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ compile-flags: -O -Zmerge-functions=disabled
1+
//@ compile-flags: -O -Zmerge-functions=disabled -Cdebuginfo=0
22
#![crate_type = "lib"]
33
#![feature(generic_nonzero)]
44

tests/incremental/hashes/enum_constructors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ pub fn change_constructor_variant_c_like() {
318318
}
319319

320320
#[cfg(not(any(cfail1,cfail4)))]
321-
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,optimized_mir")]
321+
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes")]
322322
#[rustc_clean(cfg="cfail3")]
323-
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes,optimized_mir")]
323+
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes")]
324324
#[rustc_clean(cfg="cfail6")]
325325
pub fn change_constructor_variant_c_like() {
326326
let _x = Clike::C;

tests/incremental/hashes/for_loops.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ pub fn change_loop_body() {
2828
}
2929

3030
#[cfg(not(any(cfail1,cfail4)))]
31-
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes, optimized_mir")]
31+
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes")]
3232
#[rustc_clean(cfg="cfail3")]
33-
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes, optimized_mir")]
33+
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes")]
3434
#[rustc_clean(cfg="cfail6")]
3535
pub fn change_loop_body() {
3636
let mut _x = 0;
@@ -180,7 +180,7 @@ pub fn add_loop_label_to_break() {
180180
#[cfg(not(any(cfail1,cfail4)))]
181181
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes")]
182182
#[rustc_clean(cfg="cfail3")]
183-
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes, optimized_mir")]
183+
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes")]
184184
#[rustc_clean(cfg="cfail6")]
185185
pub fn add_loop_label_to_break() {
186186
let mut _x = 0;

tests/incremental/hashes/let_expressions.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn change_mutability_of_slot() {
9191
}
9292

9393
#[cfg(not(any(cfail1,cfail4)))]
94-
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,typeck")]
94+
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,typeck,optimized_mir")]
9595
#[rustc_clean(cfg="cfail3")]
9696
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes,typeck,optimized_mir")]
9797
#[rustc_clean(cfg="cfail6")]
@@ -176,7 +176,7 @@ pub fn change_mutability_of_binding_in_pattern() {
176176
}
177177

178178
#[cfg(not(any(cfail1,cfail4)))]
179-
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,typeck")]
179+
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,typeck,optimized_mir")]
180180
#[rustc_clean(cfg="cfail3")]
181181
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes,typeck,optimized_mir")]
182182
#[rustc_clean(cfg="cfail6")]
@@ -193,9 +193,9 @@ pub fn add_initializer() {
193193
}
194194

195195
#[cfg(not(any(cfail1,cfail4)))]
196-
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,typeck,optimized_mir")]
196+
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,typeck")]
197197
#[rustc_clean(cfg="cfail3")]
198-
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes,typeck,optimized_mir")]
198+
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes,typeck")]
199199
#[rustc_clean(cfg="cfail6")]
200200
pub fn add_initializer() {
201201
let _x: i16 = 3i16;
@@ -210,9 +210,9 @@ pub fn change_initializer() {
210210
}
211211

212212
#[cfg(not(any(cfail1,cfail4)))]
213-
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes, optimized_mir")]
213+
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes")]
214214
#[rustc_clean(cfg="cfail3")]
215-
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes, optimized_mir")]
215+
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes")]
216216
#[rustc_clean(cfg="cfail6")]
217217
pub fn change_initializer() {
218218
let _x = 5u16;

tests/incremental/hashes/loop_expressions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ pub fn change_loop_body() {
2828
}
2929

3030
#[cfg(not(any(cfail1,cfail4)))]
31-
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes, optimized_mir")]
31+
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes")]
3232
#[rustc_clean(cfg="cfail3")]
33-
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes, optimized_mir")]
33+
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes")]
3434
#[rustc_clean(cfg="cfail6")]
3535
pub fn change_loop_body() {
3636
let mut _x = 0;

tests/incremental/hashes/match_expressions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub fn change_mutability_of_binding_in_pattern(x: u32) -> u32 {
227227

228228
// Ignore optimized_mir in cfail2, the only change to optimized MIR is a span.
229229
#[cfg(not(any(cfail1,cfail4)))]
230-
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,typeck")]
230+
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,optimized_mir,typeck")]
231231
#[rustc_clean(cfg="cfail3")]
232232
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes,optimized_mir,typeck")]
233233
#[rustc_clean(cfg="cfail6")]

tests/incremental/hashes/while_loops.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ pub fn change_loop_body() {
2828
}
2929

3030
#[cfg(not(any(cfail1,cfail4)))]
31-
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes, optimized_mir")]
31+
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes")]
3232
#[rustc_clean(cfg="cfail3")]
33-
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes, optimized_mir")]
33+
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes")]
3434
#[rustc_clean(cfg="cfail6")]
3535
pub fn change_loop_body() {
3636
let mut _x = 0;
@@ -53,9 +53,9 @@ pub fn change_loop_condition() {
5353
}
5454

5555
#[cfg(not(any(cfail1,cfail4)))]
56-
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes, optimized_mir")]
56+
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes")]
5757
#[rustc_clean(cfg="cfail3")]
58-
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes, optimized_mir")]
58+
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes")]
5959
#[rustc_clean(cfg="cfail6")]
6060
pub fn change_loop_condition() {
6161
let mut _x = 0;
@@ -211,7 +211,7 @@ pub fn change_continue_label() {
211211
#[cfg(not(any(cfail1,cfail4)))]
212212
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes")]
213213
#[rustc_clean(cfg="cfail3")]
214-
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes")]
214+
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes, optimized_mir")]
215215
#[rustc_clean(cfg="cfail6")]
216216
pub fn change_continue_label() {
217217
let mut _x = 0;

tests/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination-initial.diff

+49-10
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,70 @@
22
+ // MIR for `cycle` after DeadStoreElimination-initial
33

44
fn cycle(_1: i32, _2: i32, _3: i32) -> () {
5+
debug x => _1;
6+
debug y => _2;
7+
debug z => _3;
58
let mut _0: ();
6-
let mut _4: bool;
7-
let mut _5: i32;
9+
let mut _4: ();
10+
let mut _5: bool;
11+
let _6: i32;
12+
let mut _7: i32;
13+
let mut _8: i32;
14+
let mut _9: i32;
15+
let mut _10: !;
16+
let _11: ();
17+
let mut _12: !;
18+
scope 1 {
19+
debug temp => _6;
20+
}
821

922
bb0: {
10-
_4 = cond() -> [return: bb1, unwind continue];
23+
goto -> bb1;
1124
}
1225

1326
bb1: {
14-
switchInt(_4) -> [1: bb2, otherwise: bb3];
27+
StorageLive(_5);
28+
_5 = cond() -> [return: bb2, unwind continue];
1529
}
1630

1731
bb2: {
18-
- _5 = _3;
19-
- _3 = _2;
20-
- _2 = _1;
21-
- _1 = _5;
32+
switchInt(move _5) -> [0: bb4, otherwise: bb3];
33+
}
34+
35+
bb3: {
36+
StorageLive(_6);
37+
- _6 = _3;
38+
+ nop;
39+
StorageLive(_7);
40+
- _7 = _2;
41+
- _3 = move _7;
2242
+ nop;
2343
+ nop;
44+
StorageDead(_7);
45+
StorageLive(_8);
46+
- _8 = _1;
47+
- _2 = move _8;
2448
+ nop;
2549
+ nop;
26-
_4 = cond() -> [return: bb1, unwind continue];
50+
StorageDead(_8);
51+
StorageLive(_9);
52+
- _9 = _6;
53+
- _1 = move _9;
54+
+ nop;
55+
+ nop;
56+
StorageDead(_9);
57+
- _4 = const ();
58+
+ nop;
59+
StorageDead(_6);
60+
StorageDead(_5);
61+
goto -> bb1;
2762
}
2863

29-
bb3: {
64+
bb4: {
65+
StorageLive(_11);
66+
_0 = const ();
67+
StorageDead(_11);
68+
StorageDead(_5);
3069
return;
3170
}
3271
}

tests/mir-opt/dead-store-elimination/cycle.rs

+12-27
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,28 @@
44
//@ needs-unwind
55
//@ unit-test: DeadStoreElimination-initial
66

7-
#![feature(core_intrinsics, custom_mir)]
8-
use std::intrinsics::mir::*;
9-
107
#[inline(never)]
118
fn cond() -> bool {
129
false
1310
}
1411

1512
// EMIT_MIR cycle.cycle.DeadStoreElimination-initial.diff
16-
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
1713
fn cycle(mut x: i32, mut y: i32, mut z: i32) {
1814
// CHECK-LABEL: fn cycle(
19-
// CHECK-NOT: {{_.*}} = {{_.*}};
20-
// CHECK-NOT: {{_.*}} = move {{_.*}};
21-
22-
// We use custom MIR to avoid generating debuginfo, that would force to preserve writes.
23-
mir!(
24-
let condition: bool;
25-
{
26-
Call(condition = cond(), ReturnTo(bb1), UnwindContinue())
27-
}
28-
bb1 = {
29-
match condition { true => bb2, _ => ret }
30-
}
31-
bb2 = {
32-
let temp = z;
33-
z = y;
34-
y = x;
35-
x = temp;
36-
Call(condition = cond(), ReturnTo(bb1), UnwindContinue())
37-
}
38-
ret = {
39-
Return()
40-
}
41-
)
15+
// CHECK-NOT: {{_.*}} =
16+
// CHECK: {{_.*}} = cond()
17+
// CHECK-NOT: {{_.*}} =
18+
// CHECK: _0 = const ();
19+
// CHECK-NOT: {{_.*}} =
20+
while cond() {
21+
let temp = z;
22+
z = y;
23+
y = x;
24+
x = temp;
25+
}
4226
}
4327

4428
fn main() {
29+
// CHECK-LABEL: fn main(
4530
cycle(1, 2, 3);
4631
}

tests/mir-opt/issue_101973.inner.GVN.panic-abort.diff

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
StorageLive(_4);
3131
StorageLive(_5);
3232
_5 = _1;
33-
nop;
3433
- StorageLive(_14);
3534
- _14 = BitAnd(_5, const 255_u32);
3635
- _4 = BitOr(const 0_u32, move _14);

tests/mir-opt/issue_101973.inner.GVN.panic-unwind.diff

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
StorageLive(_4);
3131
StorageLive(_5);
3232
_5 = _1;
33-
nop;
3433
- StorageLive(_14);
3534
- _14 = BitAnd(_5, const 255_u32);
3635
- _4 = BitOr(const 0_u32, move _14);

tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff

-3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@
4040

4141
bb2: {
4242
StorageLive(_7);
43-
_7 = &(*_2)[0 of 3];
4443
StorageLive(_8);
45-
_8 = &(*_2)[1 of 3];
4644
StorageLive(_9);
47-
_9 = &(*_2)[2 of 3];
4845
StorageDead(_9);
4946
StorageDead(_8);
5047
StorageDead(_7);

tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff

-3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@
4040

4141
bb2: {
4242
StorageLive(_7);
43-
_7 = &(*_2)[0 of 3];
4443
StorageLive(_8);
45-
_8 = &(*_2)[1 of 3];
4644
StorageLive(_9);
47-
_9 = &(*_2)[2 of 3];
4845
StorageDead(_9);
4946
StorageDead(_8);
5047
StorageDead(_7);

0 commit comments

Comments
 (0)