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: Store coverage source regions as Span until codegen (take 2) #134497

Merged
merged 5 commits into from
Dec 20, 2024

Conversation

Zalathar
Copy link
Contributor

This is an attempt to re-land #133418:

Historically, coverage spans were converted into line/column coordinates during the MIR instrumentation pass.

This PR moves that conversion step into codegen, so that coverage spans spend most of their time stored as Span instead.

In addition to being conceptually nicer, this also reduces the size of coverage mappings in MIR, because Span is smaller than 4x u32.

That PR was reverted by #133608, because in some circumstances not covered by our test suite we were emitting coverage metadata that was causing llvm-cov to exit with an error (#133606).


The implementation here is mostly the same, but adapted for subsequent changes in the relevant code (e.g. #134163).

I believe that the changes in #134163 should be sufficient to prevent the problem that required the original PR to be reverted. But I haven't been able to reproduce the original breakage in a regression test, and the llvm-cov error message is extremely unhelpful, so I can't completely rule out the possibility of this breaking again.

r? jieyouxu (reviewer of the original PR)

This will avoid confusion with actual `Span` spans.
In codegen, a used function with `FunctionCoverageInfo` but no mappings has
historically indicated a bug. However, that will no longer be the case after
moving some fallible span-processing steps into codegen.
@Zalathar Zalathar added the A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) label Dec 19, 2024
@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 19, 2024
@rustbot
Copy link
Collaborator

rustbot commented Dec 19, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

The implementation looks good to me, and I'm in favoring of making this change. Not having a regression test makes me a bit nervous, but unless we are able to minimize an example that we can use as a regression test (i.e. not a full-blown giant project), I don't think that is super actionable. I think we'll need to find out in nightly if anyone runs into the original problem again, because regardless of making this change or not, I think we do want an MCVE for the original ICE. Furthermore, I think the only way we might be able to minimize one is from more examples. EDIT: we now have a synthetic test example.

Just one question.

@Zalathar Zalathar changed the title coverage: Store coverage source regions as Span until codegen (take 2) coverage: Store coverage source regions as Span until codegen (take 2) Dec 19, 2024
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

The test changes LGTM, you can r=me after PR CI is green.

@Zalathar
Copy link
Contributor Author

I can confirm that if I backport the new test to the point just after #133418 was merged, and do x test coverage-run, the llvm-cov tool fails with a “truncated coverage data” error, which is the same error message as in the bug report.

(We don't know for sure that it's the same error, because llvm-cov's error reporting for malformed data is really bad, but it's good enough to convince me that the test is doing its job.)

@jieyouxu
Copy link
Member

It's as good as we're going to get, without nudging llvm-cov to produce better diagnostics.

@Zalathar
Copy link
Contributor Author

🟩

@bors r=jieyouxu

@bors
Copy link
Contributor

bors commented Dec 19, 2024

📌 Commit aced4dc has been approved by jieyouxu

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 19, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 19, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#134463 (compiletest: don't register predefined `MSVC`/`NONMSVC` FileCheck prefixes)
 - rust-lang#134487 (Add reference annotations for the `coverage` attribute)
 - rust-lang#134497 (coverage: Store coverage source regions as `Span` until codegen (take 2))
 - rust-lang#134502 (Update std libc version to 0.2.169)
 - rust-lang#134506 (Remove a duplicated check that doesn't do anything anymore.)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 19, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#134463 (compiletest: don't register predefined `MSVC`/`NONMSVC` FileCheck prefixes)
 - rust-lang#134487 (Add reference annotations for the `coverage` attribute)
 - rust-lang#134497 (coverage: Store coverage source regions as `Span` until codegen (take 2))
 - rust-lang#134502 (Update std libc version to 0.2.169)
 - rust-lang#134506 (Remove a duplicated check that doesn't do anything anymore.)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 19, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#134463 (compiletest: don't register predefined `MSVC`/`NONMSVC` FileCheck prefixes)
 - rust-lang#134487 (Add reference annotations for the `coverage` attribute)
 - rust-lang#134497 (coverage: Store coverage source regions as `Span` until codegen (take 2))
 - rust-lang#134502 (Update std libc version to 0.2.169)
 - rust-lang#134506 (Remove a duplicated check that doesn't do anything anymore.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 57cbd07 into rust-lang:master Dec 20, 2024
6 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Dec 20, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 20, 2024
Rollup merge of rust-lang#134497 - Zalathar:spans, r=jieyouxu

coverage: Store coverage source regions as `Span` until codegen (take 2)

This is an attempt to re-land rust-lang#133418:

> Historically, coverage spans were converted into line/column coordinates during the MIR instrumentation pass.

> This PR moves that conversion step into codegen, so that coverage spans spend most of their time stored as Span instead.

> In addition to being conceptually nicer, this also reduces the size of coverage mappings in MIR, because Span is smaller than 4x u32.

That PR was reverted by rust-lang#133608, because in some circumstances not covered by our test suite we were emitting coverage metadata that was causing `llvm-cov` to exit with an error (rust-lang#133606).

---

The implementation here is *mostly* the same, but adapted for subsequent changes in the relevant code (e.g. rust-lang#134163).

I believe that the changes in rust-lang#134163 should be sufficient to prevent the problem that required the original PR to be reverted. But I haven't been able to reproduce the original breakage in a regression test, and the `llvm-cov` error message is extremely unhelpful, so I can't completely rule out the possibility of this breaking again.

r? jieyouxu (reviewer of the original PR)
@Zalathar Zalathar deleted the spans branch December 20, 2024 02:17
remi-delmas-3000 pushed a commit to remi-delmas-3000/kani that referenced this pull request Jan 6, 2025
The original SourceRegion was moved to the llvm backend and made
private by rust-lang/rust#134497.
We implement our own local version of it to maintain our handling
of SourceRegion for coverage properties.
remi-delmas-3000 pushed a commit to remi-delmas-3000/kani that referenced this pull request Jan 7, 2025
The original SourceRegion was moved to the llvm backend and made
private by rust-lang/rust#134497.
We implement our own local version of it to maintain our handling
of SourceRegion for coverage properties.
remi-delmas-3000 pushed a commit to remi-delmas-3000/kani that referenced this pull request Jan 7, 2025
The original SourceRegion was moved to the llvm backend and made
private by rust-lang/rust#134497.
We implement our own local version of it to maintain our handling
of SourceRegion for coverage properties.
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.

4 participants