Commit Graph

502 Commits

Author SHA1 Message Date
Nicholas Nethercote 6b0beecd95 Remove PER_QUERY_GATHER_ACTIVE_JOBS_FNS.
And also `gather_active_jobs` for each query. This is done by generating
`collect_active_jobs_from_all_queries` and having it do things more
directly.
2026-02-27 07:55:47 +11:00
Nicholas Nethercote 65cf5d73ab Minimize gather_active_jobs.
Currently `gather_active_jobs` and `gather_active_jobs_inner` do some of
the work each. This commit changes things so that `gather_active_jobs`
is just a thin wrapper around `gather_active_jobs_inner`. This paves the
way for removing `gather_active_jobs` in the next commit.
2026-02-27 07:55:45 +11:00
Nicholas Nethercote 8f0ca1d253 Remove QUERY_KEY_HASH_VERIFY.
And also `query_key_hash_verify` for each query. This is done by
generating `query_key_hash_verify_all` and having it do things more
directly.
2026-02-27 07:19:19 +11:00
Jonathan Brouwer 3eafea8d3a Rollup merge of #153120 - Zalathar:execute, r=nnethercote
Clean up some code related to `QueryVTable::execute_query_fn`

This PR is an assortment of small cleanups to code that interacts with `execute_query_fn` in the query vtable.

I also experimented with trying to replace the macro-generated `__rust_end_short_backtrace` functions with a single shared generic function, but I couldn't manage to avoid breaking short backtraces, so I left a note behind to document my attempt.

r? nnethercote (or compiler)
2026-02-26 09:57:06 +01:00
Nicholas Nethercote 9ba101f44a Rename Storage as Cache.
Because `Storage` is a vague name that I've never liked.
2026-02-26 19:18:51 +11:00
Nicholas Nethercote fbea6ddcd2 Rename trait Key as trait QueryKey`
Because `Key` is extremely generic and hard to search for.

Also rename `LocalKey` and `AsLocalKey` similarly, for consistency.
2026-02-26 19:18:48 +11:00
Zalathar fb42537104 Rename some query plumbing to match QueryVTable::execute_query_fn 2026-02-26 18:53:50 +11:00
Nicholas Nethercote 608d85f989 Move two functions into hooks.
`QuerySystem` has two function pointers: `encode_query_results` and
`try_mark_green`. These exist so that `rustc_middle` can call functions
from upstream crates.

But we have a more general mechanism for that: hooks. So this commit
converts these two cases into hooks.
2026-02-25 17:30:47 +11:00
Nicholas Nethercote b76b26db3b Remove QuerySystemFns.
It has a single use and doesn't provide any real value. Removing it
allows the removal of two `for<'tcx>` qualifiers.
2026-02-25 17:30:17 +11:00
Nicholas Nethercote 4a5ee0421f Rename PerQueryVTables as QueryVTables.
The `Per` isn't really necessary.
2026-02-25 08:26:28 +11:00
Nicholas Nethercote 2bc5167e99 Merge QueryEngine into QueryVTable.
`QueryEngine` is a struct with one function pointer per query. This
commit removes it by moving each function pointer into the relevant
query's vtable, which is already a collection of function pointers for
that query. This makes things simpler.
2026-02-25 08:26:27 +11:00
Nicholas Nethercote 06cd823158 Rename some Cache type variables as C.
Currently type variables that impl `QueryCache` are called either `C` or
`Cache`. I find the former clearer because single char type variables
names are very common and longer type variable names are easy to mistake
for type or trait names -- e.g. I find the trait bound `C: QueryCache`
much easier and faster to read than `Cache: QueryCache`.
2026-02-25 08:26:26 +11:00
Nicholas Nethercote e45224c4af Improve how QueryCaches and QueryStates are stored.
`QuerySystem` has these fields:
```
pub states: QueryStates<'tcx>,
pub caches: QueryCaches<'tcx>,
pub query_vtables: PerQueryVTables<'tcx>,
```
Each one has an entry for each query.

Some methods that take a query-specific `QueryVTable` need to access the
corresponding query-specific states and/or caches. So `QueryVTable`
stores the *byte offset* to the relevant fields within `states` and
`caches`, and uses that to (with `unsafe`) access the fields. This is
bizarre, and I hope it made sense in the past when the code was
structured differently.

