Commit Graph

2778 Commits

Author SHA1 Message Date
León Orell Valerian Liehr
e06196da5b
Rollup merge of #142347 - azhogin:azhogin/async-drop-storage-live-dead-fix, r=oli-obk
Async drop - fix for StorageLive/StorageDead codegen for pinned future

Fixes: rust-lang/rust#140429, Fixes: rust-lang/rust#140531, Fixes: rust-lang/rust#141761, Fixes: rust-lang/rust#141409.

StorageLive/StorageDead codegen is corrected for pinned async drop future.
2025-06-15 23:51:56 +02:00
Matthias Krüger
db23a76217
Rollup merge of #141811 - mejrs:bye_locals, r=compiler-errors
Unimplement unsized_locals

Implements https://github.com/rust-lang/compiler-team/issues/630

Tracking issue here: https://github.com/rust-lang/rust/issues/111942

Note that this just removes the feature, not the implementation, and does not touch `unsized_fn_params`. This is because it is required to support `Box<dyn FnOnce()>: FnOnce()`.

There may be more that should be removed (possibly in follow up prs)
- the `forget_unsized` function and `forget` intrinsic.
- the `unsized_locals` test directory; I've just fixed up the tests for now
- various codegen support for unsized values and allocas

cc ``@JakobDegen`` ``@oli-obk`` ``@Noratrieb`` ``@programmerjake`` ``@bjorn3``

``@rustbot`` label F-unsized_locals

Fixes rust-lang/rust#79409
2025-06-14 11:27:10 +02:00
Andrew Zhogin
d6a9081612 Async drop - fix for StorageLive/StorageDead codegen for pinned async drop future 2025-06-14 15:10:08 +07:00
mejrs
c0e02e26b3 Unimplement unsized_locals 2025-06-13 01:16:36 +02:00
Ralf Jung
62418f4c56 intrinsics: rename min_align_of to align_of 2025-06-12 17:50:25 +02:00
bors
bdb04d6c4f Auto merge of #141763 - lcnr:fixme-gamer, r=BoxyUwU
`FIXME(-Znext-solver)` triage

r? `@BoxyUwU`
2025-06-11 11:47:05 +00:00
bors
8ce2287586 Auto merge of #142299 - fmease:rollup-u86s80a, r=fmease
Rollup of 16 pull requests

Successful merges:

 - rust-lang/rust#134442 (Specify the behavior of `file!`)
 - rust-lang/rust#140372 (Exhaustively handle parsed attributes in CheckAttr)
 - rust-lang/rust#140766 (Stabilize keylocker)
 - rust-lang/rust#141642 (Note the version and PR of removed features when using it)
 - rust-lang/rust#141818 (Don't create .msi installer for gnullvm hosts)
 - rust-lang/rust#141909 (Add central execution context to bootstrap)
 - rust-lang/rust#141992 (use `#[naked]` for `__rust_probestack`)
 - rust-lang/rust#142101 (core::ptr: deduplicate more method docs)
 - rust-lang/rust#142102 (docs: Small clarification on the usage of read_to_string and read_to_end trait methods)
 - rust-lang/rust#142124 (Allow transmute casts in pre-runtime-MIR)
 - rust-lang/rust#142240 (deduplicate the rest of AST walker functions)
 - rust-lang/rust#142258 (platform-support.md: Mention specific Linux kernel version or later)
 - rust-lang/rust#142262 (Mark `core::slice::memchr` as `#[doc(hidden)]`)
 - rust-lang/rust#142271 (compiler: fn ptrs should hit different lints based on ABI)
 - rust-lang/rust#142275 (rustdoc: Refractor `clean_ty_generics`)
 - rust-lang/rust#142288 (const_eval: fix some outdated comments)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-10 17:51:43 +00:00
León Orell Valerian Liehr
e8be230f1f
Rollup merge of #142124 - oli-obk:transmute-cast, r=scottmcm
Allow transmute casts in pre-runtime-MIR

r? ``@scottmcm``

cc ``@BoxyUwU``

turns out in https://github.com/rust-lang/rust/pull/138393 I erroneously used transmute casts in fd3da4bebd/compiler/rustc_mir_build/src/builder/matches/test.rs (L209)

I don't think they have any issues using them before runtime, we just checked for them because we didn't have code exercising those code paths
2025-06-10 16:54:50 +02:00
bors
c6a955468b Auto merge of #141485 - dianqk:early_otherwise_branch_loop, r=oli-obk
mir-opt: Do not create storage marks in EarlyOtherwiseBranch

Fixes #141212.

The first commit add `StorageDead` by creating new indirect BB that makes CFG more complicated, but I think it's better to just not create storage marks.

