Skip to content

Start moving wf checking away from HIR #142030

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

Merged
merged 16 commits into from
Jul 1, 2025
Merged

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jun 4, 2025

I'm trying to only access the HIR in the error path. My hope is that once we move significant portions of wfcheck off HIR that incremental will be able to cache wfcheck queries significantly better.

I think I am reaching a blocker because we normally need to provide good spans to ObligationCause, so that the trait solver can report good errors. In some cases I have been able to use bad spans and improve them depending on the ObligationCauseCode (by loading HIR in the case where we actually want to error). To scale that further we'll likely need to remove spans from the ObligationCause entirely (leaving it to some variants of ObligationCauseCode to have a span when they can't recompute the information later). Unsure this is the right approach, but we've already been using it. I will create an MCP about it, but that should not affect this PR, which is fairly limited in where it does those kind of tricks.

Especially b862d88 is interesting here, because I think it improves spans in all cases

@rustbot
Copy link
Collaborator

rustbot commented Jun 4, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jun 4, 2025
@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 4, 2025

@bors2 try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Jun 4, 2025

⌛ Trying commit e38ae45 with merge 2a676f2

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jun 4, 2025
Start moving wf checking away from HIR

I'm trying to only access the HIR in the error path. My hope is that once we move significant portions of wfcheck off HIR that incremental will be able to cache wfcheck queries significantly better.

I think I am reaching a blocker because we normally need to provide good spans to `ObligationCause`, so that the trait solver can report good errors. In some cases I have been able to use bad spans and improve them depending on the `ObligationCauseCode` (by loading HIR in the case where we actually want to error). To scale that further we'll likely need to remove spans from the `ObligationCause` entirely (leaving it to some variants of `ObligationCauseCode` to have a span when they can't recompute the information later). Unsure this is the right approach, but we've already been using it. I will create an MCP about it, but that should not affect this PR, which is fairly limited in where it does those kind of tricks.

Especially b862d88 is interesting here, because I think it improves spans in all cases
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 4, 2025
@rust-bors
Copy link

rust-bors bot commented Jun 4, 2025

☀️ Try build successful (CI)
Build commit: 2a676f2 (2a676f231127fb1728da0a95c8deb1e1fb8bf0eb)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2a676f2): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.1%, 0.5%] 7
Improvements ✅
(primary)
-0.4% [-0.4%, -0.4%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.4% [-0.4%, -0.4%] 2

Max RSS (memory usage)

Results (primary -3.0%, secondary 0.3%)

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)
1.6% [1.5%, 1.7%] 2
Regressions ❌
(secondary)
2.0% [1.2%, 3.9%] 8
Improvements ✅
(primary)
-7.6% [-10.2%, -5.1%] 2
Improvements ✅
(secondary)
-2.3% [-2.9%, -1.8%] 5
All ❌✅ (primary) -3.0% [-10.2%, 1.7%] 4

Cycles

