about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2025-01-08Don't create cycles by normalizing opaques defined in the body we're checkingMichael Goulet-1/+6
2025-01-06Transmute from NonNull to pointer when elaborating a box deref (MCP807)Scott McMurray-13/+14
2025-01-04Auto merge of #135031 - RalfJung:intrinsics-without-body, r=oli-obkbors-1/+2
rustc_intrinsic: support functions without body We synthesize a HIR body `loop {}` but such bodyless intrinsics. Most of the diff is due to turning `ItemKind::Fn` into a brace (named-field) enum variant, because it carries a `bool`-typed field now. This is to remember whether the function has a body. MIR building panics to avoid ever translating the fake `loop {}` body, and the intrinsic logic uses the lack of a body to implicitly mark that intrinsic as must-be-overridden. I first tried actually having no body rather than generating the fake body, but there's a *lot* of code that assumes that all function items have HIR and MIR, so this didn't work very well. Then I noticed that even `rustc_intrinsic_must_be_overridden` intrinsics have MIR generated (they are filled with an `Unreachable` terminator) so I guess I am not the first to discover this. ;) r? `@oli-obk`
2025-01-04rustc_intrinsic: support functions without body; they are implicitly marked ↵Ralf Jung-1/+2
as must-be-overridden
2025-01-03remove unused function paramsMatthias Krüger-19/+9
2024-12-27MatchBranchSimplification: Consider empty-unreachable otherwise branchclubby789-9/+21
2024-12-24Auto merge of #134625 - compiler-errors:unsafe-binders-ty, r=oli-obkbors-2/+5
Begin to implement type system layer of unsafe binders Mostly TODOs, but there's a lot of match arms that are basically just noops so I wanted to split these out before I put up the MIR lowering/projection part of this logic. r? oli-obk Tracking: - https://github.com/rust-lang/rust/issues/130516
2024-12-23Always run tail_expr_drop_order lint on promoted MIRMichael Goulet-1/+2
2024-12-22Begin to implement type system layer of unsafe bindersMichael Goulet-2/+5
2024-12-22Delete `Rvalue::Len`Scott McMurray-90/+1
Everything's moved to `PtrMetadata` instead.
2024-12-20coverage: Rename `basic_coverage_blocks` to just `graph`Zalathar-93/+61
During coverage instrumentation, this variable always holds the coverage graph, which is a simplified view of the MIR control-flow graph. The new name is clearer in context, and also shorter.
2024-12-19Rollup merge of #134497 - Zalathar:spans, r=jieyouxuMatthias Krüger-150/+18
coverage: Store coverage source regions as `Span` until codegen (take 2) This is an attempt to re-land #133418: > Historically, coverage spans were converted into line/column coordinates during the MIR instrumentation pass. > This PR moves that conversion step into codegen, so that coverage spans spend most of their time stored as Span instead. > In addition to being conceptually nicer, this also reduces the size of coverage mappings in MIR, because Span is smaller than 4x u32. That PR was reverted by #133608, because in some circumstances not covered by our test suite we were emitting coverage metadata that was causing `llvm-cov` to exit with an error (#133606). --- The implementation here is *mostly* the same, but adapted for subsequent changes in the relevant code (e.g. #134163). I believe that the changes in #134163 should be sufficient to prevent the problem that required the original PR to be reverted. But I haven't been able to reproduce the original breakage in a regression test, and the `llvm-cov` error message is extremely unhelpful, so I can't completely rule out the possibility of this breaking again. r? jieyouxu (reviewer of the original PR)
2024-12-19Rollup merge of #133702 - RalfJung:single-variant, r=oli-obk许杰友 Jieyou Xu (Joe)-25/+12
Variants::Single: do not use invalid VariantIdx for uninhabited enums ~~Stacked on top of https://github.com/rust-lang/rust/pull/133681, only the last commit is new.~~ Currently, `Variants::Single` for an empty enum contains a `VariantIdx` of 0; looking that up in the enum variant list will ICE. That's quite confusing. So let's fix that by adding a new `Variants::Empty` case for types that have 0 variants. try-job: i686-msvc
2024-12-19coverage: Store coverage source regions as `Span` until codegenZalathar-150/+18
2024-12-18mir-opt: Do not handle the cleanup BB in the EarlyOtherwiseBranchDianQK-0/+4
2024-12-18mir: require `is_cleanup` when creating `BasicBlockData`DianQK-15/+19
2024-12-18mir-opt: a sub-BB of a cleanup BB must also be a cleanup BBDianQK-1/+2
2024-12-18Reapply "Auto merge of #129047 - DianQK:early_otherwise_branch_scalar, ↵DianQK-85/+175
r=cjgillot" This reverts commit 16a02664e66afbfcd738b600d4a409e809040695.
2024-12-18make no-variant types a dedicated Variants variantRalf Jung-3/+3
2024-12-18Variants::Single: do not use invalid VariantIdx for uninhabited enumsRalf Jung-25/+12
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-8/+5
`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-16rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structuresJonathan Dönszelmann-2/+2
2024-12-14Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, ↵bors-21/+0
r=davidtwco,RalfJung Bounds-check with PtrMetadata instead of Len in MIR Rather than emitting `Len(*_n)` in array index bounds checks, emit `PtrMetadata(copy _n)` instead -- with some asterisks for arrays and `&mut` that need it to be done slightly differently. We're getting pretty close to removing `Len` entirely, actually. I think just one more PR after this (for slice drop shims). r? mir
2024-12-13Rollup merge of #133938 - nnethercote:rustc_mir_dataflow-renamings, r=oli-obkMatthias Krüger-24/+24
`rustc_mir_dataflow` cleanups, including some renamings Some opinionated commits in this collection, let's see how we go. r? `@cjgillot`
2024-12-13Auto merge of #133899 - scottmcm:strip-mir-debuginfo, r=oli-obkbors-0/+37
We don't need `NonNull::as_ptr` debuginfo In order to stop pessimizing the use of local variables in core, skip debug info for MIR temporaries in tiny (single-BB) functions. For functions as simple as this -- `Pin::new`, etc -- nobody every actually wants debuginfo for them in the first place. They're more like intrinsics than real functions, and stepping over them is good.
2024-12-13Stabilize async closuresMichael Goulet-2/+0
2024-12-10Implement projection and shim for AFIDTMichael Goulet-3/+53
2024-12-10We don't need `NonNull::as_ptr` debuginfoScott McMurray-0/+37
Stop pessimizing the use of local variables in core by skipping debug info for MIR temporaries in tiny (single-BB) functions. For functions as simple as this -- `Pin::new`, etc -- nobody every actually wants debuginfo for them in the first place. They're more like intrinsics than real functions, and stepping over them is good.
2024-12-10Rollup merge of #134029 - Zalathar:zero, r=oli-obkLeón Orell Valerian Liehr-5/+102
coverage: Use a query to find counters/expressions that must be zero As of #133446, this query (`coverage_ids_info`) determines which counter/expression IDs are unused. So with only a little extra work, we can take the code that was using that information to determine which coverage counters/expressions must be zero, and move that inside the query as well. There should be no change in compiler output.
2024-12-10Rollup merge of #133946 - Zalathar:ready-first, r=oli-obkLeón Orell Valerian Liehr-146/+125
coverage: Prefer to visit nodes whose predecessors have been visited In coverage instrumentation, we need to traverse the control-flow graph and decide what kind of counter (physical counter or counter-expression) should be used for each node that needs a counter. The existing traversal order is complex and hard to tweak. This new traversal order tries to be a bit more principled, by always preferring to visit nodes whose predecessors have already been visited, which is a good match for how the counter-creation code ends up dealing with a node's in-edges and out-edges. For several of the coverage tests, this ends up being a strict improvement in reducing the size of the coverage metadata, and also reducing the number of physical counters needed. (The new traversal should hopefully also allow some further code simplifications in the future.) --- This is made possible by the separate simplification pass introduced by #133849. Without that, almost any change to the traversal order ends up increasing the size of the expression table or the number of physical counters.
2024-12-10Rename some `Analysis` and `ResultsVisitor` methods.Nicholas Nethercote-8/+8
The words "before" and "after" have an obvious temporal meaning, e.g. `seek_before_primary_effect`, `visit_statement_{before,after}_primary_effect`. But "before" is also used to name the effect that occurs before the primary effect of a statement/terminator; this is `Effect::Before`. This leads to the confusing possibility of talking about things happening "before/after the before event". This commit removes this awkward overloading of "before" by renaming `Effect::Before` as `Effect::Early`. It also renames some of the `Analysis` and `ResultsVisitor` methods to be more consistent. Here are the before and after names: - `Effect::{Before,Primary}` -> `Effect::{Early,Primary}` - `apply_before_statement_effect` -> `apply_early_statement_effect` - `apply_statement_effect` -> `apply_primary_statement_effect` - `visit_statement_before_primary_effect` -> `visit_after_early_statement_effect` - `visit_statement_after_primary_effect` -> `visit_after_primary_statement_effect` (And s/statement/terminator/ for all the terminator events.)
2024-12-10Improve terminology in `elaborate_drops.rs`.Nicholas Nethercote-16/+16
It uses `MaybeInitializedPlaces` and `MaybeUninitializedPlaces`, but calls the results `live` and `dead`. This is very confusing given that there are also analyses called `MaybeLiveLocals` and `MaybeStorageLive` and `MaybeStorageDead`. This commit changes it to use `maybe_init` and `maybe_uninit`.
2024-12-09Rollup merge of #134073 - DianQK:fix-131227, r=oli-obkLeón Orell Valerian Liehr-2/+7
dataflow_const_prop: do not eval a ptr address in SwitchInt Fixes #131227.
2024-12-09dataflow_const_prop: do not eval a ptr address in SwitchIntDianQK-2/+7
2024-12-09Auto merge of #133891 - nnethercote:MixedBitSet, r=Mark-Simulacrumbors-26/+29
Introduce `MixedBitSet` `ChunkedBitSet` is good at avoiding excessive memory usage for programs with very large functgions where dataflow bitsets have very large domain sizes. But it's overly heavyweight for small bitsets, because any non-empty `ChunkedBitSet` takes up at least 256 bytes. This PR introduces `MixedBitSet`, which is a simple bitset that uses `BitSet` for small/medium bitsets and `ChunkedBitSet` for large bitsets. It's a speed and memory usage win. r? `@Mark-Simulacrum`
2024-12-08coverage: Use a query to find counters/expressions that must be zeroZalathar-4/+101
This query (`coverage_ids_info`) already determines which counter/expression IDs are unused, so it only takes a little extra effort to also determine which counters/expressions must have a value of zero.
2024-12-08coverage: Move `CoverageIdsInfo` into `mir::coverage`Zalathar-2/+2
2024-12-07coverage: Prefer to visit nodes whose predecessors have been visitedZalathar-146/+125
2024-12-05Change `ChunkedBitSet<MovePathIndex>`s to `MixedBitSet`.Nicholas Nethercote-26/+29
It's a performance win because `MixedBitSet` is faster and uses less memory than `ChunkedBitSet`. Also reflow some overlong comment lines in `lint_tail_expr_drop_order.rs`.
2024-12-04fn_sig_for_fn_abi should return a ty::FnSig, no need for a binderMichael Goulet-2/+2
2024-12-04coverage: Remove the expression simplifier from `CoverageCounters`Zalathar-51/+4
These simplifications are now handled by the transcribe step.
2024-12-04coverage: Use a separate counter type during counter creationZalathar-73/+94
2024-12-04coverage: Add an extra "transcribe" step after counter creationZalathar-3/+170
2024-12-04coverage: Use a single `make_phys_counter` methodZalathar-19/+4
This is more convenient for subsequent patches.
2024-12-04coverage: Rename `CounterIncrementSite` to just `Site`Zalathar-13/+14
A "site" is a node or edge in the coverage graph.
2024-12-04coverage: Extract `subtracted_sum` in counter creationZalathar-8/+8
2024-12-03Bounds-check with PtrMetadata instead of Len in MIRScott McMurray-21/+0
2024-12-02Rollup merge of #133732 - nnethercote:fix-Z-dump-mir-dataflow, r=compiler-errorsGuillaume Gomez-1/+1
Fix `-Zdump-mir-dataflow` r? `@cjgillot`
2024-12-02Rollup merge of #133751 - lcnr:no-trait-solving-on-type, r=compiler-errorsGuillaume Gomez-1/+1
remove `Ty::is_copy_modulo_regions` Using these functions is likely incorrect if an `InferCtxt` is available, I moved this function to `TyCtxt` (and added it to `LateContext`) and added a note to the documentation that one should prefer `Infer::type_is_copy_modulo_regions` instead. I didn't yet move `is_sized` and `is_freeze`, though I think we should move these as well. r? `@compiler-errors` cc #132279
2024-12-02remove `Ty::is_copy_modulo_regions`lcnr-1/+1