about summary refs log tree commit diff
path: root/compiler/rustc_middle
AgeCommit message (Collapse)AuthorLines
2025-02-21Rollup merge of #137204 - nnethercote:clarify-MIR-dialects-and-phases, ↵Matthias Krüger-60/+64
r=RalfJung Clarify MIR dialects and phases I found the existing code and docs hard to understand. r? `@Zalathar`
2025-02-21Move methods from Map to TyCtxt, part 3.Nicholas Nethercote-38/+40
Continuing the work from #137162. Every method gains a `hir_` prefix.
2025-02-21Store `TyCtxt` instead of `Map` in some iterators.Nicholas Nethercote-19/+19
2025-02-21Clarify a comment.Nicholas Nethercote-1/+1
2025-02-21Make `PassWhere` impl `Copy`.Nicholas Nethercote-1/+1
It's a very small and simple type.
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-21Rename `InternedObligationCauseCode`.Nicholas Nethercote-15/+17
It's a misleading name, because it's not interned.
2025-02-20Remove `BackendRepr::Uninhabited`, replaced with an `uninhabited: bool` ↵Zachary S-1/+2
field in `LayoutData`. Also update comments that refered to BackendRepr::Uninhabited.
2025-02-20Turn order dependent trait objects future incompat warning into a hard errorOli Scherer-52/+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-20Remove unused items from `query.rs`.Nicholas Nethercote-6/+0
2025-02-20Move `StatementAsExpression` to where it's actually used.Nicholas Nethercote-6/+0
Also minimize some visibilities in the destination file.
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-13/+7
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-19Auto merge of #136539 - matthewjasper:late-normalize-errors, r=compiler-errorsbors-1/+1
Emit dropck normalization errors in borrowck Borrowck generally assumes that any queries it runs for type checking will succeed, thinking that HIR typeck will have errored first if there was a problem. However as of #98641, dropck isn't run on HIR, so there's no direct guarantee that it doesn't error. While a type being well-formed might be expected to ensure that its fields are well-formed, this is not the case for types containing a type projection: ```rust pub trait AuthUser { type Id; } pub trait AuthnBackend { type User: AuthUser; } pub struct AuthSession<Backend: AuthnBackend> { data: Option<<<Backend as AuthnBackend>::User as AuthUser>::Id>, } pub trait Authz: Sized { type AuthnBackend: AuthnBackend<User = Self>; } pub fn run_query<User: Authz>(auth: AuthSession<User::AuthnBackend>) {} // ^ No User: AuthUser bound is required or inferred. ``` While improvements to trait solving might fix this in the future, for now we go for a pragmatic solution of emitting an error from borrowck (by rerunning dropck outside of a query) and making drop elaboration check if an error has been emitted previously before panicking for a failed normalization. Closes #103899 Closes #135039 r? `@compiler-errors` (feel free to re-assign)
2025-02-19Make fewer crates depend on rustc_ast_irMichael Goulet-13/+7
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-18Auto merge of #137235 - matthiaskrgr:rollup-2kjua2t, r=matthiaskrgrbors-95/+47
Rollup of 10 pull requests Successful merges: - #135711 (Do not ICE on default_field_value const with lifetimes) - #136599 (librustdoc: more usages of `Joined::joined`) - #136876 (Locking documentation updates) - #137000 (Deeply normalize item bounds in new solver) - #137126 (fix docs for inherent str constructors) - #137161 (Pattern Migration 2024: fix incorrect messages/suggestions when errors arise in macro expansions) - #137191 (Update mdbook and move error_index_generator) - #137203 (Improve MIR modification) - #137206 (Make E0599 a structured error) - #137218 (misc `layout_of` cleanup) r? `@ghost` `@rustbot` modify labels: rollup
2025-02-18Rollup merge of #137218 - lukas-code:layout_of_cleanup, r=compiler-errorsMatthias Krüger-25/+46
misc `layout_of` cleanup See individual commits for details. r? `@oli-obk` but feel free to reassign
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-18update `cfg(bootstrap)`Josh Stone-1/+0
2025-02-18Remove scrutinee_hir_id from ExprKind::Matchbjorn3-1/+0
It is unused
2025-02-18clean up layout error diagnosticsLukas Markeffsky-25/+25
- group the fluent slugs together - reword (internal-only) "too generic" error to be more in line with the other errors
2025-02-18document and test all `LayoutError` variantsLukas Markeffsky-0/+21
2025-02-18Auto merge of #137162 - nnethercote:remove-Map-2, r=Zalatharbors-97/+94
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-97/+94
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 #137168 - klensy:rc--, r=lcnrMatthias Krüger-3/+1
correct comment Rc was removed in #113573, so r? `@lcnr`
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-17Clean up dropck code a bitMatthew Jasper-1/+1
- Remove `Result` that couldn't be Err on valid compilation. - Always compute errors on failure.
2025-02-17Auto merge of #137164 - matthiaskrgr:rollup-dj5826k, r=matthiaskrgrbors-6/+9
Rollup of 7 pull requests Successful merges: - #137095 (Replace some u64 hashes with Hash64) - #137100 (HIR analysis: Remove unnecessary abstraction over list of clauses) - #137105 (Restrict DerefPure for Cow<T> impl to T = impl Clone, [impl Clone], str.) - #137120 (Enable `relative-path-include-bytes-132203` rustdoc-ui test on Windows) - #137125 (Re-add missing empty lines in the releases notes) - #137145 (use add-core-stubs / minicore for a few more tests) - #137149 (Remove SSE ABI from i586-pc-windows-msvc) r? `@ghost` `@rustbot` modify labels: rollup
2025-02-17correct commentklensy-3/+1
2025-02-17Rollup merge of #137100 - fmease:hirtylow-rm-clauses-wrapper, r=compiler-errorsMatthias Krüger-1/+1
HIR analysis: Remove unnecessary abstraction over list of clauses `rustc_hir_analysis::bounds::Bounds` with its methods is nowadays a paper-thin wrapper around `Vec<(Clause, Span)>`s and `Vec::push` essentially. Its existence slightly annoyed me (and I keep opening its corresp. file instead of the identically named `bounds.rs` in `hir_ty_lowering/` that I actually want most of the time :P). Opening to check if you agree with inlining it. r? compiler-errors or reassign
2025-02-17Rollup merge of #137095 - saethlin:use-hash64-for-hashes, r=workingjubileeMatthias Krüger-5/+8
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.