about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform
AgeCommit message (Collapse)AuthorLines
2023-06-06Write to stdout if `-` is given as output fileJing Peng-4/+11
If `-o -` or `--emit KIND=-` is provided, output will be written to stdout instead. Binary output (`obj`, `llvm-bc`, `link` and `metadata`) being written this way will result in an error unless stdout is not a tty. Multiple output types going to stdout will trigger an error too, as they will all be mixded together.
2023-06-05cleanup some skip_binder -> subst_identityKyle Matsuda-1/+1
2023-06-04Auto merge of #112240 - cjgillot:recurse-inline, r=scottmcmbors-3/+6
Only check inlining counter after recursing. This PR aims to reduce the strength of https://github.com/rust-lang/rust/pull/105119 even more. In the current implementation, we check the inline count before recursing. This means that we never actually reach inlining depth 3. This PR checks the counter after recursion, to give a chance to inline at depth >= 3. r? `@scottmcm` cc `@JakobDegen`
2023-06-03Only check inlining counter after recusing.Camille GILLOT-3/+6
2023-06-02Rollup merge of #112168 - scottmcm:lower-div-rem-unchecked-to-mir, r=oli-obkMichael Goulet-23/+28
Lower `unchecked_div`/`_rem` to MIR's `BinOp::Div`/`Rem` As described in <https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.BinOp.html#variant.Div>, the ordinary `BinOp`s for these are already UB for division by zero ([or overflow](https://llvm.org/docs/LangRef.html#sdiv-instruction), [demo](https://rust.godbolt.org/z/71e7P7Exh)), as MIR building is responsible for inserting code to panic for those cases regardless of whether the overflow checks are enabled. So we can lower these in the same arm that lowers `wrapping_add` to MIR `BinOp::Add` and such, as all these cases turn into ordinary `Rvalue::BinaryOp`s.
2023-06-02Separate AnonConst from ConstBlock in HIR.Camille GILLOT-4/+2
2023-06-02Auto merge of #111677 - fee1-dead-contrib:rustc_const_eval-translatable, ↵bors-7/+26
r=oli-obk,RalfJung Use translatable diagnostics in `rustc_const_eval` This PR: * adds a `no_span` parameter to `note` / `help` attributes when using `Subdiagnostic` to allow adding notes/helps without using a span * has minor tweaks and changes to error messages
2023-06-01Auto merge of #112040 - cjgillot:separate-const-switch, r=oli-obkbors-17/+30
Enable ConstGoto and SeparateConstSwitch passes by default These 2 passes implement a limited form of jump-threading. Filing this PR to see if enabling them would be lighter than https://github.com/rust-lang/rust/pull/107009.
2023-06-01fix diagnostic messageDeadbeef-2/+4
2023-06-01improve debug message by eagerly translatingDeadbeef-2/+2
2023-06-01Use translatable diagnostics in `rustc_const_eval`Deadbeef-7/+24
2023-06-01Auto merge of #112002 - saethlin:enable-sroa, r=oli-obk,scottmcmbors-5/+45
Enable ScalarReplacementOfAggregates in optimized builds Like MatchBranchSimplification, this pass is known to produce significant runtime improvements in Cranelift artifacts, and I believe based on the perf runs here that the primary effect of this pass is to empower MatchBranchSimplification. ScalarReplacementOfAggregates on its own has little effect on anything, but when this was rebased up to include https://github.com/rust-lang/rust/pull/112001 we started seeing significant and majority-positive results. Based on the fact that we see most of the regressions in debug builds (https://github.com/rust-lang/rust/pull/112002#issuecomment-1566270144) and some rather significant ones in cycles and wall time, I'm only enabling this in optimized builds at the moment.
2023-06-01Lower unchecked_{div, rem} to BinOp::{Div, Rem}Scott McMurray-23/+28
2023-05-31Enable ScalarReplacementOfAggregatesBen Kimock-5/+45
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-26Auto merge of #111858 - clubby789:fluent-alphabetical, r=jyn514,compiler-errorsbors-40/+41
Ensure Fluent messages are in alphabetical order Fixes #111847 This adds a tidy check to ensure Fluent messages are in alphabetical order, as well as sorting all existing messages. I think the error could be worded better, would appreciate suggestions. <details> <summary>Script used to sort files</summary> ```py import sys import re fn = sys.argv[1] with open(fn, 'r') as f: data = f.read().split("\n") chunks = [] cur = "" for line in data: if re.match(r"^([a-zA-Z0-9_]+)\s*=\s*", line): chunks.append(cur) cur = "" cur += line + "\n" chunks.append(cur) chunks.sort() with open(fn, 'w') as f: f.write(''.join(chunks).strip("\n\n") + "\n") ``` </details>
2023-05-25Ensure Fluent messages are in alphabetical orderclubby789-40/+41
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