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: Unexpand spans with find_ancestor_inside_same_ctxt #119336

Merged
merged 1 commit into from
Dec 28, 2023

Conversation

Zalathar
Copy link
Contributor

Back in #118525 (comment) it was observed that our unexpand_into_body_span now looks very similar to Span::find_ancestor_inside.

At the time I tried switching over, but doing so resulted in incorrect coverage mappings (or assertion failures), so I left a FIXME comment instead.

After some investigation, I identified the two problems with my original approach:

  • I should have been using find_ancestor_inside_same_ctxt instead, since we want a span that's inside the body and has the same context as the body.
  • For async functions, we were actually using the post-expansion body span, which is why we needed to forcibly set the unexpanded span's context to match the body span. For body spans produced by macro-expansion, we already have special-case code to detect this and use the pre-expansion call site as the body span. By making this code also detect async desugaring, I was able to end up with a body span that works properly with find_ancestor_inside_same_ctxt, avoiding the need to forcibly change the span context.

@rustbot
Copy link
Collaborator

rustbot commented Dec 27, 2023

r? @petrochenkov

(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 27, 2023
@rustbot
Copy link
Collaborator

rustbot commented Dec 27, 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 27, 2023
@petrochenkov petrochenkov 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 27, 2023
@Zalathar
Copy link
Contributor Author

@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 27, 2023
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Dec 27, 2023

📌 Commit be6b059 has been approved by petrochenkov

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 Dec 27, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 27, 2023
…nkov

coverage: Unexpand spans with `find_ancestor_inside_same_ctxt`

Back in rust-lang#118525 (comment) it was observed that our `unexpand_into_body_span` now looks very similar to `Span::find_ancestor_inside`.

At the time I tried switching over, but doing so resulted in incorrect coverage mappings (or assertion failures), so I left a `FIXME` comment instead.

After some investigation, I identified the two problems with my original approach:
- I should have been using `find_ancestor_inside_same_ctxt` instead, since we want a span that's inside the body and has the same context as the body.
- For async functions, we were actually using the post-expansion body span, which is why we needed to forcibly set the unexpanded span's context to match the body span. For body spans produced by macro-expansion, we already have special-case code to detect this and use the pre-expansion call site as the body span. By making this code also detect async desugaring, I was able to end up with a body span that works properly with `find_ancestor_inside_same_ctxt`, avoiding the need to forcibly change the span context.
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 27, 2023
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#119336 (coverage: Unexpand spans with `find_ancestor_inside_same_ctxt`)
 - rust-lang#119349 (refactor(liveness): move walk_expr outside of every match branch)
 - rust-lang#119359 (Simplify Parser::ident_or_error)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Contributor

bors commented Dec 28, 2023

⌛ Testing commit be6b059 with merge 8e34642...

@bors
Copy link
Contributor

bors commented Dec 28, 2023

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing 8e34642 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 28, 2023
@bors bors merged commit 8e34642 into rust-lang:master Dec 28, 2023
12 checks passed
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8e34642): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 670.933s -> 670.201s (-0.11%)
Artifact size: 312.35 MiB -> 312.31 MiB (-0.01%)

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) merged-by-bors This PR was explicitly merged by bors. 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.

6 participants