about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src/match_branches.rs
AgeCommit message (Collapse)AuthorLines
2025-05-26mir-opt: Do not transform non-int type in match_branchesdianqk-2/+4
2025-04-20mir-opt: Use one MirPatch in MatchBranchSimplificationdianqk-23/+14
2025-04-19Rollup merge of #139042 - compiler-errors:do-not-optimize-switchint, r=saethlinChris Denton-1/+1
Do not remove trivial `SwitchInt` in analysis MIR This PR ensures that we don't prematurely remove trivial `SwitchInt` terminators which affects both the borrow-checking and runtime semantics (i.e. UB) of the code. Previously the `SimplifyCfg` optimization was removing `SwitchInt` terminators when they was "trivial", i.e. when all arms branched to the same basic block, even if that `SwitchInt` terminator had the side-effect of reading an operand which (for example) may not be initialized or may point to an invalid place in memory. This behavior is unlike all other optimizations, which are only applied after "analysis" (i.e. borrow-checking) is finished, and which Miri disables to make sure the compiler doesn't silently remove UB. Fixing this code "breaks" (i.e. unmasks) code that used to borrow-check but no longer does, like: ```rust fn foo() { let x; let (0 | _) = x; } ``` This match expression should perform a read because `_` does not shadow the `0` literal pattern, and the compiler should have to read the match scrutinee to compare it to 0. I've checked that this behavior does not actually manifest in practice via a crater run which came back clean: https://github.com/rust-lang/rust/pull/139042#issuecomment-2767436367 As a side-note, it may be tempting to suggest that this is actually a good thing or that we should preserve this behavior. If we wanted to make this work (i.e. trivially optimize out reads from matches that are redundant like `0 | _`), then we should be enabling this behavior *after* fixing this. However, I think it's kinda unprincipled, and for example other variations of the code don't even work today, e.g.: ```rust fn foo() { let x; let (0.. | _) = x; } ```
2025-04-12In `rustc_mir_tranform`, iterate over index newtypes instead of intsYotam Ofek-9/+8
2025-04-08Do not optimize out SwitchInt before borrowck, or if Zmir-preserve-ubMichael Goulet-1/+1
2025-03-15Stop relying on rustc_type_ir in non-type-system cratesMichael Goulet-5/+4
2025-02-14Move `MirPatch` from `rustc_middle` to `rustc_mir_transform`.Nicholas Nethercote-1/+1
Because it's only used in `rustc_mir_transform`. (Presumably it is currently in `rustc_middle` because lots of other MIR-related stuff is, but that's not a hard requirement.) And because `rustc_middle` is huge and it's always good to make it smaller.
2025-01-23Disable non-required MIR opts with `optimize(none)`clubby789-0/+4
Co-authored-by: Waffle Lapkin <waffle.lapkin@gmail.com>
2024-12-27MatchBranchSimplification: Consider empty-unreachable otherwise branchclubby789-9/+21
2024-11-26Remove -Zfuel.Camille GILLOT-5/+0
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-24/+32
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-03compiler: Directly use rustc_abi in mir_transformJubilee Young-1/+1
2024-09-13Rename and reorder lots of lifetimes.Nicholas Nethercote-1/+1
- Replace non-standard names like 's, 'p, 'rg, 'ck, 'parent, 'this, and 'me with vanilla 'a. These are cases where the original name isn't really any more informative than 'a. - Replace names like 'cx, 'mir, and 'body with vanilla 'a when the lifetime applies to multiple fields and so the original lifetime name isn't really accurate. - Put 'tcx last in lifetime lists, and 'a before 'b.
2024-09-10Improve comment formatting.Nicholas Nethercote-5/+9
By reflowing comment lines that are too long, and a few that are very short. Plus some other very minor formatting tweaks.
2024-09-09Reduce visibilities, and add `warn(unreachable_pub)`.Nicholas Nethercote-1/+1
Lots of unnecessary `pub`s in this crate. Most are downgraded to `pub(super)`, though some don't need any visibility.
2024-09-03Rollup merge of #129926 - nnethercote:mv-SanityCheck-and-MirPass, r=cjgillotMatthias Krüger-1/+1
Move `SanityCheck` and `MirPass` They are currently in `rustc_middle`. This PR moves them to `rustc_mir_transform`, which makes more sense. r? ``@cjgillot``
2024-09-03Move `MirPass` to `rustc_mir_transform`.Nicholas Nethercote-1/+1
Because that's now the only crate that uses it. Moving stuff out of `rustc_middle` is always welcome. I chose to use `impl crate::MirPass`/`impl crate::MirLint` (with explicit `crate::`) everywhere because that's the only mention of `MirPass`/`MirLint` used in all of these files. (Prior to this change, `MirPass` was mostly imported via `use rustc_middle::mir::*` items.)
2024-09-02chore: Fix typos in 'compiler' (batch 2)Alexander Cyon-10/+10
2024-08-03Re-enable SimplifyToExp in match_branches.DianQK-4/+1
2024-08-03Simplify match based on the cast result of `IntToInt`.DianQK-62/+79
2024-07-29Reformat `use` declarations.Nicholas Nethercote-1/+2
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-10ScalarInt: size mismatches are a bug, do not delay the panicRalf Jung-1/+1
2024-04-20Auto merge of #124156 - DianQK:disable-match_branches, r=RalfJungbors-1/+4
Disable SimplifyToExp in MatchBranchSimplification Due to the miscompilation mentioned in #124150, We need to disable MatchBranchSimplification temporarily. To fully resolve this issue, my plan is: 1. Disable SimplifyToExp in MatchBranchSimplification (this PR). 2. Remove all potentially unclear transforms in #124122. 3. Gradually add back the removed transforms (possibly multiple PRs). r? `@Nilstrieb` or `@oli-obk`
2024-04-20Disable SimplifyToExp in MatchBranchSimplificationDianQK-1/+4
2024-04-19ScalarInt: add methods to assert being a (u)int of given sizeRalf Jung-2/+1
2024-04-08Change the return type of `can_simplify` to `Option<()>`DianQK-28/+26
2024-04-08Add comments for `CompareType`DianQK-8/+11
2024-04-08Updating the MIR with MirPatchDianQK-50/+54
2024-04-08Transforms a match containing negative numbers into an assignment statement ↵DianQK-11/+38
as well
2024-04-08Transforms match into an assignment statementDianQK-7/+223
2024-04-08Refactor `MatchBranchSimplification`DianQK-133/+205
2024-01-07Merge dead bb pruning and unreachable bb deduplication.Camille GILLOT-1/+1
2023-12-10remove redundant importssurechen-1/+0
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-09-21rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::ConstRalf Jung-6/+6
2023-07-25inline format!() args from rustc_codegen_llvm to the end (4)Matthias Krüger-1/+1
r? @WaffleLapkin
2023-05-27Try enabling MatchBranchSimplificationBen Kimock-2/+7
2023-04-23Use param_env_reveal_all_normalized in MIR opts.Camille GILLOT-1/+1
2022-12-09Remove unneeded field from `SwitchTargets`Jakob Degen-6/+6
2022-07-07Make MIR basic blocks field publicTomasz Miąsko-2/+2
This makes it possible to mutably borrow different fields of the MIR body without resorting to methods like `basic_blocks_local_decls_mut_and_var_debug_info`. To preserve validity of control flow graph caches in the presence of modifications, a new struct `BasicBlocks` wraps together basic blocks and control flow graph caches. The `BasicBlocks` dereferences to `IndexVec<BasicBlock, BasicBlockData>`. On the other hand a mutable access requires explicit `as_mut()` call.
2022-05-02fix most compiler/ doctestsElliot Roberts-2/+2
2021-12-02Update passes with new interfaceDylan MacKenzie-4/+4
2021-09-07Rename rustc_mir to rustc_const_eval.Camille GILLOT-1/+1
2021-09-07Move rustc_mir::transform to rustc_mir_transform.Camille GILLOT-0/+176