Commit Graph

3566 Commits

Author SHA1 Message Date
Jonathan Brouwer
50ee4f4d26 Rollup merge of #163126 - charliermarsh:charlie/conflicts, r=oli-obk
Skip redundant storage-conflict updates during coroutine layout

## Summary

When computing coroutine storage conflicts, we currently record conflicts between every pair in the live set. This PR instead remembers the last live set whose conflicts were recorded; if the current set is a subset, we skip the matrix updates. For example, after recording `{a, b, c}`, observing `{a, b}` adds no new conflicts.

I used an LLM to profile this change, and saw a compiler CPU reduction in the following projects:

- Codex: 2.69%
- Ruff: 2.84%
- uv: 5.28%
- ty: 3.28%
2026-09-22 22:50:35 +02:00
bors
6bb1652a02 Auto merge of #163165 - JonathanBrouwer:rollup-qpPoMbu, r=JonathanBrouwer
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#162628 (Move `Const` from `rustc_middle` to `rustc_type_ir`)
 - rust-lang/rust#159589 (Avoid leaking opaque hidden types via auto trait candidates)
 - rust-lang/rust#147790 (constify comparison traits on sliced types)
 - rust-lang/rust#162325 (powerpc64-ibm-aix: fix cfg(target_abi) value)
 - rust-lang/rust#162786 (regression test for GCE inherent projection ICE)
 - rust-lang/rust#163065 (windows Dir::rename: remove incorrect is_dir query)
 - rust-lang/rust#163138 (feat(time): add `Duration::{WEEK, DAY, HOUR, MINUTE}`)
 - rust-lang/rust#163162 (Remove unused `make3.sh` CI script)
2026-09-22 17:35:56 +00:00
Charlie Marsh
501b40c89d Document coroutine storage-conflict fast path 2026-09-22 13:15:17 -04:00
James Barford-Evans
af2f1f375c use ConstExt for methods that do not yet exist in rustc_type_ir 2026-09-22 13:04:44 +01:00
Jonathan Brouwer
1c6030f386 Rollup merge of #162998 - saethlin:dse-ret-is-arg, r=oli-obk
Avoid generating overlapping assignments in DSE

This is a fix for https://github.com/rust-lang/rust/issues/162997.

Considering we also had https://github.com/rust-lang/rust/pull/155680, I really wonder if this pass should be using LivenessTransferFunction at all.
2026-09-22 13:23:35 +02:00
Charlie Marsh
140373788f Skip redundant storage-conflict updates during coroutine layout 2026-09-21 14:20:15 -04: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
Roland Xu
d0f47c836d Rollup merge of #160097 - Rachit2323:const-mutation-needs-drop, r=jackh726
fix const_item_mutation lint to use needs_drop instead of has_dtor

Description:
The const_item_mutation lint was only checking if the outer type has a direct Drop impl (has_dtor). But if a field inside the type has a Drop impl, that drop logic can also observe the mutation — so the warning should be suppressed in that case too.

This fixes a false positive where the lint would warn on code like:

```O.inner.val = 42;```

even when Inner has a Drop impl that prints the value — meaning the mutation IS observable and the warning is wrong.

Fix: replace has_dtor check with needs_drop, which checks the whole type including all fields inside it.
2026-09-20 09:23:34 +08:00
Ben Kimock
c973b50510 Avoid generating overlapping assignments in DSE 2026-09-19 10:47:30 -04:00
Jonathan Brouwer
94a62335e9 Rollup merge of #162785 - saethlin:match_branch_simplification, r=oli-obk
Avoid creating overlapping assignments in MatchBranchSimplification

MatchBranchSimplification can turn a match into an assignment, but doesn't make sure the LHS and RHS do not overlap. For example, the enum version of the mir-opt test in this PR is currently compiled with `-Zmir-opt-level=0 -Zmir-enable-passes=+MatchBranchSimplification` to
```
fn g(_1: Foo) -> Foo {
    let mut _0: Foo;
    let mut _2: Foo;
    let mut _3: *const Foo;
    let mut _4: u8;

    bb0: {
        _2 = copy _1;
        _3 = &raw const _2;
        _4 = discriminant((*_3));
        _2 = no_retag copy (*_3); // Since _3 = &raw const 2 above, this overlaps!
        _0 = copy _2;
        return;
    }
}
```
While this is technically a miscompile, I haven't found any way to turn this into something exciting, in part because the only thing that can be made to overlap here is a by-value enum discriminant which is always register-sized so backends lower this in a way that is okay with overlapping.
2026-09-17 16:50:52 +02:00
Jonathan Brouwer
a6a54687e5 Rollup merge of #161873 - mejrs:bug, r=tiif
move bug and span_bug macros to rustc_span

