@@ -70,7 +70,6 @@ struct Instrumentor<'a, 'tcx> {
70
70
mir_body : & ' a mut mir:: Body < ' tcx > ,
71
71
hir_info : ExtractedHirInfo ,
72
72
basic_coverage_blocks : CoverageGraph ,
73
- coverage_counters : CoverageCounters ,
74
73
}
75
74
76
75
impl < ' a , ' tcx > Instrumentor < ' a , ' tcx > {
@@ -80,9 +79,8 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
80
79
debug ! ( ?hir_info, "instrumenting {:?}" , mir_body. source. def_id( ) ) ;
81
80
82
81
let basic_coverage_blocks = CoverageGraph :: from_mir ( mir_body) ;
83
- let coverage_counters = CoverageCounters :: new ( & basic_coverage_blocks) ;
84
82
85
- Self { tcx, mir_body, hir_info, basic_coverage_blocks, coverage_counters }
83
+ Self { tcx, mir_body, hir_info, basic_coverage_blocks }
86
84
}
87
85
88
86
fn inject_counters ( & ' a mut self ) {
@@ -103,16 +101,18 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
103
101
// and all `Expression` dependencies (operands) are also generated, for any other
104
102
// `BasicCoverageBlock`s not already associated with a coverage span.
105
103
let bcb_has_coverage_spans = |bcb| coverage_spans. bcb_has_coverage_spans ( bcb) ;
106
- self . coverage_counters
107
- . make_bcb_counters ( & self . basic_coverage_blocks , bcb_has_coverage_spans) ;
104
+ let coverage_counters = CoverageCounters :: make_bcb_counters (
105
+ & self . basic_coverage_blocks ,
106
+ bcb_has_coverage_spans,
107
+ ) ;
108
108
109
- let mappings = self . create_mappings ( & coverage_spans) ;
110
- self . inject_coverage_statements ( bcb_has_coverage_spans) ;
109
+ let mappings = self . create_mappings ( & coverage_spans, & coverage_counters ) ;
110
+ self . inject_coverage_statements ( bcb_has_coverage_spans, & coverage_counters ) ;
111
111
112
112
self . mir_body . function_coverage_info = Some ( Box :: new ( FunctionCoverageInfo {
113
113
function_source_hash : self . hir_info . function_source_hash ,
114
- num_counters : self . coverage_counters . num_counters ( ) ,
115
- expressions : self . coverage_counters . take_expressions ( ) ,
114
+ num_counters : coverage_counters. num_counters ( ) ,
115
+ expressions : coverage_counters. into_expressions ( ) ,
116
116
mappings,
117
117
} ) ) ;
118
118
}
@@ -122,7 +122,11 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
122
122
///
123
123
/// Precondition: All BCBs corresponding to those spans have been given
124
124
/// coverage counters.
125
- fn create_mappings ( & self , coverage_spans : & CoverageSpans ) -> Vec < Mapping > {
125
+ fn create_mappings (
126
+ & self ,
127
+ coverage_spans : & CoverageSpans ,
128
+ coverage_counters : & CoverageCounters ,
129
+ ) -> Vec < Mapping > {
126
130
let source_map = self . tcx . sess . source_map ( ) ;
127
131
let body_span = self . hir_info . body_span ;
128
132
@@ -135,8 +139,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
135
139
. bcbs_with_coverage_spans ( )
136
140
// For each BCB with spans, get a coverage term for its counter.
137
141
. map ( |( bcb, spans) | {
138
- let term = self
139
- . coverage_counters
142
+ let term = coverage_counters
140
143
. bcb_counter ( bcb)
141
144
. expect ( "all BCBs with spans were given counters" )
142
145
. as_term ( ) ;
@@ -157,9 +160,10 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
157
160
fn inject_coverage_statements (
158
161
& mut self ,
159
162
bcb_has_coverage_spans : impl Fn ( BasicCoverageBlock ) -> bool ,
163
+ coverage_counters : & CoverageCounters ,
160
164
) {
161
165
// Process the counters associated with BCB nodes.
162
- for ( bcb, counter_kind) in self . coverage_counters . bcb_node_counters ( ) {
166
+ for ( bcb, counter_kind) in coverage_counters. bcb_node_counters ( ) {
163
167
let do_inject = match counter_kind {
164
168
// Counter-increment statements always need to be injected.
165
169
BcbCounter :: Counter { .. } => true ,
@@ -178,7 +182,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
178
182
}
179
183
180
184
// Process the counters associated with BCB edges.
181
- for ( from_bcb, to_bcb, counter_kind) in self . coverage_counters . bcb_edge_counters ( ) {
185
+ for ( from_bcb, to_bcb, counter_kind) in coverage_counters. bcb_edge_counters ( ) {
182
186
let do_inject = match counter_kind {
183
187
// Counter-increment statements always need to be injected.
184
188
BcbCounter :: Counter { .. } => true ,
0 commit comments