@@ -386,8 +386,11 @@ fn bcb_filtered_successors<'a, 'tcx>(
386
386
/// ensures a loop is completely traversed before processing Blocks after the end of the loop.
387
387
#[ derive( Debug ) ]
388
388
pub ( super ) struct TraversalContext {
389
- /// From one or more backedges returning to a loop header.
390
- loop_backedges : Option < ( Vec < BasicCoverageBlock > , BasicCoverageBlock ) > ,
389
+ /// BCB with one or more incoming loop backedges, indicating which loop
390
+ /// this context is for.
391
+ ///
392
+ /// If `None`, this is the non-loop context for the function as a whole.
393
+ loop_header : Option < BasicCoverageBlock > ,
391
394
392
395
/// Worklist of BCBs to be processed in this context.
393
396
worklist : VecDeque < BasicCoverageBlock > ,
@@ -406,7 +409,7 @@ impl<'a> TraverseCoverageGraphWithLoops<'a> {
406
409
let backedges = find_loop_backedges ( basic_coverage_blocks) ;
407
410
408
411
let worklist = VecDeque :: from ( [ basic_coverage_blocks. start_node ( ) ] ) ;
409
- let context_stack = vec ! [ TraversalContext { loop_backedges : None , worklist } ] ;
412
+ let context_stack = vec ! [ TraversalContext { loop_header : None , worklist } ] ;
410
413
411
414
// `context_stack` starts with a `TraversalContext` for the main function context (beginning
412
415
// with the `start` BasicCoverageBlock of the function). New worklists are pushed to the top
@@ -422,8 +425,8 @@ impl<'a> TraverseCoverageGraphWithLoops<'a> {
422
425
self . context_stack
423
426
. iter ( )
424
427
. rev ( )
425
- . filter_map ( |context| context. loop_backedges . as_ref ( ) )
426
- . map ( |( from_bcbs , _to_bcb ) | from_bcbs . as_slice ( ) )
428
+ . filter_map ( |context| context. loop_header )
429
+ . map ( |header_bcb| self . backedges [ header_bcb ] . as_slice ( ) )
427
430
}
428
431
429
432
pub ( super ) fn next ( & mut self ) -> Option < BasicCoverageBlock > {
@@ -443,7 +446,7 @@ impl<'a> TraverseCoverageGraphWithLoops<'a> {
443
446
if self . backedges [ bcb] . len ( ) > 0 {
444
447
debug ! ( "{bcb:?} is a loop header! Start a new TraversalContext..." ) ;
445
448
self . context_stack . push ( TraversalContext {
446
- loop_backedges : Some ( ( self . backedges [ bcb] . clone ( ) , bcb ) ) ,
449
+ loop_header : Some ( bcb) ,
447
450
worklist : VecDeque :: new ( ) ,
448
451
} ) ;
449
452
}
@@ -484,7 +487,7 @@ impl<'a> TraverseCoverageGraphWithLoops<'a> {
484
487
// `Expression`s by creating a Counter in a `BasicCoverageBlock` that the
485
488
// branching block would have given an `Expression` (or vice versa).
486
489
let ( some_successor_to_add, _) =
487
- if let Some ( ( _ , loop_header) ) = context. loop_backedges {
490
+ if let Some ( loop_header) = context. loop_header {
488
491
if basic_coverage_blocks. dominates ( loop_header, successor) {
489
492
( Some ( successor) , Some ( loop_header) )
490
493
} else {
0 commit comments