Skip to content

Refactor query loading#154207

Merged
rust-bors[bot] merged 4 commits intorust-lang:mainfrom
nnethercote:refactor-query-loading
Mar 23, 2026
Merged

Refactor query loading#154207
rust-bors[bot] merged 4 commits intorust-lang:mainfrom
nnethercote:refactor-query-loading

Conversation

@nnethercote
Copy link
Copy Markdown
Contributor

Some refactoring of code relating to query result loading. Details in individual commits.

r? @Zalathar

It's very small and only has two call sites. The tiny loss of DRY is
worth it to shrink `QueryVTable`.
We can only reach this point if `try_load_from_disk_fn` fails, and the
condition of this assertion is basically just the inverse of what
`try_load_from_disk_fn` does. Basically it's like this:
```
fn foo() -> bool { a && b }

fn bar() {
    if foo() {
        return;
    }
    assert!(!a || !b);
}
```
The assertion is just confusing and provides little value.
@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 22, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 22, 2026

Zalathar is not on the review rotation at the moment.
They may take a while to respond.

@nnethercote
Copy link
Copy Markdown
Contributor 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 22, 2026
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 22, 2026
// we should actually be able to load it.
debug_assert!(
!(query.is_loadable_from_disk_fn)(tcx, key, prev_index),
!((query.will_cache_on_disk_for_key_fn)(tcx, key) && loadable_from_disk(tcx, prev_index)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: It seems weird to inline this call site only to then immediately delete it, when we could rearrange the commits to do the deletion first.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was feeling my way with the commits; the plan wasn't totally clear when I started. Inlining this first made it easier for me to see the correspondence between this assertion and load_from_disk_or_invoke_provider_green.

Comment on lines +492 to +493
let value = (query.try_load_from_disk_fn)(tcx, key, prev_index, dep_node_index);
let (value, verify) = if let Some(value) = value {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In this situation I think it would be good to:

  • Use match instead of if let, which I think is a better fit for the “similar conceptual weight” of the two arms, despite adding an extra layer of indentation. Match syntax also puts the Some(value) binding closer to the code that actually uses it.
  • Inline the value variable into the match scrutinee position, to avoid the confusion of it actually being optional.
  • Get rid of the let (value, verify) =, and instead declare two uninitialized variables outside the block, which are then assigned in the respective match arms:
let value;
let verify;
match (query.try_load_from_disk_fn)(tcx, key, prev_index, dep_node_index) {
    Some(value) => {
        ...
        value = ...;
        verify = ...;
    None => {
        ...
        value = ...;
        verify = ...;
    }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've done that, except I did Some(loaded_value) otherwise value gets shadowed.

Comment on lines -511 to -516
// We always expect to find a cached result for things that can be forced from `DepNode`.
debug_assert!(
!(query.will_cache_on_disk_for_key_fn)(tcx, key)
|| !tcx.key_fingerprint_style(dep_node.kind).is_maybe_recoverable(),
"missing on-disk cache entry for {dep_node:?}"
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: If we're removing this assertion, we should rearrange the commits to remove it before re-indenting the surrounding code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok. I put this commit last because I thought it might be controversial, but sounds like you're ok with it.

@Zalathar
Copy link
Copy Markdown
Member

I like these changes overall BTW; I just happened to notice a bunch of possible style improvements along the way.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 22, 2026

☀️ Try build successful (CI)
Build commit: eeb1c5b (eeb1c5bb096864ccede618219084efd96f988358, parent: 562dee4820c458d823175268e41601d4c060588a)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (eeb1c5b): comparison URL.

Overall result: no relevant changes - no action needed

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.

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

Instruction count

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

Max RSS (memory usage)

Results (primary -6.3%)

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

Cycles

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

Binary size

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

Bootstrap: 485.484s -> 484.632s (-0.18%)
Artifact size: 394.88 MiB -> 394.87 MiB (-0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 22, 2026
This one just irritates me, and I don't think it adds much value.
By removing the early return and using a `match` instead.
- The two paths are of similar conceptual weight, and `match` reflects
  that.
- This lets the `incremental_verify_ich` call be factored out.
@nnethercote nnethercote force-pushed the refactor-query-loading branch from 7d547af to 327216d Compare March 22, 2026 22:27
@nnethercote nnethercote marked this pull request as ready for review March 22, 2026 22:28
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 22, 2026
@nnethercote
Copy link
Copy Markdown
Contributor Author

@rustbot ready

@Zalathar
Copy link
Copy Markdown
Member

@bors r+ rollup=maybe

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 23, 2026

📌 Commit 327216d has been approved by Zalathar

It is now in the queue for this repository.

@rust-bors rust-bors bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Mar 23, 2026
@rust-bors rust-bors bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 23, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 23, 2026
…, r=Zalathar

Refactor query loading

Some refactoring of code relating to query result loading. Details in individual commits.

r? @Zalathar
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 23, 2026
…, r=Zalathar

Refactor query loading

Some refactoring of code relating to query result loading. Details in individual commits.

r? @Zalathar
rust-bors bot pushed a commit that referenced this pull request Mar 23, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #154241 (`rust-analyzer` subtree update)
 - #153686 (`std`: include `dlmalloc` for all non-wasi Wasm targets)
 - #154105 (bootstrap: Pass `--features=rustc` to rustc_transmute)
 - #153069 ([BPF] add target feature allows-misaligned-mem-access)
 - #154085 (Parenthesize or-patterns in prefix pattern positions in pretty printer)
 - #154191 (refactor RangeFromIter overflow-checks impl)
 - #154207 (Refactor query loading)
 - #153540 (drop derive helpers during attribute parsing)
 - #154140 (Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known.)
 - #154161 (On E0277 tweak help when single type impls traits)
 - #154218 (interpret/validity: remove unreachable error kind)
 - #154225 (diagnostics: avoid ICE in confusable_method_name for associated functions)
 - #154228 (Improve inline assembly error messages)
@rust-bors rust-bors bot merged commit 83a0bd9 into rust-lang:main Mar 23, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 23, 2026
@nnethercote nnethercote deleted the refactor-query-loading branch March 23, 2026 21:44
github-actions bot pushed a commit to rust-lang/stdarch that referenced this pull request Mar 26, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#154241 (`rust-analyzer` subtree update)
 - rust-lang/rust#153686 (`std`: include `dlmalloc` for all non-wasi Wasm targets)
 - rust-lang/rust#154105 (bootstrap: Pass `--features=rustc` to rustc_transmute)
 - rust-lang/rust#153069 ([BPF] add target feature allows-misaligned-mem-access)
 - rust-lang/rust#154085 (Parenthesize or-patterns in prefix pattern positions in pretty printer)
 - rust-lang/rust#154191 (refactor RangeFromIter overflow-checks impl)
 - rust-lang/rust#154207 (Refactor query loading)
 - rust-lang/rust#153540 (drop derive helpers during attribute parsing)
 - rust-lang/rust#154140 (Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known.)
 - rust-lang/rust#154161 (On E0277 tweak help when single type impls traits)
 - rust-lang/rust#154218 (interpret/validity: remove unreachable error kind)
 - rust-lang/rust#154225 (diagnostics: avoid ICE in confusable_method_name for associated functions)
 - rust-lang/rust#154228 (Improve inline assembly error messages)
github-actions bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Mar 26, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#154241 (`rust-analyzer` subtree update)
 - rust-lang/rust#153686 (`std`: include `dlmalloc` for all non-wasi Wasm targets)
 - rust-lang/rust#154105 (bootstrap: Pass `--features=rustc` to rustc_transmute)
 - rust-lang/rust#153069 ([BPF] add target feature allows-misaligned-mem-access)
 - rust-lang/rust#154085 (Parenthesize or-patterns in prefix pattern positions in pretty printer)
 - rust-lang/rust#154191 (refactor RangeFromIter overflow-checks impl)
 - rust-lang/rust#154207 (Refactor query loading)
 - rust-lang/rust#153540 (drop derive helpers during attribute parsing)
 - rust-lang/rust#154140 (Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known.)
 - rust-lang/rust#154161 (On E0277 tweak help when single type impls traits)
 - rust-lang/rust#154218 (interpret/validity: remove unreachable error kind)
 - rust-lang/rust#154225 (diagnostics: avoid ICE in confusable_method_name for associated functions)
 - rust-lang/rust#154228 (Improve inline assembly error messages)
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) 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.

4 participants