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 @@ -341,7 +341,7 @@ impl<'a> MakeBcbCounters<'a> {
341
341
// A BCB with only one incoming edge gets a simple `Counter` (via `make_counter()`).
342
342
// Also, a BCB that loops back to itself gets a simple `Counter`. This may indicate the
343
343
// 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) ;
345
345
if one_path_to_target || self . bcb_predecessors ( bcb) . contains ( & bcb) {
346
346
let counter_kind = self . coverage_counters . make_counter ( ) ;
347
347
if one_path_to_target {
@@ -510,11 +510,4 @@ impl<'a> MakeBcbCounters<'a> {
510
510
self . coverage_counters . bcb_counters [ to_bcb] . as_ref ( )
511
511
}
512
512
}
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
- }
520
513
}
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 {
@@ -335,7 +349,7 @@ impl BcbBranch {
335
349
to_bcb : BasicCoverageBlock ,
336
350
basic_coverage_blocks : & CoverageGraph ,
337
351
) -> Self {
338
- let edge_from_bcb = if basic_coverage_blocks. predecessors [ to_bcb ] . len ( ) > 1 {
352
+ let edge_from_bcb = if basic_coverage_blocks. bcb_has_multiple_in_edges ( from_bcb ) {
339
353
Some ( from_bcb)
340
354
} else {
341
355
None
You can’t perform that action at this time.
0 commit comments