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 #5: Fixed rare issues after testing on real-world crate Commit #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 #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 #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 #9: test coverage of inline generic struct function Commit #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 #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 #12: Optimized use of SourceMap and SourceFile Commit #13: Fixed a regression, and synched with upstream Some generated test file names changed due to some new change upstream. Commit #14: Stripping out crate disambiguators from demangled names These can vary depending on the test platform. Commit #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 #16: Modify rust-demangler to strip disambiguators by default Commit #17: Remove std::process::exit from coverage tests Due to Issue #77553, programs that call std::process::exit() do not generate coverage results on Windows MSVC. Commit #18: fix: test file paths exceeding Windows max path len
This commit is contained in:
parent
d890e64dff
commit
f5aebad28f
145 changed files with 18996 additions and 1867 deletions
File diff suppressed because it is too large
Load diff
|
@ -150,26 +150,31 @@ fn dump_matched_mir_node<'tcx, F>(
|
|||
|
||||
if let Some(spanview) = tcx.sess.opts.debugging_opts.dump_mir_spanview {
|
||||
let _: io::Result<()> = try {
|
||||
let mut file =
|
||||
create_dump_file(tcx, "html", pass_num, pass_name, disambiguator, body.source)?;
|
||||
let file_basename =
|
||||
dump_file_basename(tcx, pass_num, pass_name, disambiguator, body.source);
|
||||
let mut file = create_dump_file_with_basename(tcx, &file_basename, "html")?;
|
||||
if body.source.def_id().is_local() {
|
||||
write_mir_fn_spanview(tcx, body, spanview, &mut file)?;
|
||||
write_mir_fn_spanview(
|
||||
tcx,
|
||||
body,
|
||||
spanview,
|
||||
&file_basename,
|
||||
&mut file,
|
||||
)?;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the path to the filename where we should dump a given MIR.
|
||||
/// Also used by other bits of code (e.g., NLL inference) that dump
|
||||
/// graphviz data or other things.
|
||||
fn dump_path(
|
||||
/// Returns the file basename portion (without extension) of a filename path
|
||||
/// where we should dump a MIR representation output files.
|
||||
fn dump_file_basename(
|
||||
tcx: TyCtxt<'_>,
|
||||
extension: &str,
|
||||
pass_num: Option<&dyn Display>,
|
||||
pass_name: &str,
|
||||
disambiguator: &dyn Display,
|
||||
source: MirSource<'tcx>,
|
||||
) -> PathBuf {
|
||||
) -> String {
|
||||
let promotion_id = match source.promoted {
|
||||
Some(id) => format!("-{:?}", id),
|
||||
None => String::new(),
|
||||
|
@ -184,9 +189,6 @@ fn dump_path(
|
|||
}
|
||||
};
|
||||
|
||||
let mut file_path = PathBuf::new();
|
||||
file_path.push(Path::new(&tcx.sess.opts.debugging_opts.dump_mir_dir));
|
||||
|
||||
let crate_name = tcx.crate_name(source.def_id().krate);
|
||||
let item_name = tcx.def_path(source.def_id()).to_filename_friendly_no_crate();
|
||||
// All drop shims have the same DefId, so we have to add the type
|
||||
|
@ -206,23 +208,46 @@ fn dump_path(
|
|||
_ => String::new(),
|
||||
};
|
||||
|
||||
let file_name = format!(
|
||||
"{}.{}{}{}{}.{}.{}.{}",
|
||||
crate_name,
|
||||
item_name,
|
||||
shim_disambiguator,
|
||||
promotion_id,
|
||||
pass_num,
|
||||
pass_name,
|
||||
disambiguator,
|
||||
extension,
|
||||
);
|
||||
format!(
|
||||
"{}.{}{}{}{}.{}.{}",
|
||||
crate_name, item_name, shim_disambiguator, promotion_id, pass_num, pass_name, disambiguator,
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns the path to the filename where we should dump a given MIR.
|
||||
/// Also used by other bits of code (e.g., NLL inference) that dump
|
||||
/// graphviz data or other things.
|
||||
fn dump_path(tcx: TyCtxt<'_>, basename: &str, extension: &str) -> PathBuf {
|
||||
let mut file_path = PathBuf::new();
|
||||
file_path.push(Path::new(&tcx.sess.opts.debugging_opts.dump_mir_dir));
|
||||
|
||||
let file_name = format!("{}.{}", basename, extension,);
|
||||
|
||||
file_path.push(&file_name);
|
||||
|
||||
file_path
|
||||
}
|
||||
|
||||
/// Attempts to open the MIR dump file with the given name and extension.
|
||||
fn create_dump_file_with_basename(
|
||||
tcx: TyCtxt<'_>,
|
||||
file_basename: &str,
|
||||
extension: &str,
|
||||
) -> io::Result<io::BufWriter<fs::File>> {
|
||||
let file_path = dump_path(tcx, file_basename, extension);
|
||||
if let Some(parent) = file_path.parent() {
|
||||
fs::create_dir_all(parent).map_err(|e| {
|
||||
io::Error::new(
|
||||
e.kind(),
|
||||
format!("IO error creating MIR dump directory: {:?}; {}", parent, e),
|
||||
)
|
||||
})?;
|
||||
}
|
||||
Ok(io::BufWriter::new(fs::File::create(&file_path).map_err(|e| {
|
||||
io::Error::new(e.kind(), format!("IO error creating MIR dump file: {:?}; {}", file_path, e))
|
||||
})?))
|
||||
}
|
||||
|
||||
/// Attempts to open a file where we should dump a given MIR or other
|
||||
/// bit of MIR-related data. Used by `mir-dump`, but also by other
|
||||
/// bits of code (e.g., NLL inference) that dump graphviz data or
|
||||
|
@ -235,11 +260,11 @@ pub(crate) fn create_dump_file(
|
|||
disambiguator: &dyn Display,
|
||||
source: MirSource<'tcx>,
|
||||
) -> io::Result<io::BufWriter<fs::File>> {
|
||||
let file_path = dump_path(tcx, extension, pass_num, pass_name, disambiguator, source);
|
||||
if let Some(parent) = file_path.parent() {
|
||||
fs::create_dir_all(parent)?;
|
||||
}
|
||||
Ok(io::BufWriter::new(fs::File::create(&file_path)?))
|
||||
create_dump_file_with_basename(
|
||||
tcx,
|
||||
&dump_file_basename(tcx, pass_num, pass_name, disambiguator, source),
|
||||
extension,
|
||||
)
|
||||
}
|
||||
|
||||
/// Write out a human-readable textual representation for the given MIR.
|
||||
|
|
|
@ -16,9 +16,13 @@ const ANNOTATION_RIGHT_BRACKET: char = '\u{2989}'; // Unicode `Z NOTATION LEFT B
|
|||
const NEW_LINE_SPAN: &str = "</span>\n<span class=\"line\">";
|
||||
const HEADER: &str = r#"<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>coverage_of_if_else - Code Regions</title>
|
||||
<style>
|
||||
<head>"#;
|
||||
const START_BODY: &str = r#"</head>
|
||||
<body>"#;
|
||||
const FOOTER: &str = r#"</body>
|
||||
</html>"#;
|
||||
|
||||
const STYLE_SECTION: &str = r#"<style>
|
||||
.line {
|
||||
counter-increment: line;
|
||||
}
|
||||
|
@ -72,16 +76,12 @@ const HEADER: &str = r#"<!DOCTYPE html>
|
|||
/* requires hover over a span ONLY on its first line */
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>"#;
|
||||
|
||||
const FOOTER: &str = r#"
|
||||
</body>
|
||||
</html>"#;
|
||||
</style>"#;
|
||||
|
||||
/// Metadata to highlight the span of a MIR BasicBlock, Statement, or Terminator.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SpanViewable {
|
||||
pub bb: BasicBlock,
|
||||
pub span: Span,
|
||||
pub id: String,
|
||||
pub tooltip: String,
|
||||
|
@ -92,6 +92,7 @@ pub fn write_mir_fn_spanview<'tcx, W>(
|
|||
tcx: TyCtxt<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
spanview: MirSpanview,
|
||||
title: &str,
|
||||
w: &mut W,
|
||||
) -> io::Result<()>
|
||||
where
|
||||
|
@ -126,16 +127,17 @@ where
|
|||
}
|
||||
}
|
||||
}
|
||||
write_spanview_document(tcx, def_id, span_viewables, w)?;
|
||||
write_document(tcx, def_id, span_viewables, title, w)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Generate a spanview HTML+CSS document for the given local function `def_id`, and a pre-generated
|
||||
/// list `SpanViewable`s.
|
||||
pub fn write_spanview_document<'tcx, W>(
|
||||
pub fn write_document<'tcx, W>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def_id: DefId,
|
||||
mut span_viewables: Vec<SpanViewable>,
|
||||
title: &str,
|
||||
w: &mut W,
|
||||
) -> io::Result<()>
|
||||
where
|
||||
|
@ -153,6 +155,9 @@ where
|
|||
source_map.span_to_snippet(fn_span).expect("function should have printable source")
|
||||
);
|
||||
writeln!(w, "{}", HEADER)?;
|
||||
writeln!(w, "<title>{}</title>", title)?;
|
||||
writeln!(w, "{}", STYLE_SECTION)?;
|
||||
writeln!(w, "{}", START_BODY)?;
|
||||
write!(
|
||||
w,
|
||||
r#"<div class="code" style="counter-reset: line {}"><span class="line">{}"#,
|
||||
|
@ -182,6 +187,7 @@ where
|
|||
end_pos.to_usize(),
|
||||
ordered_viewables.len()
|
||||
);
|
||||
let curr_id = &ordered_viewables[0].id;
|
||||
let (next_from_pos, next_ordered_viewables) = write_next_viewable_with_overlaps(
|
||||
tcx,
|
||||
from_pos,
|
||||
|
@ -204,13 +210,17 @@ where
|
|||
from_pos = next_from_pos;
|
||||
if next_ordered_viewables.len() != ordered_viewables.len() {
|
||||
ordered_viewables = next_ordered_viewables;
|
||||
alt = !alt;
|
||||
if let Some(next_ordered_viewable) = ordered_viewables.first() {
|
||||
if &next_ordered_viewable.id != curr_id {
|
||||
alt = !alt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if from_pos < end_pos {
|
||||
write_coverage_gap(tcx, from_pos, end_pos, w)?;
|
||||
}
|
||||
write!(w, r#"</span></div>"#)?;
|
||||
writeln!(w, r#"</span></div>"#)?;
|
||||
writeln!(w, "{}", FOOTER)?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -273,7 +283,7 @@ fn statement_span_viewable<'tcx>(
|
|||
}
|
||||
let id = format!("{}[{}]", bb.index(), i);
|
||||
let tooltip = tooltip(tcx, &id, span, vec![statement.clone()], &None);
|
||||
Some(SpanViewable { span, id, tooltip })
|
||||
Some(SpanViewable { bb, span, id, tooltip })
|
||||
}
|
||||
|
||||
fn terminator_span_viewable<'tcx>(
|
||||
|
@ -289,7 +299,7 @@ fn terminator_span_viewable<'tcx>(
|
|||
}
|
||||
let id = format!("{}:{}", bb.index(), terminator_kind_name(term));
|
||||
let tooltip = tooltip(tcx, &id, span, vec![], &data.terminator);
|
||||
Some(SpanViewable { span, id, tooltip })
|
||||
Some(SpanViewable { bb, span, id, tooltip })
|
||||
}
|
||||
|
||||
fn block_span_viewable<'tcx>(
|
||||
|
@ -304,7 +314,7 @@ fn block_span_viewable<'tcx>(
|
|||
}
|
||||
let id = format!("{}", bb.index());
|
||||
let tooltip = tooltip(tcx, &id, span, data.statements.clone(), &data.terminator);
|
||||
Some(SpanViewable { span, id, tooltip })
|
||||
Some(SpanViewable { bb, span, id, tooltip })
|
||||
}
|
||||
|
||||
fn compute_block_span<'tcx>(data: &BasicBlockData<'tcx>, body_span: Span) -> Span {
|
||||
|
@ -456,6 +466,7 @@ where
|
|||
remaining_viewables.len()
|
||||
);
|
||||
// Write the overlaps (and the overlaps' overlaps, if any) up to `to_pos`.
|
||||
let curr_id = &remaining_viewables[0].id;
|
||||
let (next_from_pos, next_remaining_viewables) = write_next_viewable_with_overlaps(
|
||||
tcx,
|
||||
from_pos,
|
||||
|
@ -480,7 +491,11 @@ where
|
|||
from_pos = next_from_pos;
|
||||
if next_remaining_viewables.len() != remaining_viewables.len() {
|
||||
remaining_viewables = next_remaining_viewables;
|
||||
subalt = !subalt;
|
||||
if let Some(next_ordered_viewable) = remaining_viewables.first() {
|
||||
if &next_ordered_viewable.id != curr_id {
|
||||
subalt = !subalt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if from_pos <= viewable.span.hi() {
|
||||
|
@ -649,8 +664,12 @@ fn fn_span<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Span {
|
|||
tcx.hir().local_def_id_to_hir_id(def_id.as_local().expect("expected DefId is local"));
|
||||
let fn_decl_span = tcx.hir().span(hir_id);
|
||||
let body_span = hir_body(tcx, def_id).value.span;
|
||||
debug_assert_eq!(fn_decl_span.ctxt(), body_span.ctxt());
|
||||
fn_decl_span.to(body_span)
|
||||
if fn_decl_span.ctxt() == body_span.ctxt() {
|
||||
fn_decl_span.to(body_span)
|
||||
} else {
|
||||
// This probably occurs for functions defined via macros
|
||||
body_span
|
||||
}
|
||||
}
|
||||
|
||||
fn hir_body<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx rustc_hir::Body<'tcx> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue