From 90b4c86335f625f64e6238614d4c7cfd0dbbb37a Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Wed, 17 Apr 2024 18:14:16 -0700 Subject: [PATCH] Ensure `[rust] debuginfo-level-std` doesn't change core's MIR --- compiler/rustc_mir_transform/src/inline.rs | 12 ++- compiler/rustc_session/src/options.rs | 3 + src/bootstrap/src/core/builder.rs | 8 ++ ...ine_coroutine.main.Inline.panic-abort.diff | 1 + ...ne_coroutine.main.Inline.panic-unwind.diff | 1 + ...ecked_shl.PreCodegen.after.panic-abort.mir | 6 ++ ...cked_shl.PreCodegen.after.panic-unwind.mir | 6 ++ ...p_forward.PreCodegen.after.panic-abort.mir | 79 +------------------ ..._forward.PreCodegen.after.panic-unwind.mir | 79 +------------------ 9 files changed, 38 insertions(+), 157 deletions(-) diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 1182a7384028..625d8f53939f 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -699,7 +699,17 @@ impl<'tcx> Inliner<'tcx> { // Insert all of the (mapped) parts of the callee body into the caller. caller_body.local_decls.extend(callee_body.drain_vars_and_temps()); caller_body.source_scopes.extend(&mut callee_body.source_scopes.drain(..)); - if self.tcx.sess.opts.debuginfo != DebugInfo::None { + if self + .tcx + .sess + .opts + .unstable_opts + .inline_mir_preserve_debug + .unwrap_or(self.tcx.sess.opts.debuginfo != DebugInfo::None) + { + // Note that we need to preserve these in the standard library so that + // people working on rust can build with or without debuginfo while + // still getting consistent results from the mir-opt tests. caller_body.var_debug_info.append(&mut callee_body.var_debug_info); } caller_body.basic_blocks_mut().extend(callee_body.basic_blocks_mut().drain(..)); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index c4d802a222b3..6a2975263cf8 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1717,6 +1717,9 @@ options! { "enable MIR inlining (default: no)"), inline_mir_hint_threshold: Option = (None, parse_opt_number, [TRACKED], "inlining threshold for functions with inline hint (default: 100)"), + inline_mir_preserve_debug: Option = (None, parse_opt_bool, [TRACKED], + "when MIR inlining, whether to preserve debug info for callee variables \ + (default: preserve for debuginfo != None, otherwise remove)"), inline_mir_threshold: Option = (None, parse_opt_number, [TRACKED], "a default MIR inlining threshold (default: 50)"), input_stats: bool = (false, parse_bool, [UNTRACKED], diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 499a74be6b15..80c38b80e774 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -2102,6 +2102,14 @@ impl<'a> Builder<'a> { // break when incremental compilation is enabled. So this overrides the "no inlining // during incremental builds" heuristic for the standard library. rustflags.arg("-Zinline-mir"); + + // always pass this after the next `#[cfg(bootstrap)]` update. + if compiler.stage != 0 { + // Similarly, we need to keep debug info for functions inlined into other std functions, + // even if we're not going to output debuginfo for the crate we're currently building, + // so that it'll be available when downstream consumers of std try to use it. + rustflags.arg("-Zinline-mir-preserve-debug"); + } } if self.config.rustc_parallel diff --git a/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff index fcfa5953fc2c..859082c31119 100644 --- a/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff @@ -16,6 +16,7 @@ + scope 3 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new) { + debug pointer => _3; + scope 4 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new_unchecked) { ++ debug pointer => _3; + } + } + scope 5 (inlined g::{closure#0}) { diff --git a/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff index 69c632a9043d..44b06c34972a 100644 --- a/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff @@ -16,6 +16,7 @@ + scope 3 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new) { + debug pointer => _3; + scope 4 (inlined Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:19:5: 19:8}>::new_unchecked) { ++ debug pointer => _3; + } + } + scope 5 (inlined g::{closure#0}) { diff --git a/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.panic-abort.mir index cadebcdf1f87..845673601b2f 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.panic-abort.mir @@ -13,11 +13,17 @@ fn checked_shl(_1: u32, _2: u32) -> Option { debug b => _5; } scope 3 (inlined core::num::::overflowing_shl) { + debug self => _1; + debug rhs => _2; let mut _4: u32; let mut _5: bool; scope 4 (inlined core::num::::wrapping_shl) { + debug self => _1; + debug rhs => _2; let mut _3: u32; scope 5 (inlined core::num::::unchecked_shl) { + debug self => _1; + debug rhs => _3; } } } diff --git a/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.panic-unwind.mir index cadebcdf1f87..845673601b2f 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.checked_shl.PreCodegen.after.panic-unwind.mir @@ -13,11 +13,17 @@ fn checked_shl(_1: u32, _2: u32) -> Option { debug b => _5; } scope 3 (inlined core::num::::overflowing_shl) { + debug self => _1; + debug rhs => _2; let mut _4: u32; let mut _5: bool; scope 4 (inlined core::num::::wrapping_shl) { + debug self => _1; + debug rhs => _2; let mut _3: u32; scope 5 (inlined core::num::::unchecked_shl) { + debug self => _1; + debug rhs => _3; } } } diff --git a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-abort.mir index 9ff61d35fc51..cfb9134a1f13 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-abort.mir @@ -4,89 +4,12 @@ fn step_forward(_1: u16, _2: usize) -> u16 { debug x => _1; debug n => _2; let mut _0: u16; - scope 1 (inlined ::forward) { - debug start => _1; - debug n => _2; - let mut _8: u16; - scope 2 { - } - scope 3 (inlined ::forward_checked) { - scope 4 { - scope 6 (inlined core::num::::checked_add) { - let mut _7: bool; - scope 7 { - } - scope 8 (inlined core::num::::overflowing_add) { - let mut _5: (u16, bool); - let _6: bool; - scope 9 { - } - } - } - } - scope 5 (inlined convert::num::ptr_try_from_impls:: for u16>::try_from) { - let mut _3: bool; - let mut _4: u16; - } - } - scope 10 (inlined Option::::is_none) { - scope 11 (inlined Option::::is_some) { - } - } - scope 12 (inlined core::num::::wrapping_add) { - } - } bb0: { - StorageLive(_4); - StorageLive(_3); - _3 = Gt(_2, const 65535_usize); - switchInt(move _3) -> [0: bb1, otherwise: bb5]; + _0 = ::forward(move _1, move _2) -> [return: bb1, unwind unreachable]; } bb1: { - _4 = _2 as u16 (IntToInt); - StorageDead(_3); - StorageLive(_6); - StorageLive(_5); - _5 = CheckedAdd(_1, _4); - _6 = (_5.1: bool); - StorageDead(_5); - StorageLive(_7); - _7 = unlikely(move _6) -> [return: bb2, unwind unreachable]; - } - - bb2: { - switchInt(move _7) -> [0: bb3, otherwise: bb4]; - } - - bb3: { - StorageDead(_7); - StorageDead(_6); - goto -> bb7; - } - - bb4: { - StorageDead(_7); - StorageDead(_6); - goto -> bb6; - } - - bb5: { - StorageDead(_3); - goto -> bb6; - } - - bb6: { - assert(!const true, "attempt to compute `{} + {}`, which would overflow", const core::num::::MAX, const 1_u16) -> [success: bb7, unwind unreachable]; - } - - bb7: { - StorageLive(_8); - _8 = _2 as u16 (IntToInt); - _0 = Add(_1, _8); - StorageDead(_8); - StorageDead(_4); return; } } diff --git a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-unwind.mir index 36cba172a1a3..cacc1224aba4 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-unwind.mir @@ -4,89 +4,12 @@ fn step_forward(_1: u16, _2: usize) -> u16 { debug x => _1; debug n => _2; let mut _0: u16; - scope 1 (inlined ::forward) { - debug start => _1; - debug n => _2; - let mut _8: u16; - scope 2 { - } - scope 3 (inlined ::forward_checked) { - scope 4 { - scope 6 (inlined core::num::::checked_add) { - let mut _7: bool; - scope 7 { - } - scope 8 (inlined core::num::::overflowing_add) { - let mut _5: (u16, bool); - let _6: bool; - scope 9 { - } - } - } - } - scope 5 (inlined convert::num::ptr_try_from_impls:: for u16>::try_from) { - let mut _3: bool; - let mut _4: u16; - } - } - scope 10 (inlined Option::::is_none) { - scope 11 (inlined Option::::is_some) { - } - } - scope 12 (inlined core::num::::wrapping_add) { - } - } bb0: { - StorageLive(_4); - StorageLive(_3); - _3 = Gt(_2, const 65535_usize); - switchInt(move _3) -> [0: bb1, otherwise: bb5]; + _0 = ::forward(move _1, move _2) -> [return: bb1, unwind continue]; } bb1: { - _4 = _2 as u16 (IntToInt); - StorageDead(_3); - StorageLive(_6); - StorageLive(_5); - _5 = CheckedAdd(_1, _4); - _6 = (_5.1: bool); - StorageDead(_5); - StorageLive(_7); - _7 = unlikely(move _6) -> [return: bb2, unwind unreachable]; - } - - bb2: { - switchInt(move _7) -> [0: bb3, otherwise: bb4]; - } - - bb3: { - StorageDead(_7); - StorageDead(_6); - goto -> bb7; - } - - bb4: { - StorageDead(_7); - StorageDead(_6); - goto -> bb6; - } - - bb5: { - StorageDead(_3); - goto -> bb6; - } - - bb6: { - assert(!const true, "attempt to compute `{} + {}`, which would overflow", const core::num::::MAX, const 1_u16) -> [success: bb7, unwind continue]; - } - - bb7: { - StorageLive(_8); - _8 = _2 as u16 (IntToInt); - _0 = Add(_1, _8); - StorageDead(_8); - StorageDead(_4); return; } }