File tree 2 files changed +16
-9
lines changed
compiler/rustc_mir_transform/src/coverage
2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -339,7 +339,7 @@ impl<'a> MakeBcbCounters<'a> {
339
339
// A BCB with only one incoming edge gets a simple `Counter` (via `make_counter()`).
340
340
// Also, a BCB that loops back to itself gets a simple `Counter`. This may indicate the
341
341
// program results in a tight infinite loop, but it should still compile.
342
- let one_path_to_target = self . bcb_has_one_path_to_target ( bcb) ;
342
+ let one_path_to_target = ! self . basic_coverage_blocks . bcb_has_multiple_in_edges ( bcb) ;
343
343
if one_path_to_target || self . bcb_predecessors ( bcb) . contains ( & bcb) {
344
344
let counter_kind = self . coverage_counters . make_counter ( ) ;
345
345
if one_path_to_target {
@@ -508,11 +508,4 @@ impl<'a> MakeBcbCounters<'a> {
508
508
self . coverage_counters . bcb_counters [ to_bcb] . as_ref ( )
509
509
}
510
510
}
511
-
512
- /// Returns true if the BasicCoverageBlock has zero or one incoming edge. (If zero, it should be
513
- /// the entry point for the function.)
514
- #[ inline]
515
- fn bcb_has_one_path_to_target ( & self , bcb : BasicCoverageBlock ) -> bool {
516
- self . bcb_predecessors ( bcb) . len ( ) <= 1
517
- }
518
511
}
Original file line number Diff line number Diff line change @@ -199,6 +199,20 @@ impl CoverageGraph {
199
199
pub fn cmp_in_dominator_order ( & self , a : BasicCoverageBlock , b : BasicCoverageBlock ) -> Ordering {
200
200
self . dominators . as_ref ( ) . unwrap ( ) . cmp_in_dominator_order ( a, b)
201
201
}
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
+ }
202
216
}
203
217
204
218
impl Index < BasicCoverageBlock > for CoverageGraph {
@@ -334,7 +348,7 @@ impl BcbBranch {
334
348
to_bcb : BasicCoverageBlock ,
335
349
basic_coverage_blocks : & CoverageGraph ,
336
350
) -> 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 ) {
338
352
Some ( from_bcb)
339
353
} else {
340
354
None
You can’t perform that action at this time.
0 commit comments