Skip to content

Remove the anon query modifier#154122

Merged
rust-bors[bot] merged 5 commits intorust-lang:mainfrom
Zalathar:no-anon
Mar 22, 2026
Merged

Remove the anon query modifier#154122
rust-bors[bot] merged 5 commits intorust-lang:mainfrom
Zalathar:no-anon

Conversation

@Zalathar
Copy link
Member

@Zalathar Zalathar commented Mar 20, 2026

View all comments

Prior experiments:

Zulip thread: Removing the anon query modifier


There are currently three queries that use the anon modifier:

  • check_representability
  • check_representability_adt_ty
  • erase_and_anonymize_regions_ty

It seems that none of them are using anon in an essential way.

According to comments and tests, the representability queries mainly care about not being eligible for forcing (despite having a recoverable key type), so that if a cycle does occur then the entire cycle will be on the query stack. Replacing anon with a new no_force modifier gives a modest perf improvement.

The erase_and_anonymize_regions_ty query appears to be using anon to reduce the dep-graph overhead of a query that is expected to not call any other queries (and thus have no dependencies). Replacing anon with either no_hash or nothing appears to give only a very small perf hit on cargo benchmarks, which is justified by the fact that it lets us remove a lot of machinery for anonymous queries.

We still need to retain some of the machinery for anonymous tasks, because the non-query task DepKind::TraitSelect still uses it.


I have some ideas for a follow-up that will reduce dep-graph overhead by replacing all zero-dependency nodes with a singleton node, but I want to keep that separate in case it causes unexpected issues and needs to be bisected or reverted.

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 20, 2026
@Zalathar
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Mar 20, 2026
Remove the `anon` query modifier
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 20, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 20, 2026

☀️ Try build successful (CI)
Build commit: 692d51a (692d51af41afa39dad5f85946d58341bf49cae97, parent: bcf3d36c997dd9b5db4bb7f40cb91dd4cf46a305)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (692d51a): 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.3% [0.2%, 0.3%] 3
Regressions ❌
(secondary)
0.4% [0.4%, 0.4%] 1
Improvements ✅
(primary)
-0.1% [-0.1%, -0.1%] 2
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.1%] 5
All ❌✅ (primary) 0.1% [-0.1%, 0.3%] 5

Max RSS (memory usage)

Results (primary -0.5%, secondary -1.1%)

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

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

Cycles

Results (secondary 3.2%)

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

Binary size

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

Bootstrap: 483.892s -> 479.954s (-0.81%)
Artifact size: 394.73 MiB -> 394.74 MiB (0.00%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 20, 2026
@Zalathar
Copy link
Member Author

Having established a baseline, let's now try applying no_hash to erase_and_anonymize_regions_ty, as #152268 did.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Mar 20, 2026
Remove the `anon` query modifier
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 20, 2026
@zetanumbers
Copy link
Contributor

I think anon query modifier name is more obscure than no_force, so I prefer this renaming.

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 20, 2026

☀️ Try build successful (CI)
Build commit: 72b77f1 (72b77f12d7ab71769075d97a874882ea4543b03e, parent: 76be1cc4eef94daeab731ed9395a317b34d89d63)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (72b77f1): 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.3% [0.2%, 0.3%] 2
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
-0.1% [-0.2%, -0.1%] 3
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.1%] 6
All ❌✅ (primary) 0.0% [-0.2%, 0.3%] 5

Max RSS (memory usage)

