@@ -2,7 +2,7 @@ use std::cell::OnceCell;
2
2
3
3
use rustc_data_structures:: graph:: WithNumNodes ;
4
4
use rustc_index:: IndexVec ;
5
- use rustc_middle:: mir:: { self , AggregateKind , BasicBlock , Rvalue , Statement , StatementKind } ;
5
+ use rustc_middle:: mir:: { self , AggregateKind , Rvalue , Statement , StatementKind } ;
6
6
use rustc_span:: { BytePos , ExpnKind , MacroKind , Span , Symbol } ;
7
7
8
8
use super :: graph:: { BasicCoverageBlock , CoverageGraph , START_BCB } ;
@@ -51,27 +51,13 @@ impl CoverageSpans {
51
51
}
52
52
}
53
53
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
-
68
54
/// A BCB is deconstructed into one or more `Span`s. Each `Span` maps to a `CoverageSpan` that
69
55
/// references the originating BCB and one or more MIR `Statement`s and/or `Terminator`s.
70
56
/// Initially, the `Span`s come from the `Statement`s and `Terminator`s, but subsequent
71
57
/// 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.
73
59
///
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
75
61
/// is not part of the `CoverageSpan` bcb if the statement was included because it's `Span` matches
76
62
/// or is subsumed by the `Span` associated with this `CoverageSpan`, and it's `BasicBlock`
77
63
/// `dominates()` the `BasicBlock`s in this `CoverageSpan`.
@@ -81,7 +67,9 @@ struct CoverageSpan {
81
67
pub expn_span : Span ,
82
68
pub current_macro_or_none : OnceCell < Option < Symbol > > ,
83
69
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 > ,
85
73
pub is_closure : bool ,
86
74
}
87
75
@@ -92,7 +80,7 @@ impl CoverageSpan {
92
80
expn_span : fn_sig_span,
93
81
current_macro_or_none : Default :: default ( ) ,
94
82
bcb : START_BCB ,
95
- coverage_statements : vec ! [ ] ,
83
+ merged_spans : vec ! [ ] ,
96
84
is_closure : false ,
97
85
}
98
86
}
@@ -102,8 +90,6 @@ impl CoverageSpan {
102
90
span : Span ,
103
91
expn_span : Span ,
104
92
bcb : BasicCoverageBlock ,
105
- bb : BasicBlock ,
106
- stmt_index : usize ,
107
93
) -> Self {
108
94
let is_closure = match statement. kind {
109
95
StatementKind :: Assign ( box ( _, Rvalue :: Aggregate ( box ref kind, _) ) ) => {
@@ -117,39 +103,32 @@ impl CoverageSpan {
117
103
expn_span,
118
104
current_macro_or_none : Default :: default ( ) ,
119
105
bcb,
120
- coverage_statements : vec ! [ CoverageStatement :: Statement ( bb , span, stmt_index ) ] ,
106
+ merged_spans : vec ! [ span] ,
121
107
is_closure,
122
108
}
123
109
}
124
110
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 {
131
112
Self {
132
113
span,
133
114
expn_span,
134
115
current_macro_or_none : Default :: default ( ) ,
135
116
bcb,
136
- coverage_statements : vec ! [ CoverageStatement :: Terminator ( bb , span) ] ,
117
+ merged_spans : vec ! [ span] ,
137
118
is_closure : false ,
138
119
}
139
120
}
140
121
141
122
pub fn merge_from ( & mut self , mut other : CoverageSpan ) {
142
123
debug_assert ! ( self . is_mergeable( & other) ) ;
143
124
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 ) ;
145
126
}
146
127
147
128
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) ;
153
132
}
154
133
}
155
134
@@ -673,7 +652,7 @@ impl<'a> CoverageSpansGenerator<'a> {
673
652
if self . pending_dups . is_empty ( ) {
674
653
let curr_span = self . curr ( ) . span ;
675
654
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 ( ) {
677
656
debug ! ( " ... no non-overlapping statements to add" ) ;
678
657
} else {
679
658
debug ! ( " ... adding modified prev={:?}" , self . prev( ) ) ;
0 commit comments