@@ -90,23 +90,23 @@ pub(super) fn generate_coverage_spans(
9090struct CurrCovspan {
9191 span : Span ,
9292 bcb : BasicCoverageBlock ,
93- is_closure : bool ,
93+ is_hole : bool ,
9494}
9595
9696impl CurrCovspan {
97- fn new ( span : Span , bcb : BasicCoverageBlock , is_closure : bool ) -> Self {
98- Self { span, bcb, is_closure }
97+ fn new ( span : Span , bcb : BasicCoverageBlock , is_hole : bool ) -> Self {
98+ Self { span, bcb, is_hole }
9999 }
100100
101101 fn into_prev ( self ) -> PrevCovspan {
102- let Self { span, bcb, is_closure } = self ;
103- PrevCovspan { span, bcb, merged_spans : vec ! [ span] , is_closure }
102+ let Self { span, bcb, is_hole } = self ;
103+ PrevCovspan { span, bcb, merged_spans : vec ! [ span] , is_hole }
104104 }
105105
106106 fn into_refined ( self ) -> RefinedCovspan {
107- // This is only called in cases where `curr` is a closure span that has
107+ // This is only called in cases where `curr` is a hole span that has
108108 // been carved out of `prev`.
109- debug_assert ! ( self . is_closure ) ;
109+ debug_assert ! ( self . is_hole ) ;
110110 self . into_prev ( ) . into_refined ( )
111111 }
112112}
@@ -118,12 +118,12 @@ struct PrevCovspan {
118118 /// List of all the original spans from MIR that have been merged into this
119119 /// span. Mainly used to precisely skip over gaps when truncating a span.
120120 merged_spans : Vec < Span > ,
121- is_closure : bool ,
121+ is_hole : bool ,
122122}
123123
124124impl PrevCovspan {
125125 fn is_mergeable ( & self , other : & CurrCovspan ) -> bool {
126- self . bcb == other. bcb && !self . is_closure && !other. is_closure
126+ self . bcb == other. bcb && !self . is_hole && !other. is_hole
127127 }
128128
129129 fn merge_from ( & mut self , other : & CurrCovspan ) {
@@ -142,8 +142,8 @@ impl PrevCovspan {
142142 }
143143
144144 fn refined_copy ( & self ) -> RefinedCovspan {
145- let & Self { span, bcb, merged_spans : _, is_closure } = self ;
146- RefinedCovspan { span, bcb, is_closure }
145+ let & Self { span, bcb, merged_spans : _, is_hole } = self ;
146+ RefinedCovspan { span, bcb, is_hole }
147147 }
148148
149149 fn into_refined ( self ) -> RefinedCovspan {
@@ -156,12 +156,12 @@ impl PrevCovspan {
156156struct RefinedCovspan {
157157 span : Span ,
158158 bcb : BasicCoverageBlock ,
159- is_closure : bool ,
159+ is_hole : bool ,
160160}
161161
162162impl RefinedCovspan {
163163 fn is_mergeable ( & self , other : & Self ) -> bool {
164- self . bcb == other. bcb && !self . is_closure && !other. is_closure
164+ self . bcb == other. bcb && !self . is_hole && !other. is_hole
165165 }
166166
167167 fn merge_from ( & mut self , other : & Self ) {
@@ -176,16 +176,16 @@ impl RefinedCovspan {
176176/// * Remove duplicate source code coverage regions
177177/// * Merge spans that represent continuous (both in source code and control flow), non-branching
178178/// execution
179- /// * Carve out (leave uncovered) any span that will be counted by another MIR (notably, closures)
179+ /// * Carve out (leave uncovered) any "hole" spans that need to be left blank
180+ /// (e.g. closures that will be counted by their own MIR body)
180181struct SpansRefiner {
181182 /// The initial set of coverage spans, sorted by `Span` (`lo` and `hi`) and by relative
182183 /// dominance between the `BasicCoverageBlock`s of equal `Span`s.
183184 sorted_spans_iter : std:: vec:: IntoIter < SpanFromMir > ,
184185
185- /// The current coverage span to compare to its `prev`, to possibly merge, discard, force the
186- /// discard of the `prev` (and or `pending_dups`), or keep both (with `prev` moved to
187- /// `pending_dups`). If `curr` is not discarded or merged, it becomes `prev` for the next
188- /// iteration.
186+ /// The current coverage span to compare to its `prev`, to possibly merge, discard,
187+ /// or cause `prev` to be modified or discarded.
188+ /// If `curr` is not discarded or merged, it becomes `prev` for the next iteration.
189189 some_curr : Option < CurrCovspan > ,
190190
191191 /// The coverage span from a prior iteration; typically assigned from that iteration's `curr`.
@@ -229,7 +229,7 @@ impl SpansRefiner {
229229 let curr = self . curr ( ) ;
230230
231231 if prev. is_mergeable ( curr) {
232- debug ! ( " same bcb (and neither is a closure), merge with prev={prev:?} ") ;
232+ debug ! ( ?prev , "curr will be merged into prev") ;
233233 let curr = self . take_curr ( ) ;
234234 self . prev_mut ( ) . merge_from ( & curr) ;
235235 } else if prev. span . hi ( ) <= curr. span . lo ( ) {
@@ -238,15 +238,13 @@ impl SpansRefiner {
238238 ) ;
239239 let prev = self . take_prev ( ) . into_refined ( ) ;
240240 self . refined_spans . push ( prev) ;
241- } else if prev. is_closure {
241+ } else if prev. is_hole {
242242 // drop any equal or overlapping span (`curr`) and keep `prev` to test again in the
243243 // next iter
244- debug ! (
245- " curr overlaps a closure (prev). Drop curr and keep prev for next iter. prev={prev:?}" ,
246- ) ;
244+ debug ! ( ?prev, "prev (a hole) overlaps curr, so discarding curr" ) ;
247245 self . take_curr ( ) ; // Discards curr.
248- } else if curr. is_closure {
249- self . carve_out_span_for_closure ( ) ;
246+ } else if curr. is_hole {
247+ self . carve_out_span_for_hole ( ) ;
250248 } else {
251249 self . cutoff_prev_at_overlapping_curr ( ) ;
252250 }
@@ -270,10 +268,9 @@ impl SpansRefiner {
270268 }
271269 } ) ;
272270
273- // Remove spans derived from closures, originally added to ensure the coverage
274- // regions for the current function leave room for the closure's own coverage regions
275- // (injected separately, from the closure's own MIR).
276- self . refined_spans . retain ( |covspan| !covspan. is_closure ) ;
271+ // Discard hole spans, since their purpose was to carve out chunks from
272+ // other spans, but we don't want the holes themselves in the final mappings.
273+ self . refined_spans . retain ( |covspan| !covspan. is_hole ) ;
277274 self . refined_spans
278275 }
279276
@@ -316,48 +313,43 @@ impl SpansRefiner {
316313 {
317314 // Skip curr because prev has already advanced beyond the end of curr.
318315 // This can only happen if a prior iteration updated `prev` to skip past
319- // a region of code, such as skipping past a closure.
320- debug ! (
321- " prev.span starts after curr.span, so curr will be dropped (skipping past \
322- closure?); prev={prev:?}",
323- ) ;
316+ // a region of code, such as skipping past a hole.
317+ debug ! ( ?prev, "prev.span starts after curr.span, so curr will be dropped" ) ;
324318 } else {
325- self . some_curr = Some ( CurrCovspan :: new ( curr. span , curr. bcb , curr. is_closure ) ) ;
319+ self . some_curr = Some ( CurrCovspan :: new ( curr. span , curr. bcb , curr. is_hole ) ) ;
326320 return true ;
327321 }
328322 }
329323 false
330324 }
331325
332- /// If `prev`s span extends left of the closure (`curr`), carve out the closure's span from
333- /// `prev`'s span. (The closure's coverage counters will be injected when processing the
334- /// closure's own MIR.) Add the portion of the span to the left of the closure; and if the span
335- /// extends to the right of the closure, update `prev` to that portion of the span. For any
336- /// `pending_dups`, repeat the same process.
337- fn carve_out_span_for_closure ( & mut self ) {
326+ /// If `prev`s span extends left of the hole (`curr`), carve out the hole's span from
327+ /// `prev`'s span. Add the portion of the span to the left of the hole; and if the span
328+ /// extends to the right of the hole, update `prev` to that portion of the span.
329+ fn carve_out_span_for_hole ( & mut self ) {
338330 let prev = self . prev ( ) ;
339331 let curr = self . curr ( ) ;
340332
341333 let left_cutoff = curr. span . lo ( ) ;
342334 let right_cutoff = curr. span . hi ( ) ;
343- let has_pre_closure_span = prev. span . lo ( ) < right_cutoff;
344- let has_post_closure_span = prev. span . hi ( ) > right_cutoff;
345-
346- if has_pre_closure_span {
347- let mut pre_closure = self . prev ( ) . refined_copy ( ) ;
348- pre_closure . span = pre_closure . span . with_hi ( left_cutoff) ;
349- debug ! ( " prev overlaps a closure. Adding span for pre_closure={:?}" , pre_closure ) ;
350- self . refined_spans . push ( pre_closure ) ;
335+ let has_pre_hole_span = prev. span . lo ( ) < right_cutoff;
336+ let has_post_hole_span = prev. span . hi ( ) > right_cutoff;
337+
338+ if has_pre_hole_span {
339+ let mut pre_hole = prev. refined_copy ( ) ;
340+ pre_hole . span = pre_hole . span . with_hi ( left_cutoff) ;
341+ debug ! ( ?pre_hole , " prev overlaps a hole; adding pre-hole span" ) ;
342+ self . refined_spans . push ( pre_hole ) ;
351343 }
352344
353- if has_post_closure_span {
354- // Mutate `prev.span` to start after the closure (and discard curr).
345+ if has_post_hole_span {
346+ // Mutate `prev.span` to start after the hole (and discard curr).
355347 self . prev_mut ( ) . span = self . prev ( ) . span . with_lo ( right_cutoff) ;
356- debug ! ( " Mutated prev.span to start after the closure. prev={:?}" , self . prev ( ) ) ;
348+ debug ! ( prev=? self . prev ( ) , "mutated prev to start after the hole" ) ;
357349
358350 // Prevent this curr from becoming prev.
359- let closure_covspan = self . take_curr ( ) . into_refined ( ) ;
360- self . refined_spans . push ( closure_covspan ) ; // since self.prev() was already updated
351+ let hole_covspan = self . take_curr ( ) . into_refined ( ) ;
352+ self . refined_spans . push ( hole_covspan ) ; // since self.prev() was already updated
361353 }
362354 }
363355
0 commit comments