635 Commits

Author SHA1 Message Date
teor dafb6bb801 Refactor FnDecl and FnSig flags into packed structs 2026-04-16 07:08:08 +10:00
bors 17584a1819 Auto merge of #155253 - JonathanBrouwer:rollup-lERdTAB, r=JonathanBrouwer
Rollup of 19 pull requests

Successful merges:

 - rust-lang/rust#155162 (relnotes for 1.95)
 - rust-lang/rust#140763 (Change codegen of LLVM intrinsics to be name-based, and add llvm linkage support for `bf16(xN)` and `i1xN`)
 - rust-lang/rust#153604 (Fix thread::available_parallelism on WASI targets with threads)
 - rust-lang/rust#154193 (Implement EII for statics)
 - rust-lang/rust#154389 (Add more robust handling of nested query cycles)
 - rust-lang/rust#154435 (resolve: Some import resolution cleanups)
 - rust-lang/rust#155236 (Normalize individual predicate of `InstantiatedPredicates` inside `predicates_for_generics`)
 - rust-lang/rust#155243 (cg_ssa: transmute between scalable vectors)
 - rust-lang/rust#153941 (tests/debuginfo/basic-stepping.rs: Explain why all lines are not steppable)
 - rust-lang/rust#154587 (Add --verbose-run-make-subprocess-output flag to suppress verbose run-make output for passing tests)
 - rust-lang/rust#154624 (Make `DerefPure` dyn-incompatible)
 - rust-lang/rust#154929 (Add `const Default` impls for `LazyCell` and `LazyLock`)
 - rust-lang/rust#154944 (Small refactor of `arena_cache` query values)
 - rust-lang/rust#155055 (UI automation)
 - rust-lang/rust#155062 (Move tests from `tests/ui/issues/` to appropriate directories)
 - rust-lang/rust#155131 (Stabilize feature `uint_bit_width`)
 - rust-lang/rust#155147 (Stabilize feature `int_lowest_highest_one`)
 - rust-lang/rust#155174 (Improve emission of `UnknownDiagnosticAttribute` lint)
 - rust-lang/rust#155194 (Fix manpage version replacement and use verbose version)
2026-04-13 18:32:47 +00:00
Jonathan Brouwer 2f607ee662 Rollup merge of #153997 - nnethercote:closure-consistency, r=petrochenkov
Use closures more consistently in `dep_graph.rs`.

This file has several methods that take a `FnOnce() -> R` closure:
- `DepGraph::with_ignore`
- `DepGraph::with_query_deserialization`
- `DepGraph::with_anon_task`
- `DepGraphData::with_anon_task_inner`

It also has two methods that take a faux closure via an `A` argument and a `fn(TyCtxt<'tcx>, A) -> R` argument:
- DepGraph::with_task
- DepGraphData::with_task

The rationale is that the faux closure exercises tight control over what state they have access to. This seems silly when (a) they are passed a `TyCtxt`, and (b) when similar nearby functions take real closures. And they are more awkward to use, e.g. requiring multiple arguments to be gathered into a tuple. This commit changes the faux closures to real closures.

r? @Zalathar
2026-04-13 14:02:35 +02:00
John Kåre Alsaker 6442b48dee Add more robust handling of nested query cycles 2026-04-12 14:38:43 +02:00
Jonathan Brouwer 79a4c77744 Rollup merge of #155080 - nnethercote:salvage, r=petrochenkov
Simplify `try_load_from_disk_fn`.

`try_load_from_disk_fn` has a single call site. We can move some of the stuff within it to its single call site, which simplifies it, and also results in all of the query profiling code ending up in the same module. Details in individual commits.

r? @Zalathar
2026-04-10 15:33:10 +02:00
Nicholas Nethercote 4fb83f6e56 Move profiling of query loading outwards.
From `plumbing.rs` to `execution.rs`, which is where most of the other
query profiling occurs. It also avoids eliminates some fn parameters.

This means the `provided_to_erased` call in `try_from_load_disk_fn` is
now included in the profiling when previously it wasn't. This is
good because `provided_to_erased` is included in other profiling calls
(e.g. calls to `invoke_provider_fn`).
2026-04-10 14:00:28 +10:00
Nicholas Nethercote 3afb618592 Move the cache_on_disk check out of try_load_from_disk_fn.
It doesn't need to be in there, it can instead be at the single call
site. Removing it eliminates one parameter, makes `define_queries!`
smaller (which is always good), and also enables the next commit which
tidies up profiling.

This commit also changes how `value` and `verify` are initialized,
because I don't like the current way of doing it after the declaration.
2026-04-10 13:47:27 +10:00
John Kåre Alsaker 690d1938a7 Break a single query cycle in the deadlock handler 2026-04-08 20:43:31 +02:00
Jonathan Brouwer 180f3237d4 Rollup merge of #154146 - Zoxc:cycle-split-diag, r=petrochenkov
Split out the creation of `Cycle` to a new `process_cycle` function

This splits out the creation of `CycleError` to a new `process_cycle` function. This makes it a bit clearer which operations are done for diagnostic purposes vs. what's needed to break cycles.
2026-04-07 17:26:21 +02:00
Jonathan Brouwer 20bed53566 Rollup merge of #153999 - Zoxc:rem-TaggedQueryKey-def_kind-uses, r=petrochenkov
Remove `TaggedQueryKey::def_kind`

This removes `TaggedQueryKey::def_kind` by accessing the relevant query keys directly.
2026-04-07 17:26:20 +02:00
Nicholas Nethercote 15c6e6e092 Add a handle_cycle_error query modifier.
This modifier indicates that a query has a custom handler for cycles.
That custom handler must be found at
`rustc_query_impl::handle_cycle_error::$name`.

This eliminates the need for `specialize_query_vtables`, which is the
current hack to install custom handlers. It's more lines of code in
total, but indicating special treatment of a query via a modifier in
`queries.rs` is more consistent with how other aspects of queries are
handled.
2026-04-03 13:44:12 +11:00
Nicholas Nethercote d913766757 Remove the _description_fns module.
`rustc_queries` generates a macro and two modules. One of the modules
looks like this:
```
mod _description_fns {
    ...

    #[allow(unused_variables)]
    pub fn hir_module_items<'tcx>(tcx: TyCtxt<'tcx>, key: LocalModDefId) -> String {
	format!("getting HIR module items in `{}`", tcx.def_path_str(key))
    }

    ...
}
```
Members of this module are then used in `TaggedQueryKey::description`.

This commit removes the `_description_fns` module entirely. For each
query we now instead generate a description closure that is used
instead. This closure is passed in the modifiers list.

This change simplifies `rustc_queries` quite a bit. It requires adding
another query modifier, but query modifiers are how other query-specific
details are already passed to the declarative macros, so it's more
consistent.
2026-04-03 13:44:10 +11:00
Jonathan Brouwer b11b685a3f Rollup merge of #153960 - Zoxc:fatal-layout-of-cycles, r=TaKO8Ki
Make `layout_of` cycles fatal errors

This makes `layout_of` cycles fatal errors.

This is a step towards removing query cycle recovery.
2026-04-02 22:13:49 +02:00
Nicholas Nethercote deb901c896 Use closures more consistently in dep_graph.rs.
This file has several methods that take a `FnOnce() -> R` closure:
- `DepGraph::with_ignore`
- `DepGraph::with_query_deserialization`
- `DepGraph::with_anon_task`
- `DepGraphData::with_anon_task_inner`

It also has two methods that take a faux closure via an `A` argument and
a `fn(TyCtxt<'tcx>, A) -> R` argument:
- DepGraph::with_task
- DepGraphData::with_task

The rationale is that the faux closure exercises tight control over what
state they have access to. This seems silly when (a) they are passed a
`TyCtxt`, and (b) when similar nearby functions take real closures. And
they are more awkward to use, e.g. requiring multiple arguments to be
gathered into a tuple. This commit changes the faux closures to real
closures.
2026-03-31 20:21:05 +11:00
Zalathar 076dc9b06e Remove the tcx parameter from will_cache_on_disk_for_key_fn 2026-03-31 17:16:10 +11:00
Zalathar a7d2a68378 Simplify the cache_on_disk_if modifier to just cache_on_disk
Queries with both `cache_on_disk` and `separate_provide_extern` will only
disk-cache values for local keys.

