Refactor query loading#154207
Conversation
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.
|
|
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| // 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)), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| let value = (query.try_load_from_disk_fn)(tcx, key, prev_index, dep_node_index); | ||
| let (value, verify) = if let Some(value) = value { |
There was a problem hiding this comment.
In this situation I think it would be good to:
- Use
matchinstead ofif 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 theSome(value)binding closer to the code that actually uses it. - Inline the
valuevariable 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 = ...;
}
}There was a problem hiding this comment.
Ok, I've done that, except I did Some(loaded_value) otherwise value gets shadowed.
| // 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:?}" | ||
| ); |
There was a problem hiding this comment.
Nit: If we're removing this assertion, we should rearrange the commits to remove it before re-indenting the surrounding code.
There was a problem hiding this comment.
Ok. I put this commit last because I thought it might be controversial, but sounds like you're ok with it.
|
I like these changes overall BTW; I just happened to notice a bunch of possible style improvements along the way. |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (eeb1c5b): comparison URL. Overall result: no relevant changes - no action neededBenchmarking 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 Instruction countThis 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.
CyclesResults (secondary -2.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 485.484s -> 484.632s (-0.18%) |
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.
7d547af to
327216d
Compare
|
@rustbot ready |
|
@bors r+ rollup=maybe |
…, r=Zalathar Refactor query loading Some refactoring of code relating to query result loading. Details in individual commits. r? @Zalathar
…, r=Zalathar Refactor query loading Some refactoring of code relating to query result loading. Details in individual commits. r? @Zalathar
…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)
…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)
…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)
Some refactoring of code relating to query result loading. Details in individual commits.
r? @Zalathar