Commit graph

475 commits

Author SHA1 Message Date
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
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
f9958048e0 Move HashResult.
It's the only thing left in `rustc_query_system::query::dispatcher`.
2026-02-09 20:02:43 +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
f91c8083d8 Adjust make_dep_kind_vtable_for_query.
It takes an `is_anon` argument, but it's now generic over `QueryFlags`,
which contains the same `is_anon` field. So the argument is no longer
necessary.
2026-02-09 20:00:23 +11:00
Nicholas Nethercote
52caa7ae6d Remove QueryDispatcherUnerased::Dispatcher associated type.
It's always `SemiDynamicQueryDispatcher`, so we can just use that type
directly. (This requires adding some explicit generic params to
`QueryDispatcherUnerased`.) Less indirection makes the code clearer, and
this is a prerequisite for the next commit, which is a much bigger
simplification.
2026-02-09 11:03:43 +11:00
Nicholas Nethercote
d3d4fd9312 Tweak query key trait bounds.
Query keys must be stably hashable. Currently this requirement is
expressed as a where-clause on `impl QueryDispatcher for
SemiDynamicQueryDispatcher` and a where-clause on
`create_deferred_query_stack_frame`.

This commit removes those where-clause bounds and adds a single bound to
`QueryCache::Key`, which already has some other bounds. I.e. it
consolidates the bounds. It also gives them a name (`QueryCacheKey`) to
avoid repeating them. There is also a related `Key` trait in
`rustc_middle`; it should probably be merged with `QueryCacheKey` in the
future, but not today.

This cleanup helps with the next two commits, which do bigger
rearrangements, and where the where-clauses caused me some difficulties.
2026-02-09 10:23:44 +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
Jonathan Brouwer
ce3df42e35
Rollup merge of #152153 - Zalathar:descs, r=nnethercote
Incorporate query description functions into `QueryVTable`

Putting a `desc` function in each query vtable reduces the amount of parameter juggling required when creating query stack frames, because almost all of the necessary information can be found in the vtable.

There should be no change to compiler output.
2026-02-05 12:16:58 +01:00
Zalathar
438220673f Incorporate query description functions into QueryVTable 2026-02-05 18:41:34 +11:00
Jonathan Brouwer
cf2ea13042
Rollup merge of #152023 - nnethercote:rm-Value, r=nnethercote
Some `rustc_query_system` cleanups

Small improvements I found while looking closely at `rustc_query_system`. Best reviewed one commit at a time.

r? @cjgillot
2026-02-05 08:32:46 +01:00
Jonathan Brouwer
c5381dd987
Rollup merge of #152033 - Zalathar:dep-node-key, r=nnethercote
Rename trait `DepNodeParams` to `DepNodeKey`

In query system plumbing, we usually refer to a query's explicit argument value as a “key”.

The first few commits do some preliminary cleanup that would conflict with the rename; the rename itself is in the final commit.

r? nnethercote (or compiler)
2026-02-05 08:32:44 +01:00
Zalathar
892665ba11 Clean up query macros for cache_on_disk_if 2026-02-05 16:46:40 +11:00
Nicholas Nethercote
0932068b6c Move the QueryOverflow and QueryOverflowNote errors.
They are defined in `rustc_query_system` but used in `rustc_query_impl`.
This is very much *not* how things are supposed to be done; I suspect
someone got lazy and took a shortcut at some point.

This commit moves the errors into `rustc_query_impl`. This requires more
lines of code to give `rustc_query_impl` an errors module, but it's
worthwhile to do things in the normal way instead of a weird exceptional
way.
2026-02-05 09:29:46 +11:00
Nicholas Nethercote
7bcb7a281e Move rustc_middle::values module to rustc_middle::query::values.
It's a better place for it, because it relates to queries.
2026-02-05 09:29:43 +11:00
Nicholas Nethercote
a68bb0c371 Move rustc_query_system::values module into rustc_middle.
It's a tiny module with one trait and a default impl. It's not used in
`rustc_query_system`; all uses and non-default impls are in
`rustc_middle` and `rustc_query_impl`.

