@@ -2,7 +2,7 @@ use std::cell::OnceCell;
22
33use rustc_data_structures:: graph:: WithNumNodes ;
44use rustc_index:: IndexVec ;
5- use rustc_middle:: mir:: { self , AggregateKind , BasicBlock , Rvalue , Statement , StatementKind } ;
5+ use rustc_middle:: mir:: { self , AggregateKind , Rvalue , Statement , StatementKind } ;
66use rustc_span:: { BytePos , ExpnKind , MacroKind , Span , Symbol } ;
77
88use super :: graph:: { BasicCoverageBlock , CoverageGraph , START_BCB } ;
@@ -51,27 +51,13 @@ impl CoverageSpans {
5151 }
5252}
5353
54- #[ derive( Debug , Copy , Clone ) ]
55- pub ( super ) enum CoverageStatement {
56- Statement ( BasicBlock , Span , usize ) ,
57- Terminator ( BasicBlock , Span ) ,
58- }
59-
60- impl CoverageStatement {
61- pub fn span ( & self ) -> Span {
62- match self {
63- Self :: Statement ( _, span, _) | Self :: Terminator ( _, span) => * span,
64- }
65- }
66- }
67-
6854/// A BCB is deconstructed into one or more `Span`s. Each `Span` maps to a `CoverageSpan` that
6955/// references the originating BCB and one or more MIR `Statement`s and/or `Terminator`s.
7056/// Initially, the `Span`s come from the `Statement`s and `Terminator`s, but subsequent
7157/// transforms can combine adjacent `Span`s and `CoverageSpan` from the same BCB, merging the
72- /// `CoverageStatement ` vectors, and the `Span`s to cover the extent of the combined `Span`s.
58+ /// `merged_spans ` vectors, and the `Span`s to cover the extent of the combined `Span`s.
7359///
74- /// Note: A `CoverageStatement` merged into another CoverageSpan may come from a `BasicBlock` that
60+ /// Note: A span merged into another CoverageSpan may come from a `BasicBlock` that
7561/// is not part of the `CoverageSpan` bcb if the statement was included because it's `Span` matches
7662/// or is subsumed by the `Span` associated with this `CoverageSpan`, and it's `BasicBlock`
7763/// `dominates()` the `BasicBlock`s in this `CoverageSpan`.
@@ -81,7 +67,9 @@ struct CoverageSpan {
8167 pub expn_span : Span ,
8268 pub current_macro_or_none : OnceCell < Option < Symbol > > ,
8369 pub bcb : BasicCoverageBlock ,
84- pub coverage_statements : Vec < CoverageStatement > ,
70+ /// List of all the original spans from MIR that have been merged into this
71+ /// span. Mainly used to precisely skip over gaps when truncating a span.
72+ pub merged_spans : Vec < Span > ,
8573 pub is_closure : bool ,
8674}
8775
@@ -92,7 +80,7 @@ impl CoverageSpan {
9280 expn_span : fn_sig_span,
9381 current_macro_or_none : Default :: default ( ) ,
9482 bcb : START_BCB ,
95- coverage_statements : vec ! [ ] ,
83+ merged_spans : vec ! [ ] ,
9684 is_closure : false ,
9785 }
9886 }
@@ -102,8 +90,6 @@ impl CoverageSpan {
10290 span : Span ,
10391 expn_span : Span ,
10492 bcb : BasicCoverageBlock ,
105- bb : BasicBlock ,
106- stmt_index : usize ,
10793 ) -> Self {
10894 let is_closure = match statement. kind {
10995 StatementKind :: Assign ( box ( _, Rvalue :: Aggregate ( box ref kind, _) ) ) => {
@@ -117,39 +103,32 @@ impl CoverageSpan {
117103 expn_span,
118104 current_macro_or_none : Default :: default ( ) ,
119105 bcb,
120- coverage_statements : vec ! [ CoverageStatement :: Statement ( bb , span, stmt_index ) ] ,
106+ merged_spans : vec ! [ span] ,
121107 is_closure,
122108 }
123109 }
124110
125- pub fn for_terminator (
126- span : Span ,
127- expn_span : Span ,
128- bcb : BasicCoverageBlock ,
129- bb : BasicBlock ,
130- ) -> Self {
111+ pub fn for_terminator ( span : Span , expn_span : Span , bcb : BasicCoverageBlock ) -> Self {
131112 Self {
132113 span,
133114 expn_span,
134115 current_macro_or_none : Default :: default ( ) ,
135116 bcb,
136- coverage_statements : vec ! [ CoverageStatement :: Terminator ( bb , span) ] ,
117+ merged_spans : vec ! [ span] ,
137118 is_closure : false ,
138119 }
139120 }
140121
141122 pub fn merge_from ( & mut self , mut other : CoverageSpan ) {
142123 debug_assert ! ( self . is_mergeable( & other) ) ;
143124 self . span = self . span . to ( other. span ) ;
144- self . coverage_statements . append ( & mut other. coverage_statements ) ;
125+ self . merged_spans . append ( & mut other. merged_spans ) ;
145126 }
146127
147128 pub fn cutoff_statements_at ( & mut self , cutoff_pos : BytePos ) {
148- self . coverage_statements . retain ( |covstmt| covstmt. span ( ) . hi ( ) <= cutoff_pos) ;
149- if let Some ( highest_covstmt) =
150- self . coverage_statements . iter ( ) . max_by_key ( |covstmt| covstmt. span ( ) . hi ( ) )
151- {
152- self . span = self . span . with_hi ( highest_covstmt. span ( ) . hi ( ) ) ;
129+ self . merged_spans . retain ( |span| span. hi ( ) <= cutoff_pos) ;
130+ if let Some ( max_hi) = self . merged_spans . iter ( ) . map ( |span| span. hi ( ) ) . max ( ) {
131+ self . span = self . span . with_hi ( max_hi) ;
153132 }
154133 }
155134
@@ -673,7 +652,7 @@ impl<'a> CoverageSpansGenerator<'a> {
673652 if self . pending_dups . is_empty ( ) {
674653 let curr_span = self . curr ( ) . span ;
675654 self . prev_mut ( ) . cutoff_statements_at ( curr_span. lo ( ) ) ;
676- if self . prev ( ) . coverage_statements . is_empty ( ) {
655+ if self . prev ( ) . merged_spans . is_empty ( ) {
677656 debug ! ( " ... no non-overlapping statements to add" ) ;
678657 } else {
679658 debug ! ( " ... adding modified prev={:?}" , self . prev( ) ) ;
0 commit comments