about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2023-05-31Document handling of StorageDead.Camille GILLOT-0/+15
2023-05-31Auto merge of #111913 - oli-obk:valtrees2, r=lcnrbors-2/+2
Only rewrite valtree-constants to patterns and keep other constants opaque Now that we can reliably fall back to comparing constants with `PartialEq::eq` to the match scrutinee, we can 1. eagerly try to convert constants to valtrees 2. then deeply convert the valtree to a pattern 3. if the to-valtree conversion failed, create an "opaque constant" pattern. This PR specifically avoids any behavioral changes or major cleanups. What we can now do as follow ups is * move the two remaining call sites to `destructure_mir_constant` off that query * make valtree to pattern conversion infallible * this needs to be done after careful analysis of the effects. There may be user visible changes from that. based on https://github.com/rust-lang/rust/pull/111768
2023-05-31Only rewrite valtree-constants to patterns and keep other constants opaqueOli Scherer-2/+2
2023-05-31Auto merge of #112070 - lcnr:disjoint-closure-capture-ub, r=oli-obkbors-3/+0
change `BorrowKind::Unique` to be a mutating `PlaceContext` fixes #112056 I believe that `BorrowKind::Unique` is a footgun in general, so I added a FIXME and opened https://github.com/rust-lang/rust/issues/112072. This is a bit too involved for this PR though.
2023-05-29unique borrows are mutating useslcnr-3/+0
2023-05-29EarlyBinder::new -> EarlyBinder::bindlcnr-7/+7
2023-05-29Enable ConstGoto pass by default.Camille GILLOT-1/+1
2023-05-29Enable SeparateConstSwitch by default.Camille GILLOT-2/+5
2023-05-29Visit bodies in RPO for const-prop.Camille GILLOT-7/+8
2023-05-29Stop marking locals as dead in ConstProp.Camille GILLOT-7/+1
2023-05-28Auto merge of #111813 - scottmcm:pretty-mir, r=cjgillotbors-0/+155
MIR: opt-in normalization of `BasicBlock` and `Local` numbering This doesn't matter at all for actual codegen, but after spending some time reading pre-codegen MIR, I was wishing I didn't have to jump around so much in reading post-inlining code. So this add two passes that are off by default for every mir level, but can be enabled (`-Zmir-enable-passes=+ReorderBasicBlocks,+ReorderLocals`) for humans.
2023-05-28Make EarlyBinder's inner value private; and fix all of the resulting errorsKyle Matsuda-2/+5
2023-05-28Replace EarlyBinder(x) with EarlyBinder::new(x)Kyle Matsuda-7/+7
2023-05-28Auto merge of #112026 - saethlin:misaligned-addrof, r=pnkfelixbors-0/+8
Don't check for misaligned raw pointer derefs inside Rvalue::AddressOf From https://github.com/rust-lang/rust/pull/112026#issuecomment-1565686697: rustc 1.70 (stable next week) added a Mir pass to add pointer alignment checks in debug mode. Adding these checks caused some crates to break, but that was expected, since they contain broken code (https://github.com/rust-lang/rust/issues/111487) for tracking that. However, the checks added are slightly more aggressive than they should have been. Specifically, they also check the place in an `addr_of!` expression. Whether lack of alignment there is or isn't UB is unclear. This PR modifies the pass to not affect those cases. I spot checked the crater regressions and the ones I saw were not the case that this PR is modifying. It still seems good to not land anything overaggressive though
2023-05-28Auto merge of #112001 - saethlin:enable-matchbranchsimplification, r=cjgillotbors-2/+7
Enable MatchBranchSimplification This pass is one of the small number of benefits from `-Zmir-opt-level=3` that has motivated rustc_codegen_cranelift to use it: https://github.com/rust-lang/rust/blob/19ed0aade60e1c1038fe40554bcd9d01b717effa/compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs#L244-L246 Cranelift's motivation for this is _runtime_ performance improvements in debug builds. Lifting this pass all the way to `-Zmir-opt-level=1` seems to come without significant perf overhead, so that's what I'm suggesting here.
2023-05-27Exclude Rvalue::AddressOf for raw pointer deref alignment checksBen Kimock-0/+8
2023-05-27Try enabling MatchBranchSimplificationBen Kimock-2/+7
2023-05-27Rollup merge of #111952 - cjgillot:drop-replace, r=WaffleLapkinGuillaume Gomez-12/+21
Remove DesugaringKind::Replace. A simple boolean flag is enough.
2023-05-25Remove DesugaringKind::Replace.Camille GILLOT-12/+21
2023-05-25Remove ExpnKind::Inlined.Camille GILLOT-18/+0
2023-05-25Auto merge of #111925 - Manishearth:rollup-z6z6l2v, r=Manishearthbors-2/+2
Rollup of 5 pull requests Successful merges: - #111741 (Use `ObligationCtxt` in custom type ops) - #111840 (Expose more information in `get_body_with_borrowck_facts`) - #111876 (Roll compiler_builtins to 0.1.92) - #111912 (Use `Option::is_some_and` and `Result::is_ok_and` in the compiler ) - #111915 (libtest: Improve error when missing `-Zunstable-options`) r? `@ghost` `@rustbot` modify labels: rollup
2023-05-24Rollup merge of #111912 - WaffleLapkin:is_some_and_in_the_compiler, ↵Manish Goregaokar-2/+2
r=petrochenkov Use `Option::is_some_and` and `Result::is_ok_and` in the compiler `.is_some_and(..)`/`.is_ok_and(..)` replace `.map_or(false, ..)` and `.map(..).unwrap_or(false)`, making the code more readable. This PR is a sibling of https://github.com/rust-lang/rust/pull/111873#issuecomment-1561316515
2023-05-24Rollup merge of #111121 - Zalathar:ra-false-positive, r=jackh726Matthias Krüger-2/+2
Work around `rust-analyzer` false-positive type errors rust-analyzer incorrectly reports two type errors in `debug.rs`: > expected &dyn Display, found &i32 > expected &dyn Display, found &i32 This is due to a known bug in r-a: (https://github.com/rust-lang/rust-analyzer/issues/11847). In these particular cases, changing `&0` to `&0i32` seems to be enough to avoid the bug.
2023-05-24Auto merge of #111673 - cjgillot:dominator-preprocess, r=cjgillot,tmiaskobors-30/+15
Preprocess and cache dominator tree Preprocessing dominators has a very strong effect for https://github.com/rust-lang/rust/pull/111344. That pass checks that assignments dominate their uses repeatedly. Using the unprocessed dominator tree caused a quadratic runtime (number of bbs x depth of the dominator tree). This PR also caches the dominator tree and the pre-processed dominators in the MIR cfg cache. Rebase of https://github.com/rust-lang/rust/pull/107157 cc `@tmiasko`
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-2/+2
2023-05-23Rollup merge of #111501 - WaffleLapkin:drivebycleanupuwu, r=oli-obkDylan DPC-32/+9
MIR drive-by cleanups Some random drive-by cleanups I did while working with MIR/THIR.
2023-05-21PR feedback: better comments and debug assertsScott McMurray-3/+19
2023-05-21MIR: opt-in normalization of `BasicBlock` and `Local` numberingScott McMurray-0/+139
2023-05-20Don't inline functions with unsized argsJakob Degen-3/+12
2023-05-20Rollup merge of #111619 - cjgillot:profile-pass, r=WaffleLapkinDylan DPC-6/+6
Add timings for MIR passes to profiling report This will help identify which pass is responsible for a regression.
2023-05-18Take MIR dataflow analyses by mutable reference.Jason Newcomb-32/+47
2023-05-17Auto merge of #111568 - scottmcm:undo-opt, r=WaffleLapkinbors-13/+0
Stop turning transmutes into discriminant reads in mir-opt Partially reverts #109612, as after #109993 these aren't actually equivalent any more, and I'm no longer confident this was ever an improvement in the first place. Having this "simplification" meant that similar-looking code actually did somewhat different things. For example, ```rust pub unsafe fn demo1(x: std::cmp::Ordering) -> u8 { std::mem::transmute(x) } pub unsafe fn demo2(x: std::cmp::Ordering) -> i8 { std::mem::transmute(x) } ``` in nightly today is generating <https://rust.godbolt.org/z/dPK58zW18> ```llvm define noundef i8 `@_ZN7example5demo117h341ef313673d2ee6E(i8` noundef %x) unnamed_addr #0 { %0 = icmp uge i8 %x, -1 %1 = icmp ule i8 %x, 1 %2 = or i1 %0, %1 call void `@llvm.assume(i1` %2) ret i8 %x } define noundef i8 `@_ZN7example5demo217h5ad29f361a3f5700E(i8` noundef %0) unnamed_addr #0 { %x = alloca i8, align 1 store i8 %0, ptr %x, align 1 %1 = load i8, ptr %x, align 1, !range !2, !noundef !3 ret i8 %1 } ``` Which feels too different when the original code is essentially identical. --- Aside: that example is different *after* optimizations too: ```llvm define noundef i8 `@_ZN7example5demo117h341ef313673d2ee6E(i8` noundef returned %x) unnamed_addr #0 { %0 = add i8 %x, 1 %1 = icmp ult i8 %0, 3 tail call void `@llvm.assume(i1` %1) ret i8 %x } define noundef i8 `@_ZN7example5demo217h5ad29f361a3f5700E(i8` noundef returned %0) unnamed_addr #1 { ret i8 %0 } ``` so turning the `Transmute` into a `Discriminant` was arguably just making things worse, so leaving it alone instead -- and thus having less code in rustc -- seems clearly better.
2023-05-17Rollup merge of #110930 - b-naber:normalize-elaborate-drops, r=cjgillotDylan DPC-1/+26
Don't expect normalization to succeed in elaborate_drops Fixes https://github.com/rust-lang/rust/issues/110682 This was exposed through the changes in https://github.com/rust-lang/rust/pull/109247, which causes more things to be inlined. Inlining can happen before monomorphization, so we can't expect normalization to succeed. In the elaborate_drops analysis we currently have [this call](https://github.com/rust-lang/rust/blob/033aa092ab23ba14cdad27073c5e37ba0eddb428/compiler/rustc_mir_dataflow/src/elaborate_drops.rs#L278) to `normalize_erasing_regions`, which ICEs when normalization fails. The types are used to infer [whether the type needs a drop](https://github.com/rust-lang/rust/blob/033aa092ab23ba14cdad27073c5e37ba0eddb428/compiler/rustc_mir_dataflow/src/elaborate_drops.rs#L374), where `needs_drop` itself [uses `try_normalize_erasing_regions`](https://github.com/rust-lang/rust/blob/033aa092ab23ba14cdad27073c5e37ba0eddb428/compiler/rustc_middle/src/ty/util.rs#L1121). ~[`instance_mir`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.instance_mir) isn't explicit about whether it expects the instances corresponding to the `InstanceDef`s to be monomorphized (though I think in all other contexts the function is used post-monomorphization), so the use of `instance_mir` in inlining doesn't necessarily seem wrong to me.~
2023-05-17Simplify back-edge logic.Camille GILLOT-1/+1
2023-05-17Do not clone dominator tree for SSA analysis.Camille GILLOT-11/+8
2023-05-17Drive-by cleanup: `debug::term_type` => `TerminatorKind::name`Maybe Waffle-32/+9
2023-05-17Merge DominatorTree and Dominators.Camille GILLOT-17/+8
2023-05-17Cache dominators.Camille GILLOT-2/+5
2023-05-17Preprocess dominator tree to answer queries in O(1)Tomasz Miąsko-30/+24
2023-05-16Auto merge of #111556 - cjgillot:copy-prop-nrvo, r=oli-obkbors-42/+50
Merge return place with other locals in CopyProp. This reintroduces a limited form of NRVO. r? wg-mir-opt
2023-05-16Rollup merge of #111533 - clubby789:drop-tracking-error, r=oli-obkMatthias Krüger-2/+3
Handle error body in generator layout Fixes #111468 I feel like making this query return `Option<GeneratorLayout>` might be better but had some issues with that approach
2023-05-15Profile MIR passes.Camille GILLOT-6/+6
2023-05-15Move expansion of query macros in rustc_middle to rustc_middle::queryJohn Kåre Alsaker-5/+5
2023-05-14Stop turning transmutes into discriminants in mir-optScott McMurray-13/+0
Partially reverts 109612, as after 109993 these aren't actually equivalent any more, and I'm no longer confident this was ever an improvement in the first place.
2023-05-14Simplify implementation.Camille GILLOT-22/+16
2023-05-14Merge return place with other locals in CopyProp.Camille GILLOT-20/+34
2023-05-14Auto merge of #111517 - lukas-code:addr-of-mutate, r=tmiaskobors-17/+17
allow mutating function args through `&raw const` Fixes https://github.com/rust-lang/rust/issues/111502 by "turning off the sketchy optimization while we figure out if this is ok", like `@JakobDegen` said. The first commit in this PR removes some suspicious looking logic from the same method, but should have no functional changes, since it doesn't modify the `context` outside of the method. Best reviewed commit by commit. r? opsem
2023-05-13Handle error body when in generator layoutclubby789-2/+3
2023-05-13Do not ICE on deeply nested borrows.Camille GILLOT-2/+4
2023-05-13Iterate ReferencePropagation to fixpoint.Camille GILLOT-2/+4