Skip to content

Commit f5aebad

Browse files
committed
Updates to experimental coverage counter injection
This is a combination of 18 commits. Commit #2: Additional examples and some small improvements. Commit #3: fixed mir-opt non-mir extensions and spanview title elements Corrected a fairly recent assumption in runtest.rs that all MIR dump files end in .mir. (It was appending .mir to the graphviz .dot and spanview .html file names when generating blessed output files. That also left outdated files in the baseline alongside the files with the incorrect names, which I've now removed.) Updated spanview HTML title elements to match their content, replacing a hardcoded and incorrect name that was left in accidentally when originally submitted. Commit #4: added more test examples also improved Makefiles with support for non-zero exit status and to force validation of tests unless a specific test overrides it with a specific comment. Commit rust-lang#5: Fixed rare issues after testing on real-world crate Commit rust-lang#6: Addressed PR feedback, and removed temporary -Zexperimental-coverage -Zinstrument-coverage once again supports the latest capabilities of LLVM instrprof coverage instrumentation. Also fixed a bug in spanview. Commit rust-lang#7: Fix closure handling, add tests for closures and inner items And cleaned up other tests for consistency, and to make it more clear where spans start/end by breaking up lines. Commit rust-lang#8: renamed "typical" test results "expected" Now that the `llvm-cov show` tests are improved to normally expect matching actuals, and to allow individual tests to override that expectation. Commit rust-lang#9: test coverage of inline generic struct function Commit rust-lang#10: Addressed review feedback * Removed unnecessary Unreachable filter. * Replaced a match wildcard with remining variants. * Added more comments to help clarify the role of successors() in the CFG traversal Commit rust-lang#11: refactoring based on feedback * refactored `fn coverage_spans()`. * changed the way I expand an empty coverage span to improve performance * fixed a typo that I had accidently left in, in visit.rs Commit rust-lang#12: Optimized use of SourceMap and SourceFile Commit rust-lang#13: Fixed a regression, and synched with upstream Some generated test file names changed due to some new change upstream. Commit rust-lang#14: Stripping out crate disambiguators from demangled names These can vary depending on the test platform. Commit rust-lang#15: Ignore llvm-cov show diff on test with generics, expand IO error message Tests with generics produce llvm-cov show results with demangled names that can include an unstable "crate disambiguator" (hex value). The value changes when run in the Rust CI Windows environment. I added a sed filter to strip them out (in a prior commit), but sed also appears to fail in the same environment. Until I can figure out a workaround, I'm just going to ignore this specific test result. I added a FIXME to follow up later, but it's not that critical. I also saw an error with Windows GNU, but the IO error did not specify a path for the directory or file that triggered the error. I updated the error messages to provide more info for next, time but also noticed some other tests with similar steps did not fail. Looks spurious. Commit rust-lang#16: Modify rust-demangler to strip disambiguators by default Commit rust-lang#17: Remove std::process::exit from coverage tests Due to Issue rust-lang#77553, programs that call std::process::exit() do not generate coverage results on Windows MSVC. Commit rust-lang#18: fix: test file paths exceeding Windows max path len
1 parent d890e64 commit f5aebad

File tree

145 files changed

+18993
-1864
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+18993
-1864
lines changed

