about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2024-06-22GVN away PtrToPtr before comparisonsScott McMurray-12/+47
Notably this happens in `NonNull::eq` :/
2024-06-22Add a `pointee_metadata_ty_or_projection` helperScott McMurray-14/+5
2024-06-21Save 2 pointers in `TerminatorKind` (96 → 80 bytes)Scott McMurray-52/+46
These things don't need to be `Vec`s; boxed slices are enough. The frequent one here is call arguments, but MIR building knows the number of arguments from the THIR, so the collect is always getting the allocation right in the first place, and thus this shouldn't ever add the shrink-in-place overhead.
2024-06-21Auto merge of #125853 - tesuji:promote-fail-fast, r=cjgillotbors-17/+15
promote_consts: some clean-up after experimenting This is some clean-up after experimenting in #125916, Prefer to review commit-by-commit.
2024-06-21Reuse allocation for Vec<Candidate>Lzu Tao-6/+3
2024-06-20Replace `NormalizeArrayLen` with `GVN`Scott McMurray-123/+8
GVN is actually on in release, and covers all the same things (or more), with `LowerSliceLen` changed to produce `PtrMetadata`.
2024-06-20More GVN for PtrMetadataScott McMurray-12/+93
`PtrMetadata` doesn't care about `*const`/`*mut`/`&`/`&mut`, so GVN away those casts in its argument. This includes updating MIR to allow calling PtrMetadata on references too, not just raw pointers. That means that `[T]::len` can be just `_0 = PtrMetadata(_1)`, for example. # Conflicts: # tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir # tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir
2024-06-20Add a try_as_constant+try_as_local helperScott McMurray-19/+19
No behaviour changes.
2024-06-21Auto merge of #126578 - scottmcm:inlining-bonuses-too, r=davidtwcobors-31/+75
Account for things that optimize out in inlining costs This updates the MIR inlining `CostChecker` to have both bonuses and penalties, rather than just penalties. That lets us add bonuses for some things where we want to encourage inlining without risking wrapping into a gigantic cost. For example, `switchInt(const …)` we give an inlining bonus because codegen will actually eliminate the branch (and associated dead blocks) once it's monomorphized, so measuring both sides of the branch gives an unrealistically-high cost to it. Similarly, an `unreachable` terminator gets a small bonus, because whatever branch leads there doesn't actually exist post-codegen.
2024-06-20Auto merge of #126736 - matthiaskrgr:rollup-rb20oe3, r=matthiaskrgrbors-1/+4
Rollup of 7 pull requests Successful merges: - #126380 (Add std Xtensa targets support) - #126636 (Resolve Clippy `f16` and `f128` `unimplemented!`/`FIXME`s ) - #126659 (More status-quo tests for the `#[coverage(..)]` attribute) - #126711 (Make Option::as_[mut_]slice const) - #126717 (Clean up some comments near `use` declarations) - #126719 (Fix assertion failure for some `Expect` diagnostics.) - #126730 (Add opaque type corner case test) r? `@ghost` `@rustbot` modify labels: rollup
2024-06-20Rollup merge of #126717 - nnethercote:rustfmt-use-pre-cleanups, r=jieyouxuMatthias Krüger-1/+4
Clean up some comments near `use` declarations #125443 will reformat all `use` declarations in the repository. There are a few edge cases involving comments on `use` declarations that require care. This PR cleans up some clumsy comment cases, taking us a step closer to #125443 being able to merge. r? ``@lqd``
2024-06-20Auto merge of #116088 - nbdd0121:unwind, r=Amanieu,RalfJungbors-33/+1
Stabilise `c_unwind` Fix #74990 Fix #115285 (that's also where FCP is happening) Marking as draft PR for now due to `compiler_builtins` issues r? `@Amanieu`
2024-06-19Give inlining bonuses to things that optimize outScott McMurray-20/+63
2024-06-19Give `CostChecker` both penalties and bonusesScott McMurray-15/+16
2024-06-20Add blank lines after module-level `//!` comments.Nicholas Nethercote-1/+4
Most modules have such a blank line, but some don't. Inserting the blank line makes it clearer that the `//!` comments are describing the entire module, rather than the `use` declaration(s) that immediately follows.
2024-06-19Ban `ArrayToPointer` and `MutToConstPointer` from runtime MIRScott McMurray-12/+31
Apparently MIR borrowck cares about at least one of these for checking variance. In runtime MIR, though, there's no need for them as `PtrToPtr` does the same thing. (Banning them simplifies passes like GVN that no longer need to handle multiple cast possibilities.)
2024-06-19Stabilise c_unwindGary Guo-33/+1
2024-06-18Auto merge of #126623 - oli-obk:do_not_count_errors, r=davidtwcobors-1/+1
Replace all `&DiagCtxt` with a `DiagCtxtHandle<'_>` wrapper type r? `@davidtwco` This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle Basically I will add a field to the `DiagCtxtHandle` that refers back to the `InferCtxt`'s (and others) `Option<ErrorHandled>`, allowing us to immediately taint these contexts when emitting an error and not needing manual tainting anymore (which is easy to forget and we don't do in general anyway)
2024-06-18Remove redundant argument from `subdiagnostic` methodOli Scherer-1/+1
2024-06-18Rollup merge of #126587 - Zalathar:no-mir-spans, r=oli-obkGuillaume Gomez-16/+25
coverage: Add debugging flag `-Zcoverage-options=no-mir-spans` When set, this flag skips the code that normally extracts coverage spans from MIR statements and terminators. That sometimes makes it easier to debug branch coverage and MC/DC coverage instrumentation, because the coverage output is less noisy. For internal debugging only. If future code changes would make it hard to keep supporting this flag, it should be removed at that time. `@rustbot` label +A-code-coverage
2024-06-17Rollup merge of #126567 - compiler-errors:instance-kind, r=oli-obk,lcnrMatthias Krüger-72/+75
Rename `InstanceDef` -> `InstanceKind` Renames `InstanceDef` to `InstanceKind`. The `Def` here is confusing, and makes it hard to distinguish `Instance` and `InstanceDef`. `InstanceKind` makes this more obvious, since it's really just describing what *kind* of instance we have. Not sure if this is large enough to warrant a types team MCP -- it's only 53 files. I don't personally think it does, but happy to write one if anyone disagrees. cc ``@rust-lang/types`` r? types
2024-06-17coverage: Add debugging flag `-Zcoverage-options=no-mir-spans`Zalathar-16/+25
When set, this flag skips the code that normally extracts coverage spans from MIR statements and terminators. That sometimes makes it easier to debug branch coverage and MC/DC coverage, because the coverage output is less noisy. For internal debugging only. If other code changes would make it hard to keep supporting this flag, remove it.
2024-06-17Rollup merge of #126538 - Zalathar:graph, r=nnethercote许杰友 Jieyou Xu (Joe)-154/+46
coverage: Several small improvements to graph code This PR combines a few small improvements to coverage graph handling code: - Remove some low-value implementation tests that were getting in the way of other changes. - Clean up `pub` visibility. - Flatten some code using let-else. - Prefer `.copied()` over `.cloned()`. `@rustbot` label +A-code-coverage
2024-06-16Rename InstanceDef -> InstanceKindMichael Goulet-72/+75
2024-06-16promote_consts: eargerly return when there are no candidatesLzu Tao-0/+5
There is no need to do it when mustn't.
2024-06-16prefer tracing::instrument over debug stringsLzu Tao-11/+7
2024-06-16coverage: Prefer `Iterator::copied`Zalathar-1/+1
2024-06-16coverage: Flatten some graph code with let-elseZalathar-18/+17
2024-06-16coverage: Reduce/simplify visibility in `coverage::graph`Zalathar-24/+28
Using `pub(super)` makes it harder to move code between modules, and doesn't provide much privacy benefit over `pub(crate)`.
2024-06-16coverage: Remove some old low-value unit tests for graph traversalZalathar-111/+0
These tests might have originally been useful as an implementation aid, but now they don't provide enough value to justify the burden of updating them as the underlying code changes. The code they test is still exercised by the main end-to-end coverage tests.
2024-06-16coverage: Split span refinement into two separate stepsZalathar-10/+12
2024-06-16coverage: Split out a function for dividing coverage spans into bucketsZalathar-34/+52
2024-06-16coverage: Eagerly convert coverage spans to a simpler formZalathar-49/+55
2024-06-16coverage: Move most span processing back into `coverage::spans`Zalathar-155/+157
2024-06-16coverage: More consistent variable names for span processingZalathar-25/+25
2024-06-15Rollup merge of #126410 - RalfJung:smir-const-operand, r=oli-obkGuillaume Gomez-7/+7
smir: merge identical Constant and ConstOperand types The first commit renames the const operand visitor functions on regular MIR to match the type name, that was forgotten in the original rename. The second commit changes stable MIR, fixing https://github.com/rust-lang/project-stable-mir/issues/71. Previously there were two different smir types for the MIR type `ConstOperand`, one used in `Operand` and one in `VarDebugInfoContents`. Maybe we should have done this with https://github.com/rust-lang/rust/pull/125967, so there's only a single breaking change... but I saw that PR too late. Fixes https://github.com/rust-lang/project-stable-mir/issues/71
2024-06-15Rollup merge of #126354 - compiler-errors:variance, r=lcnrMatthias Krüger-21/+6
Use `Variance` glob imported variants everywhere Fully commit to using the globbed variance. Could be convinced the other way, and change this PR to not use the globbed variants anywhere, but I'd rather we do one or the other. r? lcnr
2024-06-14Use is_lang_item more aggressivelyMichael Goulet-4/+7
2024-06-13Rollup merge of #126392 - WaffleLapkin:gvn-style-ish-changes, r=scottmcmMatthias Krüger-2/+1
Small style improvement in `gvn.rs` Allowed by https://github.com/rust-lang/rust/pull/110451#discussion_r1169298319. :P r? ``@scottmcm``
2024-06-13MIR visitor: constant -> const_operandRalf Jung-7/+7
2024-06-13Small style improvement in `gvn.rs`Waffle Lapkin-2/+1
2024-06-12Use Variance glob import everywhereMichael Goulet-21/+6
2024-06-12Rollup merge of #126294 - Zalathar:spans-refiner, r=oli-obkGuillaume Gomez-203/+36
coverage: Replace the old span refiner with a single function As more and more of the span refiner's functionality has been pulled out into separate early passes, it has finally reached the point where we can remove the rest of the old `SpansRefiner` code, and replace it with a single modestly-sized function. ~~There should be no change to the resulting coverage mappings, as demonstrated by the lack of changes to test output.~~ There is *almost* no change to the resulting coverage mappings. There are some minor changes to `loop` that on inspection appear to be neutral in terms of accuracy, with the old behaviour being a slightly-horrifying implementation detail of the old code, so I think they're acceptable. Previous work in this direction includes: - #125921 - #121019 - #119208
2024-06-12coverage: Replace the old span refiner with a single functionZalathar-203/+36
As more and more of the span refiner's functionality has been pulled out into separate early passes, it has finally reached the point where we can remove the rest of the old `SpansRefiner` code, and replace it with a single modestly-sized function.
2024-06-12Use `tidy` to sort crate attributes for all compiler crates.Nicholas Nethercote-1/+3
We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
2024-06-11Auto merge of #125910 - scottmcm:single-use-consts, r=saethlinbors-104/+201
Add `SingleUseConsts` mir-opt pass The goal here is to make a pass that can be run in debug builds to simplify the common case of constants that are used just once -- that doesn't need SSA handling and avoids any potential downside of multi-use constants. In particular, to simplify the `if T::IS_ZST` pattern that's common in the standard library. By also handling the case of constants that are *never* actually used this fully replaces the `ConstDebugInfo` pass, since it has all the information needed to do that naturally from the traversal it needs to do anyway. This is roughly a wash on instructions on its own (a couple regressions, a few improvements https://github.com/rust-lang/rust/pull/125910#issuecomment-2144963361), with a bunch of size improvements. So I'd like to land it as its own PR, then do follow-ups to take more advantage of it (in the inliner, cg_ssa, etc). r? `@saethlin`
2024-06-10Rollup merge of #126159 - RalfJung:scalarint-size-mismatch, r=oli-obkMatthias Krüger-25/+21
ScalarInt: size mismatches are a bug, do not delay the panic Cc [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Why.20are.20ScalarInt.20to.20iN.2FuN.20methods.20fallible.3F) r? ``@oli-obk``
2024-06-10ScalarInt: size mismatches are a bug, do not delay the panicRalf Jung-25/+21
2024-06-10Delete `ConstDebugInfo` passScott McMurray-105/+0
2024-06-10Try keeping a bitset for which locals need debuginfo updatesScott McMurray-7/+11