r? mir-opt
2025-06-10 14:50:54 +00:00
bjorn3
9223704f4b Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
Guillaume Gomez
3a6f1b0375
Rollup merge of #142103 - scottmcm:fieldidx-in-interp, r=oli-obk
Update `InterpCx::project_field` to take `FieldIdx`

As suggested by Ralf in https://github.com/rust-lang/rust/pull/142005#discussion_r2125839015
2025-06-06 23:53:18 +02:00
Oli Scherer
c677dc26b4 Allow transmute casts in pre-runtime-MIR 2025-06-06 16:19:38 +00:00
Scott McMurray
8bce2255e8 Update InterpCx::project_field to take FieldIdx
As suggested by Ralf in 142005.
2025-06-05 19:15:56 -07:00
Oli Scherer
fd3da4bebd Replace some Option<Span> with Span and use DUMMY_SP instead of None 2025-06-05 14:14:59 +00:00
Matthias Krüger
9ec41bcf72
Rollup merge of #141932 - azhogin:azhogin/async-drop-inside-asyncgen-fix, r=oli-obk
Fix for async drop inside async gen fn

Return value (for yield) is corrected for async drop inside async gen function.
In CFG, when internal async drop future is polled and returned `Poll<()>::Pending`, then async gen resume function returns `Poll<(OptRet)>::Pending`.

Fixes rust-lang/rust#140530
2025-06-04 19:50:21 +02:00
Andrew Zhogin
d5a9a00518 Fix for async drop inside async gen fn 2025-06-04 18:45:34 +07:00
lcnr
7dac755be8 FIXME(-Znext-solver) triage
Co-authored-by: Michael Goulet <michael@errs.io>
2025-06-03 14:23:56 +02:00
Matthias Krüger
aed1171c66
Rollup merge of #141677 - azhogin:azhogin/async-drop-unexpected-type-instead-of-drop-fn-fix, r=oli-obk
Async drop - type instead of async drop fn, fixes #140484

Fixes: rust-lang/rust#140484
Fixes: rust-lang/rust#140500

Fixes ICE, when type is provided in AsyncDrop trait instead of `async fn drop()`.
Fixes ICE, when async drop fn has wrong signature.
2025-06-03 07:03:43 +02:00
Andrew Zhogin
f023a69f32 Async drop - type instead of async drop fn and incorrect drop signature don't ICE now 2025-06-01 15:22:29 +07:00
bors
f0999ffdc4 Auto merge of #139118 - scottmcm:slice-get-unchecked-intrinsic, r=workingjubilee
`slice.get(i)` should use a slice projection in MIR, like `slice[i]` does

`slice[i]` is built-in magic, so ends up being quite different from `slice.get(i)` in MIR, even though they're both doing nearly identical operations -- checking the length of the slice then getting a ref/ptr to the element if it's in-bounds.

This PR adds a `slice_get_unchecked` intrinsic for `impl SliceIndex for usize` to use to fix that, so it no longer needs to do a bunch of lines of pointer math and instead just gets the obvious single statement.  (This is *not* used for the range versions, since `slice[i..]` and `slice[..k]` can't use the mir Slice projection as they're using fenceposts, not indices.)

I originally tried to do this with some kind of GVN pattern, but realized that I'm pretty sure it's not legal to optimize `BinOp::Offset` to `PlaceElem::Index` without an extremely complicated condition.  Basically, the problem is that the `Index` projection on a dereferenced slice pointer *cares about the metadata*, since it's UB to `PlaceElem::Index` outside the range described by the metadata.  But then you cast the fat pointer to a thin pointer then offset it, that *ignores* the slice length metadata, so it's possible to write things that are legal with `Offset` but would be UB if translated in the obvious way to `Index`.  Checking (or even determining) the necessary conditions for that would be complicated and error-prone, whereas this intrinsic-based approach is quite straight-forward.

Zero backend changes, because it just lowers to MIR, so it's already supported naturally by CTFE/Miri/cg_llvm/cg_clif.
2025-05-31 21:38:21 +00:00
Jubilee
3846f2f08f
Rollup merge of #141494 - dianqk:match-br-non-int, r=wesleywiser
mir-opt: Do not transform non-int type in match_branches

Fixes #141378.

r? mir-opt
2025-05-30 13:52:26 -07:00
Scott McMurray
4668124cc7 slice.get(i) should use a slice projection in MIR, like slice[i] does 2025-05-30 12:04:41 -07:00
Trevor Gross
e0278ed5af
Rollup merge of #141551 - compiler-errors:hir-lints, r=BoxyUwU
Make two transmute-related MIR lints into HIR lint

