Commit Graph

39 Commits

Author SHA1 Message Date
Nicholas Nethercote 2aaced6344 Replace two abort_if_errors calls.
Calling `abort_if_errors` after emitting an error is guaranteed to call
`raise_fatal`, so just do that directly instead.
2026-03-02 14:26:58 +11:00
Nicholas Nethercote fc395ed961 Merge two assertion blocks in execute_job_non_incr.
It reads better that way.
2026-03-02 14:23:55 +11:00
Nicholas Nethercote 7a4daa48b8 Avoid an early return in try_execute_query.
When there are two cases of equal size and importance, I find an if/else
expression easier to read than an early return.
2026-03-02 14:21:03 +11:00
Nicholas Nethercote c0770baed8 Make from_cycle_error consume the CycleError.
This makes it clear the `CycleError` is not used after the call.
2026-03-02 14:21:03 +11:00
Nicholas Nethercote cc1b878386 Inline and remove handle_cycle_error.
It has a single use.
2026-03-02 14:21:03 +11:00
bors 28b5c1cc08 Auto merge of #153122 - Zalathar:dep-kind-vtable, r=nnethercote
Improve the forcing/promotion functions in `DepKindVTable`

This is a bundle of changes to the two function pointers in `DepKindVTable` that are responsible for forcing dep nodes, or promoting disk-cached values from the previous session into memory.

The perf improvements to incr-unchanged and incr-patched are likely from skipping more of the “promotion” plumbing for queries that never cache to disk.
2026-03-01 16:28:20 +00:00
Zalathar f7ac4266f5 Explain why some queries don't support forcing/promotion 2026-03-01 19:42:19 +11:00
Matthias Krüger 27503c450b Rollup merge of #153209 - Zalathar:hash-value-fn, r=nnethercote
Clean up `QueryVTable::hash_result` into `hash_value_fn`

This PR:
- Renames the query vtable field `hash_result` to `hash_value_fn`
- Removes the unhelpful `HashResult` type alias, which was hiding an important layer of `Option`
- Replaces the cryptic `hash_result!` helper macro with a more straightforward `if_no_hash!` helper, in line with other modifier-checking macros
- Renames a few identifiers to refer to a query's return value as `value`

There should be no change to compiler behaviour.

r? nnethercote (or compiler)
2026-03-01 09:39:59 +01:00
bors 765fd2d8c7 Auto merge of #153114 - nnethercote:rm-query-arrays, r=petrochenkov
Remove query function arrays

`define_queries!` produces four arrays of function pointers, which other functions iterate over. These aren't actually necessary.

r? @petrochenkov
2026-03-01 05:22:39 +00:00
Zalathar 2c057bb903 Clean up QueryVTable::hash_result into hash_value_fn
This commit:
- Renames the query vtable field `hash_result` to `hash_value_fn`
- Removes the unhelpful `HashResult` type alias, which was hiding an
  important layer of `Option`
- Replaces the cryptic `hash_result!` helper macro with a more straightforward
  `if_no_hash!` helper, in line with other modifier-checking macros
- Renames a few identifiers to refer to a query's return value as `value`
2026-03-01 12:59:12 +11:00
Zalathar c6d028c30a Clarify a confusing green-path function 2026-02-27 22:53:26 +11:00
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
Zalathar fb42537104 Rename some query plumbing to match QueryVTable::execute_query_fn 2026-02-26 18:53:50 +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
Zalathar bf0f5115c3 Clarify how "ensure" queries check whether they can skip execution 2026-02-24 15:19:38 +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
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
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 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
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
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
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
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 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
Zalathar e04ae80c5a Rename JobOwner to ActiveJobGuard
This commit also adds and updates some relevant comments.
2026-02-10 00:20:45 +11:00
Nicholas Nethercote 541d7fc19d Remove trait QueryDispatcher.
It existed only to bridge the divide between `rustc_query_system` and
`rustc_query_impl`. But enough pieces have been moved from the former to
the latter that the trait is no longer needed. Less indirection and
abstraction makes the code easier to understand.
2026-02-09 20:02:41 +11:00
Nicholas Nethercote a6dd4d870a Remove now-unnecessary indirection.
The previous commit moved some code from `rustc_query_system`, which
doesn't have access to `TyCtxt` and `QueryCtxt`, to `rustc_query_impl`,
which does. We can now remove quite a bit of indirection.

- Three methods in `trait QueryContext` are no longer needed
  (`next_job_id`, `current_query_job`, `start_query`). As a result,
  `QueryCtxt`'s trait impls of these methods are changed to inherent
  methods.

- `qcx: Q::Qcx` parameters are simplified to `qcx: QueryCtxt<'tcx>`.

- `*qcx.dep_context()` occurrences are simplified to `qcx.tcx`, and
  things like `qcx.dep_context().profiler()` become `qcx.tcx.prof`.

- `DepGraphData<<Q::Qcx as HasDepContext>::Deps>` becomes
  `DepGraphData<DepsType>`.

In short, various layers of indirection and abstraction are cut away.
The resulting code is simpler, more concrete, and easier to understand.
It's a good demonstration of the benefits of eliminating
`rustc_query_system`, and there will be more to come.
2026-02-08 17:01:26 +11:00
Nicholas Nethercote 6527b3404c Move a lot of rustc_query_system::plumbing to rustc_query_impl::execution (part 1).
[Note: this commit conceptually moves 75% of a file to another location,
and leaves 25% of it behind. It's impossible to preserve all the git
history. To preserve git history of the moved 75%, in this commit we
rename the file and remove the 25% from it, leaving the code in an
incomplete (uncompilable) state. In the next commit we add back the
25% in the old location.]

We are in the process of eliminating `rustc_query_system`. Chunks of it
are unused by `rustc_middle`, and so can be moved into
`rustc_query_impl`. This commit does some of that.

Mostly it's just moving code from one file to a new file. There are a
couple of non-trivial changes.

- `QueryState` and `ActiveKeyStatus` must remain in `rustc_query_system`
  because they are used by `rustc_middle`. But their inherent methods
  are not used by `rustc_middle`. So these methods are moved and
  converted to free functions.

- The visibility of some things must increase. This includes `DepGraphData`
  and some of its methods, which are now used in `rustc_query_impl`.
  This is a bit annoying but seems hard to avoid.

What little is left behind in
`compiler/rustc_query_system/src/query/plumbing.rs` will be able to
moved into `rustc_query_impl` or `rustc_middle` in the future.
2026-02-08 17:01:10 +11:00