Results (primary -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.5% [0.5%, 0.6%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.1% [-1.1%, -1.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.0% [-1.1%, 0.6%] 3

Cycles

Results (primary -2.9%, secondary 7.1%)

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

Binary size

Results (primary -0.0%, secondary -0.1%)

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.0% [-0.0%, -0.0%] 15
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.0%] 5
All ❌✅ (primary) -0.0% [-0.0%, -0.0%] 15

Bootstrap: 481.595s -> 480.03s (-0.32%)
Artifact size: 396.86 MiB -> 396.76 MiB (-0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 20, 2026
@Zalathar Zalathar force-pushed the no-anon branch 4 times, most recently from 1feb7fe to aee5aef Compare March 21, 2026 02:11
@Zalathar
Copy link
Member Author

This should now be ready for review.

r? nnethercote

This was previously not possible because `check_representability` was `anon`.
According to its comment, this query was only using `anon` to save a little bit
of work for a dep graph node that is expected to have no dependencies.

Benchmarks indicate that the perf loss, if any, is small enough to be justified
by the fact that we can now remove support for `anon` queries.

Adding `no_hash` appears to give marginally better perf results.
We still have some anon-task machinery for `DepKind::TraitSelect` tasks, but
there are no longer any queries that use the `anon` modifier.
@Zalathar
Copy link
Member Author

I updated the dev guide (plus a FIXME to migrate modifier docs into modifiers.rs), and also pulled the alphabetical sorting out into its own commit to disentangle things a bit.

The with_anon_task_inner function was already made non-pub, so nothing more to do on that front.

@bors r=nnethercote rollup=never

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 21, 2026

📌 Commit 3a62e89 has been approved by nnethercote

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 Mar 21, 2026
@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Mar 21, 2026
Remove the `anon` query modifier

Prior experiments:
- #152268
- #153996

[Zulip thread: *Removing the `anon` query modifier*](https://rust-lang.zulipchat.com/#narrow/channel/582699-t-compiler.2Fquery-system/topic/Removing.20the.20.60anon.60.20query.20modifier/with/580760962)

---

There are currently three queries that use the `anon` modifier:
- `check_representability`
- `check_representability_adt_ty`
- `erase_and_anonymize_regions_ty`

It seems that none of them are using `anon` in an essential way.

According to comments and tests, the *representability* queries mainly care about not being eligible for forcing (despite having a recoverable key type), so that if a cycle does occur then the entire cycle will be on the query stack. Replacing `anon` with a new `no_force` modifier gives a modest perf improvement.

The `erase_and_anonymize_regions_ty` query appears to be using `anon` to reduce the dep-graph overhead of a query that is expected to not call any other queries (and thus have no dependencies). Replacing `anon` with either `no_hash` or nothing appears to give only a very small perf hit on `cargo` benchmarks, which is justified by the fact that it lets us remove a lot of machinery for anonymous queries.

We still need to retain some of the machinery for anonymous *tasks*, because the non-query task `DepKind::TraitSelect` still uses it.

---

I have some ideas for a follow-up that will reduce dep-graph overhead by replacing *all* zero-dependency nodes with a singleton node, but I want to keep that separate in case it causes unexpected issues and needs to be bisected or reverted.
@JonathanBrouwer
Copy link
Contributor

Stuck, lets retry immediately
@bors p=6
@bors retry

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 21, 2026

❗ You can only retry pull requests that are approved and have a previously failed auto build.

Hint: There is currently a pending auto build on this PR. To cancel it, run @bors cancel.

@JonathanBrouwer
Copy link
Contributor

@bors yield

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 21, 2026

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #154122.

@rust-bors

This comment has been minimized.

@rust-bors rust-bors bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 22, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 22, 2026

☀️ Test successful - CI
Approved by: nnethercote
Duration: 3h 6m 37s
Pushing 562dee4 to main...

@rust-bors rust-bors bot merged commit 562dee4 into rust-lang:main Mar 22, 2026
12 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 22, 2026
@github-actions
Copy link
Contributor

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 20f19f4 (parent) -> 562dee4 (this PR)

Test differences

Show 126 test diffs

126 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 562dee4820c458d823175268e41601d4c060588a --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. dist-aarch64-linux: 2h 29m -> 1h 50m (-26.2%)
  2. dist-aarch64-apple: 1h 50m -> 1h 34m (-14.4%)
  3. x86_64-gnu-llvm-21-3: 1h 57m -> 1h 40m (-13.9%)
  4. x86_64-gnu-llvm-21-2: 1h 33m -> 1h 22m (-11.0%)
  5. dist-x86_64-msvc-alt: 2h 57m -> 2h 40m (-9.5%)
  6. dist-aarch64-msvc: 1h 32m -> 1h 40m (+9.1%)
  7. dist-apple-various: 1h 41m -> 1h 32m (-9.0%)
  8. x86_64-mingw-1: 2h 39m -> 2h 54m (+9.0%)
  9. x86_64-gnu-llvm-21-1: 1h 6m -> 1h 11m (+8.8%)
  10. i686-gnu-nopt-2: 2h 11m -> 2h 22m (+8.3%)
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 (562dee4): 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.3% [0.2%, 0.3%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.2% [-0.2%, -0.2%] 2
Improvements ✅
(secondary)
-0.1% [-0.2%, -0.1%] 2
All ❌✅ (primary) 0.1% [-0.2%, 0.3%] 5

Max RSS (memory usage)

Results (primary -1.2%)

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

Cycles

Results (secondary 0.5%)

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)
2.5% [2.0%, 2.8%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.6% [-5.6%, -5.6%] 1
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 496.727s -> 485.484s (-2.26%)
Artifact size: 396.96 MiB -> 394.88 MiB (-0.52%)

@Zalathar
Copy link
Member Author

Small regressions to cargo were expected, and everything else is green.

I'm experimenting with #154162 to undo those small regressions, but that work will have to be judged on its own perf/complexity merits.

nnethercote added a commit to nnethercote/rust that referenced this pull request Mar 22, 2026
Prior to rust-lang#154122 it wasn't used on all paths, so we only computed it
when necessary -- sometimes in `check_if_ensure_can_skip_execution`,
sometimes in one of two places in `execute_job_incr` -- and pass around
`Option<DepNode>` to allow this.

But now it's always used, so this commit makes us compute it earlier,
which simplifies things.
- `check_if_ensure_can_skip_execution` can be made simpler, returning a
  bool and eliminating the need for `EnsureCanSkip`.
- `execute_job_incr` no longer uses two slightly different methods to
  create a `DepNode` (`get_or_insert_with` vs `unwrap_or_else`).
nnethercote added a commit to nnethercote/rust that referenced this pull request Mar 23, 2026
Prior to rust-lang#154122 it wasn't used on all paths, so we only computed it
when necessary -- sometimes in `check_if_ensure_can_skip_execution`,
sometimes in one of two places in `execute_job_incr` -- and pass around
`Option<DepNode>` to allow this.

But now it's always used, so this commit makes us compute it earlier,
which simplifies things.
- `check_if_ensure_can_skip_execution` can be made simpler, returning a
  bool and eliminating the need for `EnsureCanSkip`.
- `execute_job_incr` no longer uses two slightly different methods to
  create a `DepNode` (`get_or_insert_with` vs `unwrap_or_else`).
nnethercote added a commit to nnethercote/rust that referenced this pull request Mar 23, 2026
Prior to rust-lang#154122 it wasn't used on all paths, so we only computed it
when necessary -- sometimes in `check_if_ensure_can_skip_execution`,
sometimes in one of two places in `execute_job_incr` -- and pass around
`Option<DepNode>` to allow this.

But now it's always used, so this commit makes us compute it earlier,
which simplifies things.
- `check_if_ensure_can_skip_execution` can be made simpler, returning a
  bool and eliminating the need for `EnsureCanSkip`.
- `execute_job_incr` no longer uses two slightly different methods to
  create a `DepNode` (`get_or_insert_with` vs `unwrap_or_else`).
@panstromek
Copy link
Contributor

perf trirage:

Marking as triaged based on the comment above.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-rustc-dev-guide Area: rustc-dev-guide merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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