-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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: Discard spans that fill the entire function body #121135
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Function name: closure_unit_return::explicit_unit | ||
Raw bytes (14): 0x[01, 01, 00, 02, 01, 07, 01, 01, 10, 01, 05, 05, 02, 02] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 0 | ||
Number of file 0 mappings: 2 | ||
- Code(Counter(0)) at (prev + 7, 1) to (start + 1, 16) | ||
- Code(Counter(0)) at (prev + 5, 5) to (start + 2, 2) | ||
|
||
Function name: closure_unit_return::explicit_unit::{closure#0} (unused) | ||
Raw bytes (9): 0x[01, 01, 00, 01, 00, 08, 16, 02, 06] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 0 | ||
Number of file 0 mappings: 1 | ||
- Code(Zero) at (prev + 8, 22) to (start + 2, 6) | ||
|
||
Function name: closure_unit_return::implicit_unit | ||
Raw bytes (14): 0x[01, 01, 00, 02, 01, 10, 01, 01, 10, 01, 05, 05, 02, 02] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 0 | ||
Number of file 0 mappings: 2 | ||
- Code(Counter(0)) at (prev + 16, 1) to (start + 1, 16) | ||
- Code(Counter(0)) at (prev + 5, 5) to (start + 2, 2) | ||
|
||
Function name: closure_unit_return::implicit_unit::{closure#0} (unused) | ||
Raw bytes (9): 0x[01, 01, 00, 01, 00, 11, 16, 02, 06] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 0 | ||
Number of file 0 mappings: 1 | ||
- Code(Zero) at (prev + 17, 22) to (start + 2, 6) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
LL| |#![feature(coverage_attribute)] | ||
LL| |// edition: 2021 | ||
LL| | | ||
LL| |// Regression test for an inconsistency between functions that return the value | ||
LL| |// of their trailing expression, and functions that implicitly return `()`. | ||
LL| | | ||
LL| 1|fn explicit_unit() { | ||
LL| 1| let closure = || { | ||
LL| 0| (); | ||
LL| 0| }; | ||
LL| | | ||
LL| 1| drop(closure); | ||
LL| 1| () // explicit return of trailing value | ||
LL| 1|} | ||
LL| | | ||
LL| 1|fn implicit_unit() { | ||
LL| 1| let closure = || { | ||
LL| 0| (); | ||
LL| 0| }; | ||
LL| | | ||
LL| 1| drop(closure); | ||
LL| 1| // implicit return of `()` | ||
LL| 1|} | ||
LL| | | ||
LL| |#[coverage(off)] | ||
LL| |fn main() { | ||
LL| | explicit_unit(); | ||
LL| | implicit_unit(); | ||
LL| |} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#![feature(coverage_attribute)] | ||
// edition: 2021 | ||
|
||
// Regression test for an inconsistency between functions that return the value | ||
// of their trailing expression, and functions that implicitly return `()`. | ||
|
||
fn explicit_unit() { | ||
let closure = || { | ||
(); | ||
}; | ||
|
||
drop(closure); | ||
() // explicit return of trailing value | ||
} | ||
|
||
fn implicit_unit() { | ||
let closure = || { | ||
(); | ||
}; | ||
|
||
drop(closure); | ||
// implicit return of `()` | ||
} | ||
|
||
#[coverage(off)] | ||
fn main() { | ||
explicit_unit(); | ||
implicit_unit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For some cases like
fn foo() { }
, I wonder if this heuristic will trigger incorrectly? Since all the changes in the tests are for the better, I'm not super worried about that.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 thought about adding a special-case to detect functions with a non-empty body span and no extracted spans, in order to explicitly add a span that covers the whole body. But currently it doesn't seem to be necessary, so I haven't bothered.
For
fn foo() {}
, I believe the way it currently works is that we generate a span for the signature, and there's another zero-width span right at the end of the body (representing the return), and the span refiner then merges those together into something that covers the whole body.(None of this is ideal, but sadly that's the reality of trying to heuristically extract coverage spans from MIR. Right now I'm happy to be able to make any progress in simplifying the span refiner into something a bit more maintainable.)