1
1
use crate :: coverageinfo:: ffi:: { Counter , CounterExpression , ExprKind } ;
2
2
3
+ use rustc_data_structures:: captures:: Captures ;
3
4
use rustc_data_structures:: fx:: FxIndexSet ;
4
5
use rustc_index:: bit_set:: BitSet ;
5
6
use rustc_middle:: mir:: coverage:: {
@@ -193,26 +194,11 @@ impl<'tcx> FunctionCoverage<'tcx> {
193
194
if self . is_used { self . function_coverage_info . function_source_hash } else { 0 }
194
195
}
195
196
196
- /// Generate an array of CounterExpressions, and an iterator over all `Counter`s and their
197
- /// associated `Regions` (from which the LLVM-specific `CoverageMapGenerator` will create
198
- /// `CounterMappingRegion`s.
199
- pub fn get_expressions_and_counter_regions (
200
- & self ,
201
- ) -> ( Vec < CounterExpression > , impl Iterator < Item = ( Counter , & CodeRegion ) > ) {
202
- let counter_expressions = self . counter_expressions ( ) ;
203
- // Expression IDs are indices into `self.expressions`, and on the LLVM
204
- // side they will be treated as indices into `counter_expressions`, so
205
- // the two vectors should correspond 1:1.
206
- assert_eq ! ( self . function_coverage_info. expressions. len( ) , counter_expressions. len( ) ) ;
207
-
208
- let counter_regions = self . counter_regions ( ) ;
209
-
210
- ( counter_expressions, counter_regions)
211
- }
212
-
213
197
/// Convert this function's coverage expression data into a form that can be
214
198
/// passed through FFI to LLVM.
215
- fn counter_expressions ( & self ) -> Vec < CounterExpression > {
199
+ pub ( crate ) fn counter_expressions (
200
+ & self ,
201
+ ) -> impl Iterator < Item = CounterExpression > + ExactSizeIterator + Captures < ' _ > {
216
202
// We know that LLVM will optimize out any unused expressions before
217
203
// producing the final coverage map, so there's no need to do the same
218
204
// thing on the Rust side unless we're confident we can do much better.
@@ -223,23 +209,23 @@ impl<'tcx> FunctionCoverage<'tcx> {
223
209
_ => Counter :: from_term ( operand) ,
224
210
} ;
225
211
226
- self . function_coverage_info
227
- . expressions
228
- . iter ( )
229
- . map ( |& Expression { lhs, op, rhs } | CounterExpression {
212
+ self . function_coverage_info . expressions . iter ( ) . map ( move |& Expression { lhs, op, rhs } | {
213
+ CounterExpression {
230
214
lhs : counter_from_operand ( lhs) ,
231
215
kind : match op {
232
216
Op :: Add => ExprKind :: Add ,
233
217
Op :: Subtract => ExprKind :: Subtract ,
234
218
} ,
235
219
rhs : counter_from_operand ( rhs) ,
236
- } )
237
- . collect :: < Vec < _ > > ( )
220
+ }
221
+ } )
238
222
}
239
223
240
224
/// Converts this function's coverage mappings into an intermediate form
241
225
/// that will be used by `mapgen` when preparing for FFI.
242
- fn counter_regions ( & self ) -> impl Iterator < Item = ( Counter , & CodeRegion ) > {
226
+ pub ( crate ) fn counter_regions (
227
+ & self ,
228
+ ) -> impl Iterator < Item = ( Counter , & CodeRegion ) > + ExactSizeIterator {
243
229
// Historically, mappings were stored directly in counter/expression
244
230
// statements in MIR, and MIR optimizations would sometimes remove them.
245
231
// That's mostly no longer true, so now we detect cases where that would
0 commit comments