This allows them to be used without depending on rustc_middle.

This is done by using a rustc_interface callback so that, if the callback is set, a internal compiler error diagnostic is printed through that. After that the panic is initiated.

r? @jdonszelmann @bjorn3
2026-09-15 23:26:55 +02:00
mejrs
6aaabbb863 compiler: fix bug and span_bug imports 2026-09-15 16:20:18 +02:00
cclfmht
e98eee9156 GVN: Fix the check on provenance before interning
We only checked the provenance for a part of the allocation that will be
interned. Fixed by adding a method under `InterpCx` to check the whole
allocation.
2026-09-15 21:30:25 +08:00
cclfmht
d1f64b05c8 GVN: Do not intern allocation containing provenance
GVN only checked whether the portion of allocation referred by `MPlaceTy`
contains provenance, but we then intern the whole allocation. This causes
ICE if the unchecked part contains provenance. This commit extends the
check to the whole allocation.

Also, removes a check for unsized local in `try_as_evaluated_constant`
which seems to duplicate with the one in `op_to_prop_const`.
2026-09-15 21:30:25 +08:00
Ben Kimock
324f136401 Fix a bug in MatchBranchSimplification 2026-09-15 01:07:15 -04:00
Jonathan Brouwer
305d36bc80 Rollup merge of #162630 - nnethercote:simplify-Diag-G, r=oli-obk
Simplify the `G` in `Diag<'a, G>`

The `EmissionGuarantee` trait isn't necessary, and just complicates things. Details in individual commits.

r? @oli-obk
2026-09-14 15:16:02 +02:00
Jonathan Brouwer
d66ffb02e8 Rollup merge of #162641 - JonathanBrouwer:unused_args, r=BoxyUwU
Remove unused arguments of functions

That these arguments are unused was hidden by the `#[trace::instrument]` macro, which uses the arguments.
I don't see an easy way to avoid this from happening in the future.
2026-09-12 16:44:06 +02:00
Jonathan Brouwer
f42e056e4c Rollup merge of #162678 - Zalathar:ssa-transform, r=hanna-kruppe
Disconnect `rustc_codegen_ssa` from `rustc_mir_transform`

