Commit Graph

677 Commits

Author SHA1 Message Date
Jonathan Brouwer
ad31c6cbe7 Rollup merge of #162889 - Zalathar:non-query, r=Enselic
Add some docs for each non-query DepKind

Most of these non-query dep-kinds lack any docs, and the docs that do exist are not very accurate.

These new docs should hopefully be more useful, though they cannot claim to be exhaustive.

"Anonymous tasks" remain under-documented, but that's beyond the scope of this particular PR.

---

This is an internal-docs-only change; there should be no change to compiler behaviour.
2026-09-21 20:47:31 +02:00
Nicholas Nethercote
30b8dfc353 Remove G generic param from Diag<'_, G>
It encodes the `emit` behaviour, one of:
- `BugAbort`: Abort as a bug.
- `FatalAbort`: Abort as a fatal error.
- `ErrorGuaranteed`: Return an `ErrorGuaranteed` (the default).
- `()`: return `()`.

This is useful but `Diag` is very widely used and it's arguably not
useful enough to be worth the generic parameter. This commit removes it.

Benefits:
- Many fewer generic parameters, including many functions where the
  genericity is entirely uninteresting. This includes every
  `Diagnostic::into_diag` and `Subdiagnostic::add_to_diag`. Removes the
  need for the comment about `<G>` on `trait Diagnostic`.
- No `PhantomData` in `Diag`.
- Makes bootstrapping a bit faster.

The downside is there is no longer a single `emit` method.
- Getting a `!` return type requires calling `emit_bug` or `emit_fatal`.
  This only affects a few call sites.
- Getting an `ErrorGuaranteed` return type requires calling `emit_err`.
  This affects a lot of call sites. (It arguably makes call sites more
  self-documenting.)
- Using the wrong `emit_*` on a diagnostic causes a runtime abort, which
  previously couldn't occur. Seems unlikely, but it's not impossible.
- Note: If no particular return type is needed, `emit` can be used for
  any diagnostic. (Bug/fatal diagnostics will still trigger abort.)
2026-09-21 09:57:42 +10:00
Zalathar
76fa1f2dca Add some docs for each non-query DepKind 2026-09-20 12:48:30 +10:00
Nicholas Nethercote
2598e89f8a Simplify query stack printing
Currently it uses `eprintln!` for the "query stack during panic" header
and "end of query stack" footer and
`struct_failure_note(..).with_span(..).emit()` for the stack frames. The
difference is curious.

Looking more closely:
- failure notes lack a leading label (e.g. no "note: ");
- although the failure note is given a span, the span never renders
  because the `AnnotateSnippetEmitter` used for the query stack has an
  empty source map field;
- the JSON emitter is never involved here.

Therefore, the only difference between using `struct_failure_note` and
`eprintln!` is that the former prints in bold. But boldness for frames
isn't important; indeed, normal backtrace frames don't use bold.

So the commit changes query stack frame printing to use `eprintln!`,
removes some now unnecessary `dcx` arguments, and also removes
`struct_failure_note`. That leaves "For more information about an error,
try `rustc --explain {}`" as the only use of `FailureNote`.
2026-09-18 18:47:07 +10:00
Nicholas Nethercote
79d24a0679 Move operations out of rustc_middle::query::job
Generally `rustc_middle::query` has types while `rustc_query_impl` has
operations. So this commit moves some operations from the former to the
latter. Some of them are just moved, while others are inlined and
removed.
2026-09-17 10:52:30 +10:00
mejrs
6aaabbb863 compiler: fix bug and span_bug imports 2026-09-15 16:20:18 +02:00
aerooneqq
69afc99f50 Refactor HygieneEncodeContext
* Refactor `HygieneEncodeContext`
* Review: remove comment outdated part
* Review: return `raw_encode_syntax_context` as a free function
* Review: small cleanups
* Review: add comment about expansions data `Option`
* Review: don't set explicit capacity
* Review: return `queued` -> `latest`
* Remove not needed changes
* Fix `Rc` cloning
* Return comment
2026-09-11 08:18:39 +00:00
Jonathan Brouwer
37fcc078fe Rollup merge of #161433 - nnethercote:overhaul-rustc_middle-query, r=Zalathar
Overhaul `rustc_middle::query`

Overhaul `rustc_middle::query`

The file/module structure is a mess. High-level changes:
- The vaguely-named mish-mash file `plumbing.rs` is split across multiple other files.
- The vaguely-named `inner.rs` gains some additions and becomes `calls.rs`.
- `system.rs` is added.
- New file `query_api.rs` is added. It contains the big macro, which is renamed from `define_callbacks` to `define_query_api`.

This is a follow-up to rust-lang/rust#160843, which did a similar restructuring of `rustc_query_impl`.

