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
|
@ -428,58 +428,22 @@ impl SourceMap {
|
|||
}
|
||||
}
|
||||
|
||||
/// Return the SourceFile that contains the given `BytePos`
|
||||
pub fn lookup_source_file(&self, pos: BytePos) -> Lrc<SourceFile> {
|
||||
let idx = self.lookup_source_file_idx(pos);
|
||||
(*self.files.borrow().source_files)[idx].clone()
|
||||
}
|
||||
|
||||
/// Looks up source information about a `BytePos`.
|
||||
pub fn lookup_char_pos(&self, pos: BytePos) -> Loc {
|
||||
let chpos = self.bytepos_to_file_charpos(pos);
|
||||
match self.lookup_line(pos) {
|
||||
Ok(SourceFileAndLine { sf: f, line: a }) => {
|
||||
let line = a + 1; // Line numbers start at 1
|
||||
let linebpos = f.lines[a];
|
||||
let linechpos = self.bytepos_to_file_charpos(linebpos);
|
||||
let col = chpos - linechpos;
|
||||
|
||||
let col_display = {
|
||||
let start_width_idx = f
|
||||
.non_narrow_chars
|
||||
.binary_search_by_key(&linebpos, |x| x.pos())
|
||||
.unwrap_or_else(|x| x);
|
||||
let end_width_idx = f
|
||||
.non_narrow_chars
|
||||
.binary_search_by_key(&pos, |x| x.pos())
|
||||
.unwrap_or_else(|x| x);
|
||||
let special_chars = end_width_idx - start_width_idx;
|
||||
let non_narrow: usize = f.non_narrow_chars[start_width_idx..end_width_idx]
|
||||
.iter()
|
||||
.map(|x| x.width())
|
||||
.sum();
|
||||
col.0 - special_chars + non_narrow
|
||||
};
|
||||
debug!("byte pos {:?} is on the line at byte pos {:?}", pos, linebpos);
|
||||
debug!("char pos {:?} is on the line at char pos {:?}", chpos, linechpos);
|
||||
debug!("byte is on line: {}", line);
|
||||
assert!(chpos >= linechpos);
|
||||
Loc { file: f, line, col, col_display }
|
||||
}
|
||||
Err(f) => {
|
||||
let col_display = {
|
||||
let end_width_idx = f
|
||||
.non_narrow_chars
|
||||
.binary_search_by_key(&pos, |x| x.pos())
|
||||
.unwrap_or_else(|x| x);
|
||||
let non_narrow: usize =
|
||||
f.non_narrow_chars[0..end_width_idx].iter().map(|x| x.width()).sum();
|
||||
chpos.0 - end_width_idx + non_narrow
|
||||
};
|
||||
Loc { file: f, line: 0, col: chpos, col_display }
|
||||
}
|
||||
}
|
||||
let sf = self.lookup_source_file(pos);
|
||||
let (line, col, col_display) = sf.lookup_file_pos_with_col_display(pos);
|
||||
Loc { file: sf, line, col, col_display }
|
||||
}
|
||||
|
||||
// If the corresponding `SourceFile` is empty, does not return a line number.
|
||||
pub fn lookup_line(&self, pos: BytePos) -> Result<SourceFileAndLine, Lrc<SourceFile>> {
|
||||
let idx = self.lookup_source_file_idx(pos);
|
||||
|
||||
let f = (*self.files.borrow().source_files)[idx].clone();
|
||||
let f = self.lookup_source_file(pos);
|
||||
|
||||
match f.lookup_line(pos) {
|
||||
Some(line) => Ok(SourceFileAndLine { sf: f, line }),
|
||||
|
@ -934,27 +898,8 @@ impl SourceMap {
|
|||
/// Converts an absolute `BytePos` to a `CharPos` relative to the `SourceFile`.
|
||||
pub fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos {
|
||||
let idx = self.lookup_source_file_idx(bpos);
|
||||
let map = &(*self.files.borrow().source_files)[idx];
|
||||
|
||||
// The number of extra bytes due to multibyte chars in the `SourceFile`.
|
||||
let mut total_extra_bytes = 0;
|
||||
|
||||
for mbc in map.multibyte_chars.iter() {
|
||||
debug!("{}-byte char at {:?}", mbc.bytes, mbc.pos);
|
||||
if mbc.pos < bpos {
|
||||
// Every character is at least one byte, so we only
|
||||
// count the actual extra bytes.
|
||||
total_extra_bytes += mbc.bytes as u32 - 1;
|
||||
// We should never see a byte position in the middle of a
|
||||
// character.
|
||||
assert!(bpos.to_u32() >= mbc.pos.to_u32() + mbc.bytes as u32);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert!(map.start_pos.to_u32() + total_extra_bytes <= bpos.to_u32());
|
||||
CharPos(bpos.to_usize() - map.start_pos.to_usize() - total_extra_bytes as usize)
|
||||
let sf = &(*self.files.borrow().source_files)[idx];
|
||||
sf.bytepos_to_file_charpos(bpos)
|
||||
}
|
||||
|
||||
// Returns the index of the `SourceFile` (in `self.files`) that contains `pos`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue