-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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: Make #[coverage(..)]
apply recursively to nested functions
#126721
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Function name: <impl::MyStruct>::off_on (unused) | ||
Raw bytes (9): 0x[01, 01, 00, 01, 00, 0e, 05, 00, 13] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 0 | ||
Number of file 0 mappings: 1 | ||
- Code(Zero) at (prev + 14, 5) to (start + 0, 19) | ||
|
||
Function name: <impl::MyStruct>::on_inherit (unused) | ||
Raw bytes (9): 0x[01, 01, 00, 01, 00, 16, 05, 00, 17] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 0 | ||
Number of file 0 mappings: 1 | ||
- Code(Zero) at (prev + 22, 5) to (start + 0, 23) | ||
|
||
Function name: <impl::MyStruct>::on_on (unused) | ||
Raw bytes (9): 0x[01, 01, 00, 01, 00, 19, 05, 00, 12] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 0 | ||
Number of file 0 mappings: 1 | ||
- Code(Zero) at (prev + 25, 5) to (start + 0, 18) | ||
|
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,42 @@ | ||
LL| |#![feature(coverage_attribute)] | ||
LL| |//@ edition: 2021 | ||
LL| | | ||
LL| |// Checks that `#[coverage(..)]` can be applied to impl and impl-trait blocks, | ||
LL| |// and is inherited by any enclosed functions. | ||
LL| | | ||
LL| |struct MyStruct; | ||
LL| | | ||
LL| |#[coverage(off)] | ||
LL| |impl MyStruct { | ||
LL| | fn off_inherit() {} | ||
LL| | | ||
LL| | #[coverage(on)] | ||
LL| 0| fn off_on() {} | ||
LL| | | ||
LL| | #[coverage(off)] | ||
LL| | fn off_off() {} | ||
LL| |} | ||
LL| | | ||
LL| |#[coverage(on)] | ||
LL| |impl MyStruct { | ||
LL| 0| fn on_inherit() {} | ||
LL| | | ||
LL| | #[coverage(on)] | ||
LL| 0| fn on_on() {} | ||
LL| | | ||
LL| | #[coverage(off)] | ||
LL| | fn on_off() {} | ||
LL| |} | ||
LL| | | ||
LL| |trait MyTrait { | ||
LL| | fn method(); | ||
LL| |} | ||
LL| | | ||
LL| |#[coverage(off)] | ||
LL| |impl MyTrait for MyStruct { | ||
LL| | fn method() {} | ||
LL| |} | ||
LL| | | ||
LL| |#[coverage(off)] | ||
LL| |fn main() {} | ||
|
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,41 @@ | ||
#![feature(coverage_attribute)] | ||
//@ edition: 2021 | ||
|
||
// Checks that `#[coverage(..)]` can be applied to impl and impl-trait blocks, | ||
// and is inherited by any enclosed functions. | ||
|
||
struct MyStruct; | ||
|
||
#[coverage(off)] | ||
impl MyStruct { | ||
fn off_inherit() {} | ||
|
||
#[coverage(on)] | ||
fn off_on() {} | ||
|
||
#[coverage(off)] | ||
fn off_off() {} | ||
} | ||
|
||
#[coverage(on)] | ||
impl MyStruct { | ||
fn on_inherit() {} | ||
|
||
#[coverage(on)] | ||
fn on_on() {} | ||
|
||
#[coverage(off)] | ||
fn on_off() {} | ||
} | ||
|
||
trait MyTrait { | ||
fn method(); | ||
} | ||
|
||
#[coverage(off)] | ||
impl MyTrait for MyStruct { | ||
fn method() {} | ||
} | ||
|
||
#[coverage(off)] | ||
fn main() {} |
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,24 @@ | ||
Function name: module::off::on (unused) | ||
Raw bytes (9): 0x[01, 01, 00, 01, 00, 0c, 05, 00, 0f] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 0 | ||
Number of file 0 mappings: 1 | ||
- Code(Zero) at (prev + 12, 5) to (start + 0, 15) | ||
|
||
Function name: module::on::inherit (unused) | ||
Raw bytes (9): 0x[01, 01, 00, 01, 00, 14, 05, 00, 14] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 0 | ||
Number of file 0 mappings: 1 | ||
- Code(Zero) at (prev + 20, 5) to (start + 0, 20) | ||
|
||
Function name: module::on::on (unused) | ||
Raw bytes (9): 0x[01, 01, 00, 01, 00, 17, 05, 00, 0f] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 0 | ||
Number of file 0 mappings: 1 | ||
- Code(Zero) at (prev + 23, 5) to (start + 0, 15) | ||
|
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,38 @@ | ||
LL| |#![feature(coverage_attribute)] | ||
LL| |//@ edition: 2021 | ||
LL| | | ||
LL| |// Checks that `#[coverage(..)]` can be applied to modules, and is inherited | ||
LL| |// by any enclosed functions. | ||
LL| | | ||
LL| |#[coverage(off)] | ||
LL| |mod off { | ||
LL| | fn inherit() {} | ||
LL| | | ||
LL| | #[coverage(on)] | ||
LL| 0| fn on() {} | ||
LL| | | ||
LL| | #[coverage(off)] | ||
LL| | fn off() {} | ||
LL| |} | ||
LL| | | ||
LL| |#[coverage(on)] | ||
LL| |mod on { | ||
LL| 0| fn inherit() {} | ||
LL| | | ||
LL| | #[coverage(on)] | ||
LL| 0| fn on() {} | ||
LL| | | ||
LL| | #[coverage(off)] | ||
LL| | fn off() {} | ||
LL| |} | ||
LL| | | ||
LL| |#[coverage(off)] | ||
LL| |mod nested_a { | ||
LL| | mod nested_b { | ||
LL| | fn inner() {} | ||
LL| | } | ||
LL| |} | ||
LL| | | ||
LL| |#[coverage(off)] | ||
LL| |fn main() {} | ||
|
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,37 @@ | ||
#![feature(coverage_attribute)] | ||
//@ edition: 2021 | ||
|
||
// Checks that `#[coverage(..)]` can be applied to modules, and is inherited | ||
// by any enclosed functions. | ||
|
||
#[coverage(off)] | ||
mod off { | ||
fn inherit() {} | ||
|
||
#[coverage(on)] | ||
fn on() {} | ||
|
||
#[coverage(off)] | ||
fn off() {} | ||
} | ||
|
||
#[coverage(on)] | ||
mod on { | ||
fn inherit() {} | ||
|
||
#[coverage(on)] | ||
fn on() {} | ||
|
||
#[coverage(off)] | ||
fn off() {} | ||
} | ||
|
||
#[coverage(off)] | ||
mod nested_a { | ||
mod nested_b { | ||
fn inner() {} | ||
} | ||
} | ||
|
||
#[coverage(off)] | ||
fn main() {} |
Oops, something went wrong.
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.
Is it fine for this query to just call itself recursively (via the query system) to walk up the def tree, or is there something special I have to do here?
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.
Presumably it'd make sense to do some sort of path compression/memoisation so that the query is only linear in the number of items, rather than quadratic. But not quite sure what exists to do that in the compiler.
(Each item performs a number of queries equivalent to their number of parents, rather than just one to check their immediate parent which is cached.)
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.
Given that I'm calling
tcx.coverage_attr_on
(and not recursing onfn coverage_attr_on
directly), my understanding is that the query system will memoize the result.So individual functions will only recurse until they hit something (typically the enclosing mod/impl) for which there is a previously-memoized result.
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.
Yea this is totally fine. We do this for a lot of queries (e.g.
generics_of
)