Streamline QueryVTableUnerased into GetQueryVTable rust-lang/rust#152841

Merged

30 comments and reviews loaded in 1.32s

Zalathar Avatar
Zalathar on 2026-02-19 11:22:23 UTC · edited
Zalathar Avatar
Zalathar on 2026-02-19 11:22:23 UTC · edited
View on GitHub

View all comments

QueryDispatcherUnerased is an awkward name for an awkward trait.

We can make it a bit more straightforward by removing its responsibility for erasing query values, and by observing that its only real responsibility beyond that is to know how to obtain the vtable for a particlar query from tcx.

Zalathar Avatar
Zalathar on 2026-02-19 11:22:33 UTC
Zalathar Avatar
Zalathar on 2026-02-19 11:22:33 UTC
View on GitHub

@bors try @rust-timer queue

rust-timer Avatar
rust-timer on 2026-02-19 11:22:36 UTC · hidden as outdated
rust-timer Avatar
rust-timer on 2026-02-19 11:22:36 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-02-19 11:22:38 UTC · hidden as outdated
rust-bors Avatar
rust-bors on 2026-02-19 11:22:38 UTC · hidden as outdated
View on GitHub

⌛ Trying commit 3680e69 with merge b46d288

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

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

Zalathar Avatar
Zalathar on 2026-02-19 11:25:28 UTC
Zalathar Avatar
Zalathar on 2026-02-19 11:25:28 UTC
View on GitHub
  • The NAME associated constant will be removed by #152747; I've left it alone in this PR to make rebasing easier.
