about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2024-09-09Remove unnecessary lifetime from `OperandCollector`.Nicholas Nethercote-4/+4
Also put the remaining lifetimes into the usual order.
2024-09-09Remove unnecessary lifetimes in dataflow structs.Nicholas Nethercote-17/+17
There are four related dataflow structs: `MaybeInitializedPlaces`, `MaybeUninitializedPlaces`, and `EverInitializedPlaces`, `DefinitelyInitializedPlaces`. They all have a `&Body` and a `&MoveData<'tcx>` field. The first three use different lifetimes for the two fields, but the last one uses the same lifetime for both. This commit changes the first three to use the same lifetime, removing the need for one of the lifetimes. Other structs that also lose a lifetime as a result of this are `LivenessContext`, `LivenessResults`, `InitializationData`. It then does similar things in various other structs.
2024-09-09Improve consistency in `LowerIntrinsics`.Nicholas Nethercote-62/+63
In some cases `target` and `arg` are obtained fallibly, and in some cases they are obtained infallibly. This commit changes them all to infallible.
2024-09-09Use `LocalDecls` in a couple of places.Nicholas Nethercote-4/+2
It's nicer than the `IndexVec` type.
2024-09-09Make `CallSite` non-`Copy`.Nicholas Nethercote-1/+1
It doesn't need to be, and it's 72 bytes on 64-bit platforms, which is fairly large.
2024-09-09Remove some unnecessary dereferences.Nicholas Nethercote-3/+3
2024-09-09Remove an unnecessary `continue`.Nicholas Nethercote-1/+0
Nothing comes after it within the loop.
2024-09-09Use `let`/`else` to de-indent `ElaborateBoxDerefs::run_pass`.Nicholas Nethercote-47/+44
2024-09-09Simplify `verify_candidate_branch`.Nicholas Nethercote-37/+23
Let chains are perfect for this kind of function.
2024-09-09Streamline `AbortUnwindingCalls`.Nicholas Nethercote-27/+14
Currently it constructs two vectors `calls_to_terminated` and `cleanups_to_remove` in the main loop, and then processes them after the main loop. But the processing can be done in the main loop, avoiding the need for the vectors.
2024-09-09Factor out some more repetitive code.Nicholas Nethercote-9/+2
2024-09-09Reduce visibilities, and add `warn(unreachable_pub)`.Nicholas Nethercote-120/+125
Lots of unnecessary `pub`s in this crate. Most are downgraded to `pub(super)`, though some don't need any visibility.
2024-09-08add FIXME(const-hack)Ralf Jung-3/+3
2024-09-07Rollup merge of #129847 - compiler-errors:async-cycle, r=davidtwcoMatthias Krüger-1/+12
Do not call query to compute coroutine layout for synthetic body of async closure There is code in the MIR validator that attempts to prevent query cycles when inlining a coroutine into itself, and will use the coroutine layout directly from the body when it detects that's the same coroutine as the one that's being validated. After #128506, this logic didn't take into account the fact that the coroutine def id will differ if it's the "by-move body" of an async closure. This PR implements that. Fixes #129811
2024-09-07Don't build by-move body when async closure is taintedMichael Goulet-2/+9
2024-09-06Rollup merge of #130013 - jonathan-conder:await_coverage, r=ZalatharMatthias Krüger-34/+37
coverage: Count await when the Future is immediately ready Currently `await` is only counted towards coverage if the containing function is suspended and resumed at least once. This is because it expands to code which contains a branch on the discriminant of `Poll`. By treating it like a branching macro (e.g. `assert!`), these implementation details will be hidden from the coverage results. I added a test to ensure the fix works in simple cases, but the heuristic of picking only the first await-related covspan might be unreliable. I plan on testing more thoroughly with a real codebase over the next couple of weeks. closes #98712
2024-09-06Rollup merge of #129969 - GrigorenkoPV:boxed-ty, r=compiler-errorsMatthias Krüger-4/+8
Make `Ty::boxed_ty` return an `Option` Looks like a good place to use Rust's type system. --- Most of https://github.com/rust-lang/rust/blob/4ac7bcbaad8d6fd7a51bdf1b696cbc3ba4c796cf/compiler/rustc_middle/src/ty/sty.rs#L971-L1963 looks like it could be moved to `TyKind` (then I guess `Ty` should be made to deref to `TyKind`).
2024-09-06coverage: Treat await similar to a macroJonathan Conder-34/+37
Currently `await` is only counted towards coverage if the containing function is suspended and resumed at least once. This is because it expands to code which contains a branch on the discriminant of `Poll`. By treating it like a branching macro (e.g. `assert!`), these implementation details will be hidden from the coverage results.
2024-09-06Make `Ty::boxed_ty` return an `Option`Pavel Grigorenko-4/+8
2024-09-05Rollup merge of #129720 - nnethercote:simplify-dest_prop-mm, r=cjgillotMatthias Krüger-67/+46
Simplify DestProp memory management The DestProp MIR pass has some convoluted memory management. This PR simplifies it. r? ```@davidtwco```
2024-09-05Rollup merge of #129706 - compiler-errors:scratch, r=estebankMatthias Krüger-2/+3
Rename dump of coroutine by-move-body to be more consistent, fix ICE in dump_mir First, we add a missing match for `DefKind::SyntheticCoroutineBody` in `dump_mir`. Fixes #129703. The second commit (directly below) serves as a test. Second, we reorder the `dump_mir` in `coroutine_by_move_body_def_id` to be *after* we adjust the body source, and change the disambiguator so it reads more like any other MIR body. This also serves as a test for the ICE, since we're dumping the MIR of a body with `DefKind::SyntheticCoroutineBody`. Third, we change the parenting of the synthetic MIR body to have the *coroutine-closure* (i.e. async closure) as its parent, so we don't have long strings of `{closure#0}-{closure#0}-{closure#0}`. try-job: test-various
2024-09-04Re-parent the by-move bodyMichael Goulet-1/+2
2024-09-03Rename dump of coroutine by-move-body to be more consistent, adjust testMichael Goulet-1/+1
2024-09-03Rollup merge of #129926 - nnethercote:mv-SanityCheck-and-MirPass, r=cjgillotMatthias Krüger-93/+166
Move `SanityCheck` and `MirPass` They are currently in `rustc_middle`. This PR moves them to `rustc_mir_transform`, which makes more sense. r? ``@cjgillot``
2024-09-03Clarify a comment.Nicholas Nethercote-1/+2
2024-09-03Reduce visibility of `MirPass` and related things.Nicholas Nethercote-10/+10
They're now all just used within this crate.
2024-09-03Move `MirPass` to `rustc_mir_transform`.Nicholas Nethercote-84/+143
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.)
2024-09-03Adjust `SanityCheck`.Nicholas Nethercote-2/+15
The actual implementation remains in `rustc_mir_dataflow`, but this commit moves the `MirPass` impl to `rustc_mir_transform` and changes it to a `MirLint` (fixing a `FIXME` comment). (I originally tried moving the full implementation from `rustc_mir_dataflow` but I had some trait problems with `HasMoveData` and `RustcPeekAt` and `MaybeLiveLocals`. This commit was much smaller and simpler, but still will allow some follow-up cleanups.)
2024-09-02Rollup merge of #129877 - Sajjon:sajjon_fix_typos_batch_2, r=fee1-deadMatthias Krüger-15/+15
chore: Fix typos in 'compiler' (batch 2) Batch 2/3: Fixes typos in `compiler` (See [issue](https://github.com/rust-lang/rust/issues/129874) tracking all PRs with typos fixes)
2024-09-02chore: Fix typos in 'compiler' (batch 2)Alexander Cyon-15/+15
2024-09-02Rollup merge of #129738 - nnethercote:rustc_mir_transform-cleanups, r=cjgillotMatthias Krüger-202/+100
`rustc_mir_transform` cleanups A bunch of small improvements I made while looking closely at this code. r? `@saethlin`
2024-09-01Do not call query to compute coroutine layout for synthetic body of async ↵Michael Goulet-1/+12
closure
2024-08-31Rollup merge of #129812 - RalfJung:box-custom-alloc, r=compiler-errorsMatthias Krüger-0/+2
interpret, codegen: tweak some comments and checks regarding Box with custom allocator Cc https://github.com/rust-lang/rust/issues/95453
2024-08-31Rollup merge of #129767 - nnethercote:rm-extern-crate-tracing-4, r=jieyouxuMatthias Krüger-3/+39
Remove `#[macro_use] extern crate tracing`, round 4 Because explicit importing of macros via use items is nicer (more standard and readable) than implicit importing via #[macro_use]. Continuing the work from #124511, #124914, and #125434. After this PR no `rustc_*` crates use `#[macro_use] extern crate tracing` except for `rustc_codegen_gcc` which is a special case and I will do separately. r? ```@jieyouxu```
2024-08-31interpret, codegen: tweak some comments and checks regarding Box with custom ↵Ralf Jung-0/+2
allocator
2024-08-31Rollup merge of #129724 - nnethercote:rm-Option-bang, r=fee1-deadMatthias Krüger-66/+68
Remove `Option<!>` return types. Several compiler functions have `Option<!>` for their return type. That's odd. The only valid return value is `None`, so why is this type used? Because it lets you write certain patterns slightly more concisely. E.g. if you have these common patterns: ``` let Some(a) = f() else { return }; let Ok(b) = g() else { return }; ``` you can shorten them to these: ``` let a = f()?; let b = g().ok()?; ``` Huh. An `Option` return type typically designates success/failure. How should I interpret the type signature of a function that always returns (i.e. doesn't panic), does useful work (modifying `&mut` arguments), and yet only ever fails? This idiom subverts the type system for a cute syntactic trick. Furthermore, returning `Option<!>` from a function F makes things syntactically more convenient within F, but makes things worse at F's callsites. The callsites can themselves use `?` with F but should not, because they will get an unconditional early return, which is almost certainly not desirable. Instead the return value should be ignored. (Note that some of callsites of `process_operand`, `process_immedate`, `process_assign` actually do use `?`, though the early return doesn't matter in these cases because nothing of significance comes after those calls. Ugh.) When I first saw this pattern I had no idea how to interpret it, and it took me several minutes of close reading to understand everything I've written above. I even started a Zulip thread about it to make sure I understood it properly. "Save a few characters by introducing types so weird that compiler devs have to discuss it on Zulip" feels like a bad trade-off to me. This commit replaces all the `Option<!>` return values and uses `else`/`return` (or something similar) to replace the relevant `?` uses. The result is slightly more verbose but much easier to understand. r? ``````@cjgillot``````
2024-08-30Avoid repeated interning in `SelfArgVisitor`.Nicholas Nethercote-8/+10
2024-08-30Use `let`/`else` to reduce some indentation.Nicholas Nethercote-17/+16
2024-08-30Remove an unnecessary `continue`.Nicholas Nethercote-2/+0
2024-08-30Factor out some repetitive code.Nicholas Nethercote-81/+38
2024-08-30Remove some unnecessary constants.Nicholas Nethercote-18/+15
These are just renamings of `CoroutineArgs` constants.
2024-08-30Merge `DerefArgVisitor` and `PinArgVisitor`.Nicholas Nethercote-47/+7
They are almost identical, differing only in the `ProjectionElem` they insert. This commit merges them into a new type `SelfArgVisitor`.
2024-08-30Merge some `if`s.Nicholas Nethercote-24/+15
For more concise code.
2024-08-30Use a local variable.Nicholas Nethercote-1/+1
2024-08-30Simplify a pattern.Nicholas Nethercote-2/+1
2024-08-30Simplify creation of a set.Nicholas Nethercote-3/+1
2024-08-30Simplify a provider definition.Nicholas Nethercote-1/+1
2024-08-30Condense `use rustc_*` declarations.Nicholas Nethercote-3/+2
No reason to have two of them listed separately, after modules.
2024-08-30Remove unused features.Nicholas Nethercote-2/+0
2024-08-30Remove `#[macro_use] extern crate tracing` from `rustc_mir_transform`.Nicholas Nethercote-3/+39