Commit graph

9833 commits

Author SHA1 Message Date
Alan Egerton
13141af949
Consolidate type const checks on tcx.is_type_const 2026-02-04 19:26:13 +00:00
bjorn3
ef00ebfdec Remove is_ctfe_mir_available query
It isn't called anywhere anymore.
2026-02-04 15:58:47 +00:00
dianqk
9f9c4c8b0b
GVN: Remove invalidate_derefs 2026-02-04 21:50:52 +08: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
Zalathar
4429f0916c Rename trait DepNodeParams to DepNodeKey 2026-02-04 11:54:00 +11:00
Zalathar
7b01330133 Move trait impls into a dep_node_key submodule 2026-02-04 11:52:06 +11:00
Zalathar
d9516977cd Tidy up re-exports in rustc_middle::dep_graph 2026-02-04 11:52:06 +11:00
John Kåre Alsaker
9de16dd3eb Remove imports in queries only used by define_callbacks! 2026-02-03 21:33:16 +01:00
John Kåre Alsaker
247a022957 Fix references and remove inner queries module 2026-02-03 21:32:52 +01:00
John Kåre Alsaker
c9f4f7f443 Move the query list to queries.rs 2026-02-03 21:20:56 +01:00
bors
55407b8cdb Auto merge of #151853 - Zalathar:feed-vtable, r=oli-obk
Use the query vtable in `query_feed` plumbing

The `query_feed` function needs to be able to do two important things with (erased) query values: hash them, and debug-print them.

Both of those are things that the query's vtable already knows how to do. So by passing in a vtable to `query_feed`, we can give it a nicer signature, avoid having to unerase values in the function itself, and clean up some caller-side code as well.
2026-02-03 14:09:42 +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
Jonathan Brouwer
382c889ba4
Rollup merge of #151902 - RalfJung:place-ty-opt, r=Kobzol
explain why we dont skip some of this work when there are field projections

Perf says it doesn't help 🤷
2026-02-02 18:52:15 +01:00
Vadim Petrochenkov
c0393cf8db resolve: Report more early resolution ambiguities for imports
The new ambiguities are reported when the import's visibility is ambiguous and may depend on the resolution/expansion order.
2026-02-02 14:44:13 +03:00
Ralf Jung
c725637dc2 explain why we dont skip some of this work when there are field projections 2026-02-02 11:22:33 +01:00
Nicholas Nethercote
4ff360e997 Rename some query-related things.
Various `QueryStackFrame` variables are called `query`; `frame` is a
better name. And various `QueryInfo` variables are called `frame`;
`info` is a better name.

This eliminates some confusing `query.query()` occurrences, which is a
good sign, and some `frame.query` occurrences become `info.frame`.
2026-02-02 10:29:55 +11:00
Esteban Küber
679f38c125 On E0277 pointing at bound in derive, suggest manual impl
When encountering a bound coming from a derive macro, suggest manual impl of the trait.

Use the span for the specific param when adding bounds in builtin derive macros, so the diagnostic will point at them as well as the derive macro itself.

```
error[E0277]: can't compare `SomeNode` with `SomeNode`
  --> f29.rs:24:15
   |
24 |     accept_eq(&node);
   |     --------- ^^^^^ no implementation for `SomeNode == SomeNode`
   |     |
   |     required by a bound introduced by this call
   |
   = note: -Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs:279:39
   = help: the trait `PartialEq` is not implemented for `SomeNode`
note: required for `Id<SomeNode>` to implement `PartialEq`
  --> f29.rs:3:10
   |
 3 | #[derive(PartialEq, Eq)]
   |          ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
 4 | pub struct Id<T>(PhantomData<T>);
   |               -
   = help: consider manually implementing `PartialEq` to avoid undesired bounds
note: required by a bound in `accept_eq`
  --> f29.rs:15:23
   |
15 | fn accept_eq(_: &impl PartialEq) { }
   |                       ^^^^^^^^^ required by this bound in `accept_eq`
help: consider annotating `SomeNode` with `#[derive(PartialEq)]`
   |
