mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 11:05:36 +00:00
In order to make coverage instrumentation HIR-aware, we need to have MIR building inject marker statements at key locations, so that instrumentation can accurately reconstruct the relationship between HIR constructs and MIR-level control flow. The most important of these is `PointKind::Expr`, which associates a HIR expression with the start of the MIR that will evaluate that expression. There isn't a single convenient place to inject these, but we can get close by observing that THIR building wraps every expression in a `thir::ExprKind::Scope` node, which also contains the `HirId` of that expression. If we inject a marker whenever `thir::ExprKind::Scope` is lowered, that results in an accurate marker for every expression. Other markers are also injected at key points that don't correspond directly to a HIR node, to avoid major regressions in coverage-map quality.
21 lines
770 B
Diff
21 lines
770 B
Diff
- // MIR for `bar` before InstrumentCoverage
|
|
+ // MIR for `bar` after InstrumentCoverage
|
|
|
|
fn bar() -> bool {
|
|
let mut _0: bool;
|
|
|
|
+ coverage Code { bcb: bcb0 } => $DIR/instrument_coverage.rs:27:1: 27:17 (#0);
|
|
+ coverage Code { bcb: bcb0 } => $DIR/instrument_coverage.rs:28:5: 28:9 (#0);
|
|
+ coverage Code { bcb: bcb0 } => $DIR/instrument_coverage.rs:29:1: 29:2 (#0);
|
|
+
|
|
bb0: {
|
|
+ Coverage::VirtualCounter(bcb0);
|
|
Coverage::Point(Expr, HirId(DefId(0:4 ~ instrument_coverage[f559]::bar).3);
|
|
Coverage::Point(Expr, HirId(DefId(0:4 ~ instrument_coverage[f559]::bar).2);
|
|
_0 = const true;
|
|
Coverage::Point(FunctionEnd, HirId(DefId(0:4 ~ instrument_coverage[f559]::bar).0);
|
|
return;
|
|
}
|
|
}
|
|
|