Skip to content

Commit 51d692c

Browse files
committed
Tools, tests, and experimenting with MIR-derived coverage counters
Adds a new mir_dump output file in HTML/CSS to visualize code regions and the MIR features that they came from (including overlapping spans). See example below: Includes a basic, MIR-block-based implementation of coverage injection, available via `-Zexperimental-coverage`. This implementation has known flaws and omissions, but is simple enough to validate the new tools and tests. The existing `-Zinstrument-coverage` option currently enables function-level coverage only, which at least appears to generate accurate coverage reports at that level. Experimental coverage is not accurate at this time. When branch coverage works as intended, the `-Zexperimental-coverage` option should be removed. This PR replaces the bulk of PR rust-lang#75828, with the remaining parts of that PR distributed among other separate and indentpent PRs. This PR depends on three of those other PRs: rust-lang#76000, rust-lang#76002, and Rust compiler MCP rust-lang/compiler-team#278 Relevant issue: rust-lang#34701 - Implement support for LLVMs code coverage instrumentation ![Screen-Recording-2020-08-21-at-2](https://user-images.githubusercontent.com/3827298/90972923-ff417880-e4d1-11ea-92bb-8713c6198f6d.gif)
1 parent e36e4bd commit 51d692c

File tree

28 files changed

+2072
-299
lines changed

28 files changed

+2072
-299
lines changed

compiler/rustc_middle/src/mir/mod.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,24 @@ impl Debug for Statement<'_> {
15301530
AscribeUserType(box (ref place, ref c_ty), ref variance) => {
15311531
write!(fmt, "AscribeUserType({:?}, {:?}, {:?})", place, variance, c_ty)
15321532
}
1533-
Coverage(box ref coverage) => write!(fmt, "{:?}", coverage),
1533+
Coverage(box ref coverage) => {
1534+
let rgn = &coverage.code_region;
1535+
match coverage.kind {
1536+
CoverageKind::Counter { id, .. } => {
1537+
write!(fmt, "Coverage::Counter({:?}) for {:?}", id.index(), rgn)
1538+
}
1539+
CoverageKind::Expression { id, lhs, op, rhs } => write!(
1540+
fmt,
1541+
"Coverage::Expression({:?}) = {} {} {} for {:?}",
1542+
id.index(),
1543+
lhs.index(),
1544+
if op == coverage::Op::Add { "+" } else { "-" },
1545+
rhs.index(),
1546+
rgn
1547+
),
1548+
CoverageKind::Unreachable => write!(fmt, "Coverage::Unreachable for {:?}", rgn),
1549+
}
1550+
}
15341551
Nop => write!(fmt, "nop"),
15351552
}
15361553
}

0 commit comments

Comments
 (0)