about summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src/builder/mod.rs
AgeCommit message (Collapse)AuthorLines
2025-09-26fix doc comments to be more standardMarijn Schouten-5/+1
2025-09-01Introduce `MirDumper` and `MirWriter`.Nicholas Nethercote-14/+4
MIR dumping is a mess. There are lots of functions and entry points, e.g. `dump_mir`, `dump_mir_with_options`, `dump_polonius_mir`, `dump_mir_to_writer`. Also, it's crucial that `create_dump_file` is never called without `dump_enabled` first being checked, but there is no mechanism for ensuring this and it's hard to tell if it is satisfied on all paths. (`dump_enabled` is checked twice on some paths, however!) This commit introduces `MirWriter`, which controls the MIR writing, and encapsulates the `extra_data` closure and `options`. Two existing functions are now methods of this type. It sets reasonable defaults, allowing the removal of many `|_, _| Ok(())` closures. The commit also introduces `MirDumper`, which is layered on top of `MirWriter`, and which manages the creation of the dump files, encapsulating pass names, disambiguators, etc. Four existing functions are now methods of this type. - `MirDumper::new` will only succeed if dumps are enabled, and will return `None` otherwise, which makes it impossible to dump when you shouldn't. - It also sets reasonable defaults for various things like disambiguators, which means you no longer need to specify them in many cases. When they do need to be specified, it's now done via setter methods. - It avoids some repetition. E.g. `dump_nll_mir` previously specifed the pass name `"nll"` four times and the disambiguator `&0` three times; now it specifies them just once, to put them in the `MirDumper`. - For Polonius, the `extra_data` closure can now be specified earlier, which avoids having to pass some arguments through some functions.
2025-09-01Avoid unnecessary `mut`-ness for various closures.Nicholas Nethercote-1/+1
2025-08-21Rollup merge of #144780 - bjorn3:mir_build_debug, r=matthewjasperJacob Pratt-0/+22
Add a method to dump MIR in the middle of MIR building This makes it easier to debug issues with MIR building by inserting dump_for_debugging calls around the suspected code responsible for the bad MIR.
2025-08-15Port `#[custom_mir(..)]` to the new attribute systemSasha Pourcelot-4/+5
2025-08-13Also dump coverage infobjorn3-2/+2
2025-08-13Add a method to dump MIR in the middle of MIR buildingbjorn3-0/+22
This makes it easier to debug issues with MIR building by inserting dump_for_debugging calls around the suspected code responsible for the bad MIR.
2025-07-23Remove useless lifetime parameter.Camille GILLOT-5/+1
2025-05-30Reorder fields in `hir::ItemKind` variants.Nicholas Nethercote-1/+1
Specifically `TyAlias`, `Enum`, `Struct`, `Union`. So the fields match the textual order in the source code. The interesting part of the change is in `compiler/rustc_hir/src/hir.rs`. The rest is extremely mechanical refactoring.
2025-05-21Rollup merge of #141357 - dianne:unhardcode-unpretty-thir-tree-body-expr, ↵Matthias Krüger-4/+0
r=compiler-errors `unpretty=thir-tree`: don't require the final expr to be the body's value Two motivations for this: - I couldn't find a comment motivating this hard-coding. I can imagine it might be easier to read `unpretty=thir-flat` output if the final expression in the THIR is always the body's value, but if that's the reason, that should be the justification in the source. I can also imagine it's meant to check that all expressions will be visited by the pretty-printer, but the existing check doesn't quite do that either. - Guard patterns (#129967) contain expressions, so lowering params containing guard patterns may add more expressions to the THIR. Currently a body's params are lowered after its expression, so guard expressions in params would end up last, breaking this. As an alternative, the params could be lowered first (#141356).
2025-05-21`unpretty=thir-tree`: don't require the final expr to be the entrypointdianne-4/+0
2025-05-20typeck: catch `continue`s pointing to blocksdianne-2/+1
This taints the typeck results with errors if a `continue` is found not pointing to a loop, which fixes an ICE. A few things were going wrong here. First, since this wasn't caught in typeck, we'd end up building the THIR and then running liveness lints on ill-formed HIR. Since liveness assumes all `continue`s point to loops, it wasn't setting a live node for the `continue`'s destination. However, the fallback for this was faulty; it would create a new live node to represent the erroneous state after the analysis's RWU table had already been built. This would ICE if the new live node was used in operations, such as merging results from the arms of a match. I've removed this error-recovery since it was buggy, and we should really catch bad labels before liveness. I've also replaced an outdated comment about when liveness lints are run. At this point, I think the call to `check_liveness` could be moved elsewhere, but if it can be run when the typeck results are tainted by errors, it'll need some slight refactoring so it can bail out in that case. In lieu of that, I've added an assertion.
2025-05-04Initial support for dynamically linked cratesBryanskiy-1/+3
2025-04-17Replace infallible `name_or_empty` methods with fallible `name` methods.Nicholas Nethercote-1/+1
I'm removing empty identifiers everywhere, because in practice they always mean "no identifier" rather than "empty identifier". (An empty identifier is impossible.) It's better to use `Option` to mean "no identifier" because you then can't forget about the "no identifier" possibility. Some specifics: - When testing an attribute for a single name, the commit uses the `has_name` method. - When testing an attribute for multiple names, the commit uses the new `has_any_name` method. - When using `match` on an attribute, the match arms now have `Some` on them. In the tests, we now avoid printing empty identifiers by not printing the identifier in the `error:` line at all, instead letting the carets point out the problem.
2025-04-03Upvars HirIds always have the same owner, thus just use an ItemLocalIdOli Scherer-2/+6
2025-04-03Auto merge of #139234 - compiler-errors:query-tweak, r=oli-obkbors-2/+2
Misc query tweaks Remove some redundant work around `cache_on_disk` and `ensure_ok`, since `Result<(), ErrorGuaranteed>` queries don't need to cache or recompute their "value" if they are only used for their result.
2025-04-02Use return_result_from_ensure_ok a bit moreMichael Goulet-2/+2
2025-04-02Move methods from `Map` to `TyCtxt`, part 5.Nicholas Nethercote-1/+1
This eliminates all methods on `Map`. Actually removing `Map` will occur in a follow-up PR.
2025-03-18Move `hir::Item::ident` into `hir::ItemKind`.Nicholas Nethercote-1/+1
`hir::Item` has an `ident` field. - It's always non-empty for these item kinds: `ExternCrate`, `Static`, `Const`, `Fn`, `Macro`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`, Trait`, TraitAalis`. - It's always empty for these item kinds: `ForeignMod`, `GlobalAsm`, `Impl`. - For `Use`, it is non-empty for `UseKind::Single` and empty for `UseKind::{Glob,ListStem}`. All of this is quite non-obvious; the only documentation is a single comment saying "The name might be a dummy name in case of anonymous items". Some sites that handle items check for an empty ident, some don't. This is a very C-like way of doing things, but this is Rust, we have sum types, we can do this properly and never forget to check for the exceptional case and never YOLO possibly empty identifiers (or possibly dummy spans) around and hope that things will work out. The commit is large but it's mostly obvious plumbing work. Some notable things. - A similar transformation makes sense for `ast::Item`, but this is already a big change. That can be done later. - Lots of assertions are added to item lowering to ensure that identifiers are empty/non-empty as expected. These will be removable when `ast::Item` is done later. - `ItemKind::Use` doesn't get an `Ident`, but `UseKind::Single` does. - `lower_use_tree` is significantly simpler. No more confusing `&mut Ident` to deal with. - `ItemKind::ident` is a new method, it returns an `Option<Ident>`. It's used with `unwrap` in a few places; sometimes it's hard to tell exactly which item kinds might occur. None of these unwraps fail on the test suite. It's conceivable that some might fail on alternative input. We can deal with those if/when they happen. - In `trait_path` the `find_map`/`if let` is replaced with a loop, and things end up much clearer that way. - `named_span` no longer checks for an empty name; instead the call site now checks for a missing identifier if necessary. - `maybe_inline_local` doesn't need the `glob` argument, it can be computed in-function from the `renamed` argument. - `arbitrary_source_item_ordering::check_mod` had a big `if` statement that was just getting the ident from the item kinds that had one. It could be mostly replaced by a single call to the new `ItemKind::ident` method. - `ItemKind` grows from 56 to 64 bytes, but `Item` stays the same size, and that's what matters, because `ItemKind` only occurs within `Item`.
2025-03-12Move methods from `Map` to `TyCtxt`, part 4.Nicholas Nethercote-2/+2
Continuing the work from #137350. Removes the unused methods: `expect_variant`, `expect_field`, `expect_foreign_item`. Every method gains a `hir_` prefix.
2025-03-08Auto merge of #137502 - compiler-errors:global-asm-aint-mir-body, r=oli-obkbors-1/+2
Don't include global asm in `mir_keys`, fix error body synthesis r? oli-obk Fixes #137470 Fixes #137471 Fixes #137472 Fixes #137473 try-job: test-various try-job: x86_64-apple-2
2025-03-06Generate the right MIR for by use closuresSantiago Pastorino-2/+2
2025-03-06Construct MIR error body for global_asm correctlyMichael Goulet-1/+2
2025-02-22Make a fake body to store typeck results for global_asmMichael Goulet-1/+4
2025-02-21Put a `BlockTailInfo` in `BlockFrame::TailExpr`.Nicholas Nethercote-16/+5
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-18Move methods from `Map` to `TyCtxt`, part 2.Nicholas Nethercote-4/+3
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-01Rename `tcx.ensure_with_value()` to `tcx.ensure_done()`Zalathar-1/+1
2025-02-01Rename `tcx.ensure()` to `tcx.ensure_ok()`Zalathar-1/+1
2025-01-31Remove the `mir_build` hook.Nicholas Nethercote-4/+3
It was downgraded from a query in #122721 but it can just be a vanilla function because it's not called in `rustc_middle`.
2025-01-18Consolidate ad-hoc MIR lints into real pass-manager-based MIR lintsMichael Goulet-6/+1
2025-01-10mir_build: check annotated functions w/out callersDavid Wood-0/+2
2025-01-04rustc_intrinsic: support functions without body; they are implicitly marked ↵Ralf Jung-0/+14
as must-be-overridden
2024-12-19Rename Scope.id to Scope.local_id, remove trivial accessorMichael Goulet-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-12-17Explain why `build` was renamed to `builder`Zalathar-0/+5
2024-12-17Rename `rustc_mir_build::build` to `builder`Zalathar-0/+1135