11use crate :: coverageinfo:: ffi:: { Counter , CounterExpression , ExprKind } ;
22
3+ use rustc_data_structures:: captures:: Captures ;
34use rustc_data_structures:: fx:: FxIndexSet ;
45use rustc_index:: bit_set:: BitSet ;
56use rustc_middle:: mir:: coverage:: {
@@ -193,26 +194,11 @@ impl<'tcx> FunctionCoverage<'tcx> {
193194 if self . is_used { self . function_coverage_info . function_source_hash } else { 0 }
194195 }
195196
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-
213197 /// Convert this function's coverage expression data into a form that can be
214198 /// 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 < ' _ > {
216202 // We know that LLVM will optimize out any unused expressions before
217203 // producing the final coverage map, so there's no need to do the same
218204 // thing on the Rust side unless we're confident we can do much better.
@@ -223,23 +209,23 @@ impl<'tcx> FunctionCoverage<'tcx> {
223209 _ => Counter :: from_term ( operand) ,
224210 } ;
225211
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 {
230214 lhs : counter_from_operand ( lhs) ,
231215 kind : match op {
232216 Op :: Add => ExprKind :: Add ,
233217 Op :: Subtract => ExprKind :: Subtract ,
234218 } ,
235219 rhs : counter_from_operand ( rhs) ,
236- } )
237- . collect :: < Vec < _ > > ( )
220+ }
221+ } )
238222 }
239223
240224 /// Converts this function's coverage mappings into an intermediate form
241225 /// 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 {
243229 // Historically, mappings were stored directly in counter/expression
244230 // statements in MIR, and MIR optimizations would sometimes remove them.
245231 // That's mostly no longer true, so now we detect cases where that would
0 commit comments