Simplify the cache_on_disk_if modifier to just cache_on_disk rust-lang/rust#154576

Merged

26 comments and reviews loaded in 1.05s

Zalathar Avatar
Zalathar on 2026-03-30 10:14:40 UTC · edited
Zalathar Avatar
Zalathar on 2026-03-30 10:14:40 UTC · edited
View on GitHub

View all comments

Thanks to #154304, there is now only one remaining query with a non-trivial cache-on-disk condition (check_liveness). But prior experiments at #153441 (comment) indicate that check_liveness can also be made non-disk-caching with little or no measurable effect.

This PR takes advantage of those facts to replace the cache_on_disk_if modifier with a simpler cache_on_disk modifier:

  • When combined with separate_provide_extern, only values for “local” keys are cached to disk.
  • For any other query with cache_on_disk, values are cached to disk unconditionally.

r? nnethercote (or compiler)

Zalathar Avatar
Zalathar on 2026-03-30 10:15:22 UTC
Zalathar Avatar
Zalathar on 2026-03-30 10:15:22 UTC
View on GitHub
Zalathar Avatar
Zalathar on 2026-03-30 10:15:27 UTC
Zalathar Avatar
Zalathar on 2026-03-30 10:15:27 UTC
View on GitHub

@bors try @rust-timer queue

rust-timer Avatar
rust-timer on 2026-03-30 10:15:31 UTC · hidden as outdated
rust-timer Avatar
rust-timer on 2026-03-30 10:15:31 UTC · hidden as outdated
View on GitHub

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

rust-bors Avatar
rust-bors on 2026-03-30 10:15:33 UTC · hidden as outdated
rust-bors Avatar
rust-bors on 2026-03-30 10:15:33 UTC · hidden as outdated
View on GitHub

⌛ Trying commit cc70ec0 with merge 72527f8

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

Workflow: https://github.com/rust-lang/rust/actions/runs/23739649784

zetanumbers Avatar
zetanumbers on 2026-03-30 11:24:20 UTC
zetanumbers Avatar
zetanumbers on 2026-03-30 11:24:20 UTC
View on GitHub

Ok, that's good

zetanumbers Avatar
zetanumbers on 2026-03-30 13:56:20 UTC
zetanumbers Avatar
zetanumbers on 2026-03-30 13:56:20 UTC
View on GitHub
rust-bors Avatar
rust-bors on 2026-03-30 16:24:33 UTC
rust-bors Avatar
rust-bors on 2026-03-30 16:24:33 UTC
View on GitHub

💔 Test for 72527f8 failed: CI

lqd Avatar
lqd on 2026-03-30 16:26:33 UTC
lqd Avatar
lqd on 2026-03-30 16:26:33 UTC
View on GitHub

timeout
@bors try

rust-bors Avatar
rust-bors on 2026-03-30 16:26:39 UTC · hidden as outdated
rust-bors Avatar
rust-bors on 2026-03-30 16:26:39 UTC · hidden as outdated
View on GitHub

⌛ Trying commit cc70ec0 with merge 5a1a969

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

Workflow: https://github.com/rust-lang/rust/actions/runs/23755579483

rust-bors Avatar
rust-bors on 2026-03-30 18:34:09 UTC
rust-bors Avatar
rust-bors on 2026-03-30 18:34:09 UTC
View on GitHub

☀️ Try build successful (CI)
Build commit: 5a1a969 (5a1a969187f4afe604cb916bc5740a09c5062f4b, parent: cf7da0b7277cad05b79f91b60c290aa08a17a6f0)

rust-timer Avatar
rust-timer on 2026-03-30 18:34:13 UTC · hidden as outdated
rust-timer Avatar
rust-timer on 2026-03-30 18:34:13 UTC · hidden as outdated
View on GitHub

Queued 5a1a969 with parent cf7da0b, future comparison URL.
There are currently 0 preceding artifacts in the queue.
It will probably take at least ~1.0 hours until the benchmark run finishes.

rust-timer Avatar
rust-timer on 2026-03-30 19:14:23 UTC
rust-timer Avatar
rust-timer on 2026-03-30 19:14:23 UTC
View on GitHub

Finished benchmarking commit (5a1a969): 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.8% [0.8%, 0.8%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.6%, -0.1%] 8
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 1.4%)

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

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

Cycles

Results (secondary -1.6%)

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

Binary size

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

Bootstrap: 483.836s -> 485.128s (0.27%)
Artifact size: 394.90 MiB -> 394.80 MiB (-0.02%)

