-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
coverage: Sort the expansion tree to help choose a single BCB for child expansions #149587
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
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
r? compiler |
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.
LGTM, r=me unless you want to make any changes. Apologies for the delay in getting to the review.
| nodes.sort_by_key(|_expn_id, node| node.dfs_rank); | ||
|
|
||
| // Verify that the depth-first search visited each node exactly once. | ||
| for (i, &ExpnNode { dfs_rank, .. }) in nodes.values().enumerate() { |
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.
Would it make sense to do this only when debug assertions are enabled?
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.
In theory I don't think this can ever fail, but the consequences for being wrong are potentially very bad.
If we accidentally emit malformed coverage mappings due to some unexpected arrangement of macro spans, we get bug reports about llvm-cov exiting with an unhelpful fatal error, which tends to completely break people's coverage workflows.
This makes it possible for subsequent operations to iterate over all nodes, while assuming that every node occurs before all of its descendants.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@bors r=davidtwco |
coverage: Sort the expansion tree to help choose a single BCB for child expansions
This PR is another incremental step on the road towards proper coverage instrumentation of expansion regions.
When creating coverage mappings for each relevant span in a function body, the current implementation also needs to do a separate tree traversal for each child expansion (e.g. macro calls like `println!("foo")`), in order to associate a single control-flow point (BCB) with that macro call's span.
This PR changes things so that we now keep track of the “minimum” and ”maximum” BCB associated with each node in the expansion tree, which makes it much easier for the parent node to get a single BCB (min or max) for each of its child expansions.
In order to make this (relatively) easy, we first need to sort the tree nodes into depth-first order. Once that's taken care of, we can iterate over all the nodes in reverse order, knowing that each node's children will have been visited before visiting the node itself.
Rollup of 8 pull requests Successful merges: - #149587 (coverage: Sort the expansion tree to help choose a single BCB for child expansions) - #150071 (Add dist step for Enzyme) - #150288 (Add scalar support for offload) - #151091 (Add new "hide deprecated items" setting in rustdoc) - #151255 (rustdoc: Fix ICE when deprecated note is not resolved on the correct `DefId`) - #151375 (Fix terminal width dependent tests) - #151384 (add basic `TokenStream` api tests) - #151391 (rustc-dev-guide subtree update) r? @ghost
Rollup merge of #149587 - tree-sort, r=davidtwco coverage: Sort the expansion tree to help choose a single BCB for child expansions This PR is another incremental step on the road towards proper coverage instrumentation of expansion regions. When creating coverage mappings for each relevant span in a function body, the current implementation also needs to do a separate tree traversal for each child expansion (e.g. macro calls like `println!("foo")`), in order to associate a single control-flow point (BCB) with that macro call's span. This PR changes things so that we now keep track of the “minimum” and ”maximum” BCB associated with each node in the expansion tree, which makes it much easier for the parent node to get a single BCB (min or max) for each of its child expansions. In order to make this (relatively) easy, we first need to sort the tree nodes into depth-first order. Once that's taken care of, we can iterate over all the nodes in reverse order, knowing that each node's children will have been visited before visiting the node itself.
Rollup of 8 pull requests Successful merges: - rust-lang/rust#149587 (coverage: Sort the expansion tree to help choose a single BCB for child expansions) - rust-lang/rust#150071 (Add dist step for Enzyme) - rust-lang/rust#150288 (Add scalar support for offload) - rust-lang/rust#151091 (Add new "hide deprecated items" setting in rustdoc) - rust-lang/rust#151255 (rustdoc: Fix ICE when deprecated note is not resolved on the correct `DefId`) - rust-lang/rust#151375 (Fix terminal width dependent tests) - rust-lang/rust#151384 (add basic `TokenStream` api tests) - rust-lang/rust#151391 (rustc-dev-guide subtree update) r? @ghost
This PR is another incremental step on the road towards proper coverage instrumentation of expansion regions.
When creating coverage mappings for each relevant span in a function body, the current implementation also needs to do a separate tree traversal for each child expansion (e.g. macro calls like
println!("foo")), in order to associate a single control-flow point (BCB) with that macro call's span.This PR changes things so that we now keep track of the “minimum” and ”maximum” BCB associated with each node in the expansion tree, which makes it much easier for the parent node to get a single BCB (min or max) for each of its child expansions.
In order to make this (relatively) easy, we first need to sort the tree nodes into depth-first order. Once that's taken care of, we can iterate over all the nodes in reverse order, knowing that each node's children will have been visited before visiting the node itself.