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: Restrict empty-span expansion to only cover { and } #132675

Merged
merged 5 commits into from
Nov 10, 2024

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Nov 6, 2024

Coverage instrumentation has some tricky code for converting a coverage-relevant Span into a set of start/end line/byte-column coordinates that will be embedded in the CGU's coverage metadata.

A big part of this complexity is special code for handling empty spans, which are expanded into non-empty spans (if possible) because LLVM's coverage reporter does not handle empty spans well.

This PR simplifies that code by restricting it to only apply in two specific situations: when the character after the empty span is {, or the character before the empty span is }.

(As an added benefit, this means that the expanded spans no longer extend awkwardly beyond the end of a physical line, which was common under the previous implementation.)

Along the way, this PR also removes some unhelpful code for dealing with function source code spread across multiple files. Functions currently can't have coverage spans in multiple files, and if that ever changes (e.g. to properly support expansion regions) then this code will need to be completely overhauled anyway.

@Zalathar Zalathar added the A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) label Nov 6, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 6, 2024

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Nov 6, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 6, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@fee1-dead
Copy link
Member

r? compiler

@rustbot rustbot assigned pnkfelix and unassigned fee1-dead Nov 6, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Nov 7, 2024

r? jieyouxu

@rustbot rustbot assigned jieyouxu and unassigned pnkfelix Nov 7, 2024
This isn't strictly necessary, but makes it easier to distinguish `body_span`
from the specific `span` being processed.
We already had a dedicated `LocalFileId` index type, but previously we used a
raw `u32` for global file IDs, because index types were harder to pass through
FFI.
Functions currently can't have mappings in multiple files, and if that ever
changes (e.g. to properly support expansion regions), this code will need to be
completely overhauled anyway.
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.

Thanks, this looks good to me for the most part, two nits.

@jieyouxu
Copy link
Member

jieyouxu commented Nov 9, 2024

@rustbot author

@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 Nov 9, 2024
@Zalathar
Copy link
Contributor Author

Pass a LocalFileId to CoverageSpan::from_source_region (diff).

@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 Nov 10, 2024
@jieyouxu
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Nov 10, 2024

📌 Commit 925dfc8 has been approved by jieyouxu

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Nov 10, 2024

⌛ Testing commit 925dfc8 with merge 791894f...

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 10, 2024
coverage: Restrict empty-span expansion to only cover `{` and `}`

Coverage instrumentation has some tricky code for converting a coverage-relevant `Span` into a set of start/end line/byte-column coordinates that will be embedded in the CGU's coverage metadata.

A big part of this complexity is special code for handling empty spans, which are expanded into non-empty spans (if possible) because LLVM's coverage reporter does not handle empty spans well.

This PR simplifies that code by restricting it to only apply in two specific situations: when the character after the empty span is `{`, or the character before the empty span is `}`.

(As an added benefit, this means that the expanded spans no longer extend awkwardly beyond the end of a physical line, which was common under the previous implementation.)

Along the way, this PR also removes some unhelpful code for dealing with function source code spread across multiple files. Functions currently can't have coverage spans in multiple files, and if that ever changes (e.g. to properly support expansion regions) then this code will need to be completely overhauled anyway.
@jieyouxu
Copy link
Member

@bors retry r- (yielding priority to a revert to fix a bootstrap issue)

@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 Nov 10, 2024
@jieyouxu
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 10, 2024

📌 Commit 925dfc8 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 10, 2024
@jieyouxu
Copy link
Member

(Yielding to #132846)

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 10, 2024
coverage: Restrict empty-span expansion to only cover `{` and `}`

Coverage instrumentation has some tricky code for converting a coverage-relevant `Span` into a set of start/end line/byte-column coordinates that will be embedded in the CGU's coverage metadata.

A big part of this complexity is special code for handling empty spans, which are expanded into non-empty spans (if possible) because LLVM's coverage reporter does not handle empty spans well.

This PR simplifies that code by restricting it to only apply in two specific situations: when the character after the empty span is `{`, or the character before the empty span is `}`.

(As an added benefit, this means that the expanded spans no longer extend awkwardly beyond the end of a physical line, which was common under the previous implementation.)

Along the way, this PR also removes some unhelpful code for dealing with function source code spread across multiple files. Functions currently can't have coverage spans in multiple files, and if that ever changes (e.g. to properly support expansion regions) then this code will need to be completely overhauled anyway.
@bors
Copy link
Contributor

bors commented Nov 10, 2024

⌛ Testing commit 925dfc8 with merge 772f79d...

@jieyouxu
Copy link
Member

@bors r- retry

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 10, 2024
@jieyouxu
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 10, 2024

📌 Commit 925dfc8 has been approved by jieyouxu

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Nov 10, 2024

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

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 10, 2024
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#132675 (coverage: Restrict empty-span expansion to only cover `{` and `}`)
 - rust-lang#132849 (Miri subtree update)
 - rust-lang#132858 (Update minifer version to `0.3.2`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b95232d into rust-lang:master Nov 10, 2024
6 of 7 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 10, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 10, 2024
Rollup merge of rust-lang#132675 - Zalathar:empty-spans, r=jieyouxu

coverage: Restrict empty-span expansion to only cover `{` and `}`

Coverage instrumentation has some tricky code for converting a coverage-relevant `Span` into a set of start/end line/byte-column coordinates that will be embedded in the CGU's coverage metadata.

A big part of this complexity is special code for handling empty spans, which are expanded into non-empty spans (if possible) because LLVM's coverage reporter does not handle empty spans well.

This PR simplifies that code by restricting it to only apply in two specific situations: when the character after the empty span is `{`, or the character before the empty span is `}`.

(As an added benefit, this means that the expanded spans no longer extend awkwardly beyond the end of a physical line, which was common under the previous implementation.)

Along the way, this PR also removes some unhelpful code for dealing with function source code spread across multiple files. Functions currently can't have coverage spans in multiple files, and if that ever changes (e.g. to properly support expansion regions) then this code will need to be completely overhauled anyway.
@Zalathar Zalathar deleted the empty-spans branch November 10, 2024 22:13
mati865 pushed a commit to mati865/rust that referenced this pull request Nov 12, 2024
coverage: Restrict empty-span expansion to only cover `{` and `}`

Coverage instrumentation has some tricky code for converting a coverage-relevant `Span` into a set of start/end line/byte-column coordinates that will be embedded in the CGU's coverage metadata.

A big part of this complexity is special code for handling empty spans, which are expanded into non-empty spans (if possible) because LLVM's coverage reporter does not handle empty spans well.

This PR simplifies that code by restricting it to only apply in two specific situations: when the character after the empty span is `{`, or the character before the empty span is `}`.

(As an added benefit, this means that the expanded spans no longer extend awkwardly beyond the end of a physical line, which was common under the previous implementation.)

Along the way, this PR also removes some unhelpful code for dealing with function source code spread across multiple files. Functions currently can't have coverage spans in multiple files, and if that ever changes (e.g. to properly support expansion regions) then this code will need to be completely overhauled anyway.
mati865 pushed a commit to mati865/rust that referenced this pull request Nov 12, 2024
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#132675 (coverage: Restrict empty-span expansion to only cover `{` and `}`)
 - rust-lang#132849 (Miri subtree update)
 - rust-lang#132858 (Update minifer version to `0.3.2`)

r? `@ghost`
`@rustbot` modify labels: rollup
github-merge-queue bot pushed a commit to model-checking/kani that referenced this pull request Nov 13, 2024
Changes required due to
- rust-lang/rust#132675 (coverage: Restrict
empty-span expansion to only cover { and })

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
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.

7 participants