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