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: Clean up encoding of per-function coverage mapping payloads #115671

Merged
merged 6 commits into from
Sep 12, 2023

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Sep 8, 2023

This PR contains several small improvements to the code in rustc_codegen_llvm::coverageinfo::mapgen that prepares a function's coverage mappings for FFI, and passes them over to LLVM to be encoded into a vector of bytes.

These changes are in preparation for some future changes to the coverage implementation, but they should all stand on their own as worthwhile.

There shouldn't be any changes to the resulting coverage mappings, as verified by the existing tests/coverage-map and tests/run-coverage suites.

The changes are mostly independent of each other, though they are indirectly affected by the indentation changes made when introducing GlobalFileTable.

@rustbot
Copy link
Collaborator

rustbot commented Sep 8, 2023

r? @wesleywiser

(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. A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) labels Sep 8, 2023
Copy link
Member

@wesleywiser wesleywiser left a comment

Choose a reason for hiding this comment

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

Thanks @Zalathar! It's really great seeing these improvements to the code coverage happen 🙂

I just had one small suggestion for you.

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs Outdated Show resolved Hide resolved
@Zalathar Zalathar force-pushed the mapgen branch 3 times, most recently from 7d2963d to 7418d2e Compare September 9, 2023 00:33
@Zalathar

This comment was marked as outdated.

@Zalathar Zalathar force-pushed the mapgen branch 3 times, most recently from 90b0516 to e1e081a Compare September 9, 2023 03:04
@Zalathar
Copy link
Contributor Author

Zalathar commented Sep 9, 2023

@Zalathar
Copy link
Contributor Author

Zalathar commented Sep 9, 2023

After trying a few things, I've settled on storing the local-to-global file mappings in an IndexVec<u32, u32> which lets me use IndexVec::push to obtain new local file IDs.

This makes more long-term sense than trying to use zip/enumerate, because when macro-expansion mappings are eventually implemented at some point, there will no longer be a simple 1:1 mapping between filenames and local file IDs.

This struct was only being used to hold the global file table, and one of its
methods didn't even use the table. Changing its methods to ordinary functions
makes it easier to see where the table is mutated.
If two or more mappings cover exactly the same region, their relative order
will now be preserved from `get_expressions_and_counter_regions`, rather than
being disturbed by implementation details of an unstable sort.

The current order is: counter mappings, expression mappings, zero mappings.

(LLVM will also perform its own stable sort on these mappings, but that sort
only compares file ID, start location, and `RegionKind`.)
We already know in advance how many entries will be pushed onto this vector.
Instead of writing coverage mappings into a supplied `&RustString`, this
function can just create the buffer itself and return the resulting vector of
bytes.
These expressions and counter regions are only needed by the function that
encodes a function's coverage mappings payload.
This removes an ad-hoc implementation of `group_by`.
@wesleywiser
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Sep 11, 2023

📌 Commit 6e968b1 has been approved by wesleywiser

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 Sep 11, 2023
@bors
Copy link
Contributor

bors commented Sep 12, 2023

⌛ Testing commit 6e968b1 with merge 725afd2...

@bors
Copy link
Contributor

bors commented Sep 12, 2023

☀️ Test successful - checks-actions
Approved by: wesleywiser
Pushing 725afd2 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 12, 2023
@bors bors merged commit 725afd2 into rust-lang:master Sep 12, 2023
11 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Sep 12, 2023
@Zalathar Zalathar deleted the mapgen branch September 12, 2023 01:47
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (725afd2): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.5% [-0.5%, -0.5%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.6% [-2.8%, -2.4%] 2
All ❌✅ (primary) - - 0

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.0% [2.0%, 3.5%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 631.821s -> 631.364s (-0.07%)
Artifact size: 317.91 MiB -> 317.87 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