1- use std:: cell:: OnceCell ;
2-
31use rustc_data_structures:: graph:: WithNumNodes ;
42use rustc_index:: IndexVec ;
53use rustc_middle:: mir;
6- use rustc_span:: { BytePos , ExpnKind , MacroKind , Span , Symbol , DUMMY_SP } ;
4+ use rustc_span:: { BytePos , Span , Symbol , DUMMY_SP } ;
75
86use super :: graph:: { BasicCoverageBlock , CoverageGraph , START_BCB } ;
97use crate :: coverage:: ExtractedHirInfo ;
@@ -66,8 +64,7 @@ impl CoverageSpans {
6664#[ derive( Debug , Clone ) ]
6765struct CoverageSpan {
6866 pub span : Span ,
69- pub expn_span : Span ,
70- pub current_macro_or_none : OnceCell < Option < Symbol > > ,
67+ pub visible_macro : Option < Symbol > ,
7168 pub bcb : BasicCoverageBlock ,
7269 /// List of all the original spans from MIR that have been merged into this
7370 /// span. Mainly used to precisely skip over gaps when truncating a span.
@@ -77,23 +74,16 @@ struct CoverageSpan {
7774
7875impl CoverageSpan {
7976 pub fn for_fn_sig ( fn_sig_span : Span ) -> Self {
80- Self :: new ( fn_sig_span, fn_sig_span , START_BCB , false )
77+ Self :: new ( fn_sig_span, None , START_BCB , false )
8178 }
8279
8380 pub ( super ) fn new (
8481 span : Span ,
85- expn_span : Span ,
82+ visible_macro : Option < Symbol > ,
8683 bcb : BasicCoverageBlock ,
8784 is_closure : bool ,
8885 ) -> Self {
89- Self {
90- span,
91- expn_span,
92- current_macro_or_none : Default :: default ( ) ,
93- bcb,
94- merged_spans : vec ! [ span] ,
95- is_closure,
96- }
86+ Self { span, visible_macro, bcb, merged_spans : vec ! [ span] , is_closure }
9787 }
9888
9989 pub fn merge_from ( & mut self , other : & Self ) {
@@ -118,37 +108,6 @@ impl CoverageSpan {
118108 pub fn is_in_same_bcb ( & self , other : & Self ) -> bool {
119109 self . bcb == other. bcb
120110 }
121-
122- /// If the span is part of a macro, returns the macro name symbol.
123- pub fn current_macro ( & self ) -> Option < Symbol > {
124- self . current_macro_or_none
125- . get_or_init ( || {
126- if let ExpnKind :: Macro ( MacroKind :: Bang , current_macro) =
127- self . expn_span . ctxt ( ) . outer_expn_data ( ) . kind
128- {
129- return Some ( current_macro) ;
130- }
131- None
132- } )
133- . map ( |symbol| symbol)
134- }
135-
136- /// If the span is part of a macro, and the macro is visible (expands directly to the given
137- /// body_span), returns the macro name symbol.
138- pub fn visible_macro ( & self , body_span : Span ) -> Option < Symbol > {
139- let current_macro = self . current_macro ( ) ?;
140- let parent_callsite = self . expn_span . parent_callsite ( ) ?;
141-
142- // In addition to matching the context of the body span, the parent callsite
143- // must also be the source callsite, i.e. the parent must have no parent.
144- let is_visible_macro =
145- parent_callsite. parent_callsite ( ) . is_none ( ) && parent_callsite. eq_ctxt ( body_span) ;
146- is_visible_macro. then_some ( current_macro)
147- }
148-
149- pub fn is_macro_expansion ( & self ) -> bool {
150- self . current_macro ( ) . is_some ( )
151- }
152111}
153112
154113/// Converts the initial set of `CoverageSpan`s (one per MIR `Statement` or `Terminator`) into a
@@ -159,10 +118,6 @@ impl CoverageSpan {
159118/// execution
160119/// * Carve out (leave uncovered) any span that will be counted by another MIR (notably, closures)
161120struct CoverageSpansGenerator < ' a > {
162- /// A `Span` covering the function body of the MIR (typically from left curly brace to right
163- /// curly brace).
164- body_span : Span ,
165-
166121 /// The BasicCoverageBlock Control Flow Graph (BCB CFG).
167122 basic_coverage_blocks : & ' a CoverageGraph ,
168123
@@ -239,7 +194,6 @@ impl<'a> CoverageSpansGenerator<'a> {
239194 ) ;
240195
241196 let coverage_spans = Self {
242- body_span : hir_info. body_span ,
243197 basic_coverage_blocks,
244198 sorted_spans_iter : sorted_spans. into_iter ( ) ,
245199 some_curr : None ,
@@ -298,7 +252,7 @@ impl<'a> CoverageSpansGenerator<'a> {
298252 // **originally** the same as the original span of `prev()`. The original spans
299253 // reflect their original sort order, and for equal spans, conveys a partial
300254 // ordering based on CFG dominator priority.
301- if prev. is_macro_expansion ( ) && curr. is_macro_expansion ( ) {
255+ if prev. visible_macro . is_some ( ) && curr. visible_macro . is_some ( ) {
302256 // Macros that expand to include branching (such as
303257 // `assert_eq!()`, `assert_ne!()`, `info!()`, `debug!()`, or
304258 // `trace!()`) typically generate callee spans with identical
@@ -360,12 +314,7 @@ impl<'a> CoverageSpansGenerator<'a> {
360314 fn maybe_push_macro_name_span ( & mut self ) {
361315 let curr = self . curr ( ) ;
362316
363- let Some ( visible_macro) = curr. visible_macro ( self . body_span ) else { return } ;
364- if let Some ( prev) = & self . some_prev
365- && prev. expn_span . eq_ctxt ( curr. expn_span )
366- {
367- return ;
368- }
317+ let Some ( visible_macro) = curr. visible_macro else { return } ;
369318
370319 // The split point is relative to `curr_original_span`,
371320 // because `curr.span` may have been merged with preceding spans.
0 commit comments