Skip to content

Commit

Permalink
Updates to experimental coverage counter injection
Browse files Browse the repository at this point in the history
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
  • Loading branch information
richkadel committed Oct 5, 2020
1 parent d890e64 commit f5aebad
Show file tree
Hide file tree
Showing 145 changed files with 18,993 additions and 1,864 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2938,8 +2938,9 @@ dependencies = [

[[package]]
name = "rust-demangler"
version = "0.0.0"
version = "0.0.1"
dependencies = [
"regex",
"rustc-demangle",
]

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl CoverageMapGenerator {
let (filenames_index, _) = self.filenames.insert_full(c_filename);
virtual_file_mapping.push(filenames_index as u32);
}
debug!("Adding counter {:?} to map for {:?}", counter, region,);
mapping_regions.push(CounterMappingRegion::code_region(
counter,
current_file_id,
Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_codegen_ssa/src/coverageinfo/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ impl FunctionCoverage {
let id_to_counter =
|new_indexes: &IndexVec<InjectedExpressionIndex, MappedExpressionIndex>,
id: ExpressionOperandId| {
if id.index() < self.counters.len() {
if id == ExpressionOperandId::ZERO {
Some(Counter::zero())
} else if id.index() < self.counters.len() {
let index = CounterValueReference::from(id.index());
self.counters
.get(index)
Expand Down Expand Up @@ -179,14 +181,19 @@ impl FunctionCoverage {
// been assigned a `new_index`.
let mapped_expression_index =
MappedExpressionIndex::from(counter_expressions.len());
counter_expressions.push(CounterExpression::new(
let expression = CounterExpression::new(
lhs_counter,
match op {
Op::Add => ExprKind::Add,
Op::Subtract => ExprKind::Subtract,
},
rhs_counter,
));
);
debug!(
"Adding expression {:?} = {:?} at {:?}",
mapped_expression_index, expression, region
);
counter_expressions.push(expression);
new_indexes[original_index] = mapped_expression_index;
expression_regions.push((Counter::expression(mapped_expression_index), region));
}
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_data_structures/src/graph/dominators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use super::iterate::reverse_post_order;
use super::ControlFlowGraph;
use rustc_index::vec::{Idx, IndexVec};
use std::borrow::BorrowMut;
use std::cmp::Ordering;

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -108,6 +109,14 @@ impl<Node: Idx> Dominators<Node> {
// FIXME -- could be optimized by using post-order-rank
self.dominators(node).any(|n| n == dom)
}

/// Provide deterministic ordering of nodes such that, if any two nodes have a dominator
/// relationship, the dominator will always precede the dominated. (The relative ordering
/// of two unrelated nodes will also be consistent, but otherwise the order has no
/// meaning.) This method cannot be used to determine if either Node dominates the other.
pub fn rank_partial_cmp(&self, lhs: Node, rhs: Node) -> Option<Ordering> {
self.post_order_rank[lhs].partial_cmp(&self.post_order_rank[rhs])
}
}

pub struct Iter<'dom, Node: Idx> {
Expand Down
19 changes: 19 additions & 0 deletions compiler/rustc_middle/src/mir/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ rustc_index::newtype_index! {
}
}

impl ExpressionOperandId {
/// An expression operand for a "zero counter", as described in the following references:
///
/// * https://github.com/rust-lang/llvm-project/blob/llvmorg-8.0.0/llvm/docs/CoverageMappingFormat.rst#counter
/// * https://github.com/rust-lang/llvm-project/blob/llvmorg-8.0.0/llvm/docs/CoverageMappingFormat.rst#tag
/// * https://github.com/rust-lang/llvm-project/blob/llvmorg-8.0.0/llvm/docs/CoverageMappingFormat.rst#counter-expressions
///
/// This operand can be used to count two or more separate code regions with a single counter,
/// if they run sequentially with no branches, by injecting the `Counter` in a `BasicBlock` for
/// one of the code regions, and inserting `CounterExpression`s ("add ZERO to the counter") in
/// the coverage map for the other code regions.
pub const ZERO: Self = Self::from_u32(0);
}

rustc_index::newtype_index! {
pub struct CounterValueReference {
derive [HashStable]
Expand All @@ -22,6 +36,11 @@ rustc_index::newtype_index! {
}
}

impl CounterValueReference {
// Counters start at 1 to reserve 0 for ExpressionOperandId::ZERO.
pub const START: Self = Self::from_u32(1);
}

rustc_index::newtype_index! {
pub struct InjectedExpressionIndex {
derive [HashStable]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ macro_rules! make_mir_visitor {
}

fn super_coverage(&mut self,
_kind: & $($mutability)? Coverage,
_coverage: & $($mutability)? Coverage,
_location: Location) {
}

Expand Down
Loading

0 comments on commit f5aebad

Please sign in to comment.