about summary refs log tree commit diff
path: root/compiler/rustc_span/src
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2024-02-09 15:39:25 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2024-04-25 22:14:47 +0300
commit98804c178608fc4af22b0cb7d199297af5e1562e (patch)
treed532f976f5c36d91b096f2987c003667982c476b /compiler/rustc_span/src
parent9e6c4fddda9d3e5d6cf1b20a0fb82c128efe27ef (diff)
downloadrust-98804c178608fc4af22b0cb7d199297af5e1562e.tar.gz
rust-98804c178608fc4af22b0cb7d199297af5e1562e.zip
debuginfo: Stabilize `-Z debug-macros`, `-Z collapse-macro-debuginfo` and `#[collapse_debuginfo]`
`-Z debug-macros` is "stabilized" by enabling it by default and removing.

`-Z collapse-macro-debuginfo` is stabilized as `-C collapse-macro-debuginfo`.
It now supports all typical boolean values (`parse_opt_bool`) in addition to just yes/no.

Default value of `collapse_debuginfo` was changed from `false` to `external` (i.e. collapsed if external, not collapsed if local).
`#[collapse_debuginfo]` attribute without a value is no longer supported to avoid guessing the default.
Diffstat (limited to 'compiler/rustc_span/src')
-rw-r--r--compiler/rustc_span/src/hygiene.rs38
1 files changed, 15 insertions, 23 deletions
diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs
index 61234a97e16..6093df94179 100644
--- a/compiler/rustc_span/src/hygiene.rs
+++ b/compiler/rustc_span/src/hygiene.rs
@@ -459,28 +459,21 @@ impl HygieneData {
         span
     }
 
-    // We need to walk up and update return span if we meet macro instantiation to be collapsed
-    fn walk_chain_collapsed(
-        &self,
-        mut span: Span,
-        to: Span,
-        collapse_debuginfo_feature_enabled: bool,
-    ) -> Span {
+    fn walk_chain_collapsed(&self, mut span: Span, to: Span) -> Span {
         let orig_span = span;
         let mut ret_span = span;
-
-        debug!(
-            "walk_chain_collapsed({:?}, {:?}), feature_enable={}",
-            span, to, collapse_debuginfo_feature_enabled,
-        );
+        debug!("walk_chain_collapsed({:?}, {:?})", span, to);
         debug!("walk_chain_collapsed: span ctxt = {:?}", span.ctxt());
-        while !span.eq_ctxt(to) && span.from_expansion() {
-            let outer_expn = self.outer_expn(span.ctxt());
+        while let ctxt = span.ctxt()
+            && !ctxt.is_root()
+            && ctxt != to.ctxt()
+        {
+            let outer_expn = self.outer_expn(ctxt);
             debug!("walk_chain_collapsed({:?}): outer_expn={:?}", span, outer_expn);
             let expn_data = self.expn_data(outer_expn);
             debug!("walk_chain_collapsed({:?}): expn_data={:?}", span, expn_data);
             span = expn_data.call_site;
-            if !collapse_debuginfo_feature_enabled || expn_data.collapse_debuginfo {
+            if expn_data.collapse_debuginfo {
                 ret_span = span;
             }
         }
@@ -604,14 +597,13 @@ pub fn walk_chain(span: Span, to: SyntaxContext) -> Span {
     HygieneData::with(|data| data.walk_chain(span, to))
 }
 
-pub fn walk_chain_collapsed(
-    span: Span,
-    to: Span,
-    collapse_debuginfo_feature_enabled: bool,
-) -> Span {
-    HygieneData::with(|hdata| {
-        hdata.walk_chain_collapsed(span, to, collapse_debuginfo_feature_enabled)
-    })
+/// In order to have good line stepping behavior in debugger, for the given span we return its
+/// outermost macro call site that still has a `#[collapse_debuginfo(yes)]` property on it.
+/// We also stop walking call sites at the function body level because no line stepping can occur
+/// at the level above that.
+/// The returned span can then be used in emitted debuginfo.
+pub fn walk_chain_collapsed(span: Span, to: Span) -> Span {
+    HygieneData::with(|data| data.walk_chain_collapsed(span, to))
 }
 
 pub fn update_dollar_crate_names(mut get_name: impl FnMut(SyntaxContext) -> Symbol) {