Skip to content

Commit 90b4c86

Browse files
committed
Ensure [rust] debuginfo-level-std doesn't change core's MIR
1 parent 6094063 commit 90b4c86

9 files changed

+38
-157
lines changed

compiler/rustc_mir_transform/src/inline.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,17 @@ 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.tcx.sess.opts.debuginfo != DebugInfo::None {
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+
{
710+
// Note that we need to preserve these in the standard library so that
711+
// people working on rust can build with or without debuginfo while
712+
// still getting consistent results from the mir-opt tests.
703713
caller_body.var_debug_info.append(&mut callee_body.var_debug_info);
704714
}
705715
caller_body.basic_blocks_mut().extend(callee_body.basic_blocks_mut().drain(..));

compiler/rustc_session/src/options.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,9 @@ options! {
17171717
"enable MIR inlining (default: no)"),
17181718
inline_mir_hint_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
17191719
"inlining threshold for functions with inline hint (default: 100)"),
1720+
inline_mir_preserve_debug: Option<bool> = (None, parse_opt_bool, [TRACKED],
1721+
"when MIR inlining, whether to preserve debug info for callee variables \
1722+
(default: preserve for debuginfo != None, otherwise remove)"),
17201723
inline_mir_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
17211724
"a default MIR inlining threshold (default: 50)"),
17221725
input_stats: bool = (false, parse_bool, [UNTRACKED],

src/bootstrap/src/core/builder.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,14 @@ impl<'a> Builder<'a> {
21022102
// break when incremental compilation is enabled. So this overrides the "no inlining
21032103
// during incremental builds" heuristic for the standard library.
21042104
rustflags.arg("-Zinline-mir");
2105+
2106+
// always pass this after the next `#[cfg(bootstrap)]` update.
2107+
if compiler.stage != 0 {
2108+
// Similarly, we need to keep debug info for functions inlined into other std functions,
2109+
// even if we're not going to output debuginfo for the crate we're currently building,
2110+
// so that it'll be available when downstream consumers of std try to use it.
2111+
rustflags.arg("-Zinline-mir-preserve-debug");
2112+
}
21052113
}
21062114

21072115
if self.config.rustc_parallel

tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
+ scope 3 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new) {
1717
+ debug pointer => _3;
1818
+ scope 4 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new_unchecked) {
19+
+ debug pointer => _3;
1920
+ }
2021
+ }
2122
+ scope 5 (inlined g::{closure#0}) {

tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
+ scope 3 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new) {
1717
+ debug pointer => _3;
1818
+ scope 4 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new_unchecked) {
19+
+ debug pointer => _3;
1920
+ }
2021
+ }
2122
+ scope 5 (inlined g::{closure#0}) {

tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.panic-abort.mir

+6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ fn checked_shl(_1: u32, _2: u32) -> Option<u32> {
1313
debug b => _5;
1414
}
1515
scope 3 (inlined core::num::<impl u32>::overflowing_shl) {
16+
debug self => _1;
17+
debug rhs => _2;
1618
let mut _4: u32;
1719
let mut _5: bool;
1820
scope 4 (inlined core::num::<impl u32>::wrapping_shl) {
21+
debug self => _1;
22+
debug rhs => _2;
1923
let mut _3: u32;
2024
scope 5 (inlined core::num::<impl u32>::unchecked_shl) {
25+
debug self => _1;
26+
debug rhs => _3;
2127
}
2228
}
2329
}

tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.panic-unwind.mir

+6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ fn checked_shl(_1: u32, _2: u32) -> Option<u32> {
1313
debug b => _5;
1414
}
1515
scope 3 (inlined core::num::<impl u32>::overflowing_shl) {
16+
debug self => _1;
17+
debug rhs => _2;
1618
let mut _4: u32;
1719
let mut _5: bool;
1820
scope 4 (inlined core::num::<impl u32>::wrapping_shl) {
21+
debug self => _1;
22+
debug rhs => _2;
1923
let mut _3: u32;
2024
scope 5 (inlined core::num::<impl u32>::unchecked_shl) {
25+
debug self => _1;
26+
debug rhs => _3;
2127
}
2228
}
2329
}

tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-abort.mir

+1-78
Original file line numberDiff line numberDiff line change
@@ -4,89 +4,12 @@ fn step_forward(_1: u16, _2: usize) -> u16 {
44
debug x => _1;
55
debug n => _2;
66
let mut _0: u16;
7-
scope 1 (inlined <u16 as Step>::forward) {
8-
debug start => _1;
9-
debug n => _2;
10-
let mut _8: u16;
11-
scope 2 {
12-
}
13-
scope 3 (inlined <u16 as Step>::forward_checked) {
14-
scope 4 {
15-
scope 6 (inlined core::num::<impl u16>::checked_add) {
16-
let mut _7: bool;
17-
scope 7 {
18-
}
19-
scope 8 (inlined core::num::<impl u16>::overflowing_add) {
20-
let mut _5: (u16, bool);
21-
let _6: bool;
22-
scope 9 {
23-
}
24-
}
25-
}
26-
}
27-
scope 5 (inlined convert::num::ptr_try_from_impls::<impl TryFrom<usize> for u16>::try_from) {
28-
let mut _3: bool;
29-
let mut _4: u16;
30-
}
31-
}
32-
scope 10 (inlined Option::<u16>::is_none) {
33-
scope 11 (inlined Option::<u16>::is_some) {
34-
}
35-
}
36-
scope 12 (inlined core::num::<impl u16>::wrapping_add) {
37-
}
38-
}
397

408
bb0: {
41-
StorageLive(_4);
42-
StorageLive(_3);
43-
_3 = Gt(_2, const 65535_usize);
44-
switchInt(move _3) -> [0: bb1, otherwise: bb5];
9+
_0 = <u16 as Step>::forward(move _1, move _2) -> [return: bb1, unwind unreachable];
4510
}
4611

4712
bb1: {
48-
_4 = _2 as u16 (IntToInt);
49-
StorageDead(_3);
50-
StorageLive(_6);
51-
StorageLive(_5);
52-
_5 = CheckedAdd(_1, _4);
53-
_6 = (_5.1: bool);
54-
StorageDead(_5);
55-
StorageLive(_7);
56-
_7 = unlikely(move _6) -> [return: bb2, unwind unreachable];
57-
}
58-
59-
bb2: {
60-
switchInt(move _7) -> [0: bb3, otherwise: bb4];
61-
}
62-
63-
bb3: {
64-
StorageDead(_7);
65-
StorageDead(_6);
66-
goto -> bb7;
67-
}
68-
69-
bb4: {
70-
StorageDead(_7);
71-
StorageDead(_6);
72-
goto -> bb6;
73-
}
74-
75-
bb5: {
76-
StorageDead(_3);
77-
goto -> bb6;
78-
}
79-
80-
bb6: {
81-
assert(!const true, "attempt to compute `{} + {}`, which would overflow", const core::num::<impl u16>::MAX, const 1_u16) -> [success: bb7, unwind unreachable];
82-
}
83-
84-
bb7: {
85-
StorageLive(_8);
86-
_8 = _2 as u16 (IntToInt);
87-
_0 = Add(_1, _8);
88-
StorageDead(_8);
89-
StorageDead(_4);
9013
return;
9114
}
9215
}

tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-unwind.mir

+1-78
Original file line numberDiff line numberDiff line change
@@ -4,89 +4,12 @@ fn step_forward(_1: u16, _2: usize) -> u16 {
44
debug x => _1;
55
debug n => _2;
66
let mut _0: u16;
7-
scope 1 (inlined <u16 as Step>::forward) {
8-
debug start => _1;
9-
debug n => _2;
10-
let mut _8: u16;
11-
scope 2 {
12-
}
13-
scope 3 (inlined <u16 as Step>::forward_checked) {
14-
scope 4 {
15-
scope 6 (inlined core::num::<impl u16>::checked_add) {
16-
let mut _7: bool;
17-
scope 7 {
18-
}
19-
scope 8 (inlined core::num::<impl u16>::overflowing_add) {
20-
let mut _5: (u16, bool);
21-
let _6: bool;
22-
scope 9 {
23-
}
24-
}
25-
}
26-
}
27-
scope 5 (inlined convert::num::ptr_try_from_impls::<impl TryFrom<usize> for u16>::try_from) {
28-
let mut _3: bool;
29-
let mut _4: u16;
30-
}
31-
}
32-
scope 10 (inlined Option::<u16>::is_none) {
33-
scope 11 (inlined Option::<u16>::is_some) {
34-
}
35-
}
36-
scope 12 (inlined core::num::<impl u16>::wrapping_add) {
37-
}
38-
}
397

408
bb0: {
41-
StorageLive(_4);
42-
StorageLive(_3);
43-
_3 = Gt(_2, const 65535_usize);
44-
switchInt(move _3) -> [0: bb1, otherwise: bb5];
9+
_0 = <u16 as Step>::forward(move _1, move _2) -> [return: bb1, unwind continue];
4510
}
4611

4712
bb1: {
48-
_4 = _2 as u16 (IntToInt);
49-
StorageDead(_3);
50-
StorageLive(_6);
51-
StorageLive(_5);
52-
_5 = CheckedAdd(_1, _4);
53-
_6 = (_5.1: bool);
54-
StorageDead(_5);
55-
StorageLive(_7);
56-
_7 = unlikely(move _6) -> [return: bb2, unwind unreachable];
57-
}
58-
59-
bb2: {
60-
switchInt(move _7) -> [0: bb3, otherwise: bb4];
61-
}
62-
63-
bb3: {
64-
StorageDead(_7);
65-
StorageDead(_6);
66-
goto -> bb7;
67-
}
68-
69-
bb4: {
70-
StorageDead(_7);
71-
StorageDead(_6);
72-
goto -> bb6;
73-
}
74-
75-
bb5: {
76-
StorageDead(_3);
77-
goto -> bb6;
78-
}
79-
80-
bb6: {
81-
assert(!const true, "attempt to compute `{} + {}`, which would overflow", const core::num::<impl u16>::MAX, const 1_u16) -> [success: bb7, unwind continue];
82-
}
83-
84-
bb7: {
85-
StorageLive(_8);
86-
_8 = _2 as u16 (IntToInt);
87-
_0 = Add(_1, _8);
88-
StorageDead(_8);
89-
StorageDead(_4);
9013
return;
9114
}
9215
}

0 commit comments

Comments
 (0)