@@ -2,7 +2,7 @@ use rustc_data_structures::graph::dominators::{self, Dominators};
2
2
use rustc_data_structures:: graph:: { self , GraphSuccessors , WithNumNodes , WithStartNode } ;
3
3
use rustc_index:: bit_set:: BitSet ;
4
4
use rustc_index:: { IndexSlice , IndexVec } ;
5
- use rustc_middle:: mir:: { self , BasicBlock , BasicBlockData , Terminator , TerminatorKind } ;
5
+ use rustc_middle:: mir:: { self , BasicBlock , TerminatorKind } ;
6
6
7
7
use std:: cmp:: Ordering ;
8
8
use std:: ops:: { Index , IndexMut } ;
@@ -36,9 +36,8 @@ impl CoverageGraph {
36
36
}
37
37
let bcb_data = & bcbs[ bcb] ;
38
38
let mut bcb_successors = Vec :: new ( ) ;
39
- for successor in
40
- bcb_filtered_successors ( & mir_body, & bcb_data. terminator ( mir_body) . kind )
41
- . filter_map ( |successor_bb| bb_to_bcb[ successor_bb] )
39
+ for successor in bcb_filtered_successors ( & mir_body, bcb_data. last_bb ( ) )
40
+ . filter_map ( |successor_bb| bb_to_bcb[ successor_bb] )
42
41
{
43
42
if !seen[ successor] {
44
43
seen[ successor] = true ;
@@ -83,7 +82,7 @@ impl CoverageGraph {
83
82
let mir_cfg_without_unwind = ShortCircuitPreorder :: new ( & mir_body, bcb_filtered_successors) ;
84
83
85
84
let mut basic_blocks = Vec :: new ( ) ;
86
- for ( bb , data ) in mir_cfg_without_unwind {
85
+ for bb in mir_cfg_without_unwind {
87
86
if let Some ( last) = basic_blocks. last ( ) {
88
87
let predecessors = & mir_body. basic_blocks . predecessors ( ) [ bb] ;
89
88
if predecessors. len ( ) > 1 || !predecessors. contains ( last) {
@@ -109,7 +108,7 @@ impl CoverageGraph {
109
108
}
110
109
basic_blocks. push ( bb) ;
111
110
112
- let term = data . terminator ( ) ;
111
+ let term = mir_body [ bb ] . terminator ( ) ;
113
112
114
113
match term. kind {
115
114
TerminatorKind :: Return { .. }
@@ -316,11 +315,6 @@ impl BasicCoverageBlockData {
316
315
pub fn last_bb ( & self ) -> BasicBlock {
317
316
* self . basic_blocks . last ( ) . unwrap ( )
318
317
}
319
-
320
- #[ inline( always) ]
321
- pub fn terminator < ' a , ' tcx > ( & self , mir_body : & ' a mir:: Body < ' tcx > ) -> & ' a Terminator < ' tcx > {
322
- & mir_body[ self . last_bb ( ) ] . terminator ( )
323
- }
324
318
}
325
319
326
320
/// Represents a successor from a branching BasicCoverageBlock (such as the arms of a `SwitchInt`)
@@ -362,13 +356,15 @@ impl std::fmt::Debug for BcbBranch {
362
356
}
363
357
}
364
358
365
- // Returns the `Terminator`s non-unwind successors.
359
+ // Returns the subset of a block's successors that are relevant for the coverage
360
+ // graph, i.e. those that do not represent unwinds or unreachable branches.
366
361
// FIXME(#78544): MIR InstrumentCoverage: Improve coverage of `#[should_panic]` tests and
367
362
// `catch_unwind()` handlers.
368
363
fn bcb_filtered_successors < ' a , ' tcx > (
369
364
body : & ' a mir:: Body < ' tcx > ,
370
- term_kind : & ' a TerminatorKind < ' tcx > ,
365
+ bb : BasicBlock ,
371
366
) -> Box < dyn Iterator < Item = BasicBlock > + ' a > {
367
+ let term_kind = & body[ bb] . terminator ( ) . kind ;
372
368
Box :: new (
373
369
match & term_kind {
374
370
// SwitchInt successors are never unwind, and all of them should be traversed.
@@ -562,10 +558,7 @@ struct ShortCircuitPreorder<'a, 'tcx, F> {
562
558
563
559
impl < ' a , ' tcx , F > ShortCircuitPreorder < ' a , ' tcx , F >
564
560
where
565
- F : Fn (
566
- & ' a mir:: Body < ' tcx > ,
567
- & ' a TerminatorKind < ' tcx > ,
568
- ) -> Box < dyn Iterator < Item = BasicBlock > + ' a > ,
561
+ F : Fn ( & ' a mir:: Body < ' tcx > , BasicBlock ) -> Box < dyn Iterator < Item = BasicBlock > + ' a > ,
569
562
{
570
563
fn new ( body : & ' a mir:: Body < ' tcx > , filtered_successors : F ) -> Self {
571
564
Self {
@@ -579,26 +572,19 @@ where
579
572
580
573
impl < ' a , ' tcx , F > Iterator for ShortCircuitPreorder < ' a , ' tcx , F >
581
574
where
582
- F : Fn (
583
- & ' a mir:: Body < ' tcx > ,
584
- & ' a TerminatorKind < ' tcx > ,
585
- ) -> Box < dyn Iterator < Item = BasicBlock > + ' a > ,
575
+ F : Fn ( & ' a mir:: Body < ' tcx > , BasicBlock ) -> Box < dyn Iterator < Item = BasicBlock > + ' a > ,
586
576
{
587
- type Item = ( BasicBlock , & ' a BasicBlockData < ' tcx > ) ;
577
+ type Item = BasicBlock ;
588
578
589
- fn next ( & mut self ) -> Option < ( BasicBlock , & ' a BasicBlockData < ' tcx > ) > {
590
- while let Some ( idx ) = self . worklist . pop ( ) {
591
- if !self . visited . insert ( idx ) {
579
+ fn next ( & mut self ) -> Option < BasicBlock > {
580
+ while let Some ( bb ) = self . worklist . pop ( ) {
581
+ if !self . visited . insert ( bb ) {
592
582
continue ;
593
583
}
594
584
595
- let data = & self . body [ idx] ;
596
-
597
- if let Some ( ref term) = data. terminator {
598
- self . worklist . extend ( ( self . filtered_successors ) ( & self . body , & term. kind ) ) ;
599
- }
585
+ self . worklist . extend ( ( self . filtered_successors ) ( self . body , bb) ) ;
600
586
601
- return Some ( ( idx , data ) ) ;
587
+ return Some ( bb ) ;
602
588
}
603
589
604
590
None
0 commit comments