Make `PTR_TO_INTEGER_TRANSMUTE_IN_CONSTS` (rust-lang/rust#130540) and `UNNECESSARY_TRANSMUTES` (rust-lang/rust#136083) into "normal" HIR-based lints.

Funny enough this came up in the review of the latter (https://github.com/rust-lang/rust/pull/136083#issuecomment-2614301413), but I guess it just was overlooked.

But anywyas, there's no reason for these to be MIR lints; in fact, it makes the suggestions for them a bit more complicated than necessary.

Note that there's probably a few more simplifications and improvements to be done here. Follow-ups can be done in a separate PR, especially if they're about the messaging and suggestions themselves, which I didn't write.
2025-05-27 20:28:32 -04:00
Trevor Gross
ee4efa1f86
Rollup merge of #141252 - dianqk:gvn-repeat-index, r=saethlin
gvn: bail out unavoidable non-ssa locals in repeat

Fixes #141251.

We cannot transform `*elem` to `array[idx1]` in the following code, as `idx1` has already been modified.

```rust
    mir! {
        let array;
        let elem;
        {
            array = [*val; 5];
            elem = &array[idx1];
            idx1 = idx2;
            RET = *elem;
            Return()
        }
    }
```

Perhaps I could transform it to `array[0]`, but I prefer the conservative approach.

r? mir-opt
2025-05-27 20:28:31 -04:00
Zalathar
3f526eeec4 coverage: Revert "unused local file IDs" due to empty function names
This reverts commit 3b22c21dd8, reversing
changes made to 5f292eea6d.
2025-05-27 23:33:29 +10:00
许杰友 Jieyou Xu (Joe)
afb57cadda
Rollup merge of #141513 - nia-e:allocbytes-extend, r=RalfJung
interpret: add allocation parameters to `AllocBytes`

Necessary for a better implementation of [rust-lang/miri#4343](https://github.com/rust-lang/miri/pull/4343). Also included here is the code from that PR, adapted to this new interface for the sake of example and so that CI can run on them; the Miri changes can be reverted and merged separately, though.

r? `@RalfJung`
2025-05-27 01:29:20 +08:00
许杰友 Jieyou Xu (Joe)
0e710d0883
Rollup merge of #141431 - compiler-errors:open-drop, r=oli-obk
Emit dummy open drop for unsafe binder

Fixes rust-lang/rust#141394

We can't taint the body in wfcheck when we have a `T: Copy` bound failure, so we end up binding MIR here. Emit a dummy open drop so that drop elaboration doesn't fail.

r? oli-obk
2025-05-27 01:29:18 +08:00
dianqk
457f8ba447
mir-opt: Do not transform non-int type in match_branches 2025-05-26 18:15:54 +08:00
Nia Espera
e388a3e405
extend allocbytes with associated type 2025-05-26 00:15:16 +02:00
Michael Goulet
295a8d56f5 Make UNNECESSARY_TRANSMUTES into a HIR lint 2025-05-25 15:57:48 +00:00
Michael Goulet
5370c5753f Make PTR_TO_INTEGER_TRANSMUTE_IN_CONSTS into a HIR lint 2025-05-25 15:57:48 +00:00
dianqk
8c7faa6ed1
mir-opt: Do not create storage marks for temporary locals 2025-05-24 15:36:06 +08:00
dianqk
145d2266d9
mir-opt: Create an indirect BB to add StorageDead 2025-05-24 11:01:18 +08:00
Matthias Krüger
f7a11798e8
Rollup merge of #140967 - azhogin:azhogin/async-drop-poll-shim-for-error-dropee-fix, r=oli-obk
Async drop poll shim for error dropee generates noop body

Fixes https://github.com/rust-lang/rust/issues/140930.

When dropee type for async drop poll shim is `ty::Error(_)`, the generated poll function will be noop body. To avoid ICE in `elaborate_drop`.
2025-05-23 13:34:17 +02:00
Michael Goulet
11392f4978 Emit dummy open drop for unsafe binder 2025-05-23 10:43:21 +00:00
Andrew Zhogin
cb8fdb4d80 Async drop poll shim for error dropee generates noop body (fixes #140930) 2025-05-23 03:40:27 +07:00
bendn
8373bb17d6
use uX::from instead of _ as uX in non - const contexts 2025-05-22 17:08:32 +07:00
Matthias Krüger
cc87ae85dd
Rollup merge of #140431 - bend-n:dont_handle_bool_transmute, r=Nadrieril
dont handle bool transmute

removes `transmute(u8) -> bool` suggestion due to ambiguity, leave it for clippy

elaboration on ambiguity in question:
`transmute::<u8, bool>(x)` will codegen to an `assume(u8 < 2)`;
`_ == 1` or `_ != 0` or `_ % 2 == 0` would remove that assumption
`match _ { x @ (0 | 1) => x == 1, _ => std::hint::unreachable_unchecked() }` is very verbose

`@rustbot` label L-unnecessary_transmutes
2025-05-22 07:19:01 +02:00
Matthias Krüger
1461ca3f39
Rollup merge of #141328 - azhogin:azhogin/async-drop-ice-for-empty-impl-fix, r=oli-obk
When AsyncDrop impl is empty, sync drop generated in elaborator

Fixes #140974.
2025-05-21 15:38:10 +02:00
Andrew Zhogin
7c38b6fd28 Async drop fix for 'broken mir in AsyncDropGlue, place has deref as a later projection' (#140975) 2025-05-21 18:29:13 +07:00
Andrew Zhogin
dc794f18a4 When AsyncDrop impl is empty, sync drop generated in elaborator (Fixes #140974) 2025-05-21 18:18:27 +07:00
dianqk
be5d6c5425
gvn: bail out unavoidable non-ssa locals in repeat
We cannot transform `*elem` to `array[idx1]` in the following code,
as `idx1` has already been modified.

```rust
    mir! {
        let array;
        let elem;
        {
            array = [*val; 5];
            elem = &array[idx1];
            idx1 = idx2;
            RET = *elem;
            Return()
        }
    }
```
2025-05-19 21:35:49 +08:00
Stuart Cook
3b22c21dd8
Rollup merge of #140847 - Zalathar:unused-local-file, r=SparrowLii
coverage: Detect unused local file IDs to avoid an LLVM assertion

Each function's coverage metadata contains a *local file table* that maps local file IDs (used by the function's mapping regions) to global file IDs (shared by all functions in the same CGU).

LLVM requires all local file IDs to have at least one mapping region, and has an assertion that will fail if it detects a local file ID with no regions. To make sure that assertion doesn't fire, we need to detect and skip functions whose metadata would trigger it.

(This can't actually happen yet, because currently all of a function's spans must belong to the same file and expansion. But this will be an important edge case when adding expansion region support.)
2025-05-19 21:10:42 +10:00
Stuart Cook
599b08ada8
Rollup merge of #140874 - mejrs:rads, r=WaffleLapkin
make `rustc_attr_parsing` less dominant in the rustc crate graph

It has/had a glob re-export of `rustc_attr_data_structures`, which is a crate much lower in the graph, and a lot of crates were using it *just* (or *mostly*) for that re-export, while they can rely on `rustc_attr_data_structures` directly.

Previous graph:
![graph_1](https://github.com/user-attachments/assets/f4a5f13c-4222-4903-b56d-28c83511fcbd)

Graph with this PR:
![graph_2](https://github.com/user-attachments/assets/1e053d9c-75cc-402b-84df-86229c98277a)

The first commit keeps the re-export, and just changes the dependency if possible. The second commit is the "breaking change" which removes the re-export, and "explicitly" adds the `rustc_attr_data_structures` dependency where needed. It also switches over some src/tools/*.

The second commit is actually a lot more involved than I expected. Please let me know if it's a better idea to back it out and just keep the first commit.
2025-05-19 13:24:54 +10:00
León Orell Valerian Liehr
50b20b73da
Rollup merge of #141218 - dianqk:gvn-overlapping, r=oli-obk
gvn: avoid creating overlapping assignments

Quick fix #141038, as I couldn't find a way to avoid in-place modification. I'm considering handling all `ravlue` modifications within the `visit_statement` function.

r? mir-opt
2025-05-18 18:44:14 +02:00
León Orell Valerian Liehr
3af0c43f06
Rollup merge of #140926 - azhogin:azhogin/async-drop-coroutine-layout-returns-layout-error, r=oli-obk
Return value of coroutine_layout fn changed to Result with LayoutError

Continue of https://github.com/rust-lang/rust/pull/140902:
`coroutine_layout` fn is now returns `Result` with `LayoutError` to have consistent error with `layout_of_uncached`.
`async_drop_coroutine_layout` fn is now return `LayoutError::TooGeneric` in case of not-fully-specialized `async_drop_in_place<T>::{closure}` coroutine.
2025-05-18 18:44:12 +02:00
dianqk
d2e5a3d131
gvn: avoid creating overlapping assignments 2025-05-18 18:42:00 +08:00
Matthias Krüger
8e30998c18
Rollup merge of #141051 - compiler-errors:less-erase, r=nnethercote
Remove some unnecessary erases

Some nits I pulled out of https://github.com/rust-lang/rust/pull/140814.
2025-05-17 10:33:10 +02:00
bendn
de8e8641ae
dont handle bool transmute 2025-05-15 20:20:39 +07:00
Pietro Albini
2ce08ca5d6
update cfg(bootstrap) 2025-05-12 15:33:37 +02:00