about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform
AgeCommit message (Collapse)AuthorLines
2023-02-05Fix SROA without deaggregation.Camille GILLOT-45/+82
2023-02-04Turn projections into copies in CopyProp.Camille GILLOT-2/+2
2023-02-02Stop deaggegating MIR.Camille GILLOT-53/+0
2023-02-02Stop deaggregating enums in MIR.Camille GILLOT-39/+40
2023-02-02Handle aggregates in DataflowConstProp.Camille GILLOT-0/+25
2023-02-02Put a DefId in AggregateKind.Camille GILLOT-0/+1
2023-02-02Rollup merge of #107524 - cjgillot:both-storage, r=RalfJungMatthias Krüger-11/+14
Remove both StorageLive and StorageDead in CopyProp. Fixes https://github.com/rust-lang/rust/issues/107511 https://github.com/rust-lang/rust/pull/106908 removed StorageDead without the accompanying StorageLive. In loops, execution would see repeated StorageLive, without any StorageDead, which is UB. So when removing storage statements, we have to remove both StorageLive and StorageDead. ~I also added a MIR validation pass for StorageLive. It may be a bit overzealous.~
2023-02-01Auto merge of #107536 - GuillaumeGomez:rollup-xv7dx2h, r=GuillaumeGomezbors-6/+8
Rollup of 12 pull requests Successful merges: - #106898 (Include both md and yaml ICE ticket templates) - #107331 (Clean up eslint annotations and remove unused JS function) - #107348 (small refactor to new projection code) - #107354 (rustdoc: update Source Serif 4 from 4.004 to 4.005) - #107412 (avoid needless checks) - #107467 (Improve enum checks) - #107486 (Track bound types like bound regions) - #107491 (rustdoc: remove unused CSS from `.setting-check`) - #107508 (`Edition` micro refactor) - #107525 (PointeeInfo is advisory only) - #107527 (rustdoc: stop making unstable items transparent) - #107535 (Replace unwrap with ? in TcpListener doc) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-01-31Rollup merge of #107467 - WaffleLapkin:uneq, r=oli-obkGuillaume Gomez-6/+8
Improve enum checks Some light refactoring.
2023-01-31make unaligned_reference a hard errorRalf Jung-26/+17
2023-01-31Remove both StorageLive and StorageDead in CopyProp.Camille GILLOT-11/+14
2023-01-31Auto merge of #107443 - cjgillot:generator-less-query, r=compiler-errorsbors-1/+4
Test drop_tracking_mir before querying generator. r? `@ghost`
2023-01-30Rollup merge of #107172 - cjgillot:no-nal, r=nagisaMatthias Krüger-254/+70
Reimplement NormalizeArrayLen based on SsaLocals Based on https://github.com/rust-lang/rust/pull/106908 Fixes https://github.com/rust-lang/rust/issues/105929 Only the last commit "Reimplement NormalizeArrayLen" is relevant.
2023-01-30Replace some `_ == _ || _ == _`s with `matches!(_, _ | _)`sMaybe Waffle-2/+2
2023-01-30Use `Mutability::{is_mut, is_not}`Maybe Waffle-3/+2
2023-01-30Replace enum `==`s with `match`es where it makes senseMaybe Waffle-1/+4
2023-01-30Allow more deriving on packed structs.Nicholas Nethercote-40/+6
Currently, deriving on packed structs has some non-trivial limitations, related to the fact that taking references on unaligned fields is UB. The current approach to field accesses in derived code: - Normal case: `&self.0` - In a packed struct that derives `Copy`: `&{self.0}` - In a packed struct that doesn't derive `Copy`: `&self.0` Plus, we disallow deriving any builtin traits other than `Default` for any packed generic type, because it's possible that there might be misaligned fields. This is a fairly broad restriction. Plus, we disallow deriving any builtin traits other than `Default` for most packed types that don't derive `Copy`. (The exceptions are those where the alignments inherently satisfy the packing, e.g. in a type with `repr(packed(N))` where all the fields have alignments of `N` or less anyway. Such types are pretty strange, because the `packed` attribute is not having any effect.) This commit introduces a new, simpler approach to field accesses: - Normal case: `&self.0` - In a packed struct: `&{self.0}` In the latter case, this requires that all fields impl `Copy`, which is a new restriction. This means that the following example compiles under the old approach and doesn't compile under the new approach. ``` #[derive(Debug)] struct NonCopy(u8); #[derive(Debug) #[repr(packed)] struct MyType(NonCopy); ``` (Note that the old approach's support for cases like this was brittle. Changing the `u8` to a `u16` would be enough to stop it working. So not much capability is lost here.) However, the other constraints from the old rules are removed. We can now derive builtin traits for packed generic structs like this: ``` trait Trait { type A; } #[derive(Hash)] #[repr(packed)] pub struct Foo<T: Trait>(T, T::A); ``` To allow this, we add a `T: Copy` bound in the derived impl and a `T::A: Copy` bound in where clauses. So `T` and `T::A` must impl `Copy`. We can now also derive builtin traits for packed structs that don't derive `Copy`, so long as the fields impl `Copy`: ``` #[derive(Hash)] #[repr(packed)] pub struct Foo(u32); ``` This includes types that hand-impl `Copy` rather than deriving it, such as the following, that show up in winapi-0.2: ``` #[derive(Clone)] #[repr(packed)] struct MyType(i32); impl Copy for MyType {} ``` The new approach is simpler to understand and implement, and it avoids the need for the `unsafe_derive_on_repr_packed` check. One exception is required for backwards-compatibility: we allow `[u8]` fields for now. There is a new lint for this, `byte_slice_in_packed_struct_with_derive`.
2023-01-30Treat Drop as a rmw operationGiacomo Pasini-0/+29
Previously, a Drop terminator was considered a move in MIR. This commit changes the behavior to only treat Drop as a mutable access to the dropped place. In order for this change to be correct, we need to guarantee that a) A dropped value won't be used again b) Places that appear in a drop won't be used again before a subsequent initialization. We can ensure this to be correct at MIR construction because Drop will only be emitted when a variable goes out of scope, thus having: (a) as there is no way of reaching the old value. drop-elaboration will also remove any uninitialized drop. (b) as the place can't be named following the end of the scope. However, the initialization status, previously tracked by moves, should also be tied to the execution of a Drop, hence the additional logic in the dataflow analyses.
2023-01-29Remove obsolete comment.Camille GILLOT-1/+0
2023-01-29Reimplement NormalizeArrayLen.Camille GILLOT-253/+70
2023-01-29Test drop_tracking_mir before querying generator.Camille GILLOT-1/+4
2023-01-29Auto merge of #106908 - cjgillot:copyprop-ssa, r=oli-obkbors-4/+420
Implement simple CopyPropagation based on SSA analysis This PR extracts the "copy propagation" logic from https://github.com/rust-lang/rust/pull/106285. MIR may produce chains of assignment between locals, like `_x = move? _y`. This PR attempts to remove such chains by unifying locals. The current implementation is a bit overzealous in turning moves into copies, and in removing storage statements.
2023-01-29Auto merge of #106227 - bryangarza:ctfe-limit, r=oli-obkbors-1/+72
Use stable metric for const eval limit instead of current terminator-based logic This patch adds a `MirPass` that inserts a new MIR instruction `ConstEvalCounter` to any loops and function calls in the CFG. This instruction is used during Const Eval to count against the `const_eval_limit`, and emit the `StepLimitReached` error, replacing the current logic which uses Terminators only. The new method of counting loops and function calls should be more stable across compiler versions (i.e., not cause crates that compiled successfully before, to no longer compile when changes to the MIR generation/optimization are made). Also see: #103877
2023-01-29Auto merge of #107406 - cjgillot:eliminate-witnesses, r=compiler-errorsbors-17/+18
Only compute mir_generator_witnesses query in drop_tracking_mir mode. Attempt to fix the perf regression in https://github.com/rust-lang/rust/pull/101692 r? `@ghost`
2023-01-28Remove `HirId -> LocalDefId` map from HIR.Camille GILLOT-1/+2
2023-01-28Take a LocalDefId in hir::Visitor::visit_fn.Camille GILLOT-1/+1
2023-01-28Only compute mir_generator_witnesses query in drop_tracking_mir mode.Camille GILLOT-17/+18
2023-01-27Restrict amount of ignored locals.Camille GILLOT-9/+28
2023-01-27Separate witness type computation from the generator transform.Camille GILLOT-28/+286
2023-01-27Remember where a type was kept in MIR.Camille GILLOT-4/+13
2023-01-27Use successor location for dominator check.Camille GILLOT-1/+1
The assignment is complete only after the statement. This marks self-assignments `x = x + 1` as non-sSA.
2023-01-27Do not merge locals that have their address taken.Camille GILLOT-17/+65
2023-01-27Extract SsaLocals abstraction.Camille GILLOT-175/+240
2023-01-27Pacify tidy.Camille GILLOT-3/+3
2023-01-27Discard raw pointers from SSA locals.Camille GILLOT-2/+4
2023-01-27Only consider a local to be SSA if assignment dominates all uses.Camille GILLOT-2/+21
2023-01-27Implement SSA CopyProp pass.Camille GILLOT-0/+269
2023-01-27Allow to remove unused definitions without renumbering locals.Camille GILLOT-2/+14
2023-01-27Consider `CopyForDeref` for DestProp.Camille GILLOT-2/+3
2023-01-26fix up subst_identity vs skip_binder; add some FIXMEs as identified in reviewKyle Matsuda-1/+2
2023-01-26change fn_sig query to use EarlyBinder; remove bound_fn_sig query; add ↵Kyle Matsuda-8/+7
EarlyBinder to fn_sig in metadata
2023-01-26replace usages of fn_sig query with bound_fn_sigKyle Matsuda-3/+8
2023-01-26Disable ConstGoto opt in cleanup blocksJakob Degen-0/+9
2023-01-26Auto merge of #105582 - saethlin:instcombine-assert-inhabited, r=cjgillotbors-2/+84
InstCombine away intrinsic validity assertions This optimization (currently) fires 246 times on the standard library. It seems to fire hardly at all on the big crates in the benchmark suite. Interesting.
2023-01-24Delete `SimplifyArmIdentity` and `SimplifyBranchSame` mir optsJakob Degen-825/+0
2023-01-23Thread a ParamEnv down to might_permit_raw_initBen Kimock-8/+15
2023-01-24Improve efficiency of has_back_edge(...)Bryan Garza-10/+11
2023-01-23Add comments and remove unnecessary codeBryan Garza-0/+2
2023-01-23Move CtfeLimit MirPass to inner_mir_for_ctfeBryan Garza-1/+2
2023-01-23Revert "Move CtfeLimit to mir_const's set of passes"Bryan Garza-1/+1
This reverts commit 332542a92223b2800ed372d2d461921147f29477.