about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir
AgeCommit message (Collapse)AuthorLines
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-16/+7
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-20Simplify `Postorder` customization.Nicholas Nethercote-35/+14
`Postorder` has a `C: Customization<'tcx>` parameter, that gives it flexibility about how it computes successors. But in practice, there are only two `impls` of `Customization`, and one is for the unit type. This commit simplifies things by removing the generic parameter and replacing it with an `Option`.
2025-02-20Rollup merge of #137266 - nnethercote:mir-visitor-tweaks, r=compiler-errorsMatthias Krüger-173/+142
MIR visitor tweaks Some minor improvements I found while looking at this code. r? `@tmandry`
2025-02-20Rollup merge of #137262 - compiler-errors:ast-ir-begone, r=lcnrMatthias Krüger-2/+1
Make fewer crates depend on `rustc_ast_ir` I think it simplifies the crate graph and also exposes people less to confusion if downstream crates don't interact with `rustc_ast_ir` directly and instead just use its functionality reexported through more familiar paths. r? oli-obk since you introduced ast-ir
2025-02-20Improve how the MIR dialect/phase index is reported.Nicholas Nethercote-16/+10
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-20Improve MIR phase comments.Nicholas Nethercote-22/+29
I found the dialect/phase distinction quite confusing when I first read these comments. This commit clarifies things a bit.
2025-02-20Reflow `MirPhase` comments.Nicholas Nethercote-22/+25
Currently many of them exceed 100 chars, which makes them painful to read on a terminal that is 100 chars wide.
2025-02-19Add a .bss-like scheme for encoded const allocsBen Kimock-2/+115
2025-02-19Improve formatting within `make_mir_visitor` macro body.Nicholas Nethercote-142/+128
rustfmt doesn't touch it because it's a macro body, but it's large enough that the misformatting is annoying. This commit improves it. The most common problems fixed: - Unnecessary multi-line patterns reduced to one line. - Multi-line function headers adjusted so the parameter indentation doesn't depend on the length of the function name. (This is Rust code, not C.) - `|` used at the start of lines, not the end. - More consistent formatting of empty function bodies. - Overly long lines are broken.
2025-02-19Remove `MirVisitable`.Nicholas Nethercote-27/+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-19Add `super_local` method to the MIR visitors.Nicholas Nethercote-4/+14
`visit_local` is the only method that doesn't call a corresponding `super_local` method. This is valid, because `super_local` would be empty. But it's inconsistent with every other case; we have multiple other empty `super` methods: `super_span`, `super_ty`, etc. This commit adds an empty `super_local` and makes `visit_local` call it.
2025-02-19Make fewer crates depend on rustc_ast_irMichael Goulet-2/+1
2025-02-19Rollup merge of #137213 - nnethercote:rm-rustc_middle-mir-tcx, r=compiler-errorsMatthias Krüger-418/+397
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-418/+397
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-70/+1
r=compiler-errors Improve MIR modification A few commits that simplify code that manipulates MIR bodies. r? `@tmiasko`
2025-02-18Auto merge of #137162 - nnethercote:remove-Map-2, r=Zalatharbors-1/+1
Move methods from `Map` to `TyCtxt`, part 2. Continuing the work started in #136466. Every method gains a `hir_` prefix, though for the ones that already have a `par_` or `try_par_` prefix I added the `hir_` after that. r? Zalathar
2025-02-18Inline and replace `Statement::replace_nop`.Nicholas Nethercote-10/+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-18Move methods from `Map` to `TyCtxt`, part 2.Nicholas Nethercote-1/+1
Continuing the work started in #136466. Every method gains a `hir_` prefix, though for the ones that already have a `par_` or `try_par_` prefix I added the `hir_` after that.
2025-02-17Rollup merge of #136959 - nnethercote:simplify-SwitchSources, r=tmiaskoMatthias Krüger-17/+46
Simplify switch sources `SwitchSources` and the code around it can be simplified. r? `@tmiasko`
2025-02-17Rollup merge of #137095 - saethlin:use-hash64-for-hashes, r=workingjubileeMatthias Krüger-1/+2
Replace some u64 hashes with Hash64 I introduced the Hash64 and Hash128 types in https://github.com/rust-lang/rust/pull/110083, essentially as a mechanism to prevent hashes from landing in our leb128 encoding paths. If you just have a u64 or u128 field in a struct then derive Encodable/Decodable, that number gets leb128 encoding. So if you need to store a hash or some other value which behaves very close to a hash, don't store it as a u64. This reverts part of https://github.com/rust-lang/rust/pull/117603, which turned an encoded Hash64 into a u64. Based on https://github.com/rust-lang/rust/pull/110083, I don't expect this to be perf-sensitive on its own, though I expect that it may help stabilize some of the small rmeta size fluctuations we currently see in perf reports.
2025-02-17Update and clarify the comment on `SwitchTargets`.Nicholas Nethercote-11/+19
2025-02-17Add `SwitchTargetValue`.Nicholas Nethercote-4/+18
This is much clearer than `Option<u128>`.
2025-02-17Add a useful comment.Nicholas Nethercote-2/+9
2025-02-16Move hashes from rustc_data_structure to rustc_hashes so they can be shared ↵Ben Kimock-1/+2
with rust-analyzer
2025-02-15Don't project into `NonNull` when dropping a `Box`Scott McMurray-5/+9
2025-02-14Move `MirPatch` from `rustc_middle` to `rustc_mir_transform`.Nicholas Nethercote-259/+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-11Rollup merge of #136847 - nnethercote:simplify-intra-crate-quals, r=oli-obkMatthias Krüger-12/+14
Simplify intra-crate qualifiers. The following is a weird pattern for a file within `rustc_middle`: ``` use rustc_middle::aaa; use crate::bbb; ``` More sensible and standard would be this: ``` use crate::{aaa, bbb}; ``` I.e. we generally prefer using `crate::` to using a crate's own name. (Exceptions are things like in macros where `crate::` doesn't work because the macro is used in multiple crates.) This commit fixes a bunch of these weird qualifiers. r? `@jieyouxu`
2025-02-11Simplify intra-crate qualifiers.Nicholas Nethercote-12/+14
The following is a weird pattern for a file within `rustc_middle`: ``` use rustc_middle::aaa; use crate::bbb; ``` More sensible and standard would be this: ``` use crate::{aaa, bbb}; ``` I.e. we generally prefer using `crate::` to using a crate's own name. (Exceptions are things like in macros where `crate::` doesn't work because the macro is used in multiple crates.) This commit fixes a bunch of these weird qualifiers.
2025-02-10compiler: die immediately instead of handling unknown target codegenJubilee Young-4/+0
We cannot produce anything useful if asked to compile unknown targets. We should handle the error immediately at the point of discovery instead of propagating it upward, and preferably in the simplest way: Die. This allows cleaning up our "error-handling" spread across 5 crates.
2025-02-10Rollup merge of #136053 - Zalathar:defer-counters, r=saethlinJubilee-78/+67
coverage: Defer part of counter-creation until codegen Follow-up to #135481 and #135873. One of the pleasant properties of the new counter-assignment algorithm is that we can stop partway through the process, store the intermediate state in MIR, and then resume the rest of the algorithm during codegen. This lets it take into account which parts of the control-flow graph were eliminated by MIR opts, resulting in fewer physical counters and simpler counter expressions. Those improvements end up completely obsoleting much larger chunks of code that were previously responsible for cleaning up the coverage metadata after MIR opts, while also doing a more thorough cleanup job. (That change also unlocks some further simplifications that I've kept out of this PR to limit its scope.)
2025-02-09Rollup merge of #136722 - kornelski:visit-spans, r=chenyukangMatthias Krüger-3/+6
Visit all debug info in MIR Visitor I've been experimenting with simplifying debug info in MIR inliner, and discovered that MIR Visitor doesn't reliably visit all spans. This PR adds the missing visitor calls.
2025-02-09Auto merge of #136751 - bjorn3:update_rustfmt, r=Mark-Simulacrumbors-8/+11
Update bootstrap compiler and rustfmt The rustfmt version we previously used formats things differently from what the latest nightly rustfmt does. This causes issues for subtrees that get formatted both in-tree and in their own repo. Updating the rustfmt used in-tree solves those issues. Also bumped the bootstrap compiler as the stage0 update command always updates both at the same time.
2025-02-08occured -> occurredMichael Goulet-1/+1
2025-02-08Rustfmtbjorn3-8/+11
2025-02-08Visit fn_span of calls in MIR VisitorKornel-2/+4
2025-02-08super_local_decl should visit source_info before copying itKornel-1/+2
Visiting source_info first makes it consistent with other visitors
2025-02-07Remove Linkage::Appendingbjorn3-1/+0
It can only be used for certain LLVM internal variables like llvm.global_ctors which users are not allowed to define.
2025-02-07Remove Linkage::Privatebjorn3-1/+0
This is the same as Linkage::Internal except that it doesn't emit any symbol. Some backends may not support it and it isn't all that useful anyway.
2025-02-06coverage: Remove the old code for simplifying counters after MIR optsZalathar-31/+1
2025-02-06coverage: Defer part of counter-creation until codegenZalathar-31/+45
2025-02-06coverage: Store BCB node IDs in mappings, and resolve them in codegenZalathar-23/+28
Even though the coverage graph itself is no longer available during codegen, its nodes can still be used as opaque IDs.
2025-02-05Rollup merge of #136563 - nnethercote:clean-up-Trivials, r=lcnrJubilee-73/+1
Clean up `Trivial*Impls` macros They're currently quite messy. Details in the individual commit logs. r? `@lcnr`