13 + #[derive(PartialEq)]
14 | struct SomeNode();
   |
```
2026-02-01 18:20:30 +00:00
Stuart Cook
191c915560
Rollup merge of #151928 - tshepang:patch-2, r=Kivooeo
ty::context: clean some code a little

The explicit `return` was not needed
2026-02-01 14:26:47 +11:00
Tshepang Mbambo
1684417326
ty::context: clean some code a little
The explicit `return` was not needed
2026-02-01 00:31:55 +02:00
Tshepang Mbambo
4e02b6db0a
typeck_root_def_id: improve doc comment
This was initially written to be exhaustive, but one more type that can only be type-checked with its containing item has since been added, and was not mentioned. So, make it future-proof by mentioning just the one example.

Also, a previous refactor left this less readable.
2026-02-01 00:00:26 +02:00
bors
8afe9ff1ca Auto merge of #151911 - JonathanBrouwer:rollup-ACi3J2a, r=JonathanBrouwer
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#151908 (Remove unused method `DroplessArena::contains_slice`)
 - rust-lang/rust#151850 (refactor: add an `enum DerefAdjustKind` in favor of `Option<OverloadedDeref>`)
 - rust-lang/rust#151889 (Fix ICE when parsing frontmatter without newline)
2026-01-31 16:24:16 +00:00
Matthias Krüger
29fcd639b7
Rollup merge of #151849 - frank-king:refactor/pin-coerce-1, r=jackh726
refactor: remove `Ty::pinned_ref` in favor of `Ty::maybe_pinned_ref`

Also returns the `Region` of the reference type in `Ty::maybe_pinned_Ref`.

Part of rust-lang/rust#149130.

r? jackh726
2026-01-31 10:41:53 +01:00
Frank King
996425b295 refactor: add an enum DerefAdjustKind in favor of Option<OverloadedDeref> 2026-01-31 16:25:32 +08:00
Scott McMurray
f7931c8050 Remove some unnecessary try-related type annotations
I left a few, like
```rust
let result: Result<_, ModError<'_>> = try {
```
where it felt like seeing it might still be useful for the reader.

Feel free to push back on any of these changes if you think seeing the type would be better.
2026-01-30 18:21:19 -08:00
Jonathan Brouwer
58f03f5fe5
Rollup merge of #151281 - fee1-dead-contrib:push-zmqtzvuvlmuk, r=oli-obk
constify `Iterator`, take IV

Like its predecessors (rust-lang/rust#92433, rust-lang/rust#102225, rust-lang/rust#106541), this PR allows one to make `Iterator` implementations `const`, and thus enables the ability to have `for` loops in `const` contexts. I've also included constifying `Option as IntoIterator`, `option::IntoIter as Iterator` as a minimal dogfooding example.

But unlike its predecessors, it uses a new attribute (not unsound anymore!) that prevents any `Iterator` extension methods from being called. This is intentionally made minimal for an initial approval, the fun stuff like `.fold`, `Range as Iterator` could be done later.

cc @rust-lang/wg-const-eval, cc @oli-obk to review the compiler parts

cc rust-lang/rust#92476
2026-01-30 21:33:11 +01:00
Deadbeef
02e10b2d90 fix issues and ui tests, address reviews 2026-01-30 15:59:34 +00:00
Deadbeef
38ee80d48e add #[rustc_non_const_trait_method] 2026-01-30 15:52:38 +00:00
bors
36e2b8a3a7 Auto merge of #151860 - JonathanBrouwer:rollup-FqYVDlY, r=JonathanBrouwer
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#151376 (Fix performance issue in liveness checking)
 - rust-lang/rust#151851 (Remove redundant `IntoQueryParam` calls from query plumbing)
 - rust-lang/rust#151854 (Show break type expectation cause for let-else)
 - rust-lang/rust#151859 (Disable append-elements.rs test with debug assertions)
2026-01-30 15:41:56 +00:00
Jonathan Brouwer
cfadcbe3ea
Rollup merge of #151851 - Zalathar:into-query-param, r=lqd
Remove redundant `IntoQueryParam` calls from query plumbing

In each of these contexts, the key must have already been converted by the caller, since otherwise it wouldn't have type `Cache::Key`.

There should be no change to compiler behaviour.
2026-01-30 13:20:24 +01:00
Zalathar
09117c9b70 Use the query vtable in query_feed plumbing 2026-01-30 21:19:54 +11:00
Zalathar
e044220de5 Make will_cache_on_disk_for_key_fn optional in query vtables 2026-01-30 21:18:29 +11:00
Zalathar
d39609b719 Make is_loadable_from_disk_fn optional in query vtables 2026-01-30 21:16:25 +11:00
Zalathar
d5e80aa714 Make try_load_from_disk_fn optional in query vtables 2026-01-30 21:16:25 +11:00
Frank King
4ae5b43b0f refactor: remove Ty::pinned_ref in favor of Ty::maybe_pinned_ref
Also returns the `Region` of the reference type.
2026-01-30 14:22:41 +08:00
Zalathar
cf6796a2b0 Remove redundant IntoQueryParam calls from query plumbing
In each of these contexts, the key must have already been converted by the
caller, since otherwise it wouldn't have type `Cache::Key`.
2026-01-30 15:01:49 +11:00
Nicholas Nethercote
1c3d9abbad Reduce generics use in the query system.
`QueryStackFrame<I>` is a generic type, and the `I` parameter leaks out
to many other related types. However, it only has two instantiations in
practice:
- `QueryStackFrame<QueryStackFrameExtra>`
- `QueryStackFrame<QueryStackDeferred<'tcx>>`

And most of the places that currently use `QueryStackFrame<I>` are
actually specific to one of the instantiations. This commit removes the
unneeded genericity.

The following types are only ever used with `QueryStackDeferred<'tcx>`:
- QueryMap
- QueryJobInfo
- QueryJob
- QueryWaiter
- QueryLatchInfo
- QueryLatch
- QueryState
- QueryResult
and their `<I>` parameter is changed to `<'tcx>`.

Also, the `QueryContext::QueryInfo` associated type is removed.

`CycleError<I>` and `QueryInfo<I>` are still generic over type, because
they are used with both instantiations.

This required also adding a `<'tcx>` parameter to the traits
`QueryDispatcher` and `QueryContext`, which is annoying but I can't see
how to avoid it.
2026-01-30 10:54:28 +11:00
Jonathan Brouwer
3991cf6974
Rollup merge of #151565 - Zalathar:erase, r=petrochenkov
Rename, clarify, and document code for "erasing" query values

In order to reduce compile times and code size for the compiler itself, the query system has a mechanism for “erasing” and ”restoring” query values in certain contexts. See https://github.com/rust-lang/rust/pull/109333 for the original implementation.

Unfortunately, the erasure system has very little documentation, and involves a dizzying assortment of similarly-named types, traits, and functions.

This PR therefore renames several parts of the erasure API and implementation to hopefully be clearer, and adds comments to better explain the purpose and mechanism behind value erasure.

Summary of renames:
- fn `erase` → `erase_val` (avoiding ambiguity with module `erase`)
- fn `restore` → `restore_val`
- type `Erase<T>` → `Erased<T>` (for actual erased values of `T`)
- trait `EraseType` → `Erasable` (for types that can be erased and restored)
- associated type `EraseType::Result` → `Erasable::Storage`
- implementation-detail struct `Erased<T>` → `ErasedData<Storage>`

There should be no change to compiler behaviour.
2026-01-29 17:47:30 +01:00
Jonathan Brouwer
40d7cb890f
Rollup merge of #150271 - Jamesbarford:chore/refactor-struct-placeholder-pt2, r=lcnr
Move struct placeholder pt2

r? ghost
2026-01-29 17:47:29 +01:00
Jonathan Brouwer
9a9f303a35
Rollup merge of #147387 - azhogin:azhogin/hir_owner_parent_opt, r=petrochenkov
hir_owner_parent optimized to inlined call for non-incremental build

