Commit Graph

351 Commits

Author SHA1 Message Date
Jonathan Brouwer
900f0bcb32 Rollup merge of #159225 - bjorn3:split_incr_comp_session, r=oli-obk
Split IncrCompSession out of Session

This will allow introducing a separate incr comp session dir for the post LTO artifacts in the future. In addition it statically encodes the lifetime of the incr comp session rather than requiring an enum behind a mutex stored in the Session.

Based on https://github.com/rust-lang/rust/pull/159000
Part of https://github.com/rust-lang/compiler-team/issues/908
2026-08-05 13:36:11 +02:00
Nicholas Nethercote
c4e9932cac Remove DepKind::label_strs
It contains pre-stringified versions of all the `DepKind` variants. But
we can just stringify on demand using `format!("{:?}")`.
2026-08-03 07:26:37 +10: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
bjorn3
f9679fa4df Split IncrCompSession out of Session
This will allow introducing a separate incr comp session dir for the
post LTO artifacts in the future. In addition it statically encodes the
lifetime of the incr comp session rather than requiring an enum behind a
mutex stored in the Session.
2026-07-23 12:14:56 +02:00
bjorn3
d792ea9d7c Remove unreachable code from finalize_session_directory 2026-07-20 13:28:07 +02:00
bjorn3
823da8cc59 Remove distinction between finalized and invalid incr comp session
In both cases the incr comp session dir should no longer be accessed.
2026-07-09 09:31:49 +00:00
bjorn3
fefcf9da07 Properly handle errors in finalize_session_directory
Previously we would still try to rename the incr comp session dir after
deleting it.
2026-07-08 19:45:48 +00:00
Alejandra Gonzalez
3842da5d69 Remove dependency from rustc_codegen_ssa on rustc_incremental
This allows us to depend on `rustc_resolve` from `rustc_incremental`. Important for https://github.com/rust-lang/rust-project-goals/issues/641
2026-06-30 16:21:57 +02:00
Guillaume Gomez
d0b019e0ab Rename rustc_incremental/src/errors.rs into rustc_incremental/src/diagnostics.rs 2026-06-12 12:44:53 +02:00
bors
d2f24127d9 Auto merge of #157319 - xmakro:perf/lazy-depkind-reverse-index, r=cjgillot
Build the dep-graph reverse index lazily, per DepKind



Replace the eager per-DepKind fingerprint-to-index map built at decode with a counting sort into per-kind ranges plus a lazily-built map per kind.
2026-06-11 11:23:02 +00:00
Jacob Pratt
976acb04b6 Rollup merge of #157620 - Daniel-B-Smith:smithdb3/fileencoder-strategy, r=cjgillot
Add a strategy FnMut to inject behavior into the flush cycle

This PR adds the interface needed to avoid forking FileEncoder in https://github.com/rust-lang/rust/pull/154724.

This adds a FnMut used as a strategy/observer to see the bytes being flushed to disk. For https://github.com/rust-lang/rust/pull/154724, that would be used to calculate the metadata hash on the raw metadata bytes.

The 'static hack is pretty ugly, but otherwise, the FileEncoder lifetime goes exceptionally viral and requires some very unfortunate workarounds to avoid self referential lifetimes. That's a bit of a timebomb if the wrong FileEncoder client tries to use the new API, but the worst case outcome is a wild goose chase of lifetime chasing.

Full disclosure: I used Claude Code to generate much of the PR. I have fully reviewed the code and stand behind it.

r? @cjgillot
2026-06-11 00:34:03 -04:00
Jacob Pratt
e9b2658bf9 Rollup merge of #157352 - xmakro:fix/parallel-dep-graph-determinism, r=petrochenkov
Make the retained dep graph deterministic under the parallel frontend

Part of rust-lang/rust#154314.

The in-memory dep graph kept for `-Zquery-dep-graph` is built by `GraphEncoder::record`, which pushed each node using `try_lock` and silently dropped the node when the lock was contended. Single-threaded the only contention is a query forced re-entrantly from within `with_retained_dep_graph`, so dropping was harmless. Under the parallel frontend several encoder threads record nodes at the same time, so a contended `try_lock` dropped nodes and edges at random, leaving the retained graph nondeterministic. The dep-graph ui tests, which assert on its contents, then failed intermittently.

The reentrancy came from `check_paths` emitting its diagnostics while holding the retained graph: the error path calls `def_path_str`, which can create new dep nodes and re-enter the encoder. This reads the path results into owned values while the lock is held and emits the diagnostics afterwards, so `record` never re-enters while the lock is held. `record` can then block on the lock unconditionally instead of using `try_lock`, so concurrent encoders never drop a node or edge.
2026-06-11 00:34:01 -04:00
Daniel Smith
6324b4afbf Add flush strategy to allow observing bytes before they are flushed. 2026-06-09 20:49:39 -04:00
bjorn3
f484629863 Assert incr comp in copy_cgu_workproduct_to_incr_comp_cache_dir
It was already only called when incr comp is enabled and this allows
cleaning up the callers a bit.
2026-06-07 13:24:14 +00:00
bjorn3
9419baeee8 Use WorkProductMap instead of FxIndexMap
This is an UnordMap internally. Iteration order for the work product map
should not matter aside from the place it is serialized where sorting by
WorkProductId is sufficient.
2026-06-07 13:24:12 +00:00
xmakro
0f7c98f2a3 Build the dep-graph reverse index lazily, per DepKind
Replace the eager per-DepKind fingerprint-to-index map built at decode
with a counting sort into per-kind ranges plus a lazily-built map per
kind.
2026-06-05 05:08:57 -07:00
xmakro
51001cf7ef Make the retained dep graph deterministic under the parallel frontend
The in-memory dep graph kept for `-Zquery-dep-graph` is built by
`GraphEncoder::record`, which pushed each node using `try_lock` and
silently dropped the node when the lock was contended. Single-threaded
the only contention is a query forced re-entrantly from within
`with_retained_dep_graph`, so dropping was harmless. Under the parallel
frontend several encoder threads record nodes at the same time, so a
contended `try_lock` dropped nodes and edges at random, leaving the
retained graph nondeterministic and making the dep-graph ui tests, which
assert on its contents, fail intermittently.

Remove that reentrancy in `check_paths`: read the graph into owned
results while the lock is held, then emit the diagnostics afterwards.
The only query forced inside the old closure was `def_path_str` (for the
error messages), which can create dep nodes and re-enter the encoder;
doing the emission after the lock is released means `record` never
re-enters while the lock is held. `record` can then block on the lock
unconditionally instead of using `try_lock`, so concurrent encoders
never drop a node or edge.

This only affects compilation with `-Zquery-dep-graph`; with the flag
off the retained graph is absent and nothing changes.
2026-06-04 08:40:28 -07:00
aerooneqq
f3b0a0e266 Comments cleanup 2026-05-18 10:41:15 +03:00
aerooneqq
1f60130485 Add hir_ prefixes for queries 2026-05-18 08:51:08 +03:00
aerooneqq
5f6b026721 Merge several hir-level queries into single owner query 2026-05-15 11:16:56 +03:00
mejrs
4a13f36265 Remove more spans from AttributeKind 2026-05-02 17:41:30 +02:00
Nicholas Nethercote
01e933f888 Move four fields from ParseSess to Session.
`ParseSess` is separate from, but sits within, `Session`. The separation
is because there are some places (e.g. `Parser` methods) where
`ParseSess` is available but `Session` is not.

However, `ParseSess` has four fields that are only accessed from places
where `Session` is also available. This commit moves those fields to
`Session`. This means that `ParseSess` only contains the fields it
genuinely needs, and various `sess.psess.foo` occurrences are reduced to
`sess.foo`.
2026-04-29 09:27:04 +10:00
mejrs
9515f52d61 Change ItemKind::Trait to have named fields. 2026-04-24 19:03:16 +02:00
Stuart Cook
63712e0f9d Rollup merge of #154529 - Zalathar:setup-dep-graph, r=cjgillot
Make `setup_dep_graph` incremental-only and more straightforward

The existing code contains some very strange control flow that can put the dep graph into an inconsistent and untested state if streaming output setup fails.

(Specifically, that failure would put `DepGraph` into an "empty" state intended for non-incremental compilation, but other parts of the compiler would still think that incremental mode is enabled due to `sess.opts.incremental`.)

This PR therefore performs a big overhaul of `setup_dep_graph` by:

- Returning immediately in non-incremental mode.
- Exiting immediately if dep-graph streaming output couldn't be set up.
- Inlining some "helper" functions that were more confusing than helpful.
2026-04-05 13:38:16 +10:00
bors
a25435bcf7 Auto merge of #154304 - zetanumbers:typeck_root, r=petrochenkov
Make typeck a tcx method which calls typeck_root query



Currently typeck query itself calls `tcx.typeck(tcx.typeck_root_def_id(key))` if its key isn't a type-check root. I thought this might be an overhead and made typeck a tcx method which calls typeck_root query instead.

This is a step to simplify `cache_on_disk_if` query modifier.

@petrochenkov please run perf
2026-03-29 19:37:29 +00:00
Zalathar
369c801eaf Clean up enum LoadResult
- Make the enum non-public
- Replace the generic `<T>` with concrete fields
- Rename variant `LoadDepGraph` to `IoError`
2026-03-29 15:00:01 +11:00
Zalathar
6e6701e2bd Make setup_dep_graph incremental-only and more straightforward
The existing code contains some very strange control flow that can put the dep
graph into an inconsistent and untested state if streaming output setup fails.

(Specifically, that failure would put `DepGraph` into an "empty" state intended
for non-incremental compilation, but other parts of the compiler would still
think that incremental mode is enabled due to `sess.opts.incremental`.)

This commit therefore performs a big overhaul of `setup_dep_graph` by:

- Returning immediately in non-incremental mode.
- Exiting immediately if dep-graph streaming output couldn't be set up.
- Inlining some "helper" functions that were more confusing than helpful.
2026-03-29 14:59:51 +11:00
Zalathar
a63d476105 Move build_dep_graph into rustc_incremental::persist::load
Moving this code here makes the subsequent cleanup easier.
2026-03-29 14:37:44 +11:00
Zalathar
10d29ee606 Extract -Zassert-incr-state into a separate helper function
This code is only needed by an obscure `-Z` flag, so pulling it out of the main
path makes the normal logic easier to follow.
2026-03-28 21:52:55 +11:00
Zalathar
29be0590f4 Use the normal arg-parsing machinery for -Zassert-incr-state 2026-03-28 21:52:55 +11:00
Daria Sukhonina
94ed03acb5 Make typeck a tcx method which calls typeck_root query 2026-03-28 12:38:44 +03:00
Stuart Cook
ee64422ffa Rollup merge of #154110 - lambdageek:fix/incr-compile-note, r=wesleywiser
Change "error finalizing incremental compilation" text and emit it as a note, not a warning

As mentioned in https://github.com/rust-lang/rust/issues/151181#issuecomment-3762036971 and https://github.com/rust-lang/rust/issues/151181#issuecomment-4068842260 the current message could be improved:

1. Right now it displays as "warning: error ..." which is confusing (is it an error or a warning)
2. It doesn't give the user a clear indication of what the consequences are
3. The _current_ build is successful. The _next_ build might be slower

The new message is now

```text
note: did not finalize incremental compilation session directory ...
  |
  = help: the next build will not be able to reuse work from this compilation
```

I started a zulip thread [#t-compiler/incremental > Ergonomics of "error finalizing incremental session"](https://rust-lang.zulipchat.com/#narrow/channel/241847-t-compiler.2Fincremental/topic/Ergonomics.20of.20.22error.20finalizing.20incremental.20session.22/with/580191447)
2026-03-28 15:01:38 +11:00
Zalathar
505dabc2a0 Tiny improvements to incremental header reads/writes
The standard library has helper methods for converting integers to/from
little-endian bytes, for checked conversion from `usize` to `u8`, and for
treating `&mut T` as `&mut [T; 1]`.
2026-03-27 13:46:50 +11:00
Zalathar
a7fa2dfd8e Clean up the API for opening/checking incremental-compilation files
Returning dedicated structs and enums makes the meaning of each return value
more obvious, and provides a more natural home for documentation.

The intermediate `load_data` function was unhelpful, and has been inlined into
the main function.
2026-03-27 13:46:50 +11: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
Aleksey Kliger
4845f78422 Reword the incremental finalize diagnostic
Remove the confusing word "error".  The diagnostic is already prefixed
with a level when it is displayed, so this is redundant and possibly
confusing ("warning: error ...").

Add some help text summarizing the impact of what happened: the next
build won't be able to reuse work from the current run.
2026-03-17 16:46:05 -04:00
Aleksey Kliger
384f363b70 change "error finalizing incremental compilation" from warning to note
The warning has no error code, so in a `-D warnings` environment, it's
impossible to ignore if it consistently breaks your build.  Change it
to a note so it is still visible, but doesn't break the build
2026-03-13 14:37:26 -04:00
Zalathar
d7490855d5 Inline and simplify some code for saving incremental data to disk
Main changes:
- Inline `encode_query_cache` and `TyCtxt::serialize_query_result_cache`
- Pull value promotion out of `OnDiskCache::drop_serialized_data`
- Panic if `on_disk_cache` is None in an incremental-only path
2026-03-08 21:27:50 +11:00
Josh Stone
eb093cfd5d Reformat with the new stage0 2026-03-07 10:42:02 -08:00
Jonathan Brouwer
eb5f275181 Rollup merge of #152844 - Zalathar:retain-dep-graph, r=JonathanBrouwer
Rename `DepGraphQuery` to `RetainedDepGraph`

This is a revised subset of https://github.com/rust-lang/rust/pull/152836 that only performs an internal renaming, and does not touch the `-Zquery-dep-graph` flag.

The new name and comments for `RetainedDepGraph` should hopefully do a better job of communicating that it is not used in normal compiler operation, even in incremental mode.
2026-02-20 13:24:57 +01:00
Jonathan Brouwer
c0fe6943ae Rollup merge of #152759 - jdonszelmann:simpler-get-attrs, r=jonathanbrouwer
Simpler `find_attr!()`

r? @JonathanBrouwer
cc: @jyn514
2026-02-20 13:24:55 +01:00
Zalathar
19e0c62e10 Rename DepGraphQuery to RetainedDepGraph 2026-02-20 20:55:09 +11:00
Jana Dönszelmann
decec173ec remove AttributeKind everywhere 2026-02-20 09:50:16 +01:00
Jana Dönszelmann
63edc913fa change all uses 2026-02-20 09:50:16 +01:00
Nicholas Nethercote
c4a69d4712 Bring back enum DepKind.
It was removed in #115920 to enable it being moved to
`rustc_query_system`, a move that has recently been reversed. It's much
simpler as an enum.

Also:
- Remove the overly complicated `Debug` impl for `DepKind`.
- Remove the trivial `DepKind` associated constants (`NULL` et al.)
- Add an assertion to ensure that the number of `DepKinds` fits within a
  `u16`.
- Rename `DEP_KIND_VARIANTS` as `DEP_KIND_NUM_VARIANTS`, to make it
  clearer that it's a count, not a collection.
- Use `stringify!` in one place to make the code clearer.
2026-02-19 09:05:37 +11:00
Nicholas Nethercote
1d410c5831 Fix a typo. 2026-02-19 08:56:42 +11:00
Zalathar
9eaedddb7f Rename dep node "fingerprints" to distinguish key and value hashes 2026-02-18 17:20:32 +11:00
Nicholas Nethercote
1d83208683 De-genericize the dep graph.
By removing the generic `D` parameter from `DepGraph`, `DepGraphData`,
`CurrentDepGraph`, `SerializedDepGraph`, `SerializedNodeHeader`, and
`EncoderState`.
2026-02-15 13:07:37 +11:00
Nicholas Nethercote
32e6a1a0ab Remove QueryContext.
`rustc_query_system` has been reduced so much that it's no longer
needed. This avoids a lot of indirection and abstraction.
2026-02-15 13:07:35 +11:00
John Kåre Alsaker
8c5ce26e43 Replace parallel! macro with par_fns function and rename join to par_join 2026-02-12 12:20:18 +01:00