11use  super :: graph:: { BasicCoverageBlock ,  BasicCoverageBlockData ,  CoverageGraph ,  START_BCB } ; 
22
33use  rustc_data_structures:: graph:: WithNumNodes ; 
4+ use  rustc_index:: bit_set:: BitSet ; 
45use  rustc_middle:: mir:: { 
56    self ,  AggregateKind ,  BasicBlock ,  FakeReadCause ,  Rvalue ,  Statement ,  StatementKind ,  Terminator , 
67    TerminatorKind , 
@@ -10,6 +11,42 @@ use rustc_span::{BytePos, ExpnKind, MacroKind, Span, Symbol};
1011
1112use  std:: cell:: OnceCell ; 
1213
14+ pub ( super )  struct  CoverageSpans  { 
15+     coverage_spans :  Vec < CoverageSpan > , 
16+     bcbs_with_coverage_spans :  BitSet < BasicCoverageBlock > , 
17+ } 
18+ 
19+ impl  CoverageSpans  { 
20+     pub ( super )  fn  generate_coverage_spans ( 
21+         mir_body :  & mir:: Body < ' _ > , 
22+         fn_sig_span :  Span , 
23+         body_span :  Span , 
24+         basic_coverage_blocks :  & CoverageGraph , 
25+     )  -> Self  { 
26+         let  coverage_spans = CoverageSpansGenerator :: generate_coverage_spans ( 
27+             mir_body, 
28+             fn_sig_span, 
29+             body_span, 
30+             basic_coverage_blocks, 
31+         ) ; 
32+ 
33+         let  mut  bcbs_with_coverage_spans = BitSet :: new_empty ( basic_coverage_blocks. num_nodes ( ) ) ; 
34+         for  coverage_span in  & coverage_spans { 
35+             bcbs_with_coverage_spans. insert ( coverage_span. bcb ) ; 
36+         } 
37+ 
38+         Self  {  coverage_spans,  bcbs_with_coverage_spans } 
39+     } 
40+ 
41+     pub ( super )  fn  bcb_has_coverage_spans ( & self ,  bcb :  BasicCoverageBlock )  -> bool  { 
42+         self . bcbs_with_coverage_spans . contains ( bcb) 
43+     } 
44+ 
45+     pub ( super )  fn  bcb_span_pairs ( & self )  -> impl  Iterator < Item  = ( BasicCoverageBlock ,  Span ) >  + ' _  { 
46+         self . coverage_spans . iter ( ) . map ( |& CoverageSpan  {  bcb,  span,  .. } | ( bcb,  span) ) 
47+     } 
48+ } 
49+ 
1350#[ derive( Debug ,  Copy ,  Clone ) ]  
1451pub ( super )  enum  CoverageStatement  { 
1552    Statement ( BasicBlock ,  Span ,  usize ) , 
@@ -35,7 +72,7 @@ impl CoverageStatement {
3572/// or is subsumed by the `Span` associated with this `CoverageSpan`, and it's `BasicBlock` 
3673/// `dominates()` the `BasicBlock`s in this `CoverageSpan`. 
3774#[ derive( Debug ,  Clone ) ]  
38- pub ( super )   struct  CoverageSpan  { 
75+ struct  CoverageSpan  { 
3976    pub  span :  Span , 
4077    pub  expn_span :  Span , 
4178    pub  current_macro_or_none :  OnceCell < Option < Symbol > > , 
@@ -162,7 +199,7 @@ impl CoverageSpan {
162199///  * Merge spans that represent continuous (both in source code and control flow), non-branching 
163200///    execution 
164201///  * Carve out (leave uncovered) any span that will be counted by another MIR (notably, closures) 
165- pub   struct  CoverageSpans < ' a ,  ' tcx >  { 
202+ struct  CoverageSpansGenerator < ' a ,  ' tcx >  { 
166203    /// The MIR, used to look up `BasicBlockData`. 
167204mir_body :  & ' a  mir:: Body < ' tcx > , 
168205
@@ -218,7 +255,7 @@ pub struct CoverageSpans<'a, 'tcx> {
218255refined_spans :  Vec < CoverageSpan > , 
219256} 
220257
221- impl < ' a ,  ' tcx >  CoverageSpans < ' a ,  ' tcx >  { 
258+ impl < ' a ,  ' tcx >  CoverageSpansGenerator < ' a ,  ' tcx >  { 
222259    /// Generate a minimal set of `CoverageSpan`s, each representing a contiguous code region to be 
223260/// counted. 
224261/// 
@@ -246,7 +283,7 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
246283        body_span :  Span , 
247284        basic_coverage_blocks :  & ' a  CoverageGraph , 
248285    )  -> Vec < CoverageSpan >  { 
249-         let  mut  coverage_spans = CoverageSpans  { 
286+         let  mut  coverage_spans = Self  { 
250287            mir_body, 
251288            fn_sig_span, 
252289            body_span, 
@@ -734,7 +771,7 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
734771
735772/// If the MIR `Statement` has a span contributive to computing coverage spans, 
736773/// return it; otherwise return `None`. 
737- pub ( super )   fn  filtered_statement_span ( statement :  & Statement < ' _ > )  -> Option < Span >  { 
774+ fn  filtered_statement_span ( statement :  & Statement < ' _ > )  -> Option < Span >  { 
738775    match  statement. kind  { 
739776        // These statements have spans that are often outside the scope of the executed source code 
740777        // for their parent `BasicBlock`. 
@@ -781,7 +818,7 @@ pub(super) fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span>
781818
782819/// If the MIR `Terminator` has a span contributive to computing coverage spans, 
783820/// return it; otherwise return `None`. 
784- pub ( super )   fn  filtered_terminator_span ( terminator :  & Terminator < ' _ > )  -> Option < Span >  { 
821+ fn  filtered_terminator_span ( terminator :  & Terminator < ' _ > )  -> Option < Span >  { 
785822    match  terminator. kind  { 
786823        // These terminators have spans that don't positively contribute to computing a reasonable 
787824        // span of actually executed source code. (For example, SwitchInt terminators extracted from 
@@ -828,7 +865,7 @@ pub(super) fn filtered_terminator_span(terminator: &Terminator<'_>) -> Option<Sp
828865/// [^1]Expansions result from Rust syntax including macros, syntactic sugar, 
829866/// etc.). 
830867#[ inline]  
831- pub ( super )   fn  function_source_span ( span :  Span ,  body_span :  Span )  -> Span  { 
868+ fn  function_source_span ( span :  Span ,  body_span :  Span )  -> Span  { 
832869    let  original_span = original_sp ( span,  body_span) . with_ctxt ( body_span. ctxt ( ) ) ; 
833870    if  body_span. contains ( original_span)  {  original_span }  else  {  body_span } 
834871} 
0 commit comments