This commit moves `QueryState` and `QueryCache` inside `QueryVTable`. As
a result, the query-specific states and/or caches are directly
accessible, and no unsafe offset computations are required. Much simpler
and more normal. Also, `QueryCaches` and `QueryStates` are no longer
needed, which makes `define_callbacks!` a bit simpler.

The commit also rename the fields and their getters to `states` and
`caches`.
2026-02-25 08:13:56 +11:00
Jonathan Brouwer 68bff20d1d Rollup merge of #153033 - Zalathar:ensure, r=nnethercote
Clarify how "ensure" queries check whether they can skip execution

The current `check_cache: bool` field in QueryMode is confusing for a few reasons:

- It actually refers to checking the *disk cache*, not the in-memory cache.
- It gives no indication of what condition is being checked, or why.
- It obscures the link between `tcx.ensure_ok()` and `tcx.ensure_done()`, and the actual check.

This PR replaces that field with an `EnsureMode` enum that distinguishes between ensure-ok and ensure-done, and leaves the actual check as an implementation detail of the ensure-done mode.

This PR also renames `ensure_must_run` → `check_if_ensure_can_skip_execution`, and uses a return struct to more clearly indicate how this helper function gives permission for its caller to skip execution of a query that would otherwise be executed. This also inverts the sense of the returned boolean, which was previously “must run” but is now ”skip execution”.

r? nnethercote (or compiler)
2026-02-24 14:41:58 +01:00
Zalathar 16fbd29fcf Streamline QueryVTableUnerased into GetQueryVTable 2026-02-24 15:29:19 +11:00
Zalathar bf0f5115c3 Clarify how "ensure" queries check whether they can skip execution 2026-02-24 15:19:38 +11:00
bors b3869b94cd Auto merge of #152791 - nnethercote:rm-const-FLAGS, r=Zalathar
Remove `const FLAGS`.

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152791)*

The performance wins provided by these types are meagre, and I don't think they justify the code complexity they introduce.

r? @Zalathar
2026-02-23 19:11:54 +00:00
John Kåre Alsaker 9f7d502d64 Remove deterministic picking from query cycle handling 2026-02-23 01:31:59 +01:00
Nicholas Nethercote 5aebfd648b Rename query_dispatcher and reduce its use.
It's now `query_vtable` because its return type changed. And thanks to
the previous commit it can be manually inlined in several places. (The
only remaining calls to it are in `make_dep_kind_vtable_for_query`,
which are more challenging to remove.)
2026-02-23 07:20:24 +11:00
Nicholas Nethercote 6c12694b64 Remove SemiDynamicQueryDispatcher and QueryFlags.
`SemiDynamicQueryDispatcher` is just a `QueryVTable` wrapper with an
additional `const FLAGS: QueryFlags` generic parameter that contains
three booleans. This arrangement exists as a performance optimization.
But the performance effects are very small and it adds quite a bit of
complexity to an already overly-complex part of the codebase. If it
didn't exist and somebody proposed adding it and asked me to review, I
almost certainly wouldn't approve it.

This commit removes it. The three booleans in `QueryFlags` are moved
into `QueryVTable` The non-trivial methods of
`SemiDynamicQueryDispatcher` become methods of `QueryVTable`.
2026-02-23 07:20:21 +11:00
Nicholas Nethercote bc1b6b8b32 Reduce $K and $V usage in query macros.
Within `define_callbacks!`:
- Use `Key<'tcx>` where possible instead of `$($K)*`.
- Use `Value<'tcx>` where possible instead of `$V`.

In the other `define_*!` macros:
- Use `$K:ty` where possible instead of `$($K:tt)*`.
- Add comments about unused `$K` and `$V` cases.
- Add `()` key types to the special nodes in the `define_dep_nodes!`
  invocation for consistency with normal queries.
