@@ -450,7 +450,7 @@ impl<'a> TraverseCoverageGraphWithLoops<'a> {
450450 worklist : VecDeque :: new ( ) ,
451451 } ) ;
452452 }
453- self . extend_worklist ( bcb) ;
453+ self . add_successors_to_worklists ( bcb) ;
454454 return Some ( bcb) ;
455455 } else {
456456 // Strip contexts with empty worklists from the top of the stack
@@ -461,10 +461,11 @@ impl<'a> TraverseCoverageGraphWithLoops<'a> {
461461 None
462462 }
463463
464- pub fn extend_worklist ( & mut self , bcb : BasicCoverageBlock ) {
464+ pub fn add_successors_to_worklists ( & mut self , bcb : BasicCoverageBlock ) {
465465 let Self { basic_coverage_blocks, .. } = * self ;
466466 let successors = & basic_coverage_blocks. successors [ bcb] ;
467467 debug ! ( "{:?} has {} successors:" , bcb, successors. len( ) ) ;
468+
468469 for & successor in successors {
469470 if successor == bcb {
470471 debug ! (
@@ -473,43 +474,42 @@ impl<'a> TraverseCoverageGraphWithLoops<'a> {
473474 bcb
474475 ) ;
475476 // Don't re-add this successor to the worklist. We are already processing it.
477+ // FIXME: This claims to skip just the self-successor, but it actually skips
478+ // all other successors as well. Does that matter?
476479 break ;
477480 }
478- for context in self . context_stack . iter_mut ( ) . rev ( ) {
479- // Add successors of the current BCB to the appropriate context. Successors that
480- // stay within a loop are added to the BCBs context worklist. Successors that
481- // exit the loop (they are not dominated by the loop header) must be reachable
482- // from other BCBs outside the loop, and they will be added to a different
483- // worklist.
484- //
485- // Branching blocks (with more than one successor) must be processed before
486- // blocks with only one successor, to prevent unnecessarily complicating
487- // `Expression`s by creating a Counter in a `BasicCoverageBlock` that the
488- // branching block would have given an `Expression` (or vice versa).
489- let ( some_successor_to_add, _) =
490- if let Some ( loop_header) = context. loop_header {
491- if basic_coverage_blocks. dominates ( loop_header, successor) {
492- ( Some ( successor) , Some ( loop_header) )
493- } else {
494- ( None , None )
495- }
496- } else {
497- ( Some ( successor) , None )
498- } ;
499-
500- // FIXME: The code below had debug messages claiming to add items to a
501- // particular end of the worklist, but was confused about which end was
502- // which. The existing behaviour has been preserved for now, but it's
503- // unclear what the intended behaviour was.
504-
505- if let Some ( successor_to_add) = some_successor_to_add {
506- if basic_coverage_blocks. successors [ successor_to_add] . len ( ) > 1 {
507- context. worklist . push_back ( successor_to_add) ;
508- } else {
509- context. worklist . push_front ( successor_to_add) ;
510- }
511- break ;
512- }
481+
482+ // Add successors of the current BCB to the appropriate context. Successors that
483+ // stay within a loop are added to the BCBs context worklist. Successors that
484+ // exit the loop (they are not dominated by the loop header) must be reachable
485+ // from other BCBs outside the loop, and they will be added to a different
486+ // worklist.
487+ //
488+ // Branching blocks (with more than one successor) must be processed before
489+ // blocks with only one successor, to prevent unnecessarily complicating
490+ // `Expression`s by creating a Counter in a `BasicCoverageBlock` that the
491+ // branching block would have given an `Expression` (or vice versa).
492+
493+ let context = self
494+ . context_stack
495+ . iter_mut ( )
496+ . rev ( )
497+ . find ( |context| match context. loop_header {
498+ Some ( loop_header) => basic_coverage_blocks. dominates ( loop_header, successor) ,
499+ None => true ,
500+ } )
501+ . unwrap_or_else ( || bug ! ( "should always fall back to the root non-loop context" ) ) ;
502+ debug ! ( "adding to worklist for {:?}" , context. loop_header) ;
503+
504+ // FIXME: The code below had debug messages claiming to add items to a
505+ // particular end of the worklist, but was confused about which end was
506+ // which. The existing behaviour has been preserved for now, but it's
507+ // unclear what the intended behaviour was.
508+
509+ if basic_coverage_blocks. successors [ successor] . len ( ) > 1 {
510+ context. worklist . push_back ( successor) ;
511+ } else {
512+ context. worklist . push_front ( successor) ;
513513 }
514514 }
515515 }
0 commit comments