about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir
AgeCommit message (Collapse)AuthorLines
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-15Port `#[custom_mir(..)]` to the new attribute systemSasha Pourcelot-42/+0
2025-08-15Auto merge of #145423 - Zalathar:rollup-9jtefpl, r=Zalatharbors-2/+0
Rollup of 21 pull requests Successful merges: - rust-lang/rust#118087 (Add Ref/RefMut try_map method) - rust-lang/rust#122661 (Change the desugaring of `assert!` for better error output) - rust-lang/rust#142640 (Implement autodiff using intrinsics) - rust-lang/rust#143075 (compiler: Allow `extern "interrupt" fn() -> !`) - rust-lang/rust#144865 (Fix tail calls to `#[track_caller]` functions) - rust-lang/rust#144944 (E0793: Clarify that it applies to unions as well) - rust-lang/rust#144947 (Fix description of unsigned `checked_exact_div`) - rust-lang/rust#145004 (Couple of minor cleanups) - rust-lang/rust#145005 (strip prefix of temporary file names when it exceeds filesystem name length limit) - rust-lang/rust#145012 (Tail call diagnostics to include lifetime info) - rust-lang/rust#145065 (resolve: Introduce `RibKind::Block`) - rust-lang/rust#145120 (llvm: Accept new LLVM lifetime format) - rust-lang/rust#145189 (Weekly `cargo update`) - rust-lang/rust#145235 (Minor `[const]` tweaks) - rust-lang/rust#145275 (fix(compiler/rustc_codegen_llvm): apply `target-cpu` attribute) - rust-lang/rust#145322 (Resolve the prelude import in `build_reduced_graph`) - rust-lang/rust#145331 (Make std use the edition 2024 prelude) - rust-lang/rust#145369 (Do not ICE on private type in field of unresolved struct) - rust-lang/rust#145378 (Add `FnContext` in parser for diagnostic) - rust-lang/rust#145389 ([rustdoc] Revert "rustdoc search: prefer stable items in search results") - rust-lang/rust#145392 (coverage: Remove intermediate data structures from mapping creation) r? `@ghost` `@rustbot` modify labels: rollup
2025-08-15Auto merge of #144591 - RalfJung:pattern-valtrees, r=BoxyUwUbors-0/+5
Patterns: represent constants as valtrees Const patterns are always valtrees now. Let's represent that in the types. We use `ty::Value` for this since it nicely packages value and type, and has some convenient methods. Cc `@Nadrieril` `@BoxyUwU`
2025-08-14Complete functionality and general cleanupMarcelo Domínguez-2/+0
2025-08-14Rollup merge of #145323 - scrabsha:push-pqwvmznzzmpr, r=jdonszelmannGuillaume Gomez-17/+1
Port the `#[linkage]` attribute to the new attribute system r? `@jdonszelmann`
2025-08-14use ty::Value instead of manual pairs of types and valtreesRalf Jung-0/+5
2025-08-13Port the `#[linkage]` attribute to the new attribute systemSasha Pourcelot-17/+1
2025-08-13Rollup merge of #144949 - nnethercote:more-Printer-cleanups, r=davidtwcoGuillaume Gomez-2/+2
More `Printer` cleanups A sequel to rust-lang/rust#144776. r? ```@davidtwco```
2025-08-13Fix parallel rustc not being reproducible due to unstable sorting of items.ywxt-31/+36
2025-08-12make no_mangle explicit on foreign itemsJana Dönszelmann-1/+1
2025-08-08Rollup merge of #144999 - Zalathar:remove-mcdc, r=oli-obkStuart Cook-123/+1
coverage: Remove all unstable support for MC/DC instrumentation Preliminary support for a partial implementation of “Modified Condition/Decision Coverage” instrumentation was added behind the unstable flag `-Zcoverage-options=mcdc` in 2024. These are the most substantial PRs involved: - rust-lang/rust#123409 - rust-lang/rust#126733 At the time, I accepted these PRs with relatively modest scrutiny, because I did not want to stand in the way of independent work on MC/DC instrumentation. My hope was that ongoing work by interested contributors would lead to the code becoming clearer and more maintainable over time. --- However, that MC/DC code has proven itself to be a major burden on overall maintenance of coverage instrumentation, and a major obstacle to other planned improvements, such as internal changes needed for proper support of macro expansion regions. I have also become reluctant to accept any further MC/DC-related changes that would increase this burden. That tension has resulted in an unhappy impasse. On one hand, the present MC/DC implementation is not yet complete, and shows little sign of being complete at an acceptable level of code quality in the foreseeable future. On the other hand, the continued existence of this partial MC/DC implementation is imposing serious maintenance burdens on every other aspect of coverage instrumentation, and is preventing some of the very improvements that would make it easier to accept expanded MC/DC support in the future. While I know this will be disappointing to some, I think the healthy way forward is accept that I made the wrong call in accepting the current implementation, and to remove it entirely from the compiler.
2025-08-06Rollup merge of #144998 - dianqk:visit-no-use-proj, r=cjgillotGuillaume Gomez-14/+20
mir: Do not modify NonUse in `super_projection_elem` Split from rust-lang/rust#142771. r? cjgillot
2025-08-06mir: Do not modify NonUse in `super_projection_elem`dianqk-14/+20
2025-08-06coverage: Remove all unstable support for MC/DC instrumentationZalathar-123/+1
2025-08-06Rename some `PrettyPrinter` methods.Nicholas Nethercote-2/+2
More consistency.
2025-08-05Rollup merge of #144920 - compiler-errors:span-arg, r=lqdSamuel Tardieu-3/+3
Dont print arg span in MIR dump for tail call r? WaffleLapkin This makes the MIR dump for tail call terminators consistent w/ regular calls.
2025-08-05Rollup merge of #144890 - WaffleLapkin:project_fields, r=lcnrSamuel Tardieu-20/+21
Add `InterpCx::project_fields` I was hoping for a much bigger improvement and this is lukewarm at best ^^' Still, I think this makes sense.
2025-08-04Dont print arg span in MIR dump for tail callMichael Goulet-3/+3
2025-08-04small refactor of `InterpResult`Waffle Lapkin-20/+21
- don't need type alias to default type argument - `Residual` impl allows to use more std APIs (like `<[T; N]>::try_map`)
2025-08-03Rename `Printer` variables.Nicholas Nethercote-17/+17
Currently they are mostly named `cx`, which is a terrible name for a type that impls `Printer`/`PrettyPrinter`, and is easy to confuse with other types like `TyCtxt`. This commit changes them to `p`. A couple of existing `p` variables had to be renamed to make way.
2025-08-02Rollup merge of #144478 - joshtriplett:doc-code-formatting-prep, r=AmanieuSamuel Tardieu-1/+2
Improve formatting of doc code blocks We don't currently apply automatic formatting to doc comment code blocks. As a result, it has built up various idiosyncracies, which make such automatic formatting difficult. Some of those idiosyncracies also make things harder for human readers or other tools. This PR makes a few improvements to doc code formatting, in the hopes of making future automatic formatting easier, as well as in many cases providing net readability improvements. I would suggest reading each commit separately, as each commit contains one class of changes.
2025-07-31remove rustc_attr_data_structuresJana Dönszelmann-1/+1
2025-07-30const-eval: full support for pointer fragmentsRalf Jung-116/+129
2025-07-27miri: for ABI mismatch errors, say which argument is the problemRalf Jung-1/+6
2025-07-25Improve and regularize comment placement in doc codeJosh Triplett-1/+2
Because doc code does not get automatically formatted, some doc code has creative placements of comments that automatic formatting can't handle. Reformat those comments to make the resulting code support standard Rust formatting without breaking; this is generally an improvement to readability as well. Some comments are not indented to the prevailing indent, and are instead aligned under some bit of code. Indent them to the prevailing indent, and put spaces *inside* the comments to align them with code. Some comments span several lines of code (which aren't the line the comment is about) and expect alignment. Reformat them into one comment not broken up by unrelated intervening code. Some comments are placed on the same line as an opening brace, placing them effectively inside the subsequent block, such that formatting would typically format them like a line of that block. Move those comments to attach them to what they apply to. Some comments are placed on the same line as a one-line braced block, effectively attaching them to the closing brace, even though they're about the code inside the block. Reformat to make sure the comment will stay on the same line as the code it's commenting.
2025-07-24Rollup merge of #144094 - saethlin:codegen-the-main-fn, r=petrochenkovLeón Orell Valerian Liehr-4/+2
Ensure we codegen the main fn This fixes two bugs. The one that was identified in the linked issue is that when we have a `main` function, mono collection didn't consider it as an extra collection root. The other is that since CGU partitioning doesn't know about the call edges between the entrypoint functions, naively it can put them in different CGUs and mark them all as internal. Which would result in LLVM just deleting all of them. There was an existing hack to exclude `lang = "start"` from internalization, which I've extended to include `main`. Fixes https://github.com/rust-lang/rust/issues/144052
2025-07-23Remove useless lifetime parameter.Camille GILLOT-19/+18
2025-07-23Give an AllocId to ConstValue::Slice.Camille GILLOT-30/+30
2025-07-21Ensure we codegen and don't internalize the entrypointBen Kimock-4/+2
2025-07-18Rollup merge of #142673 - oli-obk:uninit-read-mem, r=RalfJungMatthias Krüger-2/+5
Show the offset, length and memory of uninit read errors r? ``@RalfJung`` I want to improve memory dumps in general. Not sure yet how to do so best within rust diagnostics, but in a perfect world I could generate a dummy in-memory file (that contains the rendered memory dump) that we then can then provide regular rustc `Span`s to. So we'd basically report normal diagnostics for them with squiggly lines and everything.
2025-07-18Rollup merge of #143293 - folkertdev:naked-function-kcfi, r=compiler-errorsMatthias Krüger-7/+6
fix `-Zsanitizer=kcfi` on `#[naked]` functions fixes https://github.com/rust-lang/rust/issues/143266 With `-Zsanitizer=kcfi`, indirect calls happen via generated intermediate shim that forwards the call. The generated shim preserves the attributes of the original, including `#[unsafe(naked)]`. The shim is not a naked function though, and violates its invariants (like having a body that consists of a single `naked_asm!` call). My fix here is to match on the `InstanceKind`, and only use `codegen_naked_asm` when the instance is not a `ReifyShim`. That does beg the question whether there are other `InstanceKind`s that could come up. As far as I can tell the answer is no: calling via `dyn` seems to work find, and `#[track_caller]` is disallowed in combination with `#[naked]`. r? codegen ````@rustbot```` label +A-naked cc ````@maurer```` ````@rcvalle````
2025-07-17Report the range of uninit bytes in CTFE errorsOli Scherer-2/+5
2025-07-16use `codegen_instance_attrs` where an instance is (easily) availableFolkert de Vries-7/+6
2025-07-16add `const_make_global`; err for `const_allocate` ptrs if didn't callDeadbeef-1/+1
Co-Authored-By: Ralf Jung <post@ralfj.de> Co-Authored-By: Oli Scherer <github333195615777966@oli-obk.de>
2025-07-13Rollup merge of #143634 - nia-e:init-and-wildcards, r=RalfJungMatthias Krüger-24/+37
interpret/allocation: expose init + write_wildcards on a range Part of https://github.com/rust-lang/miri/pull/4456, so that we can mark down when a foreign access to our memory happened. Should this also move `prepare_for_native_access()` itself into Miri, given that everything there can be implemented on Miri's side? r? `````@RalfJung`````
2025-07-11Remove support for SwitchInt edge effects in backward dataflow analysesTomasz Miąsko-39/+1
Those effects are untested and unused. Remove them along with the implementation of `BasicBlocks::switch_sources`.
2025-07-10interpret/allocation: expose init + write_wildcards on a rangeNia Espera-24/+37
2025-07-09Add opaque TypeId handles for CTFEOli Scherer-5/+31
2025-07-07compiler: Parse `p-` specs in datalayout string, allow definition of custom ↵Edoardo Marangoni-20/+19
default data address space
2025-07-03Rollup merge of #134006 - klensy:typos, r=nnethercoteJana Dönszelmann-3/+3
setup typos check in CI This allows to check typos in CI, currently for compiler only (to reduce commit size with fixes). With current setup, exclude list is quite short, so it worth trying? Also includes commits with actual typo fixes. MCP: https://github.com/rust-lang/compiler-team/issues/817 typos check currently turned for: * ./compiler * ./library * ./src/bootstrap * ./src/librustdoc After merging, PRs which enables checks for other crates (tools) can be implemented too. Found typos will **not break** other jobs immediately: (tests, building compiler for perf run). Job will be marked as red on completion in ~ 20 secs, so you will not forget to fix it whenever you want, before merging pr. Check typos: `python x.py test tidy --extra-checks=spellcheck` Apply typo fixes: `python x.py test tidy --extra-checks=spellcheck:fix` (in case if there only 1 suggestion of each typo) Current fail in this pr is expected and shows how typo errors emitted. Commit with error will be removed after r+.
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-3/+3
2025-07-02interpret: move the native call preparation logic into MiriRalf Jung-9/+2
2025-07-01Rollup merge of #143262 - dianqk:non_exhaustive, r=oli-obkGuillaume Gomez-0/+2
mir: Mark `Statement` and `BasicBlockData` as `#[non_exhaustive]` Ensure they are always created using constructors. r? oli-obk
2025-07-01Auto merge of #141875 - nnethercote:ByteSymbol, r=petrochenkovbors-1/+1
Introduce `ByteSymbol` It's like `Symbol` but for byte strings. The interner is now used for both `Symbol` and `ByteSymbol`. E.g. if you intern `"dog"` and `b"dog"` you'll get a `Symbol` and a `ByteSymbol` with the same index and the characters will only be stored once. The motivation for this is to eliminate the `Arc`s in `ast::LitKind`, to make `ast::LitKind` impl `Copy`, and to avoid the need to arena-allocate `ast::LitKind` in HIR. The latter change reduces peak memory by a non-trivial amount on literal-heavy benchmarks such as `deep-vector` and `tuple-stress`. `Encoder`, `Decoder`, `SpanEncoder`, and `SpanDecoder` all get some changes so that they can handle normal strings and byte strings.
2025-07-01mir: Mark `Statement` and `BasicBlockData` as `#[non_exhaustive]`dianqk-0/+2
Ensure they are always created using constructors.
2025-06-30Rollup merge of #143140 - RalfJung:ptr-into-parts, r=oli-obkMatthias Krüger-16/+24
give Pointer::into_parts a more scary name and offer a safer alternative `into_parts` is a bit too innocent of a name for a somewhat subtle operation. r? `@oli-obk`