-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
coverage: Skip spans that can't be un-expanded back to the function body #118525
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,14 +63,14 @@ fn bcb_to_initial_coverage_spans<'a, 'tcx>( | |
|
||
let statement_spans = data.statements.iter().filter_map(move |statement| { | ||
let expn_span = filtered_statement_span(statement)?; | ||
let span = function_source_span(expn_span, body_span); | ||
let span = unexpand_into_body_span(expn_span, body_span)?; | ||
|
||
Some(CoverageSpan::new(span, expn_span, bcb, is_closure(statement))) | ||
}); | ||
|
||
let terminator_span = Some(data.terminator()).into_iter().filter_map(move |terminator| { | ||
let expn_span = filtered_terminator_span(terminator)?; | ||
let span = function_source_span(expn_span, body_span); | ||
let span = unexpand_into_body_span(expn_span, body_span)?; | ||
|
||
Some(CoverageSpan::new(span, expn_span, bcb, false)) | ||
}); | ||
|
@@ -180,14 +180,16 @@ fn filtered_terminator_span(terminator: &Terminator<'_>) -> Option<Span> { | |
/// Returns an extrapolated span (pre-expansion[^1]) corresponding to a range | ||
/// within the function's body source. This span is guaranteed to be contained | ||
/// within, or equal to, the `body_span`. If the extrapolated span is not | ||
/// contained within the `body_span`, the `body_span` is returned. | ||
/// contained within the `body_span`, `None` is returned. | ||
/// | ||
/// [^1]Expansions result from Rust syntax including macros, syntactic sugar, | ||
/// etc.). | ||
#[inline] | ||
fn function_source_span(span: Span, body_span: Span) -> Span { | ||
fn unexpand_into_body_span(span: Span, body_span: Span) -> Option<Span> { | ||
use rustc_span::source_map::original_sp; | ||
|
||
// FIXME(#118525): Consider switching from `original_sp` to `Span::find_ancestor_inside`, | ||
// which is similar but gives slightly different results in some edge cases. | ||
let original_span = original_sp(span, body_span).with_ctxt(body_span.ctxt()); | ||
if body_span.contains(original_span) { original_span } else { body_span } | ||
body_span.contains(original_span).then_some(original_span) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function looks a lot like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was mostly just modifying the existing code, and didn't know about I tried switching over, and the results are mostly the same, with a few small differences in some corner cases. At a glance the changes seem like they might be improvements, but I'm not confident in that conclusion. What I might do is stick with the status quo ( |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,5 +50,5 @@ | |
LL| |#[inline(always)] | ||
LL| 0|fn error() { | ||
LL| 0| panic!("error"); | ||
LL| 0|} | ||
LL| |} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
Function name: unreachable::UNREACHABLE_CLOSURE::{closure#0} | ||
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0f, 27, 00, 49] | ||
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0f, 27, 00, 47] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 0 | ||
Number of file 0 mappings: 1 | ||
- Code(Counter(0)) at (prev + 15, 39) to (start + 0, 73) | ||
- Code(Counter(0)) at (prev + 15, 39) to (start + 0, 71) | ||
|
||
Function name: unreachable::unreachable_function | ||
Raw bytes (9): 0x[01, 01, 00, 01, 01, 11, 01, 02, 02] | ||
Raw bytes (9): 0x[01, 01, 00, 01, 01, 11, 01, 01, 25] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 0 | ||
Number of file 0 mappings: 1 | ||
- Code(Counter(0)) at (prev + 17, 1) to (start + 2, 2) | ||
- Code(Counter(0)) at (prev + 17, 1) to (start + 1, 37) | ||
|
||
Function name: unreachable::unreachable_intrinsic | ||
Raw bytes (9): 0x[01, 01, 00, 01, 01, 16, 01, 02, 02] | ||
Raw bytes (9): 0x[01, 01, 00, 01, 01, 16, 01, 01, 2c] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 0 | ||
Number of file 0 mappings: 1 | ||
- Code(Counter(0)) at (prev + 22, 1) to (start + 2, 2) | ||
- Code(Counter(0)) at (prev + 22, 1) to (start + 1, 44) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't comfortable with actually switching to
Span::find_ancestor_inside
as part of this PR, since I don't quite understand the subtle differences from the status quo.So instead I'm leaving this note to indicate that it might be worth looking into.