r? @Zalathar
2026-08-26 14:02:33 +02:00
mejrs
589bb91122 Move Limit 2026-08-21 10:33:56 +02:00
Nicholas Nethercote
669f21cc06 Move cycle-related things into job.rs
Because cycles are stored within `QueryWaiter`.

Also, rename `Cycle` as `QueryCycle`, to be less generic and match most
of the other nearby types.
2026-08-21 10:27:40 +10:00
Nicholas Nethercote
64e146e94c Move Session::used_features to QuerySystem
It makes sense next to `QuerySystem::side_effects`, and this enables the
use of `DepNodeIndex` for the values instead of the type-erased `u32`.
2026-08-19 21:23:34 +10:00
Nicholas Nethercote
a63c33b717 Move GlobalCtxt::dep_kind_vtables
To `QuerySystem`, next to `query_vtables`. It's a better spot for it.
2026-08-18 14:55:08 +10:00
Nicholas Nethercote
86c2ea09e1 Remove the crate's doc comment
It's out of date.
2026-08-11 12:54:31 +10:00
Nicholas Nethercote
d6c550356a Rename profiling_support.rs as self_profile.rs
It's a clearer name.
2026-08-11 12:54:24 +10:00
Nicholas Nethercote
ae1b655c80 Move some job-related stuff into job.rs 2026-08-11 12:54:24 +10:00
Nicholas Nethercote
b99843c7a2 Move GetQueryVTable into query_vtables.rs
It's a more sensible home than `lib.rs`.
2026-08-11 12:54:24 +10:00
Nicholas Nethercote
04df355d86 Rename plumbing.rs as incremental.rs
Because it now contains only things related to incremental. Also move
two functions relating to incremental from `execution.rs` to
`incremental.rs`.
2026-08-11 12:54:24 +10:00
Nicholas Nethercote
c0b0065f06 Move four functions from plumbing.rs to execution.rs
These four functions are all only used within `execution.rs`, so they no
longer need `pub(crate)`.

This is the first step toward eliminating `plumbing.rs`.
2026-08-11 12:54:24 +10:00
Nicholas Nethercote
9e37f3950e Rename query_impl.rs as query_vtables.rs
The current name is very generic and the file is mostly about query
vtables.
2026-08-11 12:54:24 +10:00
Nicholas Nethercote
9e2147f559 Move create_cycle_error to mod handle_cycle_error
It's a more sensible home than `mod job`.
2026-08-11 12:54:24 +10:00
Nicholas Nethercote
0f7dbc062c Fix a use item
`lib.rs` imports `DepNode`/`DepNodeIndex` even though it doesn't use
them directly. And then `execution.rs` uses that one. Weird.

This commit fixes things to be more normal.
2026-08-11 12:54:24 +10:00
Chris Denton
4641990929 Remove ensure_sufficient_stack 2026-08-09 19:58:29 +00:00
Jonathan Brouwer
57a359351d Rename rustc_query_impl/error.rs to diagnostics.rs 2026-08-08 14:50:23 +02:00
Jonathan Brouwer
8c0bfd589a Rollup merge of #160130 - xmakro:cleanup/deterministic-verify-sampling, r=cjgillot
Select cache values to verify by key fingerprint, not value fingerprint

rustc verifies ~1/32 of values loaded from the incremental cache by re-hashing them. The subset is selected by the value fingerprint, so it changes whenever a value changes and between any two compiler builds. That makes verification failures flaky to reproduce, and it moves the re-hashing cost around between the two builds rustc-perf compares, which is why rustc-perf forces `-Zincremental-verify-ich` on every benchmarked invocation.

This PR selects by the key fingerprint and the session count instead. Both are fixed for a given previous session, so re-running a failed build verifies the same nodes and a verification failure reproduces on retry. `to_smaller_hash` mixes both fingerprint halves because neither half is evenly distributed on its own: `DefPathHash` keys share the `StableCrateId`, `HirId` keys carry a sequential id.

The per-session sampling rate is unchanged at 1/32, and `-Zincremental-verify-ich` is unchanged. Coverage over time improves: the subset rotates with the session count and sweeps the entire cache every 32 sessions, while under value selection a node whose value never changed kept its roll forever, so 31/32 of unchanging values were never verified on a given toolchain.

Between two compiler builds the subset still differs, because key fingerprints incorporate the rustc version through `StableCrateId`. Pinning the version via `RUSTC_FORCE_RUSTC_VERSION` and `RUSTC_OVERRIDE_VERSION_STRING` makes corresponding sessions identical; session counts align because both builds run the same scenario sequence from a fresh incremental directory. That would let rustc-perf stop forcing full verification and measure the incremental configuration users actually run.

