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

Lines changed: 11 additions & 4 deletions
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

Lines changed: 3 additions & 10 deletions
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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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;

0 commit comments

Comments
 (0)