635 Commits

Author SHA1 Message Date
Nicholas Nethercote d08f97d739 Remove QueryVTable::construct_dep_node.
It's just a wrapper for `DepNode::construct` and it only has three uses.
Better to just have one way of doing things.
2026-03-04 20:57:06 +11:00
Nicholas Nethercote d863850574 Streamline cache-related query functions.
There are three query vtable functions related to the `cache_on_disk_if`
modifier:
- `will_cache_on_disk_for_key_fn`
- `try_load_from_disk_fn`
- `is_loadable_from_disk_fn`

These are all function ptrs within an `Option`. They each have a wrapper
that returns `false`/`None` if the function ptr is missing.

This commit removes the `Option` wrappers. In the `None` case we now set
the function ptr to a trivial closure that returns `false`/`None`. The
commit also removes some typedefs that each have a single use. All this
is a bit simpler, with less indirection.

Note that `QueryVTable::hash_value_fn` is still an `Option`. Unlike the
above three functions, which have trivial behaviour in the `None` case,
`hash_value_fn` is used in ways where the `Some`/`None` distinction is
more meaningful.
2026-03-04 20:57:02 +11:00
John Kåre Alsaker 91c7627c0f Remove cycle_fatal query modifier
This removes the `cycle_fatal` query modifier as it has no effect on its current users.

The default `CycleErrorHandling::Error` mode does the same as `cycle_fatal` when the default impl of `FromCycleError` is used. The return types of queries using `cycle_fatal` however have no specialized `FromCycleError` impl.
2026-03-04 08:14:34 +01:00
Nicholas Nethercote 6a07088b1b Remove Clone derive from ImplicitCtxt.
It's unnecessary.
2026-03-04 07:18:07 +11:00
Nicholas Nethercote e8a28e78a9 Remove tls::with_related_context.
This function gets the current `ImplicitCtxt` and checks that its `tcx`
matches the passed-in `tcx`. It's an extra bit of sanity checking: when
you already have a `tcx`, and you need access to the non-`tcx` parts of
`ImplicitCtxt`, check that your `tcx` matches the one in `ImplicitCtxt`.

However, it's only used in two places: `start_query` and
`current_query_job`. The non-checked alternatives (`with_context`,
`with_context_opt`) are used in more places, including some where a
`tcx` is available. And things would have to go catastrophically wrong
for the check to fail -- e.g. if we somehow end up with multiple
`TyCtxt`s. In my opinion it's just an extra case to understand in
`tls.rs` that adds little value.

This commit removes it. This avoids the need for `tcx` parameters in a
couple of places. The commit also adjusts how `start_query` sets up its
`ImplicitCtxt` to more closely match how similar functions do it, i.e.
with `..icx.clone()` for the unchanged fields.
2026-03-04 07:08:43 +11:00
Nicholas Nethercote ff3d308966 Eliminate Representability::Infinite.
This variant was a fallback value used to continue analysis after a
`Representability` error, but it's no longer needed thanks to the
previous commit. This means `Representability` can now be reduced to a
unit type that exists just so `FromCycleError` can exist for the
`representability` query. (There is potential for additional cleanups
here, but those are beyond the scope of this PR.)

This means the `representability`/`representability_adt_ty` queries no
longer have a meaningful return value, i.e. they are check-only queries.
So they now have a `check_` prefix added. And the `rtry!` macro is no
longer needed.
2026-03-04 07:02:39 +11:00
Nicholas Nethercote 52b4de34ec Abort after printing infinite type errors.
Currently, `Representability::from_cycle_error` prints an "infinite
size" error and then returns `Representability::Infinite`, which lets
analysis continue. This commit changes it so it just aborts after
printing the error. This has two benefits.

First, the error messages are better. The error messages we get after
continuing are mostly bad -- we usually get another cycle error, e.g.
about drop checking or layout, which is not much use to the user, and
then abort after that. The only exception is `issue-105231.rs` where a
"conflicting implementations" error is now omitted, but there are three
other errors before that one so it's no great loss.

Second, it allows some simplifications: see the next commit.
2026-03-04 07:02:36 +11:00
Zalathar 083b5db476 Make rustc_with_all_queries! pass query modifiers as named values 2026-03-03 16:43:46 +11:00
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
mu001999 7f3bbe371f Report unused features 2026-03-02 09:38:03 +08: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