Coverage across compiler releases is unchanged: the version salt reshuffles the subset each release under either scheme, and compiletest forces full verification in all incremental tests.
2026-08-05 13:36:03 +02:00
Vadim Petrochenkov
2b4375dadc rustc: Support --jobs options for limiting parallelism in various parts of the compiler 2026-07-29 15:22:16 +03:00
Makro
012c35624e Select cache values to verify by key fingerprint, not value fingerprint 2026-07-29 09:00:38 +00:00
Jonathan Brouwer
0a1a25a0b6 Rollup merge of #159990 - nnethercote:predicate-to-clause, r=oli-obk
Many "predicate"-to-"clause" renamings

Lots of names weren't changed to account for the introduction of the `Clause` type as a specialized form of `Predicate`, presumably because it was tedious. This commit converts as many of them as I could find. It's mostly very tedious renamings of types, functions, variables, and queries. The more interesting ones are a couple of files (`predicates_of.rs`, `impossible_predicates.rs`) and a MIR pass (`ImpossiblePredicates`).

r? @oli-obk
2026-07-28 21:07:39 +02:00
Nicholas Nethercote
ff161b18b5 Many "predicate"-to-"clause" renamings
Lots of names weren't changed to account for the introduction of the
`Clause` type as a specialized form of `Predicate`, presumably because
it was tedious. This commit converts as many of them as I could find.
It's mostly very tedious renamings of types, functions, variables, and
queries. The more interesting ones are a couple of files
(`predicates_of.rs`, `impossible_predicates.rs`) and a MIR pass
(`ImpossiblePredicates`).
2026-07-28 11:48:45 +10:00
xmakro
1d85e5957b Skip query machinery when promoting disk-cached values 2026-07-23 20:13:41 +00:00
mejrs
ac91844c53 Fixup Limit imports 2026-07-21 15:26:08 +02:00
Daria Sukhonina
c60e5614e1 rustc: Avoid passing jobserver proxy around the compiler
It is used once, when marking a `rustc_thread_pool` worker thread as blocked.
`rustc_thread_pool` already has access to the jobserver proxy, so we can move its use from outside of `mark_blocked` to inside of it.
2026-07-16 17:22:47 +03:00
Jacob Pratt
c997ea45be Rollup merge of #158163 - xmakro:fix-variances-cycle-recovery-count, r=petrochenkov
Fix too-short variance slice in `variances_of` cycle recovery

This changes the cycle-error fallback in `variances_of` to size the slice the same way the provider does in [`variance/solve.rs:117`](32ea3615cc/compiler/rustc_hir_analysis/src/variance/solve.rs (L117)).

This can otherwise ICE under the parallel frontend in `relate_args_with_variances` for items that inherit their generics from a parent (like a tuple struct constructor). See https://github.com/rust-lang/rust/issues/154560#issuecomment-4749155547
2026-06-27 22:13:50 -04:00
Adwin White
3dbe96a5a1 add IsRigid marker to TyKind::Alias and constants 2026-06-25 17:12:10 +08:00
xmakro
c2c6cb43e8 Fix too-short variance slice in variances_of cycle recovery 2026-06-19 19:54:29 -07:00
John Kåre Alsaker
218a0755ae Remove ensure_done execution path 2026-06-13 01:28:47 +02:00
Esteban Küber
2c7186a725 Reduce verbosity of cycle errors when possible
When pointing at each step of cycle errors, do not include the code snippet when the note points at the same place as the previous one (by setting the note's span to DUMMY_SP).
2026-06-04 16:10:12 +00:00
xmakro
2a52dc4fbe Avoid leaking the query-job collection warning into panic output
`collect_active_query_jobs` with `CollectActiveJobsKind::PartialAllowed`
is only used to print the query stack when the compiler panics. It
intentionally skips any query state shard whose lock it cannot take
without waiting, since a complete job map is not needed for that.

Under the parallel front-end another thread can still hold a shard lock
while the panic is being reported, so the skip happens nondeterministically
and the `warn!` was printed into the panic output. Because warnings are
shown by default, this leaked a "Failed to collect active jobs" line into
the diagnostics of panicking compilations and made their output unstable.

Lower the message to `debug!` so it stays available with `RUSTC_LOG` but
no longer pollutes the default output.
2026-06-02 18:13:50 -07:00
Daria Sukhonina
9d82fcee10 Formatter 2026-05-26 12:01:50 +03:00
Daria Sukhonina
0a36812006 Fix and update changes 2026-05-26 12:01:03 +03:00
Daria Sukhonina
76c099caf4 Rename helper QueryVTable method back 2026-05-26 11:50:32 +03:00
Daria Sukhonina
239e4dd9e8 Remove will_cache_on_disk_for_key_fn and AsLocalQueryKey 2026-05-26 11:42:48 +03:00
John Kåre Alsaker
8aafed8a17 Add sync option to -Z threads to force synchronization on one thread 2026-05-07 02:06:18 +02:00
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