The direct dependency from `rustc_codegen_ssa` to `rustc_mir_transform` allowed codegen to reuse some MIR-transform code for identifying unnecessary landing pads (for https://github.com/rust-lang/rust/pull/143208).

However, we can achieve the same result by calling through a hook on `TyCtxt`, eliminating the crate dependency.

---

There should be no change to compiler output.
2026-09-12 16:44:05 +02:00
Zalathar
df15f022ef Disconnect rustc_codegen_ssa from rustc_mir_transform
The direct dependency from `rustc_codegen_ssa` to `rustc_mir_transform` allowed
codegen to reuse some MIR-transform code for identifying unnecessary landing
pads.

However, we can achieve the same result by calling through a hook on `TyCtxt`,
eliminating the crate dependency.
2026-09-12 21:59:29 +10:00
Zalathar
16cd82578a Use GrowableBitSet in the main loop of rustc_mir_transform::sroa
The bitset entries tracked by this code don't have a naturally fixed domain, so
using GrowableBitSet makes more sense than repeatedly resizing a DenseBitSet.
2026-09-12 21:26:16 +10:00
Jonathan Brouwer
0957d026bb Remove unused argument of simplify_rvalue 2026-09-12 09:26:58 +02:00
bors
9c99d05505 Auto merge of #162517 - khyperia:yeet-type-const, r=BoxyUwU
yeet `type const`



tracking issue: https://github.com/rust-lang/rust/issues/132980

zulip thread context (design decussion of future of gca): [#project-const-generics > talkies at last @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/260443-project-const-generics/topic/talkies.20at.20last/near/620368825)

this PR does two things:

- implement `#[rustc_always_gca]` (bikeshed name thread: [#project-const-generics > #&#91;always_gca&#93; bikeshed](https://rust-lang.zulipchat.com/#narrow/channel/260443-project-const-generics/topic/.23.5Balways_gca.5D.20bikeshed/with/622249110) )
- remove `type const` syntax

it also migrates the test suite to the syntax introduced in https://github.com/rust-lang/rust/pull/162179 i.e. the new way to write `type const` is now `const ITEM: T = core::direct_const_arg!(V);` (ouch my hands, that took a while)

r? @BoxyUwU
2026-09-12 07:18:22 +00:00
Nicholas Nethercote
09bf6de39e Remove EmissionGuarantee
It's a trait that is used to give `Diag::emit` different return types
depending on the `G` in `Diag<'_, G>`. It works, but it's overkill.
There are only four different `G` types in practice (`BugAbort`,
`FatalAbort`, `ErrorGuaranteed`, and `()`) and having inherent `emit`
methods for each of those four concrete `Diag<'_, G>` types is good
enough.

This commit makes that change. This removes `EmissionGuarantee`
trait bounds from many places, which is nice.
2026-09-12 11:21:03 +10:00
Jonathan Brouwer
87840b1afc Rollup merge of #161413 - clubby789:remove-is-optimization, r=saethlin
mir-transform: Remove `is_optimization_stage`

Based on rust-lang/rust#160524 until that one is merged

https://github.com/rust-lang/rust/pull/160524#discussion_r3802378929
2026-09-11 21:15:01 +02:00
khyperia
06e076ee7e yeet braces from DefKind::Const 2026-09-11 17:08:12 +02:00
rabindra789
1a533b6b78 mir: validate Move call arguments are locals or box derefs 2026-09-09 19:22:43 +05:30
Zalathar
127c51cbef Avoid an unnecessary GrowableBitSet in rustc_mir_transform::coroutine
This code appears to only need a variation of `DenseBitSet::contains` that
doesn't panic on out-of-domain values.
2026-09-09 20:11:09 +10:00
Zalathar
80035347c4 Avoid an intermediate GrowableBitSet in rustc_mir_transform::sroa
This code only uses `GrowableBitSet` as a way to resize a `DenseBitSet` while
retaining its values.
2026-09-09 20:11:09 +10:00
Jamie Hill-Daniel
f59ff9df89 mir-transform: Remove is_optimization_stage 2026-09-07 17:24:03 +01:00
Jonathan Brouwer
b61a76f895 Rollup merge of #162354 - Zalathar:comptime, r=oli-obk
Make comptime functions ineligible for coverage

- https://github.com/rust-lang/rust/pull/159777
- https://github.com/rust-lang/rust/pull/161808
---

As reported in https://github.com/rust-lang/rust/pull/161808, the assertion in https://github.com/rust-lang/rust/pull/159777 causes the compiler to ICE when it tries to generate an unused-function record for comptime functions, because comptime functions aren't allowed to have a symbol name. This can occur when trying to instrument `core`, for example.

Compile-time-only functions don't generate code, so instrumenting them for coverage is useless anyway. This PR therefore makes them ineligible for coverage, which avoids the problem.
2026-09-07 17:08:10 +02:00
Zalathar
0027ee1612 Make comptime functions ineligible for coverage
Compile-time-only functions don't generate code, so instrumenting them for
coverage is useless.

This also avoids an ICE when trying to get the function's symbol name for an
unused-function record, which can occur when instrumenting `core`.

Co-Authored-By: Rachel Barker <rachel.barker@ferrous-systems.com>
2026-09-07 19:59:03 +10:00
Jacob Pratt
f86d0cfdc1 Rollup merge of #162384 - RalfJung:EnumSizeOpt, r=saethlin
remove EnumSizeOpt

This was landed years ago but has never been enabled due to odd issues that came up when merging it. The issues never got investigated (or at least, not with any conclusions). The author of the pass [said](https://github.com/rust-lang/rust/issues/154413#issuecomment-4150682443) they don't have time to work on it and recommend removing it.

So... let's do that.
r? @saethlin
Fixes rust-lang/rust#154413
2026-09-07 04:06:37 -04:00
Ralf Jung
eb7a027e05 remove EnumSizeOpt 2026-09-06 20:50:32 +02:00
bors
46a266b9fb Auto merge of #162353 - jhpratt:rollup-ytKtbHa, r=jhpratt
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#161517 (coverage: Switch over to hybrid HIR-aware coverage spans )
 - rust-lang/rust#162030 (Prevent `--test` to be used in `rustdoc-html` testsuite)
 - rust-lang/rust#162329 (Suggest extra borrows for nested reference arguments)
2026-09-06 05:41:36 +00:00
bors
dbad1bab60 Auto merge of #162105 - Zalathar:arena-cache, r=nnethercote
Avoid the `arena_cache` modifier for several queries



The `arena_cache` query modifier is convenient, but we can potentially avoid some overhead by allocating values into the central `tcx.arena` when possible.

There should be no change to compiler output.
2026-09-06 02:32:06 +00:00
Zalathar
f521dd4ed9 Switch over to hybrid HIR-aware coverage spans
Instead of trying to heuristically recover source-code spans from MIR soup, we
can now take advantage of the `CoverageKind::Point` statements injected for
specific HIR expressions.

This is a transitional implementation that lets us remove the old MIR-soup
code, but still relies heavily on the existing span-refinement heuristics, and
does not take advantage of the full possibilities of HIR-aware coverage
instrumentation.

In order to avoid annoying never-executed spans in code that contains
assertions, a heuristic has been added that ignores any expression within the
arguments of a macro-expanded function call that returns `!`.

Some coverage tests now require `//@ min-llvm-version: 23`, due to changes in
how LLVM sorts the coverage mapping entries.
2026-09-06 10:24:48 +10:00
Zalathar
436bc15d57 Add CoverageKind::Point
This variant will be used for marker statements that are injected when a HIR
expression is about to be lowered to MIR, and at other points relevant to
coverage instrumentation.

Adding this variant in its own commit keeps the mundane plumbing steps separate
from later changes that will perform injection and analysis.
2026-09-06 10:24:48 +10:00
Zalathar
ccf5d59c6a Extract CoverageKind::is_removed_after_analysis 2026-09-06 10:24:48 +10:00
bors
f248f40387 Auto merge of #160524 - clubby789:opt-level-opt-none, r=RalfJung
mir-transform: Treat `optimize(none)` the same as `opt-level=0`



cc @RalfJung
2026-09-05 20:19:46 +00:00
Zalathar
6ea33483a1 Use the central arena for query mir_shims 2026-09-06 00:35:46 +10:00
Zalathar
30c55b32d5 Use the central arena for query mir_callgraph_cyclic 2026-09-06 00:35:46 +10:00
Jamie Hill-Daniel
13b81b7f90 Add fixme for cleaning up opt-level logic 2026-09-05 14:35:32 +02:00
Zalathar
2a3529c8b8 Use let-chains to simplify a deep HIR pattern 2026-09-03 16:44:21 +10:00
Zalathar
9c3dad95b6 Decide the effective DefId in extract_hir_info without recursion 2026-09-03 16:44:21 +10:00
Zalathar
0bce0415d5 Rename the three main coverage-info structs
- CoverageInfoHi       => CoverageEarlyInfo
- FunctionCoverageInfo => CoverageMirInfo
- CoverageIdsInfo      => CoverageCodegenInfo
2026-08-30 12:23:40 +10:00
Jonathan Brouwer
8e3d555214 Rollup merge of #159103 - aapoalas:reborrow/fix-borrowed-place, r=oli-obk
fix(reborrow): recursive implementation

If Reborrow finds '&'a mut T' fields where 'a is the Reborrowed type's first lifetime parameter (currently the only lifetime that is allowed to reborrow) then it inserts a Deref and borrow of the T, and likewise if it finds a 'T: Reborrow' field then the field type is recursed into.

This makes Reborrow always produce the correct borrow checking logic at the cost of most probably being inconsiderately expensive. The thinking is that performance will be a followup consideration.

r? @oli-obk
2026-08-28 10:15:37 +02:00
Aapo Alasuutari
5686e56377 fix(reborrow): recursive implementation
* Implement Reborrow as a recursive operation

If Reborrow finds '&'a mut T' fields then it inserts
a Deref and borrow of the T, and likewise if it finds a
'T: Reborrow' field then the field type is recursed into.

This makes Reborrow always produce the correct borrow checking logic at
the cost of most probably being inconsiderately expensive. The thinking
is that performance will be a followup consideration.
* PhantomDeref
* Simpler deref test

* Add more PhantomDeref unreachability assertions
* Write out lifetime omission
* Document ProjectionElem::PhantomDeref
* Comment half of reborrow tests
* fix PhantomDeref conflicting with AccessDepth::Shallow
* Recheck CoerceShared in borrowck TypeChecker to ensure its lifetimes make sense
* Fix rebase
* Changes... but where to?
* Typo fix

* Improve comment
* Use fully_perform_op to evaluate CoerceShared trait in borrowck
* More CoerceShared comment
* Comment rest of Reborrow tests

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2026-08-27 20:03:59 +00:00
Zalathar
2304aedd83 Change is_eligible_for_coverage from a hook to a query
This check is called from a few different places when coverage is enabled, so
we should probably let the query system take care of memoizing results and
tracking dependencies.
2026-08-26 22:58:51 +10:00
Rachit2323
940498dad7 fix const_item_mutation lint to use needs_drop instead of has_dtor 2026-08-24 12:25:29 +05:30
Philipp Krones
be9e487747 Fix clippy::needless_bool fallout
Simplify bool condition in llvm CI download availability check in bootstrap
2026-08-23 19:46:01 +02:00