Commit Graph

553 Commits

Author SHA1 Message Date
bors b2fabe39bd Auto merge of #153673 - JonathanBrouwer:rollup-cGOKonI, r=JonathanBrouwer
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#153560 (Introduce granular tidy_ctx's check in extra_checks)
 - rust-lang/rust#153666 (Add a regression test for rust-lang/rust#153599)
 - rust-lang/rust#153493 (Remove `FromCycleError` trait)
 - rust-lang/rust#153549 (tests/ui/binop: add annotations for reference rules)
 - rust-lang/rust#153641 (Move `Spanned`.)
 - rust-lang/rust#153663 (Remove `TyCtxt::node_lint` method and `rustc_middle::lint_level` function)
 - rust-lang/rust#153664 (Add test for rust-lang/rust#109804)
2026-03-11 05:12:10 +00:00
Daria Sukhonina 9418745354 Run code formatter 2026-03-10 15:15:14 +03:00
Daria Sukhonina b707e7ae52 Remove FromCycleError trait before code formatting
Currently `QueryVTable`'s `value_from_cycle_error` function pointer uses the `FromCycleError` trait to call query cycle handling code and to construct an erroneous query output value.
This trick however relies too heavily on trait impl specialization and makes those impls inconsistent (which is bad AFAIK).
Instead this commit directly modifies `value_from_cycle_error` function pointer upon vtable initialization and gets rid of `FromCycleError`.
2026-03-10 15:13:47 +03:00
Nicholas Nethercote 18ade8478e Streamline ActiveJobGuard completion.
`ActiveJobGuard::complete` and `ActiveJobGuard::drop` have very similar
code, though non-essential structural differences obscure this a little.

This commit factors out the common code into a new method
`ActiveJobGuard::complete_inner`. It also inlines and remove
`expect_job`, which ends up having a single call site.
2026-03-09 09:53:57 +11:00
Nicholas Nethercote e41bf75d1e Move ActiveJobGuard definition next to its impls. 2026-03-09 09:43:47 +11:00
Jonathan Brouwer 35152ef343 Rollup merge of #153561 - Zalathar:try-mark-green, r=nnethercote
Replace the `try_mark_green` hook with direct calls to `tcx.dep_graph`

All of the existing call sites are directly touching `tcx.dep_graph` anyway, so the extra layer of indirection provides no real benefit.

There should be no change to compiler behaviour.

r? nnethercote (or compiler)
2026-03-08 19:04:37 +01:00
Nicholas Nethercote face186874 Use &C::Key less in queries.
Currently we use a mix of `C::Key` and `&C::Key` parameters. The former
is more common and a bit nicer, so convert some of the latter. This
results in less converting between the two types, and fewer sigils.
2026-03-08 22:54:12 +11:00
Zalathar 0a369a799f Replace the try_mark_green hook with direct calls to tcx.dep_graph
All of the existing call sites are directly touching `tcx.dep_graph` anyway, so
the extra layer of indirection provides no real benefit.
2026-03-08 21:53:13 +11:00
bors c7b206bba4 Auto merge of #153383 - nnethercote:overhaul-ensure_ok, r=Zalathar
Overhaul `ensure_ok`

The interaction of `ensure_ok` and the `return_result_from_ensure_ok` query modifier is weird and hacky. This PR cleans it up. Details in the individual commits.

r? @Zalathar
2026-03-08 07:03:35 +00:00
Nicholas Nethercote d4503b017e Overhaul ensure_ok.
`ensure_ok` provides a special, more efficient way of calling a query
when its return value isn't needed. But there is a complication: if the
query is marked with the `return_result_from_ensure_ok` modifier, then
it will return `Result<(), ErrorGuaranteed`. This is clunky and feels
tacked on. It's annoying to have to add a modifier to a query to declare
information present in its return type, and it's confusing that queries
called via `ensure_ok` have different return types depending on the
modifier.

This commit:

- Eliminates the `return_result_from_ensure_ok` modifier. The proc macro
  now looks at the return type and detects if it matches `Result<_,
  ErrorGuarantee>`. If so, it adds the modifier
  `returns_error_guaranteed`. (Aside: We need better terminology to
  distinguish modifiers written by the user in a `query` declaration
  (e.g. `cycle_delayed_bug`) from modifiers added by the proc macro
  (e.g. `cycle_error_handling`.))

- Introduces `ensure_result`, which replaces the use of `ensure_ok` for
  queries that return `Result<_, ErrorGuarantee>`. As a result,
  `ensure_ok` can now only be used for the "ignore the return value"
  case.
2026-03-08 09:39:39 +11:00
bors 085c58f2c0 Auto merge of #153387 - Zalathar:call-query, r=nnethercote
Get rid of `QueryVTable::call_query_method_fn`



Calling the query method to promote a value is equivalent to doing a cache lookup and then calling `execute_query_fn`, so we can just do that manually instead.

There are two “functional” differences here: If a cache hit occurs, we don't record the hit for self-profiling, and we don't register a read of the dep node. In the context of promotion, which touches *all* eligible cache entries just before writing the memory-cached values to disk, those two steps should be unnecessary overhead anyway.

r? nnethercote (or compiler)
2026-03-07 13:06:24 +00:00
bors ff086354c9 Auto merge of #153316 - nnethercote:rm-with_related_context, r=oli-obk
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.

r? @oli-obk
2026-03-06 10:21:32 +00:00
Zalathar 743d442845 Rename QueryCache::iter to for_each
Methods that perform internal iteration are typically named `for_each`.
2026-03-05 23:39:59 +11:00
Zalathar 9012d4ecb8 Get rid of QueryVTable::call_query_method_fn
Calling the query method is equivalent to doing a cache lookup and then calling
`execute_query_fn`, so we can just do that manually instead.
2026-03-05 23:35:09 +11:00
Jonathan Brouwer 62d1a712e5 Rollup merge of #153323 - nnethercote:rm-impl-QueryVTable, r=Zalathar
Remove `impl QueryVTable`

Some simplifications to `QueryVTable`, partly extracted from rust-lang/rust#153065.

r? @Zalathar
2026-03-05 06:31:37 +01:00
Jonathan Brouwer fdb18d9782 Rollup merge of #153276 - Zoxc:rem-fatal-cycle, r=nnethercote
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 19:30:38 +01:00
Jonathan Brouwer febe0bc218 Rollup merge of #153317 - nnethercote:abort-after-infinite-errors, r=oli-obk
Abort after `representability` errors

Doing so results in better error messages and makes the code a bit simpler. Details in individual commits.

r? @oli-obk
2026-03-04 19:30:38 +01:00
Jonathan Brouwer 1c44dbd580 Rollup merge of #152164 - mu001999-contrib:lint/unused_features, r=JonathanBrouwer
Lint unused features

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152164)*

Fixes rust-lang/rust#44232
Fixes rust-lang/rust#151752

---

This PR records used features through query side effect, then reports unsued features finally.
2026-03-04 19:30:36 +01:00
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