Commit Graph

526 Commits

Author SHA1 Message Date
Jonathan Brouwer 34fd06ef66 Rollup merge of #153161 - nnethercote:rejig-rustc_with_all_queries, r=Zalathar
Rejig `rustc_with_all_queries!`

There are three things relating to `rustc_with_all_queries!` that have been bugging me.

- `rustc_with_all_queries!`'s ability to receive `extra_fake_queries` lines like `[] fn Null(()) -> (),` where the only real thing is the `Null`, and everything is just pretending to be a normal query, ugh.
- `make_dep_kind_array!`: a macro produced by one macro (`define_dep_nodes!`) and used by another macro (`define_queries!`) in another crate, ugh.
- The `_dep_kind_vtable_ctors` module, which is a special module with no actual code that serves just a way of collecting vtable constructors from two different places so they can be referred to by `make_dep_kind_array!`, ugh.

By making some adjustments to how `rustc_with_all_queries!` works, all three of these things are eliminated.

r? @Zalathar
2026-03-02 20:10:35 +01:00
Nicholas Nethercote 40b2274f6c Change how query vtables are constructed.
Currently `define_dep_nodes` produces a macro `make_dep_kind_array` that
encodes the names of non-queries followed by queries. This macro is used
by `make_dep_kind_vtables` to make the full array of vtables, by
referring to vtable constructor functions that are put into `mod
_dep_kind_vtable_ctors`. Pretty weird!

This commit takes advantage of the previous commit's changes to
`rustc_with_all_queries`, which makes both query and non-query
information available. A new call to `rustc_with_all_queries` is used to
construct the vtable array. (This moves some dep_kind_vtable code from
`plumbing.rs` to `dep_kind_vtables.rs`, which is good.) It's
straightforward now with iterator chaining, and `mod
_dep_kind_vtable_ctors` is no longer needed.
2026-03-02 15:27:39 +11:00
Nicholas Nethercote 253c6965bc Make non-queries available to rustc_with_all_queries.
`rustc_with_all_queries` currently provides information about all
queries. Also, a caller can provide an ad hoc list of extra non-queries.
This is used by `define_queries` for non-query dep kinds: `Null`, `Red`,
etc. This is pretty hacky.

This commit changes `rustc_with_all_queries` so that the non-queries
information is available to all callers. (Some callers ignore the
non-query information.) This is done by adding `non_query` entries to
the primary list of queries in `rustc_queries!`.
2026-03-02 15:26:41 +11:00
Nicholas Nethercote 5bd28b85bd Remove FromCycleError impl for SymbolName.
It has no effect.

`symbol_name` is the only query that produces a `SymbolName`. If it was
marked with `cycle_delayed_bug`/`cycle_stash` then this `FromCycleError`
impl would make sense, but that's not the case. Maybe it was the case in
the past.
2026-03-02 14:26:58 +11:00
Nicholas Nethercote 5677f7c706 Rename trait Value as FromCycleError.
`Value` is an unhelpfully generic name. Standard naming procedure for a
trait with a single method is for the trait name to match the method
name, which is what this commit does. Likewise, the enclosing module is
renamed from `values` to `from_cycle_error`.

Also add a comment about some non-obvious behaviour.
2026-03-02 14:26:58 +11:00
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
Nicholas Nethercote 72a001bc25 Remove DepKindVTable::is_anon.
It's unused.
2026-03-02 14:21:00 +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 08df254a60 Don't try to promote queries that never cache to disk 2026-03-01 19:42:19 +11:00
Zalathar f7ac4266f5 Explain why some queries don't support forcing/promotion 2026-03-01 19:42:19 +11:00
Zalathar 4284edc3b4 Avoid some trivial wrapper closures in DepKindVTable 2026-03-01 19:42:17 +11:00
Zalathar c0e7a43530 Rename the function pointers in DepKindVTable
- `force_from_dep_node` → `force_from_dep_node_fn`
- `try_load_from_disk_cache` → `promote_from_disk_fn`

This commit also inlines the wrapper function around `promote_from_disk_fn`.
2026-03-01 19:41:01 +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
Jonathan Brouwer f3035e7c18 Rollup merge of #153190 - JonathanBrouwer:subdiag_variables, r=jdonszelmann
Don't allow subdiagnostic to use variables from their parent

Tangentially related to https://github.com/rust-lang/rust/issues/151366

This is PR 1/2 for structured diagnostics, will do the unstructured ones next. After the second PR I will be able to remove some code that should compensate for this PR being positive.

Regardless of this PR having a positive diff, I feel that subdiagnostics being able to use variables from their parent is very confusing, so this is for the better,.

r? @jdonszelmann
2026-02-28 12:52:57 +01:00
Jonathan Brouwer 350a964d7c Fix subdiagnostics that use non-local variables 2026-02-27 15:22:47 +00:00
Zalathar c6d028c30a Clarify a confusing green-path function 2026-02-27 22:53:26 +11:00
Nicholas Nethercote 90abedee9c Remove ENCODE_QUERY_RESULTS.
And also `encode_query_results` for each cacheable query. This is done
by generating `encode_all_query_results` and having it do things more
directly.
2026-02-27 08:03:04 +11:00
Nicholas Nethercote 7323750309 Remove ALLOC_SELF_PROFILE_QUERY_STRINGS.
And also `alloc_self_profile_query_strings` for each query. This is done
by generating the top-level `alloc_self_profile_query_strings` and
having it do things more directly.
2026-02-27 07:57:39 +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
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