Other queries with `cache_on_disk` will disk-cache all values unconditionally.
2026-03-31 17:16:10 +11:00
John Kåre Alsaker 043bd76768 Make layout_of cycles fatal errors 2026-03-24 18:25:21 +01:00
John Kåre Alsaker 3d9452681c Split out the creation of Cycle to a new process_cycle function 2026-03-24 18:17:53 +01:00
John Kåre Alsaker e6098df4d0 Remove TaggedQueryKey::def_kind 2026-03-24 17:51:43 +01:00
bors 9df83179a4 Auto merge of #154289 - jhpratt:rollup-JFDweJT, r=jhpratt
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#153964 (Fix `doc_cfg` not working as expected on trait impls)
 - rust-lang/rust#153979 (Rename various query cycle things.)
 - rust-lang/rust#154132 (Add missing num_internals feature gate to coretests/benches)
 - rust-lang/rust#154153 (core: Implement `unchecked_funnel_{shl,shr}`)
 - rust-lang/rust#154236 (Clean up query-forcing functions)
 - rust-lang/rust#154252 (Don't store current-session side effects in `OnDiskCache`)
 - rust-lang/rust#154017 ( Fix invalid add of duplicated call locations for the rustdoc scraped examples feature)
 - rust-lang/rust#154163 (enzyme submodule update)
 - rust-lang/rust#154264 (Update books)
 - rust-lang/rust#154282 (rustc-dev-guide subtree update)
2026-03-24 04:54:28 +00:00
Jacob Pratt 39343f53fd Rollup merge of #154252 - Zalathar:on-disk-cache, r=nnethercote
Don't store current-session side effects in `OnDiskCache`

This PR is a series of related cleanups to `OnDiskCache`, which is responsible for loading query return values (and side effects) that were serialized during the previous incremental-compilation session.

The primary change is to move the `current_side_effects` field out of OnDiskCache and into QuerySystem. That field was awkward because it was the only part of OnDiskCache state related to serializing the *current* compilation session, rather than loading values from the previous session.

The other commits should hopefully be straightforward.

r? nnethercote (or compiler)
2026-03-23 23:42:51 -04:00
Jacob Pratt efa7a5ea4a Rollup merge of #154236 - Zalathar:force-query, r=nnethercote
Clean up query-forcing functions

This PR takes the `force_query` function, inlines it into its only caller `force_from_dep_node_inner`, and renames the resulting function to `force_query_dep_node`. Combining the functions became possible after the removal of `rustc_query_system`, because they are now in the same crate.

There are two other notable cleanups along the way:

- Removing an unhelpful assertion and its verbose comment
  - The removed comment was originally added in https://github.com/rust-lang/rust/commit/0454a41, but is too verbose to be worth preserving inline.
- Removing a redundant cache lookup while forcing, as it is useless in the serial compiler and unnecessary (and probably unhelpful) in the parallel compiler

r? nnethercote
2026-03-23 23:42:51 -04:00
Zalathar afffa7d6e3 Don't store current-session side effects in OnDiskCache
Every other part of `OnDiskCache` deals with loading information from the
_previous_ session, except for this one field.

Moving it out to `QuerySystem` makes more sense, because that's also where
query return values are stored (inside the caches in their vtables).
2026-03-24 12:56:51 +11:00
Zalathar de15ab0065 Store value/side-effect index lists inside CacheEncoder
These lists can be considered part of the encoder state, and bundling them
inside the encoder is certainly more convenient than passing them around
separately.
2026-03-24 12:56:49 +11:00
Nicholas Nethercote 3c7ee983eb Compute DepNode for incremental queries.
Prior to #154122 it wasn't used on all paths, so we only computed it
when necessary -- sometimes in `check_if_ensure_can_skip_execution`,
sometimes in one of two places in `execute_job_incr` -- and pass around
`Option<DepNode>` to allow this.

But now it's always used, so this commit makes us compute it earlier,
which simplifies things.
- `check_if_ensure_can_skip_execution` can be made simpler, returning a
  bool and eliminating the need for `EnsureCanSkip`.
- `execute_job_incr` no longer uses two slightly different methods to
  create a `DepNode` (`get_or_insert_with` vs `unwrap_or_else`).
2026-03-24 08:54:10 +11:00
Nicholas Nethercote 1e4b453670 Remove some dep-graph assertions.
The call chain for a non-incremental query includes the following
functions:

- execute_query_non_incr_inner (assert!)
- try_execute_query (assert!)
- execute_job_non_incr (assert!)

And likewise for an incremental query:

- execute_query_incr_inner (assert!)
- try_execute_query (assert!)
- execute_job_incr (expect)

That is five distinct functions. Every one of them has an `assert!` or
`expect` call that checks that the dep-graph is/is not enabled as
expected. Three cheers for defensive programming but this feels like
overkill, particularly when `execute_job{,_non_incr,_incr}` each have a
single call site.

This commit removes the assertions in `execute_query_*` and
`try_execute_query`, leaving a check in each of the `execute_job_*`
functions.
2026-03-24 08:48:50 +11:00
Nicholas Nethercote 90ea993083 Rename various query cycle things.
The existing names have bugged me for a while. Changes:

- `CycleError` -> `Cycle`. Because we normally use "error" for a `Diag`
  with `Level::Error`, and this type is just a precursor to that. Also,
  many existing locals of this type are already named `cycle`.

- `CycleError::cycle` -> `Cycle::frames`. Because it is a sequence of
  frames, and we want to avoid `Cycle::cycle` (and `cycle.cycle`).

- `cycle_error` -> `find_and_handle_cycle`. Because that's what it does.
  The existing name is just a non-descript noun phrase.

- `mk_cycle` -> `handle_cycle`. Because it doesn't make the cycle; the
  cycle is already made. It handles the cycle, which involves (a)
  creating the error, and (b) handling the error.

- `report_cycle` -> `create_cycle_error`. Because that's what it does:
  creates the cycle error (i.e. the `Diag`).

- `value_from_cycle_error` -> `handle_cycle_error_fn`. Because most
  cases don't produce a value, they just emit an error and quit.
  And the `_fn` suffix is for consistency with other vtable fns.

- `from_cycle_error` -> `handle_cycle_error`. A similar story for this
  module.
2026-03-24 08:47:34 +11:00
Zalathar 97b1c31489 Also restore the wrapper closure for promote_from_disk_fn
This effectively reverses <https://github.com/rust-lang/rust/commit/4284edc>.

At that time, I thought GetQueryVTable might be useful for other kinds of
static lookup in the future, but after various other simplifications and
cleanups that now seems less likely, and this style is more consistent with
other vtable-related functions.
2026-03-23 21:06:06 +11:00
Zalathar 4b52951832 Combine force_from_dep_node_inner and force_query
The different parts of this function used to be split across different crates,
but nowadays they are both in `rustc_query_impl`, so they can be combined.

This commit also hoists the vtable lookup to a closure in
`make_dep_kind_vtable_for_query`, to reduce the amount of code that deals with
`GetQueryVTable`, and to make the inner function more consistent with other
functions in `execution`.
2026-03-23 21:06:06 +11:00
Zalathar b29d6df04f Remove a redundant query cache lookup while forcing
In the serial compiler, we should never be trying to force a query node that
has a cached value, because we would have already marked the node red or green
when putting its value in cache.

In the parallel compiler, we immediately re-check the cache while holding the
state shard lock anyway, and trying to avoid that lock doesn't seem worthwhile.
2026-03-23 21:06:06 +11:00
Zalathar ff75894987 Remove an unhelpful assertion from force_from_dep_node_inner
This assertion and its comment are much visually heavier than the part of the
function that actually performs important work.

This assertion is also useless, because the `codegen_unit` query does not have
a `force_from_dep_node_fn` in its DepKindVTable, so the assertion would never
be reached even in the situation it is trying to guard against.

This assertion is also redundant, because we have plenty of incremental tests
that fail if the corresponding calls to `tcx.ensure_ok().codegen_unit(..)` are
removed.
2026-03-23 21:06:03 +11:00
Nicholas Nethercote 327216d31a Refactor load_from_disk_or_invoke_provider_green.
By removing the early return and using a `match` instead.
- The two paths are of similar conceptual weight, and `match` reflects
  that.
- This lets the `incremental_verify_ich` call be factored out.
2026-03-23 09:21:16 +11:00
Nicholas Nethercote cde59f0904 Remove another assertion in load_from_disk_or_invoke_provider_green.
This one just irritates me, and I don't think it adds much value.
2026-03-23 09:12:21 +11:00
Nicholas Nethercote d52943a726 Remove assertion in load_from_disk_or_invoke_provider_green.
We can only reach this point if `try_load_from_disk_fn` fails, and the
condition of this assertion is basically just the inverse of what
`try_load_from_disk_fn` does. Basically it's like this:
```
fn foo() -> bool { a && b }

fn bar() {
    if foo() {
        return;
    }
    assert!(!a || !b);
}
```
The assertion is just confusing and provides little value.
2026-03-22 20:45:26 +11:00
Nicholas Nethercote 5841fa8650 Inline and remove QueryVTable::is_loadable_from_disk_fn.
It's very small and only has two call sites. The tiny loss of DRY is
worth it to shrink `QueryVTable`.
2026-03-22 14:32:43 +11:00
Zalathar 3a62e89822 Remove the anon query modifier
We still have some anon-task machinery for `DepKind::TraitSelect` tasks, but
there are no longer any queries that use the `anon` modifier.
2026-03-21 14:22:10 +11:00
Zalathar dbdbf09586 Use a new no_force query modifier for check_representability
These queries appear to have been using `anon` for its side-effect of making
them ineligible for forcing.

According to their comments and also `tests/incremental/issue-61323.rs`, these
queries want to avoid forcing so that if a cycle does occur, the whole cycle
will be on the query stack for the cycle handler to find.
2026-03-21 14:22:10 +11:00
Stuart Cook ef9bb40cbd Rollup merge of #153862 - Zoxc:cycle-check-rename, r=chenyukang
Rename `cycle_check` to `find_cycle`

This renames `cycle_check` to `find_cycle` as that fits a bit better.
2026-03-20 15:33:06 +11:00
Zalathar fbd3b6d944 Move query-stack-frame spans into QueryStackFrame
Code that previously used `QueryStackFrame` now uses `TaggedQueryKey` directly.

Code that previously used `Spanned<QueryStackFrame>` now uses
`QueryStackFrame`, which includes a span.
2026-03-18 10:20:16 +11:00
Jonathan Brouwer 880d85f409 Rollup merge of #153991 - zetanumbers:report_cycle_small_refactor, r=petrochenkov
Small report_cycle refactor

I think this doesn't require any explanation.
2026-03-17 17:51:35 +01:00
Daria Sukhonina b5e53dc790 Cleanup from_cycle_error::variances_of.
variances_of currently used search_for_cycle_permutation, which can fail and abort when constructed error result value does not match query input.
This commit changes variances_of to receive a def_id which means it can compute a value without using search_for_cycle_permutation, avoiding the possible abort.

Fixes #127971
2026-03-17 13:51:43 +03:00
Daria Sukhonina 45b5d5f9bf Small report_cycle refactor 2026-03-17 12:11:13 +03:00
Zalathar d57577e03d Remove redundant fields from QueryStackFrame
An explicit dep-kind is redundant here. If we want to find the query name, or
check for specific queries, we can inspect the `TaggedQueryKey` instead.

Similarly, in cases where the key is some kind of `DefId`, we can extract it
directly from the `TaggedQueryKey`.
2026-03-16 22:04:46 +11:00
Stuart Cook b8cdd7a1c7 Rollup merge of #153942 - Zalathar:imports, r=nnethercote
Re-export `rustc_middle::query::{QuerySystem, QueryVTable}`

- Follow-up to https://github.com/rust-lang/rust/pull/153760#discussion_r2928848418.
---

All of the other public items in `rustc_middle::query::plumbing` are re-exported from `query`, except for these two, for no particular reason that I can see.

Re-exporting them allows `rustc_middle::query::plumbing` to have its visibility reduced to pub(crate).

Imports within `rustc_middle` have also been updated to consistently use the re-exports in `crate::query`.

r? nnethercote
2026-03-16 18:22:57 +11:00
Stuart Cook ebd6268b44 Rollup merge of #153940 - nnethercote:rename-all-query-fns, r=Zalathar
Rename all-query functions.

There are four functions that use `for_each_query_vtable!` to call an "inner" function. They are:

- `collect_active_jobs_from_all_queries` -> `gather_active_jobs`
- `alloc_self_profile_query_strings` -> `alloc_self_profile_query_strings_for_query_cache`
- `encode_all_query_results` -> `encode_query_results`
- `query_key_hash_verify_all` -> `query_key_hash_verify`

These names are all over the place. This commit renames them as follows:

- `collect_active_query_jobs{,_inner}`
- `alloc_self_profile_query_strings{,_inner}`
- `encode_query_values{,_inner}`
- `verify_query_key_hashes{,_inner}`

This:
- puts the verb at the start
- uses `_inner` for all the inners (which makes sense now that the inners are all next to their callers)
- uses `_query_` consistently
- avoids `all`, because the plurals are enough
- uses `values` instead of `results`
- removes the `collect`/`gather` distinction, which is no longer important

r? @Zalathar
2026-03-16 18:22:56 +11:00
Zalathar aa223a0220 Re-export rustc_middle::query::{QuerySystem, QueryVTable}
All of the other public items in `rustc_middle::query::plumbing` are
re-exported from `query`, except for these two, for no particular reason that I
can see.

Re-exporting them allows `rustc_middle::query::plumbing` to have its visibility
reduced to pub(crate).

Imports within `rustc_middle` have also been updated to consistently use the
re-exports in `crate::query`.
2026-03-16 18:20:35 +11:00
Nicholas Nethercote a8024fc1d7 Remove an out-of-date comment.
It should have been removed in #153650. (The comments on
`CollectActiveJobsKind` suffice now.)
2026-03-16 16:33:52 +11:00
Nicholas Nethercote b41b0c494c Rename all-query functions.
There are four functions that use `for_each_query_vtable!` to call an "inner"
function. They are:

- collect_active_jobs_from_all_queries -> gather_active_jobs
- alloc_self_profile_query_strings -> alloc_self_profile_query_strings_for_query_cache
- encode_all_query_results -> encode_query_results
- query_key_hash_verify_all -> query_key_hash_verify

These names are all over the place. This commit renames them as follows:

- collect_active_query_jobs{,_inner}
- alloc_self_profile_query_strings{,_inner}
- encode_query_values{,_inner}
- verify_query_key_hashes{,_inner}

This:
- puts the verb at the start
- uses "inner" for all the inners (which makes sense now that the inners are
  all next to their callers)
- uses `_query_` consistently
- avoids `all`, because the plurals are enough
- uses `values` instead of `results`
- removes the `collect`/`gather` distinction, which is no longer
  important
2026-03-16 16:33:40 +11:00
Nicholas Nethercote f3f4ab9205 Remove QueryInfo.
`CycleError` has one field containing a `(Span, QueryStackFrame<I>)` and
another field containing a `QueryInfo`, which is a struct containing
just a `Span` and a `QueryStackFrame<I>`.

We already have the `Spanned` type for adding a span to something. This
commit uses it for both fields in `CycleError`, removing the need for
`QueryInfo`. Which is good for the following reasons.
- Any type with `Info` in the name is suspect, IMO.
- `QueryInfo` can no longer be confused with the similar `QueryJobInfo`.
- The doc comment on `QueryInfo` was wrong; it didn't contain a query
  key.
2026-03-16 08:54:18 +11:00
Matthias Krüger e167b9b5c4 Rollup merge of #153897 - Zalathar:use-macro, r=petrochenkov
Use less `#[macro_use]` in the query system

Macro-rules namespacing and import/export is a bit of a nightmare in general. We can tame it a bit by avoiding `#[macro_use]` as much as possible, and instead putting a `pub(crate) use` after the macro-rules declaration to make the macro importable as a normal item.

I've split this PR into two commits. The first one should hopefully be uncontroversial, while the second commit takes the extra step of declaring `rustc_with_all_queries!` as a macros-2.0 macro, which gives much nicer import/export behaviour, at the expense of having to specify `#[rustc_macro_transparency = "semiopaque"]` to still have access to macro-rules hygiene, because the default macros-2.0 hygiene is too strict here.

There should be no change to compiler behaviour.

---

I stumbled into this while investigating some other changes, such as re-exporting `rustc_middle::query::QueryVTable` or moving the big callback macro out of `rustc_middle::query::plumbing`. I think it makes sense to make this change first, to make other module-juggling tasks easier.

r? nnethercote (or compiler)
2026-03-15 16:52:45 +01:00