Skip to content
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: Hoist some complex code out of the main span refinement loop #119208

Merged
merged 6 commits into from Jan 6, 2024

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Dec 22, 2023

The span refinement loop in spans.rs takes the spans that have been extracted from MIR, and modifies them to produce more helpful output in coverage reports.

It is also one of the most complicated pieces of code in the coverage instrumentor. It has an abundance of moving pieces that make it difficult to understand, and most attempts to modify it end up accidentally changing its behaviour in unacceptable ways.

This PR nevertheless tries to make a dent in it by hoisting two pieces of special-case logic out of the main loop, and into separate preprocessing passes. Coverage tests show that the resulting mappings are almost identical, with all known differences being unimportant.

This should hopefully unlock further simplifications to the refinement loop, since it now has fewer edge cases to worry about.

@rustbot
Copy link
Collaborator

rustbot commented Dec 22, 2023

r? @WaffleLapkin

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 22, 2023
@rustbot
Copy link
Collaborator

rustbot commented Dec 22, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@Zalathar
Copy link
Contributor Author

@rustbot label +A-code-coverage

@rustbot rustbot added the A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) label Dec 22, 2023
@Zalathar
Copy link
Contributor Author

I've been playing around with various alternative implementations, in an attempt to match the old mappings exactly.

But because the old code is sensitive to lots of seemingly-irrelevant details (which is what I'm trying to get away from), I haven't come up with anything that matches perfectly.

I suspect that the way the existing code handles macro-expansions is not quite right. But the changes in this PR should be a stepping-stone towards being able to do something about that.

@Zalathar

This comment was marked as outdated.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 28, 2023
@Zalathar
Copy link
Contributor Author

I've completed my planned overhaul (diff).

The main change is that after #119336 I found a way to simplify the handling of “visible macros”, which then makes a few of the later parts of this PR a bit simpler.

I still need to make sure that the changes to closure.cov-map are acceptable; after that I'll mark this as ready.

@Zalathar
Copy link
Contributor Author

Looks good to me.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 28, 2023
Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me, but I'm lacking context on coverage stuff.

@Swatinem could you take a closer look?

Copy link
Contributor

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, though I agree with the PR description that these parts of the code are very intricate and hard to understand ;-)

The changes to the test output also look like clear improvement.

@Zalathar
Copy link
Contributor Author

Added better documentation for unexpand_into_body_span_with_prev (diff).

@rust-log-analyzer

This comment has been minimized.

@WaffleLapkin
Copy link
Member

@bors r=WaffleLapkin,Swatinem

@bors
Copy link
Contributor

bors commented Jan 2, 2024

📌 Commit aa84b52 has been approved by WaffleLapkin,Swatinem

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jan 2, 2024

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 2, 2024
@bors
Copy link
Contributor

bors commented Jan 3, 2024

☔ The latest upstream changes (presumably #119549) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 3, 2024
@Zalathar
Copy link
Contributor Author

Zalathar commented Jan 3, 2024

Rebased to resolve trivial conflicts with #119444.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 3, 2024
This draws a clear distinction between the fields/methods that are needed by
initial span extraction and preprocessing, and those that are needed by the
main "refinement" loop.
The struct itself is already non-public, so having public fields doesn't
achieve anything.
@cjgillot
Copy link
Contributor

cjgillot commented Jan 6, 2024

@bors r=WaffleLapkin,Swatinem

@bors
Copy link
Contributor

bors commented Jan 6, 2024

📌 Commit 514e026 has been approved by WaffleLapkin,Swatinem

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 6, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 6, 2024
…mpiler-errors

Rollup of 9 pull requests

Successful merges:

 - rust-lang#119208 (coverage: Hoist some complex code out of the main span refinement loop)
 - rust-lang#119216 (Use diagnostic namespace in stdlib)
 - rust-lang#119414 (bootstrap: Move -Clto= setting from Rustc::run to rustc_cargo)
 - rust-lang#119420 (Handle ForeignItem as TAIT scope.)
 - rust-lang#119468 (rustdoc-search: tighter encoding for f index)
 - rust-lang#119628 (remove duplicate test)
 - rust-lang#119638 (fix cyle error when suggesting to use associated function instead of constructor)
 - rust-lang#119640 (library: Fix warnings in rtstartup)
 - rust-lang#119642 (library: Fix a symlink test failing on Windows)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit bacddd3 into rust-lang:master Jan 6, 2024
11 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 6, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 6, 2024
Rollup merge of rust-lang#119208 - Zalathar:hoist, r=WaffleLapkin,Swatinem

coverage: Hoist some complex code out of the main span refinement loop

The span refinement loop in `spans.rs` takes the spans that have been extracted from MIR, and modifies them to produce more helpful output in coverage reports.

It is also one of the most complicated pieces of code in the coverage instrumentor. It has an abundance of moving pieces that make it difficult to understand, and most attempts to modify it end up accidentally changing its behaviour in unacceptable ways.

This PR nevertheless tries to make a dent in it by hoisting two pieces of special-case logic out of the main loop, and into separate preprocessing passes. Coverage tests show that the resulting mappings are *almost* identical, with all known differences being unimportant.

This should hopefully unlock further simplifications to the refinement loop, since it now has fewer edge cases to worry about.
@Zalathar Zalathar deleted the hoist branch January 6, 2024 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants