Add missing option to `-Zself-profile-event` help message as well as information about what the default options are
The `query-cache-hit-count` option was forgotten to be added to the help text when it was added.
The new help text also documents which of the options are part of `default`, and now conveys the information that `args` is also a compound/group option and what it contains.
The `query-cache-hit-count` option was forgotten to be added to the help text when it was added.
The new help text also documents which of the options are part of `default`,
and now conveys the information that `args` is also a compound/group option as well as what it contains.
Remove `RawDefPathHash`
`RawSpan`, `RawDefId`, and `RawDefPathHash` were all introduced to work around the fact that `StableHashCtxt` in `rustc_data_structure` is upstream of `rustc_span`. However, `DefPathHash` is just a newtype around `Fingerprint`, which is defined in `rustc_data_structure`. So by working directly with `Fingerprint` we can remove `RawDefPathHash`, which is a nice simplification.
r? @fee1-dead
`RawSpan`, `RawDefId`, and `RawDefPathHash` were all introduced to work
around the fact that `StableHashCtxt` in `rustc_data_structure` is
upstream of `rustc_span`. However, `DefPathHash` is just a newtype
around `Fingerprint`, which is defined in `rustc_data_structure`. So by
working directly with `Fingerprint` we can remove `RawDefPathHash`,
which is a nice simplification.
The reason `rustc_ast_ir` and `rustc_pattern_analysis` have nested
`cfg_attr`s is so that they don't mention `cfg(bootstrap)` when nightly
or rustc cargo feature turned on. If you don't do it like that, they stop
compiling on stable (or rather, they emit unexpected cfg warnings...).
Type fallback refactorings
- Don't merge different kinds of infer variables into `Ty` before matching them back
- Do fallback only on root vars (this is semantically equivalent to what we currently do; unifying any of the infer vars from the same equivalence class necesserily affects all of them) (this makes https://github.com/rust-lang/rust/pull/159003 a bit less hacky though)
- Do some simplification that has been allowed by the previous changes
cc @lcnr
Structurally prevent zero-count `BackendRepr::SimdVector`s
This is already *supposed* to be impossible in layout, but this emphasizes that better. This PR makes no behaviour changes; just `BackendLaneCount` instead of `u64` in https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/enum.BackendRepr.html
Ironically I was inspired to do this as part of [looking at making `Simd<T, 0>` *work*](https://rust-lang.zulipchat.com/#narrow/channel/257879-project-portable-simd/topic/Allow.20N.3D.3D0.3F/with/613345298), but importantly if that's going to happen I think it should be `BackendRepr::Memory` like other ZSTs, *not* a `BackendRepr::ScalarVector` that would need to carry around a useless LLVM value in `OperandValue::Immediate` (where it's not even clear what the LLVM type of that value would be).
Improve CFG traversal
This PR implements a new CFG traversal algorithm in `iterate_to_fixpoint` that drastically speeds up a pathological case in `cranelift-codegen`.
r? @cjgillot
This is already *supposed* to be impossible in layout, but this emphasizes that better.
Ironically I was inspired to do this as part of looking at making `Simd<T, 0>` *work*, but importantly if that's going to happen I think it should be `BackendRepr::Memory` like other ZSTs, *not* a `BackendRepr::ScalarVector` that would need to carry around a useless LLVM value in `OperandValue::Immediate` (where it's not even clear what the LLVM type of that value would be).
Update thinvec to 0.2.19
It contains `may_dangle` Drop impl under a feature flag. This allows us to use it in a lot more places, notable in types that hold `&'tcx` references. This would previously fail in borrowck in arena code.
We have to enable its "unstable" feature for this. That also enables `TrustedLen` impl, which is behind unstable flag, too. I left the flag disabled, because it regressed next-solver benchmarks, but that will be fixed in PR that needs this flag (see the comment: https://github.com/rust-lang/rust/pull/159974#issuecomment-5091132427)
Move `Limit` out of `rustc_hir`
It feels rather out of place in `rustc_hir`, so this PR moves it to `rustc_data_structures`. Part of hopefully moving attributes from `rustc_hir` to their own crate.
~~This also lets `rustc_type_ir` use it~~ actually rustc_type_ir needs to compile on stable and `rustc_data_structures` uses like 30 features 😢
Resolve: more preperation work for parallelizing the import resolution loop
This is basically rust-lang/rust#158845 but we do not:
- actually use `par_slice` because:
- we do not migrate `CmRefCell` to use `RwLocks` (yet) because of perf reasons.
The resolution loop is now in place instead of recollecting indeterminate imports.
r? @petrochenkov
Currently it is all still single threaded, but almost everything needed to make the loop use multithreaded code is done in this commit.
For performance reasons we do the resolution now in place instead of recollecting the indeterminate imports ([see benchmark pr](https://github.com/rust-lang/rust/pull/159387) and pr of this commit).
Populating external resolution tables now use `Once` to ensure only 1 thread builds the table and all others wait if they need it, this has no impact on single threaded behaviour.
`Cache(Ref)Cells` are not tackled yet because they are not needed here (and require extra work).
`Interned` does pointer equality/hashing, which is valid in two cases.
- The values are guaranteed to be unique (e.g. via interning, or
construction). This is how `rustc_middle` uses `Interned`.
- The type has "identity" and different values should be considered
distinct even if they are identical. This is how `rustc_resolve` uses
`Interned`.
PR 137202 tried to clarify things by adding a `T: Hash` constraint to
`Interned<'a, T>`. This constraint isn't actually used, because
`Interned` is hashed based on pointer value, not contents. But it was
intended to communicate the idea that a type stored in `Interned` is
actually interned, which is likely to be done with hashing. Panicking
impls of `Hash` were added for the relevant `rustc_resolve` types to
work around the fact that it doesn't use hashing-based interning.
In my opinion PR 137202 didn't improve things. The `T: Hash` constraint
is only aimed at the interning case, and even for that case it's not
quite right because you could use a `BTreeMap` to intern instead of a
`HashMap`.
This commit does several things.
- Removes the `T: Hash` constraint and the `Hash` impls for
`rustc_resolve` types added in PR 137202.
- Improves the comments on `Interned` to cover the non-interning cases.
- Removes the `PartialOrd`/`Ord` impls on `Interned` because (a) they're
not used, and (b) their meaning is unclear for the "identity" case.
- Improves the documentation in `rustc_resolve` to explain how
`Interned` usage is valid there.
thin-vec versions before 0.2.16 have a use-after-free / double-free in
`IntoIter::drop` and `ThinVec::clear` when an element's `Drop` panics
(RUSTSEC-2026-0103). The requirement now sits past the affected range.
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
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.
The type's been stable for over 6 weeks now, so let's use it! It's better for cases like this one where it's stored in a data structure.
Probably won't be materially faster, but does make the variant slightly smaller and lets some more things be `Copy`.
Specifically:
- `HashStable` -> `StableHash` (trait)
- `HashStable` -> `StableHash` (derive)
- `HashStable_NoContext` -> `StableHash_NoContext` (derive)
Note: there are some names in `compiler/rustc_macros/src/hash_stable.rs`
that are still to be renamed, e.g. `HashStableMode`.
Part of MCP 983.