about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir
AgeCommit message (Collapse)AuthorLines
2025-10-02mir-opt: Eliminate dead statements even if they are used by debuginfosdianqk-0/+25
2025-10-02mir-opt: Eliminate trivial unnecessary storage annotationsdianqk-10/+4
2025-10-02simplifycfg: Preserve debuginfos when merging bbsdianqk-0/+8
2025-10-02mir-opt: Eliminate dead ref statementsdianqk-8/+199
2025-10-02Auto merge of #147055 - beepster4096:subtype_is_not_a_projection, r=lcnrbors-28/+14
Turn ProjectionElem::Subtype into CastKind::Subtype I noticed that drop elaboration can't, in general, handle `ProjectionElem::SubType`. It creates a disjoint move path that overlaps with other move paths. (`Subslice` does too, and I'm working on a different PR to make that special case less fragile.) If its skipped and treated as the same move path as its parent then `MovePath.place` has multiple possible projections. (It would probably make sense to remove all `Subtype` projections for the canonical place but it doesn't make sense to have this special case for a problem that doesn't actually occur in real MIR.) The only reason this doesn't break is that `Subtype` is always the sole projection of the local its applied to. For the same reason, it works fine as a `CastKind` so I figured that makes more sense than documenting and validating this hidden invariant. cc rust-lang/rust#112651, rust-lang/rust#133258 r? Icnr (bc you've been the main person dealing with `Subtype` it looks like)
2025-09-29more renameBoxy Uwu-1/+1
2025-09-27Rename various "concrete opaque type" terminology to say "hidden type"Boxy Uwu-4/+3
2025-09-26ProjectionElem::Subtype -> CastKind::Subtypebeepster4096-28/+14
2025-09-24const validation: better error for maybe-null referencesRalf Jung-0/+2
2025-09-24const-eval: improve and actually test the errors when pointers might be ↵Ralf Jung-4/+1
outside the range of a scalar
2025-09-18Rollup merge of #146566 - cjgillot:mir-overlap-lint, r=saethlinStuart Cook-0/+17
Lint more overlapping assignments in MIR. In an effort to make bugs like https://github.com/rust-lang/rust/issues/146383 more easily discovered, this PR extends the "overlapping assignment" MIR lint. I had to whitelist some rvalues, as they are actually allowed to alias, like `a = a + 1`.
2025-09-17Lint overlapping assignments in MIR.Camille Gillot-0/+17
2025-09-17Auto merge of #146331 - RalfJung:copy-prov-repeat, r=oli-obkbors-60/+60
interpret: copy_provenance: avoid large intermediate buffer for large repeat counts Copying provenance worked in this odd way where the "preparation" phase (which is supposed to just extract the necessary information from the source range) already did all the work of repeating the result N times for the target range. This was needed to use the existing `insert_presorted` function on `SortedMap`. This PR generalizes `insert_presorted` so that we can avoid this odd structure on copy-provenance, and maybe even improve performance.
2025-09-17Rollup merge of #146564 - cjgillot:mir-nolen, r=scottmcmStuart Cook-21/+0
Remove Rvalue::Len again. Now that we have `RawPtrKind::FakeForPtrMetadata`, we can reimplement `Rvalue::Len` using `PtrMetadata(&raw const (fake) place)`. r? ``@scottmcm``
2025-09-16Add test.Camille Gillot-2/+2
2025-09-16Remove Rvalue::Len.Camille Gillot-21/+0
2025-09-16Rollup merge of #146402 - RalfJung:aggregate-init, r=saethlinStuart Cook-3/+5
interpret: fix overlapping aggregate initialization This fixes the problem pointed out by ````@saethlin```` in https://github.com/rust-lang/rust/issues/146383#issuecomment-3273224645. Also clarify when exactly current de-facto MIR semantics allow overlap of the LHS and RHS in an assignment.
2025-09-10clarify current MIR semantics re: overlapping assignmentRalf Jung-3/+5
and double-check that we match it in codegen
2025-09-10Rollup merge of #146391 - beepster4096:trimnt, r=saethlinMatthias Krüger-5/+7
Trim paths less in MIR dumping With this PR, the paths MIR dump filters and that are printed at the start of a dump file are no longer trimmed. They don't include the crate that is being compiled, however.
2025-09-10Rollup merge of #146178 - folkertdev:static-align, ↵Matthias Krüger-1/+10
r=jdonszelmann,ralfjung,traviscross Implement `#[rustc_align_static(N)]` on `static`s Tracking issue: https://github.com/rust-lang/rust/issues/146177 ```rust #![feature(static_align)] #[rustc_align_static(64)] static SO_ALIGNED: u64 = 0; ``` We need a different attribute than `rustc_align` because unstable attributes are tied to their feature (we can't have two unstable features use the same unstable attribute). Otherwise this uses all of the same infrastructure as `#[rustc_align]`. r? `@traviscross`
2025-09-10avoid calling insert_presorted more than onceRalf Jung-10/+16
2025-09-10interpret: copy_provenance: avoid large intermediate buffer for large repeat ↵Ralf Jung-60/+54
counts
2025-09-09don't trim paths in mir dumping when filtering and at the top of the filebeepster4096-5/+7
2025-09-09allow `#[rustc_align_static(N)]` on `static`sFolkert de Vries-1/+10
We need a different attribute than `rustc_align` because unstable attributes are tied to their feature (we can't have two unstable features use the same unstable attribute). Otherwise this uses all of the same infrastructure as `#[rustc_align]`.
2025-09-09Auto merge of #145717 - BoxyUwU:erase_regions_rename, r=lcnrbors-5/+7
rename erase_regions to erase_and_anonymize_regions I find it consistently confusing that `erase_regions` does more than replacing regions with `'erased`. it also makes some code look real goofy to be writing manual folders to erase regions with a comment saying "we cant use erase regions" :> or code that re-calls erase_regions on types with regions already erased just to anonymize all the bound regions. r? lcnr idk how i feel about the name being almost twice as long now
2025-09-09erase_regions to erase_and_anonymize_regionsBoxy-5/+7
2025-09-09Rollup merge of #146324 - RalfJung:no-ptr-fragment, r=oli-obkStuart Cook-2/+19
const-eval: disable pointer fragment support This fixes https://github.com/rust-lang/rust/issues/146291 by disabling pointer fragment support for const-eval. I want to properly fix this eventually, but won't get to it in the next few weeks, so this is an emergency patch to prevent the buggy implementation from landing on stable. The beta cutoff is on Sep 12th so if this PR lands after that, we'll need a backport.
2025-09-08const-eval: disable pointer fragment supportRalf Jung-2/+19
2025-09-07Rollup merge of #146297 - cjgillot:may-observe-address, r=saethlinMatthias Krüger-0/+18
Introduce PlaceContext::may_observe_address. A small utility method to avoid open-coding the logic in several MIR opts.
2025-09-07Introduce PlaceContext::may_observe_address.Camille GILLOT-0/+18
2025-09-05rustc_middle: clippy fixesMarijn Schouten-12/+12
2025-09-01Introduce `MirDumper` and `MirWriter`.Nicholas Nethercote-142/+144
MIR dumping is a mess. There are lots of functions and entry points, e.g. `dump_mir`, `dump_mir_with_options`, `dump_polonius_mir`, `dump_mir_to_writer`. Also, it's crucial that `create_dump_file` is never called without `dump_enabled` first being checked, but there is no mechanism for ensuring this and it's hard to tell if it is satisfied on all paths. (`dump_enabled` is checked twice on some paths, however!) This commit introduces `MirWriter`, which controls the MIR writing, and encapsulates the `extra_data` closure and `options`. Two existing functions are now methods of this type. It sets reasonable defaults, allowing the removal of many `|_, _| Ok(())` closures. The commit also introduces `MirDumper`, which is layered on top of `MirWriter`, and which manages the creation of the dump files, encapsulating pass names, disambiguators, etc. Four existing functions are now methods of this type. - `MirDumper::new` will only succeed if dumps are enabled, and will return `None` otherwise, which makes it impossible to dump when you shouldn't. - It also sets reasonable defaults for various things like disambiguators, which means you no longer need to specify them in many cases. When they do need to be specified, it's now done via setter methods. - It avoids some repetition. E.g. `dump_nll_mir` previously specifed the pass name `"nll"` four times and the disambiguator `&0` three times; now it specifies them just once, to put them in the `MirDumper`. - For Polonius, the `extra_data` closure can now be specified earlier, which avoids having to pass some arguments through some functions.
2025-09-01Indent some functions.Nicholas Nethercote-322/+322
This commit exists purely to simplify reviewing: these functions will become methods in the next commit. This commit indents them so that the next commit is more readable.
2025-09-01Use trait object references for closures.Nicholas Nethercote-41/+21
The dynamic dispatch cost doesn't matter for MIR dumping, which is perf-insensitive. And it's necessary for the next commit, which will store some `extra_data` closures in a struct.
2025-09-01Avoid unnecessary `mut`-ness for various closures.Nicholas Nethercote-14/+14
2025-09-01Inline and remove `dump_matched_mir_node`.Nicholas Nethercote-25/+11
It has a single call site.
2025-08-27Auto merge of #140737 - amandasystems:revised-constraint-search, r=lcnrbors-2/+9
Region inference: Use outlives-static constraints in constraint search Revise the extra `r: 'static` constraints added upon universe issues to add an explanation, and use that explanation during constraint blame search. This greatly simplifies the region inference logic, which now does not need to reverse-engineer the event that caused a region to outlive `'static`. This cosmetically changes the output of two UI tests. I blessed them i separate commits with separate motivations, but that can of course be squashed as desired. We probably want that. The PR was extracted out of rust-lang/rust#130227 and consists of one-third of its functional payload. r? lcnr
2025-08-26add a flag to codegen fn attrs for foreign itemsJana Dönszelmann-1/+1
2025-08-25Remove bug comments from Repeat variantRyan Lee-5/+0
Removed comments related to a bug in Repeat variant.
2025-08-23Rollup merge of #145540 - nia-e:prov-map-range, r=RalfJungSamuel Tardieu-0/+11
interpret/allocation: get_range on ProvenanceMap Helper method to grab all provenances in a given address range for an allocation, making some logic in Miri nicer.
2025-08-22Rollup merge of #145695 - cjgillot:place-elem-map, r=oli-obk,lcnrJacob Pratt-1/+35
Introduce ProjectionElem::try_map. Small utility function useful to manipulate MIR place projections.
2025-08-22interpret/allocation: get_range on ProvenanceMapNia Espera-0/+11
2025-08-22Region inference: Use outlives-static constraints in constraint searchAmanda Stjerna-2/+9
Revise the extra `r: 'static` constraints added upon universe issues to add an explanation, and use that explanation during constraint blame search. This greatly simplifies the region inference logic, which now does not need to reverse-engineer the event that caused a region to outlive 'static.
2025-08-22Auto merge of #145358 - Kobzol:symbol-name-sort, r=nnethercotebors-3/+20
Sort mono items by symbol name Trying to claw back cycles/branch/cache miss losses from https://github.com/rust-lang/rust/pull/144722.
2025-08-21Introduce ProjectionElem::try_map.Camille GILLOT-1/+35
2025-08-19Rollup merge of #145510 - cjgillot:visit-async-drop, r=davidtwco许杰友 Jieyou Xu (Joe)-2/+12
Visit and print async_fut local for async drop. This is a bugfix for a MIR local we forget to visit. I had a lot of trouble reading the docs for `async_fut`, so I'm not certain about the change to the pretty-printer.
2025-08-18Rollup merge of #145206 - scrabsha:push-uxovoqzrxnlx, r=jdonszelmannStuart Cook-42/+0
Port `#[custom_mir(..)]` to the new attribute system r? ``````````@jdonszelmann``````````
2025-08-17Auto merge of #144081 - RalfJung:const-ptr-fragments, r=oli-obkbors-116/+129
const-eval: full support for pointer fragments This fixes https://github.com/rust-lang/const-eval/issues/72 and makes `swap_nonoverlapping` fully work in const-eval by enhancing per-byte provenance tracking with tracking of *which* of the bytes of the pointer this one is. Later, if we see all the same bytes in the exact same order, we can treat it like a whole pointer again without ever risking a leak of the data bytes (that encode the offset into the allocation). This lifts the limitation that was discussed quite a bit in https://github.com/rust-lang/rust/pull/137280. For a concrete piece of code that used to fail and now works properly consider this example doing a byte-for-byte memcpy in const without using intrinsics: ```rust use std::{mem::{self, MaybeUninit}, ptr}; type Byte = MaybeUninit<u8>; const unsafe fn memcpy(dst: *mut Byte, src: *const Byte, n: usize) { let mut i = 0; while i < n { *dst.add(i) = *src.add(i); i += 1; } } const _MEMCPY: () = unsafe { let ptr = &42; let mut ptr2 = ptr::null::<i32>(); // Copy from ptr to ptr2. memcpy(&mut ptr2 as *mut _ as *mut _, &ptr as *const _ as *const _, mem::size_of::<&i32>()); assert!(*ptr2 == 42); }; ``` What makes this code tricky is that pointers are "opaque blobs" in const-eval, we cannot just let people look at the individual bytes since *we don't know what those bytes look like* -- that depends on the absolute address the pointed-to object will be placed at. The code above "breaks apart" a pointer into individual bytes, and then puts them back together in the same order elsewhere. This PR implements the logic to properly track how those individual bytes relate to the original pointer, and to recognize when they are in the right order again. We still reject constants where the final value contains a not-fully-put-together pointer: I have no idea how one could construct an LLVM global where one byte is defined as "the 3rd byte of a pointer to that other global over there" -- and even if LLVM supports this somehow, we can leave implementing that to a future PR. It seems unlikely to me anyone would even want this, but who knows.^^ This also changes the behavior of Miri, by tracking the order of bytes with provenance and only considering a pointer to have valid provenance if all bytes are in the original order again. This is related to https://github.com/rust-lang/unsafe-code-guidelines/issues/558. It means one cannot implement XOR linked lists with strict provenance any more, which is however only of theoretical interest. Practically I am curious if anyone will show up with any code that Miri now complains about - that would be interesting data. Cc `@rust-lang/opsem`
2025-08-16Visit and print async_fut local for async drop.Camille Gillot-2/+12
2025-08-15Sort mono items by symbol nameJakub Beránek-3/+20