Results (primary 1.5%)

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)
1.5% [1.5%, 1.5%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.5% [1.5%, 1.5%] 1

Binary size

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

Bootstrap: 749.479s -> 749.524s (0.01%)
Artifact size: 371.89 MiB -> 371.96 MiB (0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 4, 2025
@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 5, 2025

Improvements are real, fewer dep graph edges to encode

Regressions are real, a mix of improvements and regressions across multiple queries. I'll do some local cache grinding to see what's going on

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 5, 2025

The regression is due to some extra query system things happening:

 2,302,905  ???:<rustc_middle::dep_graph::DepsType as rustc_query_system::dep_graph::Deps>::read_deps::<<rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::DepsType>>::read_index::{closure
 1,917,000  ???:<hashbrown::raw::RawTable<(rustc_span::def_id::LocalDefId, ())>>::reserve_rehash::<hashbrown::map::make_hasher<rustc_span::def_id::LocalDefId, (), rustc_hash::FxBuildHasher>::{closure

Probably because I'm invoking more queries to avoid looking at HIR. I don't think my work pays off while we still check the HIR on so many items.

@bors
Copy link
Collaborator

bors commented Jun 6, 2025

☔ The latest upstream changes (presumably #142099) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 26, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 26, 2025
@bors
Copy link
Collaborator

bors commented Jun 26, 2025

⌛ Trying commit d587a01 with merge 128972a...

bors added a commit that referenced this pull request Jun 26, 2025
Start moving wf checking away from HIR

I'm trying to only access the HIR in the error path. My hope is that once we move significant portions of wfcheck off HIR that incremental will be able to cache wfcheck queries significantly better.

I think I am reaching a blocker because we normally need to provide good spans to `ObligationCause`, so that the trait solver can report good errors. In some cases I have been able to use bad spans and improve them depending on the `ObligationCauseCode` (by loading HIR in the case where we actually want to error). To scale that further we'll likely need to remove spans from the `ObligationCause` entirely (leaving it to some variants of `ObligationCauseCode` to have a span when they can't recompute the information later). Unsure this is the right approach, but we've already been using it. I will create an MCP about it, but that should not affect this PR, which is fairly limited in where it does those kind of tricks.

Especially b862d88 is interesting here, because I think it improves spans in all cases
@bors
Copy link
Collaborator

bors commented Jun 26, 2025

☀️ Try build successful - checks-actions
Build commit: 128972a (128972a21f1ffb28749258e5566c02e2ef7a3e49)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (128972a): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.4% [0.3%, 0.6%] 3
Improvements ✅
(primary)
-0.4% [-0.4%, -0.2%] 5
Improvements ✅
(secondary)
-0.4% [-1.0%, -0.2%] 10
All ❌✅ (primary) -0.4% [-0.4%, -0.2%] 5

Max RSS (memory usage)

Results (primary 7.3%, secondary 4.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
7.3% [7.3%, 7.3%] 1
Regressions ❌
(secondary)
4.5% [4.0%, 5.1%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 7.3% [7.3%, 7.3%] 1

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: 692.088s -> 689.03s (-0.44%)
Artifact size: 372.11 MiB -> 372.07 MiB (-0.01%)

}

fn lower_variant_ctor(tcx: TyCtxt<'_>, def_id: LocalDefId) {
pub(super) fn lower_variant_ctor(tcx: TyCtxt<'_>, def_id: LocalDefId) {
Copy link
Member

Choose a reason for hiding this comment

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

As a follow-up, it would be nice to rename these from lower_* to check_* or something.

@compiler-errors
Copy link
Member

@bors r+ rollup=never

@bors
Copy link
Collaborator

bors commented Jul 1, 2025

📌 Commit 422eea2 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 Jul 1, 2025
@bors
Copy link
Collaborator

bors commented Jul 1, 2025

⌛ Testing commit 422eea2 with merge 4e97337...

@bors
Copy link
Collaborator

bors commented Jul 1, 2025

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 4e97337 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 1, 2025
@bors bors merged commit 4e97337 into rust-lang:master Jul 1, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 1, 2025
Copy link
Contributor

github-actions bot commented Jul 1, 2025

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 076a0a2 (parent) -> 4e97337 (this PR)

Test differences

No test diffs found

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 4e973370053a5fe87ee96d43c506623e9bd1eb9d --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-apple-2: 7543.2s -> 4792.7s (-36.5%)
  2. dist-x86_64-apple: 7877.4s -> 10653.6s (35.2%)
  3. x86_64-apple-1: 9079.6s -> 7464.4s (-17.8%)
  4. dist-apple-various: 8235.0s -> 7210.4s (-12.4%)
  5. aarch64-gnu: 7205.1s -> 6476.3s (-10.1%)
  6. i686-gnu-1: 8191.8s -> 7501.9s (-8.4%)
  7. dist-various-1: 3894.8s -> 4191.9s (7.6%)
  8. mingw-check-1: 1769.9s -> 1902.3s (7.5%)
  9. mingw-check-2: 1980.0s -> 2111.2s (6.6%)
  10. dist-loongarch64-musl: 4934.2s -> 5198.5s (5.4%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4e97337): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.4% [0.3%, 0.6%] 3
Improvements ✅
(primary)
-0.4% [-0.4%, -0.4%] 2
Improvements ✅
(secondary)
-0.5% [-1.1%, -0.3%] 8
All ❌✅ (primary) -0.4% [-0.4%, -0.4%] 2

Max RSS (memory usage)

Results (primary 0.4%, secondary -0.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.0% [1.3%, 2.6%] 2
Regressions ❌
(secondary)
2.0% [1.3%, 2.7%] 2
Improvements ✅
(primary)
-2.6% [-2.6%, -2.6%] 1
Improvements ✅
(secondary)
-4.7% [-4.7%, -4.7%] 1
All ❌✅ (primary) 0.4% [-2.6%, 2.6%] 3

Cycles

Results (primary -0.9%, secondary -0.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.8% [1.4%, 2.2%] 2
Regressions ❌
(secondary)
3.5% [3.5%, 3.5%] 1
Improvements ✅
(primary)
-1.8% [-2.6%, -1.1%] 6
Improvements ✅
(secondary)
-1.6% [-2.4%, -0.9%] 6
All ❌✅ (primary) -0.9% [-2.6%, 2.2%] 8

Binary size

Results (secondary -0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Bootstrap: 461.796s -> 461.855s (0.01%)
Artifact size: 372.30 MiB -> 372.23 MiB (-0.02%)

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 1, 2025

Improvements outweigh the regressions. And measured time is improved on the only benchmark that regressed instructions

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
6 participants