petrochenkov Avatar
petrochenkov commented on 2026-02-19 12:00:13 UTC
compiler/rustc_query_impl/src/plumbing.rs · outdated
633 /// Marker type that implements [`QueryVTableGetter`] for this query.
634 pub(crate) enum VTableGetter {}
635
636 impl<'tcx> QueryVTableGetter<'tcx, FLAGS> for VTableGetter {
petrochenkov Avatar petrochenkov on 2026-02-19 11:56:28 UTC
View on GitHub

This is a trait with a single implementer (per query).
Would it be hard to refactor it into a free (per query) function somehow?
(Similarly to how restore_val was removed from the trait's interface.)

Zalathar Avatar Zalathar on 2026-02-19 12:18:22 UTC
View on GitHub

Using a free function seems tricky, because the generics needed per callee would get more complicated, and that's something I'm trying to cut down on.

compiler/rustc_query_impl/src/lib.rs · outdated
236 fn query_dispatcher(tcx: TyCtxt<'tcx>) -> SemiDynamicQueryDispatcher<'tcx, C, FLAGS>;
237
238 fn restore_val(value: C::Value) -> Self::UnerasedValue;
235 fn query_dispatcher(tcx: TyCtxt<'tcx>) -> SemiDynamicQueryDispatcher<'tcx, Self::Cache, FLAGS>;
petrochenkov Avatar petrochenkov on 2026-02-19 11:59:01 UTC
View on GitHub

If the trait method produces a query dispatcher, then I'd call the trait GetQueryDispatcher, so both say what it does and follow trait naming conventions.

Or keep "vtable", but rename SemiDynamicQueryDispatcher to SemiDynamicQueryVTable because that's also what it is.

petrochenkov Avatar petrochenkov on 2026-02-19 12:03:18 UTC
View on GitHub

... or SemiStatic, because it's still mostly dynamic :)

Zalathar Avatar Zalathar on 2026-02-19 12:15:49 UTC
View on GitHub

The name SemiDynamicQueryDispatcher is a relic from before the QueryDispatcher trait was removed, so for consistent naming I'd prefer to move away from “dispatcher” and towards ”vtable”.

I have some ideas for how to rename SemiDynamicQueryDispatcher, and possibly reduce the number of explicit FLAGS parameters everywhere, but that needs some more experimentation while I figure out what things should look like.

Zalathar Avatar Zalathar on 2026-02-19 12:21:35 UTC
View on GitHub

One of the candidates I have in mind for SemiDynamicQueryDispatcher is QueryVTableWithFlags, but I was also thinking about using that name for a trait that hides the flags in an associated constant, so that callees would accept impl QueryVTableWithFlags and not have to have a const FLAGS generic at all.

Zalathar Avatar Zalathar on 2026-02-24 01:25:10 UTC
View on GitHub
  • Thankfully most of this discussion is now irrelevant after #152791.
rust-bors Avatar
rust-bors on 2026-02-19 13:39:03 UTC
rust-bors Avatar
rust-bors on 2026-02-19 13:39:03 UTC
View on GitHub

☀️ Try build successful (CI)
Build commit: b46d288 (b46d288105b795d2d5f97fe4d4e7edc8076a0796, parent: fbd6934114e905d3cc61adbbd7e4a355eac5d0d7)

rust-timer Avatar
rust-timer on 2026-02-19 13:39:05 UTC · hidden as outdated
rust-timer Avatar
rust-timer on 2026-02-19 13:39:05 UTC · hidden as outdated
View on GitHub

Queued b46d288 with parent fbd6934, future comparison URL.
There is currently 1 preceding artifact in the queue.
It will probably take at least ~1.1 hours until the benchmark run finishes.

rust-timer Avatar
rust-timer on 2026-02-19 14:31:08 UTC · hidden as OUTDATED
rust-timer Avatar
rust-timer on 2026-02-19 14:31:08 UTC · hidden as OUTDATED
View on GitHub

Finished benchmarking commit (b46d288): comparison URL.

Overall result: ❌ regressions - 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.4%] 9
Regressions ❌
(secondary)
0.3% [0.1%, 0.5%] 35
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.2%, 0.4%] 9

Max RSS (memory usage)

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

Cycles

Results (primary 2.2%, secondary 9.1%)

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

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

Binary size

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

Bootstrap: 481.318s -> 480.997s (-0.07%)
Artifact size: 397.87 MiB -> 397.77 MiB (-0.03%)

Zalathar Avatar
Zalathar on 2026-02-20 01:13:14 UTC
Zalathar Avatar
Zalathar on 2026-02-20 01:13:14 UTC
View on GitHub

Looks like I need to try some permutations to track down what’s triggering the perf changes.

Zalathar Avatar
Zalathar on 2026-02-20 02:23:31 UTC
Zalathar Avatar
Zalathar on 2026-02-20 02:23:31 UTC
View on GitHub

The current iteration only changes the trait itself and encode_query_results, without touching the DepKindVTable functions. I'm hoping that this will be perf-neutral.

Zalathar Avatar
Zalathar on 2026-02-20 02:23:46 UTC
Zalathar Avatar
Zalathar on 2026-02-20 02:23:46 UTC
View on GitHub

@bors try @rust-timer queue

rust-timer Avatar
rust-timer on 2026-02-20 02:23:48 UTC · hidden as outdated
rust-timer Avatar
rust-timer on 2026-02-20 02:23:48 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-02-20 02:23:50 UTC · hidden as outdated
rust-bors Avatar
rust-bors on 2026-02-20 02:23:50 UTC · hidden as outdated
View on GitHub

⌛ Trying commit 73e18de with merge f16cfc0

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

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

rust-bors Avatar
rust-bors on 2026-02-20 04:35:50 UTC
rust-bors Avatar
rust-bors on 2026-02-20 04:35:50 UTC
View on GitHub

☀️ Try build successful (CI)
Build commit: f16cfc0 (f16cfc0ab2d20a448e430f462e86b78b6b8c0928, parent: ef70767064ab87b0a41400f69e1dc0b55c8d5284)

rust-timer Avatar
rust-timer on 2026-02-20 04:35:53 UTC · hidden as outdated
rust-timer Avatar
rust-timer on 2026-02-20 04:35:53 UTC · hidden as outdated
View on GitHub

Queued f16cfc0 with parent ef70767, 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-02-20 05:17:06 UTC
rust-timer Avatar
rust-timer on 2026-02-20 05:17:06 UTC
View on GitHub

Finished benchmarking commit (f16cfc0): comparison URL.

Overall result: ❌✅ regressions and improvements - 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

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

Max RSS (memory usage)

Results (primary 3.7%)

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

mean range count
Regressions ❌
(primary)
10.0% [10.0%, 10.0%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.6% [-2.6%, -2.6%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.7% [-2.6%, 10.0%] 2

Cycles

Results (primary 2.5%)

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

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

Binary size

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

Bootstrap: 496.246s -> 482.423s (-2.79%)
Artifact size: 397.86 MiB -> 397.86 MiB (-0.00%)

rust-bors Avatar
rust-bors on 2026-02-20 09:48:25 UTC · hidden as outdated
rust-bors Avatar
rust-bors on 2026-02-20 09:48:25 UTC · hidden as outdated
View on GitHub

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

nnethercote Avatar
nnethercote on 2026-02-22 07:20:24 UTC
nnethercote Avatar
nnethercote on 2026-02-22 07:20:24 UTC
View on GitHub

This looks reasonable to me. The perf regression is surprising, I wonder if #152791 will make a difference?

rust-bors Avatar
rust-bors on 2026-02-23 22:49:01 UTC · hidden as outdated
rust-bors Avatar
rust-bors on 2026-02-23 22:49:01 UTC · hidden as outdated
View on GitHub

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

Zalathar Avatar
Zalathar on 2026-02-24 01:19:05 UTC
Zalathar Avatar
Zalathar on 2026-02-24 01:19:05 UTC
View on GitHub

Let's see what perf looks like after removing const FLAGS.

@bors try @rust-timer queue

rust-timer Avatar
rust-timer on 2026-02-24 01:19:07 UTC · hidden as outdated
rust-timer Avatar
rust-timer on 2026-02-24 01:19:07 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-02-24 01:19:09 UTC · hidden as outdated
rust-bors Avatar
rust-bors on 2026-02-24 01:19:09 UTC · hidden as outdated
View on GitHub

⌛ Trying commit 2570d18 with merge f8e0d28

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

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

Zalathar Avatar
Zalathar on 2026-02-24 01:19:31 UTC
Zalathar Avatar
Zalathar on 2026-02-24 01:19:31 UTC
View on GitHub

r? nnethercote (or compiler)

rust-bors Avatar
rust-bors on 2026-02-24 03:29:15 UTC
rust-bors Avatar
rust-bors on 2026-02-24 03:29:15 UTC
View on GitHub

☀️ Try build successful (CI)
Build commit: f8e0d28 (f8e0d280371623a57b0d3cfead4cb65d3f9e15e1, parent: b3869b94cd1ed4bfa2eb28f301535d5e9599c713)

rust-timer Avatar
rust-timer on 2026-02-24 03:29:18 UTC · hidden as outdated
rust-timer Avatar
rust-timer on 2026-02-24 03:29:18 UTC · hidden as outdated
View on GitHub

Queued f8e0d28 with parent b3869b9, future comparison URL.
There is currently 1 preceding artifact in the queue.
It will probably take at least ~1.0 hours until the benchmark run finishes.

nnethercote Avatar
nnethercote commented on 2026-02-24 04:18:27 UTC
compiler/rustc_query_impl/src/plumbing.rs · resolved
325 326 }
326 327
327 pub(crate) fn encode_query_results<'a, 'tcx, Q, C: QueryCache>(
328 query: &'tcx QueryVTable<'tcx, C>,
nnethercote Avatar nnethercote on 2026-02-24 04:18:27 UTC
View on GitHub

Can you still pass in query here? That is simpler than calling Q::query_vtable. Is it possible to avoid the Q generic, and just have C and V?

Zalathar Avatar Zalathar on 2026-02-24 04:35:36 UTC
View on GitHub

Yeah, in hindsight the code I had was influenced by how things looked before some of the other recent cleanups.

rust-timer Avatar
rust-timer on 2026-02-24 04:20:09 UTC
rust-timer Avatar
rust-timer on 2026-02-24 04:20:09 UTC
View on GitHub

Finished benchmarking commit (f8e0d28): comparison URL.

Overall result: ✅ improvements - 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

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

Max RSS (memory usage)

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

Cycles

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

Binary size

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

Bootstrap: 479.41s -> 479.13s (-0.06%)
Artifact size: 395.68 MiB -> 397.73 MiB (0.52%)

nnethercote Avatar
nnethercote on 2026-02-24 04:47:33 UTC
nnethercote Avatar
nnethercote on 2026-02-24 04:47:33 UTC
View on GitHub

@bors r+

rust-bors Avatar
rust-bors on 2026-02-24 04:47:36 UTC
rust-bors Avatar
rust-bors on 2026-02-24 04:47:36 UTC
View on GitHub

📌 Commit 16fbd29 has been approved by nnethercote

It is now in the queue for this repository.

Zalathar Avatar
Zalathar on 2026-02-24 04:51:56 UTC
Zalathar Avatar
Zalathar on 2026-02-24 04:51:56 UTC
View on GitHub

These changes should have no perf effects, and the most recent perf run only shows noise, so this PR seems safe for rollup.

@bors rollup=maybe