2026-02-21 06:24:38 +11:00
Nicholas Nethercote baa74a85ee Remove DepKind name plumbing.
There is a bunch of plumbing to record the string `"foo"` for each
variant `DepKind::foo`. But that's what the `Debug `impl` now produces.
So this commit removes the plumbing.
2026-02-19 09:05:39 +11:00
Nicholas Nethercote c4a69d4712 Bring back enum DepKind.
It was removed in #115920 to enable it being moved to
`rustc_query_system`, a move that has recently been reversed. It's much
simpler as an enum.

Also:
- Remove the overly complicated `Debug` impl for `DepKind`.
- Remove the trivial `DepKind` associated constants (`NULL` et al.)
- Add an assertion to ensure that the number of `DepKinds` fits within a
  `u16`.
- Rename `DEP_KIND_VARIANTS` as `DEP_KIND_NUM_VARIANTS`, to make it
  clearer that it's a count, not a collection.
- Use `stringify!` in one place to make the code clearer.
2026-02-19 09:05:37 +11:00
Zalathar b015d5712a Rename DepNodeKey::recover to try_recover_key 2026-02-18 17:20:32 +11:00
Zalathar 9eaedddb7f Rename dep node "fingerprints" to distinguish key and value hashes 2026-02-18 17:20:32 +11:00
Zalathar db58395a6b Don't use HasDepContext in DepGraph::with_task
The need for a `HasDepContext` impl on tuples can be avoided by passing the
query vtable as part of an argument tuple instead.
2026-02-17 17:30:55 +11:00
Zalathar fbb34d8c75 Remove wrapper struct QueryCtxt
This struct was only wrapping `TyCtxt` in order to implement traits that
were removed by RUST-152636.

This commit also slightly simplifies the signature of `execute_job_incr`, by
having it call `tcx.dep_graph.data()` internally.
2026-02-17 17:30:55 +11:00
bors fef627b1eb Auto merge of #152636 - nnethercote:big-cleanups, r=Zalathar
Big query system cleanups

Recent PRs have moved a lot of code from `rustc_query_system` to `rustc_middle` and `rustc_query_impl`, where this code now has access to `TyCtxt`, e.g. rust-lang/rust#152419, rust-lang/rust#152516. As a result, a lot of abstraction and indirection that existed to work around this limitation is no longer necessary. This PR removes a lot of it.

r? @Zalathar
2026-02-16 04:20:25 +00:00
Nicholas Nethercote 7c877d994b Remove DepContext.
It's no longer needed now that we can access `TyCtxt` directly.
2026-02-15 13:07:40 +11:00
Nicholas Nethercote 414be2e6ff Remove Deps.
It's no longer needed.
2026-02-15 13:07:39 +11:00
Nicholas Nethercote 1d83208683 De-genericize the dep graph.
By removing the generic `D` parameter from `DepGraph`, `DepGraphData`,
`CurrentDepGraph`, `SerializedDepGraph`, `SerializedNodeHeader`, and
`EncoderState`.
2026-02-15 13:07:37 +11:00
Nicholas Nethercote 32e6a1a0ab Remove QueryContext.
`rustc_query_system` has been reduced so much that it's no longer
needed. This avoids a lot of indirection and abstraction.
2026-02-15 13:07:35 +11:00
Jonathan Brouwer 7c36d152b4 Rollup merge of #152582 - petrochenkov:waitvisit, r=TaKO8Ki
rustc_query_impl: Use `ControlFlow` in `visit_waiters` instead of nested options

Noticed when reviewing https://github.com/rust-lang/rust/pull/152229.
2026-02-14 22:11:55 +01:00
Nicholas Nethercote ed091aaf5d Move rustc_query_system::query::dep_graph to rustc_middle.
Most of the files within the `dep_graph` module can be moved wholesale
into `rustc_middle`. But two of them (`mod.rs` and `dep_node.rs`) have
the same name as existing files in `rustc_middle`, so for those I just
copied the contents into the existing files.

