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: Fix an unstable-sort inconsistency in coverage spans #115930

Merged
merged 3 commits into from Sep 19, 2023

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Sep 18, 2023

This code was calling sort_unstable_by, but failed to impose a total order on the initial spans. That resulted in unpredictable handling of closure spans, producing inconsistencies in the coverage maps and in user-visible coverage reports.

This PR fixes the problem by always sorting closure spans before otherwise-identical non-closure spans, and also switches to a stable sort in case the ordering is still not total.


In addition to the fix itself, this PR also contains a cleanup to the comparison function that I was working on when I discovered the bug.

This code was calling `sort_unstable_by`, but failed to impose a total order on
the initial spans. That resulted in unpredictable handling of closure spans,
producing inconsistencies in the coverage maps and in user-visible coverage
reports.

This patch fixes the problem by always sorting closure spans before
otherwise-identical non-closure spans, and also switches to a stable sort in
case the ordering is still not total.
@rustbot
Copy link
Collaborator

rustbot commented Sep 18, 2023

r? @compiler-errors

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

rustbot commented Sep 18, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

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

Choose a reason for hiding this comment

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

This file shows the inconsistent handling of closure spans caused by this bug.

Some closure signatures were already treated as non-executable, while others were being treated as part of the preceding code, depending on implementation details of the unstable sort.

Switching to `Ordering::then_with` makes control-flow less complicated, and
there is no need to use `partial_cmp` here.
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Sep 18, 2023

📌 Commit 01b67f4 has been approved by compiler-errors

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

Rollup of 8 pull requests

Successful merges:

 - rust-lang#115869 (Avoid blessing cargo deps's source code in ui tests)
 - rust-lang#115873 (Make `TyKind::Adt`'s `Debug` impl be more pretty)
 - rust-lang#115879 (Migrate diagnostics in `hir_typeck/src/cast.rs`)
 - rust-lang#115930 (coverage: Fix an unstable-sort inconsistency in coverage spans)
 - rust-lang#115931 (Move mobile topbar title creation entirely into JS)
 - rust-lang#115941 (Add myself to .mailmap)
 - rust-lang#115943 (compiletest: Don't swallow some error messages.)
 - rust-lang#115949 (Update browser-ui-test version)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3cf5a6b into rust-lang:master Sep 19, 2023
11 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Sep 19, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 19, 2023
Rollup merge of rust-lang#115930 - Zalathar:spans-bug, r=compiler-errors

coverage: Fix an unstable-sort inconsistency in coverage spans

This code was calling `sort_unstable_by`, but failed to impose a total order on the initial spans. That resulted in unpredictable handling of closure spans, producing inconsistencies in the coverage maps and in user-visible coverage reports.

This PR fixes the problem by always sorting closure spans before otherwise-identical non-closure spans, and also switches to a stable sort in case the ordering is still not total.

---

In addition to the fix itself, this PR also contains a cleanup to the comparison function that I was working on when I discovered the bug.
@Zalathar Zalathar deleted the spans-bug branch September 19, 2023 02:03
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

5 participants