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:: {
@@ -188,26 +189,11 @@ impl<'tcx> FunctionCoverage<'tcx> {
188189 if self . is_used { self . function_coverage_info . function_source_hash } else { 0 }
189190 }
190191
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-
208192 /// Convert this function's coverage expression data into a form that can be
209193 /// 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 < ' _ > {
211197 // We know that LLVM will optimize out any unused expressions before
212198 // producing the final coverage map, so there's no need to do the same
213199 // thing on the Rust side unless we're confident we can do much better.
@@ -218,23 +204,23 @@ impl<'tcx> FunctionCoverage<'tcx> {
218204 _ => Counter :: from_term ( operand) ,
219205 } ;
220206
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 {
225209 lhs : counter_from_operand ( lhs) ,
226210 kind : match op {
227211 Op :: Add => ExprKind :: Add ,
228212 Op :: Subtract => ExprKind :: Subtract ,
229213 } ,
230214 rhs : counter_from_operand ( rhs) ,
231- } )
232- . collect :: < Vec < _ > > ( )
215+ }
216+ } )
233217 }
234218
235219 /// Converts this function's coverage mappings into an intermediate form
236220 /// 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 {
238224 // Historically, mappings were stored directly in counter/expression
239225 // statements in MIR, and MIR optimizations would sometimes remove them.
240226 // That's mostly no longer true, so now we detect cases where that would
0 commit comments