Skip to content

Commit 7b8c23d

Browse files
cjgillotsaethlin
authored andcommitted
Only account for debuginfo if the user requests it.
1 parent be99243 commit 7b8c23d

File tree

38 files changed

+249
-197
lines changed

38 files changed

+249
-197
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::bug;
1718
use rustc_middle::mir::visit::Visitor;
@@ -32,10 +33,16 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
3233

3334
// If the user requests complete debuginfo, mark the locals that appear in it as live, so
3435
// we don't remove assignements to them.
35-
let mut always_live = debuginfo_locals(body);
36-
always_live.union(&borrowed_locals);
37-
38-
let mut live = MaybeTransitiveLiveLocals::new(&always_live)
36+
let mut always_live;
37+
let always_live = if preserve_debug_even_if_never_generated(tcx) {
38+
always_live = debuginfo_locals(body);
39+
always_live.union(&borrowed_locals);
40+
&always_live
41+
} else {
42+
&borrowed_locals
43+
};
44+
45+
let mut live = MaybeTransitiveLiveLocals::new(always_live)
3946
.into_engine(tcx, body)
4047
.iterate_to_fixpoint()
4148
.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
@@ -12,14 +12,14 @@ use rustc_middle::mir::visit::*;
1212
use rustc_middle::mir::*;
1313
use rustc_middle::ty::TypeVisitableExt;
1414
use rustc_middle::ty::{self, Instance, InstanceKind, ParamEnv, Ty, TyCtxt, TypeFlags};
15-
use rustc_session::config::{DebugInfo, OptLevel};
15+
use rustc_session::config::OptLevel;
1616
use rustc_span::source_map::Spanned;
1717
use rustc_span::sym;
1818
use rustc_target::abi::FieldIdx;
1919
use rustc_target::spec::abi::Abi;
2020

2121
use crate::cost_checker::CostChecker;
22-
use crate::simplify::simplify_cfg;
22+
use crate::simplify::{preserve_debug_even_if_never_generated, simplify_cfg};
2323
use crate::util;
2424
use crate::validate::validate_types;
2525
use std::iter;
@@ -696,14 +696,7 @@ impl<'tcx> Inliner<'tcx> {
696696
// Insert all of the (mapped) parts of the callee body into the caller.
697697
caller_body.local_decls.extend(callee_body.drain_vars_and_temps());
698698
caller_body.source_scopes.extend(&mut callee_body.source_scopes.drain(..));
699-
if self
700-
.tcx
701-
.sess
702-
.opts
703-
.unstable_opts
704-
.inline_mir_preserve_debug
705-
.unwrap_or(self.tcx.sess.opts.debuginfo != DebugInfo::None)
706-
{
699+
if preserve_debug_even_if_never_generated(self.tcx) {
707700
// Note that we need to preserve these in the standard library so that
708701
// people working on rust can build with or without debuginfo while
709702
// 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

44
use std::num::NonZero;

tests/crashes/101962.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@ known-bug: #101962
2+
//@ compile-flags: -Cdebuginfo=2
23

34
#![feature(core_intrinsics)]
45

tests/crashes/79409.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@ known-bug: #79409
2+
//@ compile-flags: -Cdebuginfo=2
23

34
#![feature(extern_types)]
45
#![feature(unsized_locals)]

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;

0 commit comments

Comments
 (0)