1- use super :: Error ;
2-
31use itertools:: Itertools ;
4- use rustc_data_structures:: fx:: FxHashMap ;
52use rustc_data_structures:: graph:: dominators:: { self , Dominators } ;
63use rustc_data_structures:: graph:: { self , GraphSuccessors , WithNumNodes , WithStartNode } ;
74use rustc_index:: bit_set:: BitSet ;
85use rustc_index:: { IndexSlice , IndexVec } ;
9- use rustc_middle:: mir:: coverage:: * ;
106use rustc_middle:: mir:: { self , BasicBlock , BasicBlockData , Terminator , TerminatorKind } ;
117
128use std:: cmp:: Ordering ;
@@ -15,10 +11,7 @@ use std::ops::{Index, IndexMut};
1511const ID_SEPARATOR : & str = "," ;
1612
1713/// A coverage-specific simplification of the MIR control flow graph (CFG). The `CoverageGraph`s
18- /// nodes are `BasicCoverageBlock`s, which encompass one or more MIR `BasicBlock`s, plus a
19- /// `CoverageKind` counter (to be added by `CoverageCounters::make_bcb_counters`), and an optional
20- /// set of additional counters--if needed--to count incoming edges, if there are more than one.
21- /// (These "edge counters" are eventually converted into new MIR `BasicBlock`s.)
14+ /// nodes are `BasicCoverageBlock`s, which encompass one or more MIR `BasicBlock`s.
2215#[ derive( Debug ) ]
2316pub ( super ) struct CoverageGraph {
2417 bcbs : IndexVec < BasicCoverageBlock , BasicCoverageBlockData > ,
@@ -195,13 +188,6 @@ impl CoverageGraph {
195188 self . bcbs . iter_enumerated ( )
196189 }
197190
198- #[ inline( always) ]
199- pub fn iter_enumerated_mut (
200- & mut self ,
201- ) -> impl Iterator < Item = ( BasicCoverageBlock , & mut BasicCoverageBlockData ) > {
202- self . bcbs . iter_enumerated_mut ( )
203- }
204-
205191 #[ inline( always) ]
206192 pub fn bcb_from_bb ( & self , bb : BasicBlock ) -> Option < BasicCoverageBlock > {
207193 if bb. index ( ) < self . bb_to_bcb . len ( ) { self . bb_to_bcb [ bb] } else { None }
@@ -320,14 +306,12 @@ rustc_index::newtype_index! {
320306#[ derive( Debug , Clone ) ]
321307pub ( super ) struct BasicCoverageBlockData {
322308 pub basic_blocks : Vec < BasicBlock > ,
323- pub counter_kind : Option < CoverageKind > ,
324- edge_from_bcbs : Option < FxHashMap < BasicCoverageBlock , CoverageKind > > ,
325309}
326310
327311impl BasicCoverageBlockData {
328312 pub fn from ( basic_blocks : Vec < BasicBlock > ) -> Self {
329313 assert ! ( basic_blocks. len( ) > 0 ) ;
330- Self { basic_blocks, counter_kind : None , edge_from_bcbs : None }
314+ Self { basic_blocks }
331315 }
332316
333317 #[ inline( always) ]
@@ -345,80 +329,6 @@ impl BasicCoverageBlockData {
345329 & mir_body[ self . last_bb ( ) ] . terminator ( )
346330 }
347331
348- pub fn set_counter ( & mut self , counter_kind : CoverageKind ) -> Result < Operand , Error > {
349- debug_assert ! (
350- // If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
351- // have an expression (to be injected into an existing `BasicBlock` represented by this
352- // `BasicCoverageBlock`).
353- self . edge_from_bcbs. is_none( ) || counter_kind. is_expression( ) ,
354- "attempt to add a `Counter` to a BCB target with existing incoming edge counters"
355- ) ;
356- let operand = counter_kind. as_operand ( ) ;
357- if let Some ( replaced) = self . counter_kind . replace ( counter_kind) {
358- Error :: from_string ( format ! (
359- "attempt to set a BasicCoverageBlock coverage counter more than once; \
360- {self:?} already had counter {replaced:?}",
361- ) )
362- } else {
363- Ok ( operand)
364- }
365- }
366-
367- #[ inline( always) ]
368- pub fn counter ( & self ) -> Option < & CoverageKind > {
369- self . counter_kind . as_ref ( )
370- }
371-
372- #[ inline( always) ]
373- pub fn take_counter ( & mut self ) -> Option < CoverageKind > {
374- self . counter_kind . take ( )
375- }
376-
377- pub fn set_edge_counter_from (
378- & mut self ,
379- from_bcb : BasicCoverageBlock ,
380- counter_kind : CoverageKind ,
381- ) -> Result < Operand , Error > {
382- if level_enabled ! ( tracing:: Level :: DEBUG ) {
383- // If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
384- // have an expression (to be injected into an existing `BasicBlock` represented by this
385- // `BasicCoverageBlock`).
386- if self . counter_kind . as_ref ( ) . is_some_and ( |c| !c. is_expression ( ) ) {
387- return Error :: from_string ( format ! (
388- "attempt to add an incoming edge counter from {from_bcb:?} when the target BCB already \
389- has a `Counter`"
390- ) ) ;
391- }
392- }
393- let operand = counter_kind. as_operand ( ) ;
394- if let Some ( replaced) =
395- self . edge_from_bcbs . get_or_insert_default ( ) . insert ( from_bcb, counter_kind)
396- {
397- Error :: from_string ( format ! (
398- "attempt to set an edge counter more than once; from_bcb: \
399- {from_bcb:?} already had counter {replaced:?}",
400- ) )
401- } else {
402- Ok ( operand)
403- }
404- }
405-
406- #[ inline]
407- pub fn edge_counter_from ( & self , from_bcb : BasicCoverageBlock ) -> Option < & CoverageKind > {
408- if let Some ( edge_from_bcbs) = & self . edge_from_bcbs {
409- edge_from_bcbs. get ( & from_bcb)
410- } else {
411- None
412- }
413- }
414-
415- #[ inline]
416- pub fn take_edge_counters (
417- & mut self ,
418- ) -> Option < impl Iterator < Item = ( BasicCoverageBlock , CoverageKind ) > > {
419- self . edge_from_bcbs . take ( ) . map ( |m| m. into_iter ( ) )
420- }
421-
422332 pub fn id ( & self ) -> String {
423333 format ! ( "@{}" , self . basic_blocks. iter( ) . map( |bb| bb. index( ) . to_string( ) ) . join( ID_SEPARATOR ) )
424334 }
@@ -448,17 +358,6 @@ impl BcbBranch {
448358 Self { edge_from_bcb, target_bcb : to_bcb }
449359 }
450360
451- pub fn counter < ' a > (
452- & self ,
453- basic_coverage_blocks : & ' a CoverageGraph ,
454- ) -> Option < & ' a CoverageKind > {
455- if let Some ( from_bcb) = self . edge_from_bcb {
456- basic_coverage_blocks[ self . target_bcb ] . edge_counter_from ( from_bcb)
457- } else {
458- basic_coverage_blocks[ self . target_bcb ] . counter ( )
459- }
460- }
461-
462361 pub fn is_only_path_to_target ( & self ) -> bool {
463362 self . edge_from_bcb . is_none ( )
464363 }
0 commit comments