coverage: Add enums to accommodate other kinds of coverage mappings

This commit is contained in:
Zalathar 2023-12-28 14:07:18 +11:00
parent c5932182ad
commit 124fff0777
9 changed files with 94 additions and 49 deletions

View file

@ -9,7 +9,7 @@ mod tests;
use self::counters::{BcbCounter, CoverageCounters};
use self::graph::{BasicCoverageBlock, CoverageGraph};
use self::spans::{BcbMapping, CoverageSpans};
use self::spans::{BcbMapping, BcbMappingKind, CoverageSpans};
use crate::MirPass;
@ -150,10 +150,12 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
coverage_spans
.all_bcb_mappings()
.filter_map(|&BcbMapping { bcb, span }| {
let term = term_for_bcb(bcb);
.filter_map(|&BcbMapping { kind: bcb_mapping_kind, span }| {
let kind = match bcb_mapping_kind {
BcbMappingKind::Code(bcb) => MappingKind::Code(term_for_bcb(bcb)),
};
let code_region = make_code_region(source_map, file_name, span, body_span)?;
Some(Mapping { term, code_region })
Some(Mapping { kind, code_region })
})
.collect::<Vec<_>>()
}

View file

@ -8,9 +8,15 @@ use crate::coverage::ExtractedHirInfo;
mod from_mir;
#[derive(Clone, Copy, Debug)]
pub(super) enum BcbMappingKind {
/// Associates an ordinary executable code span with its corresponding BCB.
Code(BasicCoverageBlock),
}
#[derive(Debug)]
pub(super) struct BcbMapping {
pub(super) bcb: BasicCoverageBlock,
pub(super) kind: BcbMappingKind,
pub(super) span: Span,
}
@ -38,7 +44,7 @@ impl CoverageSpans {
);
mappings.extend(coverage_spans.into_iter().map(|CoverageSpan { bcb, span, .. }| {
// Each span produced by the generator represents an ordinary code region.
BcbMapping { bcb, span }
BcbMapping { kind: BcbMappingKind::Code(bcb), span }
}));
if mappings.is_empty() {
@ -47,8 +53,13 @@ impl CoverageSpans {
// Identify which BCBs have one or more mappings.
let mut bcb_has_mappings = BitSet::new_empty(basic_coverage_blocks.num_nodes());
for &BcbMapping { bcb, span: _ } in &mappings {
let mut insert = |bcb| {
bcb_has_mappings.insert(bcb);
};
for &BcbMapping { kind, span: _ } in &mappings {
match kind {
BcbMappingKind::Code(bcb) => insert(bcb),
}
}
Some(Self { bcb_has_mappings, mappings })