about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src/strip_debuginfo.rs
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2024-12-05 00:47:36 -0800
committerScott McMurray <scottmcm@users.noreply.github.com>2024-12-10 01:29:43 -0800
commita7fc76a3ab640fa1d6d95b6b722ed4d82d4e333e (patch)
treedd21f22446884de9703a3164e076fa2e9d73ec0e /compiler/rustc_mir_transform/src/strip_debuginfo.rs
parent96e51d9482405e400dec53750f3b263d45784ada (diff)
downloadrust-a7fc76a3ab640fa1d6d95b6b722ed4d82d4e333e.tar.gz
rust-a7fc76a3ab640fa1d6d95b6b722ed4d82d4e333e.zip
We don't need `NonNull::as_ptr` debuginfo
Stop pessimizing the use of local variables in core by skipping debug info for MIR temporaries in tiny (single-BB) functions.

For functions as simple as this -- `Pin::new`, etc -- nobody every actually wants debuginfo for them in the first place.  They're more like intrinsics than real functions, and stepping over them is good.
Diffstat (limited to 'compiler/rustc_mir_transform/src/strip_debuginfo.rs')
-rw-r--r--compiler/rustc_mir_transform/src/strip_debuginfo.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/strip_debuginfo.rs b/compiler/rustc_mir_transform/src/strip_debuginfo.rs
new file mode 100644
index 00000000000..438c75726bb
--- /dev/null
+++ b/compiler/rustc_mir_transform/src/strip_debuginfo.rs
@@ -0,0 +1,34 @@
+use rustc_middle::mir::*;
+use rustc_middle::ty::TyCtxt;
+use rustc_session::config::MirStripDebugInfo;
+
+/// Conditionally remove some of the VarDebugInfo in MIR.
+///
+/// In particular, stripping non-parameter debug info for tiny, primitive-like
+/// methods in core saves work later, and nobody ever wanted to use it anyway.
+pub(super) struct StripDebugInfo;
+
+impl<'tcx> crate::MirPass<'tcx> for StripDebugInfo {
+    fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
+        sess.opts.unstable_opts.mir_strip_debuginfo != MirStripDebugInfo::None
+    }
+
+    fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
+        match tcx.sess.opts.unstable_opts.mir_strip_debuginfo {
+            MirStripDebugInfo::None => return,
+            MirStripDebugInfo::AllLocals => {}
+            MirStripDebugInfo::LocalsInTinyFunctions
+                if let TerminatorKind::Return { .. } =
+                    body.basic_blocks[START_BLOCK].terminator().kind => {}
+            MirStripDebugInfo::LocalsInTinyFunctions => return,
+        }
+
+        body.var_debug_info.retain(|vdi| {
+            matches!(
+                vdi.value,
+                VarDebugInfoContents::Place(place)
+                    if place.local.as_usize() <= body.arg_count && place.local != RETURN_PLACE,
+            )
+        });
+    }
+}