Cargo.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -2938,8 +2938,9 @@ dependencies = [
29382938

29392939
[[package]]
29402940
name = "rust-demangler"
2941-
version = "0.0.0"
2941+
version = "0.0.1"
29422942
dependencies = [
2943+
"regex",
29432944
"rustc-demangle",
29442945
]
29452946

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl CoverageMapGenerator {
126126
let (filenames_index, _) = self.filenames.insert_full(c_filename);
127127
virtual_file_mapping.push(filenames_index as u32);
128128
}
129+
debug!("Adding counter {:?} to map for {:?}", counter, region,);
129130
mapping_regions.push(CounterMappingRegion::code_region(
130131
counter,
131132
current_file_id,

compiler/rustc_codegen_ssa/src/coverageinfo/map.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ impl FunctionCoverage {
143143
let id_to_counter =
144144
|new_indexes: &IndexVec<InjectedExpressionIndex, MappedExpressionIndex>,
145145
id: ExpressionOperandId| {
146-
if id.index() < self.counters.len() {
146+
if id == ExpressionOperandId::ZERO {
147+
Some(Counter::zero())
148+
} else if id.index() < self.counters.len() {
147149
let index = CounterValueReference::from(id.index());
148150
self.counters
149151
.get(index)
@@ -179,14 +181,19 @@ impl FunctionCoverage {
179181
// been assigned a `new_index`.
180182
let mapped_expression_index =
181183
MappedExpressionIndex::from(counter_expressions.len());
182-
counter_expressions.push(CounterExpression::new(
184+
let expression = CounterExpression::new(
183185
lhs_counter,
184186
match op {
185187
Op::Add => ExprKind::Add,
186188
Op::Subtract => ExprKind::Subtract,
187189
},
188190
rhs_counter,
189-
));
191+
);
192+
debug!(
193+
"Adding expression {:?} = {:?} at {:?}",
194+
mapped_expression_index, expression, region
195+
);
196+
counter_expressions.push(expression);
190197
new_indexes[original_index] = mapped_expression_index;
191198
expression_regions.push((Counter::expression(mapped_expression_index), region));
192199
}

compiler/rustc_data_structures/src/graph/dominators/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use super::iterate::reverse_post_order;
99
use super::ControlFlowGraph;
1010
use rustc_index::vec::{Idx, IndexVec};
1111
use std::borrow::BorrowMut;
12+
use std::cmp::Ordering;
1213

1314
#[cfg(test)]
1415
mod tests;
@@ -108,6 +109,14 @@ impl<Node: Idx> Dominators<Node> {
108109
// FIXME -- could be optimized by using post-order-rank
109110
self.dominators(node).any(|n| n == dom)
110111
}
112+
113+
/// Provide deterministic ordering of nodes such that, if any two nodes have a dominator
114+
/// relationship, the dominator will always precede the dominated. (The relative ordering
115+
/// of two unrelated nodes will also be consistent, but otherwise the order has no
116+
/// meaning.) This method cannot be used to determine if either Node dominates the other.
117+
pub fn rank_partial_cmp(&self, lhs: Node, rhs: Node) -> Option<Ordering> {
118+
self.post_order_rank[lhs].partial_cmp(&self.post_order_rank[rhs])
119+
}
111120
}
112121

113122
pub struct Iter<'dom, Node: Idx> {

compiler/rustc_middle/src/mir/coverage/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ rustc_index::newtype_index! {
1414
}
1515
}
1616

17+
impl ExpressionOperandId {
18+
/// An expression operand for a "zero counter", as described in the following references:
19+
///
20+
/// * https://github.com./rust-lang/llvm-project/blob/llvmorg-8.0.0/llvm/docs/CoverageMappingFormat.rst#counter
21+
/// * https://github.com./rust-lang/llvm-project/blob/llvmorg-8.0.0/llvm/docs/CoverageMappingFormat.rst#tag
22+
/// * https://github.com./rust-lang/llvm-project/blob/llvmorg-8.0.0/llvm/docs/CoverageMappingFormat.rst#counter-expressions
23+
///
24+
/// This operand can be used to count two or more separate code regions with a single counter,
25+
/// if they run sequentially with no branches, by injecting the `Counter` in a `BasicBlock` for
26+
/// one of the code regions, and inserting `CounterExpression`s ("add ZERO to the counter") in
27+
/// the coverage map for the other code regions.
28+
pub const ZERO: Self = Self::from_u32(0);
29+
}
30+
1731
rustc_index::newtype_index! {
1832
pub struct CounterValueReference {
1933
derive [HashStable]
@@ -22,6 +36,11 @@ rustc_index::newtype_index! {
2236
}
2337
}
2438

39+
impl CounterValueReference {
40+
// Counters start at 1 to reserve 0 for ExpressionOperandId::ZERO.
41+
pub const START: Self = Self::from_u32(1);
42+
}
43+
2544
rustc_index::newtype_index! {
2645
pub struct InjectedExpressionIndex {
2746
derive [HashStable]

compiler/rustc_middle/src/mir/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ macro_rules! make_mir_visitor {
752752
}
753753

754754
fn super_coverage(&mut self,
755-
_kind: & $($mutability)? Coverage,
755+
_coverage: & $($mutability)? Coverage,
756756
_location: Location) {
757757
}
758758

0 commit comments

Comments
 (0)