File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed
compiler/rustc_mir_transform/src/coverage Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -341,7 +341,7 @@ impl<'a> MakeBcbCounters<'a> {
341341 // A BCB with only one incoming edge gets a simple `Counter` (via `make_counter()`).
342342 // Also, a BCB that loops back to itself gets a simple `Counter`. This may indicate the
343343 // program results in a tight infinite loop, but it should still compile.
344- let one_path_to_target = self . bcb_has_one_path_to_target ( bcb) ;
344+ let one_path_to_target = ! self . basic_coverage_blocks . bcb_has_multiple_in_edges ( bcb) ;
345345 if one_path_to_target || self . bcb_predecessors ( bcb) . contains ( & bcb) {
346346 let counter_kind = self . coverage_counters . make_counter ( ) ;
347347 if one_path_to_target {
@@ -510,11 +510,4 @@ impl<'a> MakeBcbCounters<'a> {
510510 self . coverage_counters . bcb_counters [ to_bcb] . as_ref ( )
511511 }
512512 }
513-
514- /// Returns true if the BasicCoverageBlock has zero or one incoming edge. (If zero, it should be
515- /// the entry point for the function.)
516- #[ inline]
517- fn bcb_has_one_path_to_target ( & self , bcb : BasicCoverageBlock ) -> bool {
518- self . bcb_predecessors ( bcb) . len ( ) <= 1
519- }
520513}
Original file line number Diff line number Diff line change @@ -199,6 +199,20 @@ impl CoverageGraph {
199199 pub fn cmp_in_dominator_order ( & self , a : BasicCoverageBlock , b : BasicCoverageBlock ) -> Ordering {
200200 self . dominators . as_ref ( ) . unwrap ( ) . cmp_in_dominator_order ( a, b)
201201 }
202+
203+ /// Returns true if the given node has 2 or more in-edges, i.e. 2 or more
204+ /// predecessors.
205+ ///
206+ /// This property is interesting to code that assigns counters to nodes and
207+ /// edges, because if a node _doesn't_ have multiple in-edges, then there's
208+ /// no benefit in having a separate counter for its in-edge, because it
209+ /// would have the same value as the node's own counter.
210+ ///
211+ /// FIXME: That assumption might not be true for [`TerminatorKind::Yield`]?
212+ #[ inline( always) ]
213+ pub ( super ) fn bcb_has_multiple_in_edges ( & self , bcb : BasicCoverageBlock ) -> bool {
214+ self . predecessors [ bcb] . len ( ) > 1
215+ }
202216}
203217
204218impl Index < BasicCoverageBlock > for CoverageGraph {
@@ -334,7 +348,7 @@ impl BcbBranch {
334348 to_bcb : BasicCoverageBlock ,
335349 basic_coverage_blocks : & CoverageGraph ,
336350 ) -> Self {
337- let edge_from_bcb = if basic_coverage_blocks. predecessors [ to_bcb ] . len ( ) > 1 {
351+ let edge_from_bcb = if basic_coverage_blocks. bcb_has_multiple_in_edges ( from_bcb ) {
338352 Some ( from_bcb)
339353 } else {
340354 None
You can’t perform that action at this time.
0 commit comments