about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir/mod.rs
AgeCommit message (Collapse)AuthorLines
2025-08-15Port `#[custom_mir(..)]` to the new attribute systemSasha Pourcelot-42/+0
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-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-07-01mir: Mark `Statement` and `BasicBlockData` as `#[non_exhaustive]`dianqk-0/+1
Ensure they are always created using constructors.
2025-06-29mir: Use the `new` method for `BasicBlockData`dianqk-1/+9
2025-04-28AsyncDrop implementation using shim codegen of ↵Andrew Zhogin-1/+29
async_drop_in_place::{closure}, scoped async drop added.
2025-04-14Move `has_self` field to `hir::AssocKind::Fn`.Nicholas Nethercote-2/+2
`hir::AssocItem` currently has a boolean `fn_has_self_parameter` field, which is misplaced, because it's only relevant for associated fns, not for associated consts or types. This commit moves it (and renames it) to the `AssocKind::Fn` variant, where it belongs. This requires introducing a new C-style enum, `AssocTag`, which is like `AssocKind` but without the fields. This is because `AssocKind` values are passed to various functions like `find_by_ident_and_kind` to indicate what kind of associated item should be searched for, and having to specify `has_self` isn't relevant there. New methods: - Predicates `AssocItem::is_fn` and `AssocItem::is_method`. - `AssocItem::as_tag` which converts `AssocItem::kind` to `AssocTag`. Removed `find_by_name_and_kinds`, which is unused. `AssocItem::descr` can now distinguish between methods and associated functions, which slightly improves some error messages.
2025-03-16Build `UserTypeProjections` lazily when visiting bindingsZalathar-82/+3
2025-03-15Move codec module back into middleMichael Goulet-2/+2
2025-03-15Fold visit into tyMichael Goulet-3/+2
2025-03-07compiler: Use size_of from the prelude instead of importedThalia Archibald-2/+2
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
2025-02-24Move `impl` blocks out of `rustc_middle/src/mir/syntax.rs`.Nicholas Nethercote-0/+11
As the comment at the top says, this file is not supposed to contain any code. But some has crept in. This commit moves it out.
2025-02-22Greatly simplify lifetime captures in edition 2024Michael Goulet-6/+3
2025-02-21Rollup merge of #137305 - nnethercote:rustc_middle-2, r=lcnrMatthias Krüger-19/+4
Tweaks in and around `rustc_middle` A bunch of tiny improvements I found while working on bigger things. r? ```@lcnr```
2025-02-21Rollup merge of #137204 - nnethercote:clarify-MIR-dialects-and-phases, ↵Matthias Krüger-14/+7
r=RalfJung Clarify MIR dialects and phases I found the existing code and docs hard to understand. r? `@Zalathar`
2025-02-21Remove some unnecessary `FIXME` comments.Nicholas Nethercote-3/+0
The comments didn't make much sense to me. I asked Matthew Jasper on Zulip about it and they said: > I think that at the time I wanted to replace all (or most of) this > with a reference to the HIR Id of the variable. I'll give this a look > to see if it's still a reasonable idea, but removing the comments is > fine. and then: > I don't think that changing this to an HirId would be better, > recovering the information from the HIR seems like too much effort in > exchange for making the MIR a little smaller.
2025-02-21Put a `BlockTailInfo` in `BlockFrame::TailExpr`.Nicholas Nethercote-1/+1
Because it has the same fields, and avoids the need to deconstruct the latter to construct the former.
2025-02-21Rename `ClearCrossCrate::assert_crate_local`.Nicholas Nethercote-2/+2
As `unwrap_crate_local`, because it follows exactly the standard form of an `unwrap` function.
2025-02-21Remove unused `Body::span_for_ty_context` method.Nicholas Nethercote-12/+0
2025-02-21Fix a typo in a comment.Nicholas Nethercote-1/+1
2025-02-20Don't store a redundant span in user-type projectionsZalathar-15/+6
This span is already present in the corresponding `CanonicalUserTypeAnnotation`, and can be retrieved via the annotation's ID.
2025-02-20Avoid a useless clone of `UserTypeProjection`Zalathar-2/+2
2025-02-20Improve how the MIR dialect/phase index is reported.Nicholas Nethercote-14/+7
The only visible change is to the filenames produce by `-Zdump-mir`. E.g. before and after: ``` h.main.003-000.analysis-post-cleanup.after.mir h.main.2-2-000.analysis-post-cleanup.after.mir ``` It also fixes a FIXME comment.
2025-02-19Remove `MirVisitable`.Nicholas Nethercote-5/+0
The `MirVisitable` trait is just a complicated way to visit either a statement or a terminator. (And its impl for `Terminator` is unused.) It has a single use. This commit removes it, replacing it with an if/else, which is shorter and simpler.
2025-02-19Rollup merge of #137213 - nnethercote:rm-rustc_middle-mir-tcx, r=compiler-errorsMatthias Krüger-1/+0
Remove `rustc_middle::mir::tcx` module. This is a really weird module. For example, what does `tcx` in `rustc_middle::mir::tcx::PlaceTy` mean? The answer is "not much". The top-level module comment says: > Methods for the various MIR types. These are intended for use after > building is complete. Awfully broad for a module that has a handful of impl blocks for some MIR types, none of which really relates to `TyCtxt`. `git blame` indicates the comment is ancient, from 2015, and made sense then. This module is now vestigial. This commit removes it and moves all the code within into `rustc_middle::mir::statement`. Some specifics: - `Place`, `PlaceRef`, `Rvalue`, `Operand`, `BorrowKind`: they all have `impl` blocks in both the `tcx` and `statement` modules. The commit merges the former into the latter. - `BinOp`, `UnOp`: they only have `impl` blocks in `tcx`. The commit moves these into `statement`. - `PlaceTy`, `RvalueInitializationState`: they are defined in `tcx`. This commit moves them into `statement` *and* makes them available in `mir::*`, like many other MIR types. r? `@tmandry`
2025-02-19Remove `rustc_middle::mir::tcx` module.Nicholas Nethercote-1/+0
This is a really weird module. For example, what does `tcx` in `rustc_middle::mir::tcx::PlaceTy` mean? The answer is "not much". The top-level module comment says: > Methods for the various MIR types. These are intended for use after > building is complete. Awfully broad for a module that has a handful of impl blocks for some MIR types, none of which really relates to `TyCtxt`. `git blame` indicates the comment is ancient, from 2015, and made sense then. This module is now vestigial. This commit removes it and moves all the code within into `rustc_middle::mir::statement`. Some specifics: - `Place`, `PlaceRef`, `Rvalue`, `Operand`, `BorrowKind`: they all have `impl` blocks in both the `tcx` and `statement` modules. The commit merges the former into the latter. - `BinOp`, `UnOp`: they only have `impl` blocks in `tcx`. The commit moves these into `statement`. - `PlaceTy`, `RvalueInitializationState`: they are defined in `tcx`. This commit moves them into `statement` *and* makes them available in `mir::*`, like many other MIR types.
2025-02-18Rollup merge of #137203 - nnethercote:improve-MIR-modification, ↵Matthias Krüger-61/+1
r=compiler-errors Improve MIR modification A few commits that simplify code that manipulates MIR bodies. r? `@tmiasko`
2025-02-18Inline and replace `Statement::replace_nop`.Nicholas Nethercote-1/+1
It has a single call site, and doesn't seem worth having as an API function.
2025-02-18Inline and remove `BasicBlockData::retain_statements`.Nicholas Nethercote-11/+0
It has a single call site, and the code is clearer this way.
2025-02-18Remove `BasicBlockData::expand_statements`.Nicholas Nethercote-49/+0
The previous commit removed its single use. `MirPatch` is a more flexible alternative.
2025-02-17Add `SwitchTargetValue`.Nicholas Nethercote-1/+1
This is much clearer than `Option<u128>`.
2025-02-14Move `MirPatch` from `rustc_middle` to `rustc_mir_transform`.Nicholas Nethercote-1/+0
Because it's only used in `rustc_mir_transform`. (Presumably it is currently in `rustc_middle` because lots of other MIR-related stuff is, but that's not a hard requirement.) And because `rustc_middle` is huge and it's always good to make it smaller.
2025-02-08Rustfmtbjorn3-4/+4
2025-02-06Clean up trivial traversal/lift impl generator macro calls.Nicholas Nethercote-4/+0
We have four macros for generating trivial traversal (fold/visit) and lift impls. - `rustc_ir::TrivialTypeTraversalImpls` - `rustc_middle::TrivialTypeTraversalImpls` - `rustc_middle::TrivialLiftImpls` - `rustc_middle::TrivialTypeTraversalAndLiftImpls` The first two are very similar. The last one just combines the second and third one. The macros themselves are ok, but their use is a mess. This commit does the following. - Removes types that no longer need a lift and/or traversal impl from the macro calls. - Consolidates the macro calls into the smallest number of calls possible, with each one mentioning as many types as possible. - Orders the types within those macro calls alphabetically, and makes the module qualification more consistent. - Eliminates `rustc_middle::mir::type_foldable`, because the macro calls were merged and the manual `TypeFoldable` impls are better placed in `structural_impls.rs`, alongside all the other ones. This makes the code more concise. Moving forward, it also makes it more obvious where new types should be added.
2025-01-31Move `find_self_call`.Nicholas Nethercote-1/+42
It's a function that does stuff with MIR and yet it weirdly has its own module in `rustc_middle::util`. This commit moves it into `rustc_middle::mir`, a more sensible home.
2025-01-24Exclude `mir::coverage` types from TypeFoldable/TypeVisitableZalathar-0/+4
These types are unlikely to ever contain type information in the foreseeable future, so excluding them from TypeFoldable/TypeVisitable avoids some unhelpful derive boilerplate.
2025-01-11rename `BitSet` to `DenseBitSet`Rémy Rakic-1/+1
This should make it clearer that this bitset is dense, with the advantages and disadvantages that it entails.
2024-12-18mir: require `is_cleanup` when creating `BasicBlockData`DianQK-2/+2
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-11-23remove remaining references to `Reveal`lcnr-2/+1
2024-11-19additional `TypingEnv` cleanupslcnr-4/+1
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-10/+17
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-03compiler: Directly use rustc_abi in metadata and middleJubilee Young-1/+1
Stop reexporting ReprOptions from middle::ty
2024-10-31stop using `ParamEnv::reveal` while handling MIRlcnr-1/+10
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-8/+8
2024-09-21Don't alloca for unused localsBen Kimock-0/+13
2024-09-13Auto merge of #107251 - dingxiangfei2009:let-chain-rescope, r=jieyouxubors-0/+3
Rescope temp lifetime in if-let into IfElse with migration lint Tracking issue #124085 This PR shortens the temporary lifetime to cover only the pattern matching and consequent branch of a `if let`. At the expression location, means that the lifetime is shortened from previously the deepest enclosing block or statement in Edition 2021. This warrants an Edition change. Coming with the Edition change, this patch also implements an edition lint to warn about the change and a safe rewrite suggestion to preserve the 2021 semantics in most cases. Related to #103108. Related crater runs: https://github.com/rust-lang/rust/pull/129466.
2024-09-11rescope temp lifetime in let-chain into IfElseDing Xiang Fei-0/+3
apply rules by span edition
2024-09-09Remove needless returns detected by clippy in the compilerEduardo Sánchez Muñoz-3/+2
2024-09-03Move `MirPass` to `rustc_mir_transform`.Nicholas Nethercote-62/+0
Because that's now the only crate that uses it. Moving stuff out of `rustc_middle` is always welcome. I chose to use `impl crate::MirPass`/`impl crate::MirLint` (with explicit `crate::`) everywhere because that's the only mention of `MirPass`/`MirLint` used in all of these files. (Prior to this change, `MirPass` was mostly imported via `use rustc_middle::mir::*` items.)