nnethercote Avatar
nnethercote commented on 2026-03-31 02:35:04 UTC
compiler/rustc_query_impl/src/query_impl.rs · outdated
129 _tcx: TyCtxt<'tcx>,
130 _key: rustc_middle::queries::$name::Key<'tcx>,
131 ) -> bool {
132 if !cfg!($cache_on_disk) {
nnethercote Avatar nnethercote on 2026-03-31 02:29:05 UTC
View on GitHub

Can you use #[cfg] instead of cfg!?

Alternatively, cfg_select! might make this function nicer.

Zalathar Avatar Zalathar on 2026-03-31 04:01:18 UTC
View on GitHub

The cfg_select! version ends up being a bit visually “messier”, but has the benefit of being very explicit about exhaustively listing all possible cases, which seems like an improvement. 👍

zetanumbers Avatar zetanumbers on 2026-03-31 11:08:12 UTC
View on GitHub

You can actually just use $cache_on_disk.

Zalathar Avatar Zalathar on 2026-04-01 01:27:47 UTC
View on GitHub

Oh that’s right, it expands to a boolean literal, so it could be used directly as a value.

We ended up going with cfg_select! to make the various cases more explicit, but that’s good to keep in mind.

nnethercote Avatar nnethercote on 2026-04-01 01:39:36 UTC
View on GitHub

I think the cfg_select! is good because it makes clear that this is compile-time selection of code fragments, and there is no relying on the optimizer to trim dead paths.

Zalathar Avatar Zalathar on 2026-04-01 02:53:48 UTC
View on GitHub

The issue I was originally trying to work around was that #[cfg(..)] can be very clunky and verbose when trying to select an expression instead of a statement.

But cfg_select! works wonderfully in that situation.

rustbot Avatar
rustbot on 2026-03-31 03:45:50 UTC
rustbot Avatar
rustbot on 2026-03-31 03:45:50 UTC
View on GitHub

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Zalathar Avatar
Zalathar on 2026-03-31 04:05:12 UTC
Zalathar Avatar
Zalathar on 2026-03-31 04:05:12 UTC
View on GitHub

@rustbot ready

nnethercote Avatar
nnethercote on 2026-03-31 05:22:58 UTC
nnethercote Avatar
nnethercote on 2026-03-31 05:22:58 UTC
View on GitHub

@bors r+

rust-bors Avatar
rust-bors on 2026-03-31 05:23:02 UTC
rust-bors Avatar
rust-bors on 2026-03-31 05:23:02 UTC
View on GitHub

📌 Commit 5b7f8e6 has been approved by nnethercote

It is now in the queue for this repository.

Zalathar Avatar
Zalathar on 2026-03-31 06:21:17 UTC
Zalathar Avatar
Zalathar on 2026-03-31 06:21:17 UTC
View on GitHub

Ah, I remembered that the dev-guide will need updating too.

Since this is rollup=never and nowhere near the top of the queue, I'll push a fix.

rustbot Avatar
rustbot on 2026-03-31 06:22:00 UTC
rustbot Avatar
rustbot on 2026-03-31 06:22:00 UTC
View on GitHub

The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes.

cc @BoxyUwU, @tshepang

rust-bors Avatar
rust-bors on 2026-03-31 06:22:00 UTC
rust-bors Avatar
rust-bors on 2026-03-31 06:22:00 UTC
View on GitHub

⚠️ A new commit 076dc9b06ec41bd6103dda22010fef784768ba5b was pushed.

This pull request was unapproved.

nnethercote Avatar
nnethercote on 2026-03-31 06:23:43 UTC
nnethercote Avatar
nnethercote on 2026-03-31 06:23:43 UTC
View on GitHub

@bors r+

rust-bors Avatar
rust-bors on 2026-03-31 06:23:46 UTC
rust-bors Avatar
rust-bors on 2026-03-31 06:23:46 UTC
View on GitHub

📌 Commit 076dc9b has been approved by nnethercote

It is now in the queue for this repository.

rust-bors Avatar
rust-bors on 2026-03-31 13:13:40 UTC · hidden as outdated
rust-bors Avatar
rust-bors on 2026-03-31 13:13:40 UTC · hidden as outdated
View on GitHub
rust-bors Avatar
rust-bors on 2026-03-31 16:43:40 UTC
rust-bors Avatar
rust-bors on 2026-03-31 16:43:40 UTC
View on GitHub

☀️ Test successful - CI
Approved by: nnethercote
Duration: 3h 29m 47s
Pushing ba11b1e to main...

github-actions Avatar
github-actions on 2026-03-31 16:46:57 UTC
github-actions Avatar
github-actions on 2026-03-31 16:46:57 UTC
View on GitHub
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 e4fdb55 (parent) -> ba11b1e (this PR)

Test differences

Show 68 test diffs

68 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 ba11b1e3f09829428844b74829146fcf7c38d3d0 --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-x86_64-apple: 1h 38m -> 2h 7m (+29.8%)
  2. aarch64-apple: 3h 39m -> 2h 51m (-21.8%)
  3. x86_64-gnu-llvm-22-1: 1h 3m -> 1h 13m (+15.6%)
  4. x86_64-gnu-llvm-21-2: 1h 25m -> 1h 37m (+14.6%)
  5. dist-aarch64-msvc: 1h 50m -> 1h 38m (-11.3%)
  6. i686-gnu-2: 1h 36m -> 1h 46m (+9.8%)
  7. i686-msvc-1: 2h 45m -> 3h 1m (+9.6%)
  8. aarch64-gnu-debug: 1h 9m -> 1h 15m (+9.5%)
  9. dist-i686-msvc: 2h 12m -> 2h 24m (+9.3%)
  10. x86_64-gnu-debug: 1h 57m -> 2h 8m (+8.9%)
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 Avatar
rust-timer on 2026-03-31 17:25:24 UTC
rust-timer Avatar
rust-timer on 2026-03-31 17:25:24 UTC
View on GitHub

Finished benchmarking commit (ba11b1e): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

@rustbot label: -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.9% [0.9%, 0.9%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.1% [-0.2%, -0.1%] 4
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -0.6%, secondary -2.0%)

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

mean range count
Regressions ❌
(primary)
2.6% [1.0%, 3.8%] 5
Regressions ❌
(secondary)
1.5% [1.5%, 1.5%] 1
Improvements ✅
(primary)
-2.8% [-4.4%, -1.0%] 7
Improvements ✅
(secondary)
-2.5% [-3.8%, -1.4%] 7
All ❌✅ (primary) -0.6% [-4.4%, 3.8%] 12

Cycles

Results (secondary -5.7%)

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

Binary size

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

Bootstrap: 484.743s -> 488.578s (0.79%)
Artifact size: 394.91 MiB -> 394.90 MiB (-0.00%)