This commit moves it into `rustc_middle`, which makes things simpler
overall.
2026-02-05 08:15:16 +11:00
Zalathar
eaff0cbdb6 Use fewer intermediate functions for short backtraces in queries
If we make sure that `compute_fn` in the query's vtable is actually named
`__rust_begin_short_backtrace`, we can avoid the need for some additional
intermediate functions and stack frames.

This is similar to how the `get_query_incr` and `get_query_non_incr` functions
are actually named `__rust_end_short_backtrace`.
2026-02-04 23:46:34 +11:00
Jonathan Brouwer
89594620f2
Rollup merge of #151893 - Zoxc:query-mod-move, r=nnethercote
Move the query list into a new `rustc_middle::queries` module

This moves the query list from `rustc_middle::query` into a new `rustc_middle::queries` module. This splits up the use of the query system from the remaining implementation of it in `rustc_middle::query`, which conceptually belong to `rustc_query_system`.

The goal is to let rustc crates define queries with their own `queries` module, and this makes `rustc_middle` also fit this pattern.

The inner `queries` module used by the macros are renamed to `query_info`, so it doesn't conflict with the new outer name.
2026-02-04 08:12:40 +01:00
Zalathar
4429f0916c Rename trait DepNodeParams to DepNodeKey 2026-02-04 11:54:00 +11:00
bors
0c40f5be0c Auto merge of #151929 - camsteffen:lengg, r=BoxyUwU
Use with_capacity in query_key_hash_verify and PlaceholderExpander

Addresses the first two items from https://github.com/rust-lang/rust/issues/137005#issuecomment-2687803558.
2026-02-03 22:20:57 +00:00
John Kåre Alsaker
247a022957 Fix references and remove inner queries module 2026-02-03 21:32:52 +01:00
Zalathar
e58538c552 Rename collect_active_jobs to several distinct names 2026-02-03 20:10:22 +11:00
bors
46c86aef65 Auto merge of #152025 - jhpratt:rollup-Kxb6k3Y, r=jhpratt
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#151378 (Codegen tests for Arm Cortex-R82)
 - rust-lang/rust#151936 (Move the `fingerprint_style` special case into `DepKindVTable` creation)
 - rust-lang/rust#152018 (Move bigint helper tracking issues)
 - rust-lang/rust#151958 (Add codegen test for SLP vectorization)
 - rust-lang/rust#151974 (Update documentation for `Result::ok()`)
 - rust-lang/rust#151975 (Work around rustfmt giving up on a large expression)
 - rust-lang/rust#151990 (Fix missing unused_variables lint when using a match guard)
 - rust-lang/rust#151995 (stabilize ptr_as_ref_unchecked)
 - rust-lang/rust#151999 (attribute parsing: pass recovery mode to Parser.)
 - rust-lang/rust#152009 (Port rustc_preserve_ub_checks to attr parser)
 - rust-lang/rust#152022 (rustc-dev-guide subtree update)

Failed merges:

 - rust-lang/rust#151968 (Remove `HasDepContext` by merging it into `QueryContext`)
2026-02-03 04:44:02 +00:00
Jonathan Brouwer
9625c1ec9f
Rollup merge of #151978 - nnethercote:query-cleanups, r=Zalathar
Query cleanups

A few small cleanups in the query system.

r? @Zalathar
2026-02-02 18:52:16 +01:00
Zalathar
09de0fd848 Use #![feature(adt_const_params)] for static query flags 2026-02-02 18:05:46 +11:00
Nicholas Nethercote
c6afd45ac1 Move depth_limit_error out of QueryContext trait.
It's defined and used in `rustc_query_impl`; `rustc_query_system`
doesn't need it. So it can just be an inherent method on `QueryCtxt`.
2026-02-02 10:41:03 +11:00
Nicholas Nethercote
8e2c9c69c6 Eliminate some 'a lifetimes.
Putting `+ 'tcx` on the `QueryDispatcher` trait lets a few other places
be simplified.
2026-02-02 10:31:41 +11:00