Continuation of https://github.com/rust-lang/rust/pull/146880 and https://github.com/rust-lang/rust/pull/147232.
'hir_owner_parent' query renamed 'hir_owner_parent_q'. hir_owner_parent inlined function added to optimize performance in case of non-incremental build.

'hir_owner_parent' query has low normalized average execution time (163ns) and good cache_hits (5773) according Daria's processed statistics. 'source_span', for comparison, has avg_ns_norm = 66ns and cache_hits = 11361.

Optimization may be profitable for queries with low normalized average execution time (to replace cache lookup into inlined call) and be significant with good cache_hits.
| Query | cache_hits | min_ns | max_ns | avg_ns_norm |
| ------------- | ------------- | ------------- | ------------- | ------------- |
source_span | 11361 | 18 | 2991 | 66
hir_owner_parent | 5773 | 52 | 1773 | 163
is_doc_hidden | 3134 | 47 | 1111 | 285
lookup_deprecation_entry | 13905 | 36 | 6208 | 287
object_lifetime_default | 5840 | 63 | 4688 | 290
upvars_mentioned | 2575 | 75 | 7722 | 322
intrinsic_raw | 21235 | 73 | 3453 | 367

Draft PR to measure performance changes.
2026-01-29 17:47:29 +01:00
Zalathar
db74048b9a Rename, clarify, and document code for "erasing" query values 2026-01-30 00:13:09 +11:00
James Barford-Evans
25c1365507 Part 2 refactoring of moving placeholder types to rustc_type_ir 2026-01-29 11:11:40 +00:00
Andrew Zhogin
a5052a093f hir_owner_parent optimized to inlined call for non-incremental build 2026-01-29 13:24:46 +07:00
Zalathar
89d7695040 Rename DynamicQuery to QueryVTable 2026-01-27 21:57:18 +11:00
Stuart Cook
3b89fc65a9
Rollup merge of #151097 - nnethercote:associated_type_defaults-query-key, r=Noratrieb
Use an associated type default for `Key::Cache`.

They currently aren't used because r-a didn't support them, but r-a support was recently merged in
https://github.com/rust-lang/rust-analyzer/pull/21243.

r? @Noratrieb
2026-01-27 17:36:36 +11:00
Stuart Cook
9108101955
Rollup merge of #151390 - nnethercote:revert, r=petrochenkov
Reintroduce `QueryStackFrame` split.

I tried removing it in rust-lang/rust#151203, to replace it with something simpler. But a couple of fuzzing failures have come up and I don't have a clear picture on how to fix them. So I'm reverting the main part of rust-lang/rust#151203.

This commit also adds the two fuzzing tests.

Fixes rust-lang/rust#151226, rust-lang/rust#151358.

r? @oli-obk
2026-01-27 17:36:36 +11:00
Nicholas Nethercote
aebcf78527 Remove unused Key/AsLocalKey impls. 2026-01-27 14:37:40 +11:00
Nicholas Nethercote
120247a76f Use an associated type default for Key::Cache.
They currently aren't used because r-a didn't support them, but r-a
support was recently merged in
https://github.com/rust-lang/rust-analyzer/pull/21243.
2026-01-27 14:37:39 +11:00
Nicholas Nethercote
0385e26e7d Reintroduce QueryStackFrame split.
I tried removing it in #151203, to replace it with something simpler.
But a couple of fuzzing failures have come up and I don't have a clear
picture on how to fix them. So I'm reverting the main part of #151203.

This commit also adds the two fuzzing tests.

Fixes #151226, #151358.
2026-01-27 09:42:38 +11:00
Jonathan Brouwer
e875916a05
Rollup merge of #151374 - BoxyUwU:borrowck_cleanup_3, r=lcnr
some more rustc_borrowck cleanups

r? lcnr
2026-01-26 18:19:14 +01:00
Boxy
dab7c0923e Misc cleanups to borrowck crate 2026-01-26 10:24:15 +00:00