From 25b615e7f4feea26ac53700d30b2752679eb0f70 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Sun, 5 Nov 2023 22:21:22 +1100 Subject: [PATCH] coverage: Assert that bcb0 starts with bb0 and has no in-edges This explains why we don't have to worry about bcb0 having multiple in-edges. --- compiler/rustc_mir_transform/src/coverage/graph.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/compiler/rustc_mir_transform/src/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs index 34ab2992e3b3f..263bfdaaabab7 100644 --- a/compiler/rustc_mir_transform/src/coverage/graph.rs +++ b/compiler/rustc_mir_transform/src/coverage/graph.rs @@ -62,6 +62,14 @@ impl CoverageGraph { Self { bcbs, bb_to_bcb, successors, predecessors, dominators: None }; let dominators = dominators::dominators(&basic_coverage_blocks); basic_coverage_blocks.dominators = Some(dominators); + + // The coverage graph's entry-point node (bcb0) always starts with bb0, + // which never has predecessors. Any other blocks merged into bcb0 can't + // have multiple (coverage-relevant) predecessors, so bcb0 always has + // zero in-edges. + assert!(basic_coverage_blocks[START_BCB].leader_bb() == mir::START_BLOCK); + assert!(basic_coverage_blocks.predecessors[START_BCB].is_empty()); + basic_coverage_blocks } @@ -211,6 +219,11 @@ impl CoverageGraph { /// FIXME: That assumption might not be true for [`TerminatorKind::Yield`]? #[inline(always)] pub(super) fn bcb_has_multiple_in_edges(&self, bcb: BasicCoverageBlock) -> bool { + // Even though bcb0 conceptually has an extra virtual in-edge due to + // being the entry point, we've already asserted that it has no _other_ + // in-edges, so there's no possibility of it having _multiple_ in-edges. + // (And since its virtual in-edge doesn't exist in the graph, that edge + // can't have a separate counter anyway.) self.predecessors[bcb].len() > 1 } }