about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
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-12/+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-12/+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-81/+33
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-11/+32
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-11/+11
- 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/+8
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/+7
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-17Rollup merge of #136671 - nnethercote:middle-limits, r=NadrierilMatthias Krüger-104/+4
Overhaul `rustc_middle::limits` In particular, to make `pattern_complexity` work more like other limits, which then enables some other simplifications. r? ``@Nadrieril``
2025-02-17Rollup merge of #136466 - nnethercote:start-removing-Map, r=cjgillotMatthias Krüger-76/+87
Start removing `rustc_middle::hir::map::Map` `rustc_middle::hir::map::Map` is now just a low-value wrapper around `TyCtxt`. This PR starts removing it. r? `@cjgillot`
2025-02-17Remove `TyCtxt::hir_krate`.Nicholas Nethercote-7/+1
It's a trivial wrapper around the `hir_crate` query with a small number of uses.
2025-02-17Overhaul the `intravisit::Map` trait.Nicholas Nethercote-20/+22
First of all, note that `Map` has three different relevant meanings. - The `intravisit::Map` trait. - The `map::Map` struct. - The `NestedFilter::Map` associated type. The `intravisit::Map` trait is impl'd twice. - For `!`, where the methods are all unreachable. - For `map::Map`, which gets HIR stuff from the `TyCtxt`. As part of getting rid of `map::Map`, this commit changes `impl intravisit::Map for map::Map` to `impl intravisit::Map for TyCtxt`. It's fairly straightforward except various things are renamed, because the existing names would no longer have made sense. - `trait intravisit::Map` becomes `trait intravisit::HirTyCtxt`, so named because it gets some HIR stuff from a `TyCtxt`. - `NestedFilter::Map` assoc type becomes `NestedFilter::MaybeTyCtxt`, because it's always `!` or `TyCtxt`. - `Visitor::nested_visit_map` becomes `Visitor::maybe_tcx`. I deliberately made the new trait and associated type names different to avoid the old `type Map: Map` situation, which I found confusing. We now have `type MaybeTyCtxt: HirTyCtxt`.
2025-02-17Move some `Map` methods onto `TyCtxt`.Nicholas Nethercote-54/+73
The end goal is to eliminate `Map` altogether. I added a `hir_` prefix to all of them, that seemed simplest. The exceptions are `module_items` which became `hir_module_free_items` because there was already a `hir_module_items`, and `items` which became `hir_free_items` for consistency with `hir_module_free_items`.
2025-02-17Remove unused `Map::hir_node_by_def_id` method.Nicholas Nethercote-4/+0
2025-02-17Rename `rustc_middle/src/hir/map/mod.rs` as `map.rs`.Nicholas Nethercote-0/+0
There is no need for the extra subdirectory, and this makes the `map` module consistent with its sibling modules `nested_filter` and `place`.
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-17Move `rustc_middle::limits` to `rustc_interface`.Nicholas Nethercote-100/+0
It's always good to make `rustc_middle` smaller. `rustc_interface` is the best destination, because it's the only crate that calls `get_recursive_limit`.
2025-02-17Improve comments about limits.Nicholas Nethercote-7/+8
2025-02-17Merge `get_limit` and `get_limit_size`.Nicholas Nethercote-13/+2
Thanks to the previous commit, they no longer need to be separate.
2025-02-17Add `pattern_complexity_limit` to `Limits`.Nicholas Nethercote-5/+15
It's similar to the other limits, e.g. obtained via `get_limit`. So it makes sense to handle it consistently with the other limits. We now use `Limit`/`usize` in most places instead of `Option<usize>`, so we use `Limit::new(usize::MAX)`/`usize::MAX` to emulate how `None` used to work. The commit also adds `Limit::unlimited`.