@@ -90,23 +90,23 @@ pub(super) fn generate_coverage_spans(
90
90
struct CurrCovspan {
91
91
span : Span ,
92
92
bcb : BasicCoverageBlock ,
93
- is_closure : bool ,
93
+ is_hole : bool ,
94
94
}
95
95
96
96
impl 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 }
99
99
}
100
100
101
101
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 }
104
104
}
105
105
106
106
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
108
108
// been carved out of `prev`.
109
- debug_assert ! ( self . is_closure ) ;
109
+ debug_assert ! ( self . is_hole ) ;
110
110
self . into_prev ( ) . into_refined ( )
111
111
}
112
112
}
@@ -118,12 +118,12 @@ struct PrevCovspan {
118
118
/// List of all the original spans from MIR that have been merged into this
119
119
/// span. Mainly used to precisely skip over gaps when truncating a span.
120
120
merged_spans : Vec < Span > ,
121
- is_closure : bool ,
121
+ is_hole : bool ,
122
122
}
123
123
124
124
impl PrevCovspan {
125
125
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
127
127
}
128
128
129
129
fn merge_from ( & mut self , other : & CurrCovspan ) {
@@ -142,8 +142,8 @@ impl PrevCovspan {
142
142
}
143
143
144
144
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 }
147
147
}
148
148
149
149
fn into_refined ( self ) -> RefinedCovspan {
@@ -156,12 +156,12 @@ impl PrevCovspan {
156
156
struct RefinedCovspan {
157
157
span : Span ,
158
158
bcb : BasicCoverageBlock ,
159
- is_closure : bool ,
159
+ is_hole : bool ,
160
160
}
161
161
162
162
impl RefinedCovspan {
163
163
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
165
165
}
166
166
167
167
fn merge_from ( & mut self , other : & Self ) {
@@ -176,7 +176,8 @@ impl RefinedCovspan {
176
176
/// * Remove duplicate source code coverage regions
177
177
/// * Merge spans that represent continuous (both in source code and control flow), non-branching
178
178
/// 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)
180
181
struct SpansRefiner {
181
182
/// The initial set of coverage spans, sorted by `Span` (`lo` and `hi`) and by relative
182
183
/// dominance between the `BasicCoverageBlock`s of equal `Span`s.
@@ -228,7 +229,7 @@ impl SpansRefiner {
228
229
let curr = self . curr ( ) ;
229
230
230
231
if prev. is_mergeable ( curr) {
231
- debug ! ( " same bcb (and neither is a closure), merge with prev={prev:?} ") ;
232
+ debug ! ( ?prev , "curr will be merged into prev") ;
232
233
let curr = self . take_curr ( ) ;
233
234
self . prev_mut ( ) . merge_from ( & curr) ;
234
235
} else if prev. span . hi ( ) <= curr. span . lo ( ) {
@@ -237,15 +238,13 @@ impl SpansRefiner {
237
238
) ;
238
239
let prev = self . take_prev ( ) . into_refined ( ) ;
239
240
self . refined_spans . push ( prev) ;
240
- } else if prev. is_closure {
241
+ } else if prev. is_hole {
241
242
// drop any equal or overlapping span (`curr`) and keep `prev` to test again in the
242
243
// next iter
243
- debug ! (
244
- " curr overlaps a closure (prev). Drop curr and keep prev for next iter. prev={prev:?}" ,
245
- ) ;
244
+ debug ! ( ?prev, "prev (a hole) overlaps curr, so discarding curr" ) ;
246
245
self . take_curr ( ) ; // Discards curr.
247
- } else if curr. is_closure {
248
- self . carve_out_span_for_closure ( ) ;
246
+ } else if curr. is_hole {
247
+ self . carve_out_span_for_hole ( ) ;
249
248
} else {
250
249
self . cutoff_prev_at_overlapping_curr ( ) ;
251
250
}
@@ -269,10 +268,9 @@ impl SpansRefiner {
269
268
}
270
269
} ) ;
271
270
272
- // Remove spans derived from closures, originally added to ensure the coverage
273
- // regions for the current function leave room for the closure's own coverage regions
274
- // (injected separately, from the closure's own MIR).
275
- 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 ) ;
276
274
self . refined_spans
277
275
}
278
276
@@ -315,47 +313,43 @@ impl SpansRefiner {
315
313
{
316
314
// Skip curr because prev has already advanced beyond the end of curr.
317
315
// This can only happen if a prior iteration updated `prev` to skip past
318
- // a region of code, such as skipping past a closure.
319
- debug ! (
320
- " prev.span starts after curr.span, so curr will be dropped (skipping past \
321
- closure?); prev={prev:?}",
322
- ) ;
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" ) ;
323
318
} else {
324
- 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 ) ) ;
325
320
return true ;
326
321
}
327
322
}
328
323
false
329
324
}
330
325
331
- /// If `prev`s span extends left of the closure (`curr`), carve out the closure's span from
332
- /// `prev`'s span. (The closure's coverage counters will be injected when processing the
333
- /// closure's own MIR.) Add the portion of the span to the left of the closure; and if the span
334
- /// extends to the right of the closure, update `prev` to that portion of the span.
335
- 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 ) {
336
330
let prev = self . prev ( ) ;
337
331
let curr = self . curr ( ) ;
338
332
339
333
let left_cutoff = curr. span . lo ( ) ;
340
334
let right_cutoff = curr. span . hi ( ) ;
341
- let has_pre_closure_span = prev. span . lo ( ) < right_cutoff;
342
- let has_post_closure_span = prev. span . hi ( ) > right_cutoff;
343
-
344
- if has_pre_closure_span {
345
- let mut pre_closure = self . prev ( ) . refined_copy ( ) ;
346
- pre_closure . span = pre_closure . span . with_hi ( left_cutoff) ;
347
- debug ! ( " prev overlaps a closure. Adding span for pre_closure={:?}" , pre_closure ) ;
348
- 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 ) ;
349
343
}
350
344
351
- if has_post_closure_span {
352
- // 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).
353
347
self . prev_mut ( ) . span = self . prev ( ) . span . with_lo ( right_cutoff) ;
354
- debug ! ( " Mutated prev.span to start after the closure. prev={:?}" , self . prev ( ) ) ;
348
+ debug ! ( prev=? self . prev ( ) , "mutated prev to start after the hole" ) ;
355
349
356
350
// Prevent this curr from becoming prev.
357
- let closure_covspan = self . take_curr ( ) . into_refined ( ) ;
358
- 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
359
353
}
360
354
}
361
355
0 commit comments