The commit also moves `QueryContext` and `incremental_verify_ich*`
because they are tightly intertwined with the dep graph code. And a
couple of error structs moved as well.
2026-02-14 18:46:05 +11:00
Nicholas Nethercote fa3b046aa5 Move QueryMode.
From `rustc_query_system::query::plumbing` to
`rustc_middle::query::plumbing`.
2026-02-14 18:38:33 +11:00
Nicholas Nethercote 924dbc46d9 Move CycleErrorHandling.
From `rustc_query_system` to `rustc_middle`.
2026-02-14 18:38:33 +11:00
Nicholas Nethercote 940f30792c Move rustc_query_system::query::caches to rustc_middle::query.
This one is straightforward.
2026-02-14 18:38:30 +11:00
Nicholas Nethercote 8b0dc1ece0 Move rustc_query_system::query::job to rustc_middle.
This includes the types `QueryInfo`, `QueryJob`, `QueryJobId`,
`QueryWaiter`, `QueryLatch`, and `QueryLatchInfo`.

`CycleError` and `QueryStack*` had to come along too, due to type
interdependencies. The `QueryStack*` types are put into a new submodule
`rustc_middle::query::stack`.
2026-02-14 18:33:13 +11:00
Nicholas Nethercote 1ac199af0a Move QueryState/ActiveKeyStatus.
From `rustc_query_state` to `rustc_middle`.
2026-02-14 18:24:47 +11:00
Vadim Petrochenkov 2ee28ca538 rustc_query_impl: Use ControlFlow in visit_waiters instead of nested options 2026-02-13 20:20:02 +03:00
Zalathar 1d6ef95075 Extract DepKindVTable constructors to their own module 2026-02-13 23:19:20 +11:00
Zalathar b9b28ba1b5 Collect active query jobs into struct QueryJobMap 2026-02-13 01:18:24 +11:00
Jacob Pratt 0e746d0a25 Rollup merge of #152434 - Zalathar:call-query, r=nnethercote
Clarify names of `QueryVTable` functions for "executing" a query

In the query system, there are several layers of functions involved in “executing” a query, with very different responsibilities at each layer, making it important to be able to tell them apart.

This PR renames two of the function pointers in `QueryVTable`, along with their associated helper functions, to hopefully do a better job of indicating what their actual responsibilities are.

r? nnethercote
2026-02-12 00:41:08 -05:00
Matthias Krüger 2194af9680 Rollup merge of #152419 - nnethercote:mv-more-query-system-code, r=Zalathar
Move more query system code

Towards the goal of eliminating `rustc_query_system`, this commit moves some code from `rustc_query_system` to `rustc_middle` and `rustc_query_impl`, and from `rustc_middle` to `rustc_query_impl`.

r? @Zalathar
2026-02-11 13:48:46 +01:00
Zalathar 0de45db240 Clarify names of QueryVTable functions for "executing" a query
This also changes the signature of `call_query_method` to not return a value,
because its only caller immediately discards the value anyway.
2026-02-11 16:50:10 +11:00
bors 7b25457166 Auto merge of #151943 - Zalathar:cache-on-disk, r=TaKO8Ki
Clean up query macros for `cache_on_disk_if`

This PR aims to make the macros for dealing with `cache_on_disk_if` a bit easier to read and work with.

There should be no change to compiler behaviour.
2026-02-10 20:57:44 +00:00
Nicholas Nethercote a34317e5a5 Move report_cycle.
From `rustc_query_system::query::job` to `rustc_query_impl::job`.
2026-02-10 18:46:05 +11:00
Nicholas Nethercote 923de04f6a Move rustc_middle::query::values to rustc_query_impl.
Because all uses are now in `rustc_query_impl`. This was made possible
by the previous commit. Less code in `rustc_middle`, hooray.
2026-02-10 18:46:05 +11:00
Nicholas Nethercote 066a935b0c Move parts of rustc_query_system::query::job to rustc_middle::job.
The latter is a new module.

As well as the code motion, some other changes were required.
- `QueryJobId` methods became free functions so they could move while
  `QueryJobId` itself stayed put. This was so `QueryMap` and
  `QueryJobInfo` could be moved.
- Some visibilities in `rustc_query_system` required changing.
- `collect_active_jobs_from_all_queries` is no longer required in `trait
  QueryContext`.
2026-02-10 16:59:33 +11:00
Zalathar c475bdaa53 Include key_hash in ActiveJobGuard
This value is a previously-computed hash of the key, so it makes sense to
bundle it with the key inside the guard, since the guard will need it on
completion anyway.
2026-02-10 00:20:47 +11:00