Skip to content

Commit c510440

Browse files
committed
coverage: Introduce CoverageKind::Mappings (not yet used)
This new kind of coverage statement only holds source region mappings, and does not represent a counter-increment or store expression details. This patch performs the plumbing needed to add a new enum arm, but does not yet adjust the MIR coverage instrumentor to use it.
1 parent 0d6e07a commit c510440

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ impl<'tcx> FunctionCoverage<'tcx> {
127127
}
128128

129129
#[instrument(level = "debug", skip(self))]
130-
fn add_mappings(&mut self, kind: CovTerm, code_regions: &[CodeRegion]) {
130+
pub(crate) fn add_mappings(&mut self, term: CovTerm, code_regions: &[CodeRegion]) {
131131
self.mappings
132-
.extend(code_regions.iter().cloned().map(|code_region| Mapping { kind, code_region }));
132+
.extend(code_regions.iter().cloned().map(|code_region| Mapping { term, code_region }));
133133
}
134134

135135
pub(crate) fn finalize(&mut self) {
@@ -240,8 +240,8 @@ impl<'tcx> FunctionCoverage<'tcx> {
240240
/// Converts this function's coverage mappings into an intermediate form
241241
/// that will be used by `mapgen` when preparing for FFI.
242242
pub(crate) fn mappings_for_ffi(&self) -> impl Iterator<Item = (Counter, &CodeRegion)> {
243-
self.mappings.iter().map(|&Mapping { kind, ref code_region }| {
244-
let counter = Counter::from_term(kind);
243+
self.mappings.iter().map(|&Mapping { term, ref code_region }| {
244+
let counter = Counter::from_term(term);
245245
(counter, code_region)
246246
})
247247
}

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
141141
CoverageKind::Unreachable => {
142142
func_coverage.add_unreachable_regions(code_regions);
143143
}
144+
CoverageKind::Mappings { term } => {
145+
func_coverage.add_mappings(term, code_regions);
146+
}
144147
}
145148
}
146149
}

compiler/rustc_middle/src/mir/coverage.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ pub enum CoverageKind {
7777
rhs: CovTerm,
7878
},
7979
Unreachable,
80+
Mappings {
81+
term: CovTerm,
82+
},
8083
}
8184

8285
impl Debug for CoverageKind {
@@ -96,6 +99,7 @@ impl Debug for CoverageKind {
9699
rhs,
97100
),
98101
Unreachable => write!(fmt, "Unreachable"),
102+
Mappings { term } => fmt.debug_struct("Mappings").field("term", term).finish(),
99103
}
100104
}
101105
}
@@ -144,11 +148,11 @@ pub struct Mapping {
144148
// Coverage codegen relies on this field order when it sorts a function's mappings.
145149
pub code_region: CodeRegion,
146150

147-
/// Kind of coverage region that this mapping represents.
151+
/// Indicates whether this mapping uses a counter value, expression value,
152+
/// or zero value.
148153
///
149-
/// Currently we only support ordinary `Code` regions, so the "kind" is
150-
/// just a term. When we add support for other region kinds allowed by
151-
/// LLVM (e.g. branch regions, expansion regions), we'll need to replace
152-
/// this with a dedicated mapping-kind enum.
153-
pub kind: CovTerm,
154+
/// FIXME: When we add support for mapping kinds other than `Code`
155+
/// (e.g. branch regions, expansion regions), replace this with a dedicated
156+
/// mapping-kind enum.
157+
pub term: CovTerm,
154158
}

compiler/rustc_mir_transform/src/coverage/query.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl CoverageVisitor {
6969
self.update_from_term(rhs);
7070
}
7171
CoverageKind::Unreachable => {}
72+
CoverageKind::Mappings { term } => self.update_from_term(term),
7273
}
7374
}
7475
}

0 commit comments

Comments
 (0)