about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2024-04-08Auto merge of #120614 - DianQK:simplify-switch-int, r=cjgillotbors-116/+436
Transforms match into an assignment statement Fixes #106459. We should be able to do some similar transformations, like `enum` to `enum`. r? mir-opt
2024-04-08Actually create ranged int types in the type system.Oli Scherer-0/+1
2024-04-08Don't change the otherwise of the switchDianQK-1/+2
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-04-07Re-enable the early otherwise branch optimizationDianQK-2/+1
2024-04-07Resolve unsound hoisting of discriminant in `EarlyOtherwiseBranch`DianQK-116/+50
2024-04-06Put checks that detect UB under their own flag below debug_assertionsBen Kimock-2/+2
2024-04-05Account for an additional reborrow inserted by UniqueImmBorrow and MutBorrowMichael Goulet-3/+8
2024-04-05Check the base of the place too!Michael Goulet-6/+20
2024-04-05Add some helpful commentsMichael Goulet-4/+56
2024-04-05Rework the ByMoveBody shim to actually work correctlyMichael Goulet-34/+90
2024-04-05Rollup merge of #123350 - compiler-errors:async-closure-by-move, r=oli-obkGuillaume Gomez-6/+14
Actually use the inferred `ClosureKind` from signature inference in coroutine-closures A follow-up to https://github.com/rust-lang/rust/pull/123349, which fixes another subtle bug: We were not taking into account the async closure kind we infer during closure signature inference. When I pass a closure directly to an arg like `fn(x: impl async FnOnce())`, that should have the side-effect of artificially restricting the kind of the async closure to `ClosureKind::FnOnce`. We weren't doing this -- that's a quick fix; however, it uncovers a second, more subtle bug with the way that `move`, async closures, and `FnOnce` interact. Specifically, when we have an async closure like: ``` let x = Struct; let c = infer_as_fnonce(async move || { println!("{x:?}"); } ``` The outer closure captures `x` by move, but the inner coroutine still immutably borrows `x` from the outer closure. Since we've forced the closure to by `async FnOnce()`, we can't actually *do* a self borrow, since the signature of `AsyncFnOnce::call_once` doesn't have a borrowed lifetime. This means that all `async move` closures that are constrained to `FnOnce` will fail borrowck. We can fix that by detecting this case specifically, and making the *inner* async closure `move` as well. This is always beneficial to closure analysis, since if we have an `async FnOnce()` that's `move`, there's no reason to ever borrow anything, so `move` isn't artificially restrictive.
2024-04-05Auto merge of #123444 - saethlin:const-eval-inline-cycles, r=tmiaskobors-4/+14
Teach MIR inliner query cycle avoidance about const_eval_select Fixes https://github.com/rust-lang/rust/issues/122659 r? tmiasko
2024-04-04Rollup merge of #123464 - fmease:rn-has-proj-to-has-aliases, r=compiler-errorsJacob Pratt-1/+1
Cleanup: Rename `HAS_PROJECTIONS` to `HAS_ALIASES` etc. The name of the bitflag `HAS_PROJECTIONS` and of its corresponding method `has_projections` is quite historical dating back to a time when projections were the only kind of alias type. I think it's time to update it to clear up any potential confusion for newcomers and to reduce unnecessary friction during contributor onboarding. r? types
2024-04-04Force `move` async-closures that are `FnOnce` to make their inner coroutines ↵Michael Goulet-6/+14
also `move`
2024-04-04Rename HAS_PROJECTIONS to HAS_ALIASES etc.León Orell Valerian Liehr-1/+1
2024-04-04Rollup merge of #123439 - Zalathar:constants, r=oli-obkMatthias Krüger-1/+1
coverage: Remove useless constants After #122972 and #123419, these constants don't serve any useful purpose, so get rid of them. `@rustbot` label +A-code-coverage
2024-04-04Auto merge of #123052 - maurer:addr-taken, r=compiler-errorsbors-3/+3
CFI: Support function pointers for trait methods Adds support for both CFI and KCFI for function pointers to trait methods by attaching both concrete and abstract types to functions. KCFI does this through generation of a `ReifyShim` on any function pointer for a method that could go into a vtable, and keeping this separate from `ReifyShim`s that are *intended* for vtable us by setting a `ReifyReason` on them. CFI does this by setting both the concrete and abstract type on every instance. This should land after #123024 or a similar PR, as it diverges the implementation of CFI vs KCFI. r? `@compiler-errors`
2024-04-04Teach MIR inliner query cycle avoidance about const_eval_selectBen Kimock-4/+14
2024-04-04coverage: Remove useless constantsZalathar-1/+1
2024-04-03Rollup merge of #123419 - petrochenkov:zeroindex, r=compiler-errorsMatthias Krüger-21/+17
rustc_index: Add a `ZERO` constant to index types It is commonly used.
2024-04-03rustc_index: Add a `ZERO` constant to index typesVadim Petrochenkov-21/+17
It is commonly used.
2024-04-03rename `expose_addr` to `expose_provenance`joboet-2/+2
2024-04-03Auto merge of #123322 - matthewjasper:remove-mir-unsafeck, ↵bors-791/+2
r=lcnr,compiler-errors Remove MIR unsafe check Now that THIR unsafeck is enabled by default in stable I think we can remove MIR unsafeck entirely. This PR also removes safety information from MIR.
2024-04-03Remove MIR unsafe checkMatthew Jasper-791/+2
This also remove safety information from MIR.
2024-04-03Auto merge of #123402 - workingjubilee:rollup-0j5ihn6, r=workingjubileebors-31/+118
Rollup of 4 pull requests Successful merges: - #122411 ( Provide cabi_realloc on wasm32-wasip2 by default ) - #123349 (Fix capture analysis for by-move closure bodies) - #123359 (Link against libc++abi and libunwind as well when building LLVM wrappers on AIX) - #123388 (use a consistent style for links) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-03Auto merge of #122225 - DianQK:nits-120268, r=cjgillotbors-14/+56
Rename `UninhabitedEnumBranching` to `UnreachableEnumBranching` Per [#120268](https://github.com/rust-lang/rust/pull/120268#discussion_r1517492060), I rename `UninhabitedEnumBranching` to `UnreachableEnumBranching` . I solved some nits to add some comments. I adjusted the workaround restrictions. This should be useful for `a <= b` and `if let Some/Ok(v)`. For enum with few variants, `early-tailduplication` should not cause compile time overhead. r? RalfJung
2024-04-02Comments, comments, commentsMichael Goulet-39/+92
2024-04-02Fix capture analysis for by-move closure bodiesMichael Goulet-16/+50
2024-04-02Auto merge of #118310 - scottmcm:three-way-compare, r=davidtwcobors-0/+3
Add `Ord::cmp` for primitives as a `BinOp` in MIR Update: most of this OP was written months ago. See https://github.com/rust-lang/rust/pull/118310#issuecomment-2016940014 below for where we got to recently that made it ready for review. --- There are dozens of reasonable ways to implement `Ord::cmp` for integers using comparison, bit-ops, and branches. Those differences are irrelevant at the rust level, however, so we can make things better by adding `BinOp::Cmp` at the MIR level: 1. Exactly how to implement it is left up to the backends, so LLVM can use whatever pattern its optimizer best recognizes and cranelift can use whichever pattern codegens the fastest. 2. By not inlining those details for every use of `cmp`, we drastically reduce the amount of MIR generated for `derive`d `PartialOrd`, while also making it more amenable to MIR-level optimizations. Having extremely careful `if` ordering to μoptimize resource usage on broadwell (#63767) is great, but it really feels to me like libcore is the wrong place to put that logic. Similarly, using subtraction [tricks](https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign) (#105840) is arguably even nicer, but depends on the optimizer understanding it (https://github.com/llvm/llvm-project/issues/73417) to be practical. Or maybe [bitor is better than add](https://discourse.llvm.org/t/representing-in-ir/67369/2?u=scottmcm)? But maybe only on a future version that [has `or disjoint` support](https://discourse.llvm.org/t/rfc-add-or-disjoint-flag/75036?u=scottmcm)? And just because one of those forms happens to be good for LLVM, there's no guarantee that it'd be the same form that GCC or Cranelift would rather see -- especially given their very different optimizers. Not to mention that if LLVM gets a spaceship intrinsic -- [which it should](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Suboptimal.20inlining.20in.20std.20function.20.60binary_search.60/near/404250586) -- we'll need at least a rustc intrinsic to be able to call it. As for simplifying it in Rust, we now regularly inline `{integer}::partial_cmp`, but it's quite a large amount of IR. The best way to see that is with https://github.com/rust-lang/rust/commit/8811efa88b25b5e41d63850e6047e8257c677858#diff-d134c32d028fbe2bf835fef2df9aca9d13332dd82284ff21ee7ebf717bfa4765R113 -- I added a new pre-codegen MIR test for a simple 3-tuple struct, and this PR change it from 36 locals and 26 basic blocks down to 24 locals and 8 basic blocks. Even better, as soon as the construct-`Some`-then-match-it-in-same-BB noise is cleaned up, this'll expose the `Cmp == 0` branches clearly in MIR, so that an InstCombine (#105808) can simplify that to just a `BinOp::Eq` and thus fix some of our generated code perf issues. (Tracking that through today's `if a < b { Less } else if a == b { Equal } else { Greater }` would be *much* harder.) --- r? `@ghost` But first I should check that perf is ok with this ~~...and my true nemesis, tidy.~~
2024-04-02Track reason for creating a `ReifyShim`Matthew Maurer-3/+3
KCFI needs to be able to tell which kind of `ReifyShim` it is examining in order to decide whether to use a concrete type (`FnPtr` case) or an abstract case (`Vtable` case). You can *almost* tell this from context, but there is one case where you can't - if a trait has a method which is *not* `#[track_caller]`, with an impl that *is* `#[track_caller]`, both the vtable and a function pointer created from that method will be `ReifyShim(def_id)`. Currently, the reason is optional to ensure no additional unique `ReifyShim`s are added without KCFI on. However, the case in which an extra `ReifyShim` is created is sufficiently rare that this may be worth revisiting to reduce complexity.
2024-04-02Avoid an `is_empty()` followed by an index op in favor of a single fallible opOli Scherer-3/+3
2024-04-02Prefer `UnordSet` over `FxHashSet` where possibleOli Scherer-3/+3
2024-03-29Auto merge of #123194 - matthiaskrgr:rollup-vhdc8hw, r=matthiaskrgrbors-6/+3
Rollup of 4 pull requests Successful merges: - #123176 (Normalize the result of `Fields::ty_with_args`) - #123186 (copy any file from stage0/lib to stage0-sysroot/lib) - #123187 (Forward port 1.77.1 release notes) - #123188 (compiler: fix few unused_peekable and needless_pass_by_ref_mut clippy lints) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-29Rollup merge of #123188 - klensy:clippy-me2, r=NilstriebMatthias Krüger-6/+3
compiler: fix few unused_peekable and needless_pass_by_ref_mut clippy lints This fixes few instances of `unused_peekable` and `needless_pass_by_ref_mut`. While i expected to fix more warnings, `needless_pass_by_ref_mut` produced too much for one PR, so i stopped here. Better reviewed commit by commit, as fixes splitted by chunks.
2024-03-29Auto merge of #122450 - Urgau:simplify-trim-paths-feature, r=michaelwoeristerbors-2/+5
Simplify trim-paths feature by merging all debuginfo options together This PR simplifies the trim-paths feature by merging all debuginfo options together, as described in https://github.com/rust-lang/rust/issues/111540#issuecomment-1994010274. And also do some correctness fixes found during the review. cc `@weihanglo` r? `@michaelwoerister`
2024-03-28Replace `RemapFileNameExt::for_codegen` with explicit callsUrgau-2/+5
2024-03-28and moreklensy-6/+3
warning: this argument is a mutable reference, but not used mutably --> compiler\rustc_mir_transform\src\coroutine.rs:1229:11 | 1229 | body: &mut Body<'tcx>, | ^^^^^^^^^^^^^^^ help: consider changing to: `&Body<'tcx>` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut warning: this argument is a mutable reference, but not used mutably --> compiler\rustc_mir_transform\src\nrvo.rs:123:11 | 123 | body: &mut mir::Body<'_>, | ^^^^^^^^^^^^^^^^^^ help: consider changing to: `&mir::Body<'_>` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut warning: this argument is a mutable reference, but not used mutably --> compiler\rustc_mir_transform\src\nrvo.rs:87:34 | 87 | fn local_eligible_for_nrvo(body: &mut mir::Body<'_>) -> Option<Local> { | ^^^^^^^^^^^^^^^^^^ help: consider changing to: `&mir::Body<'_>` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut
2024-03-27Eliminate `UbCheck` for non-standard librariesDianQK-0/+15
2024-03-27Rollup merge of #122860 - Zalathar:unused, r=cjgillotGuillaume Gomez-5/+1
coverage: Re-enable `UnreachablePropagation` for coverage builds This is a sequence of 3 related changes: - Clean up the existing code that scans for unused functions - Detect functions that were instrumented for coverage, but have had all their coverage statements removed by later MIR transforms (e.g. `UnreachablePropagation`) - Re-enable `UnreachablePropagation` in coverage builds Because we now detect functions that have lost their coverage statements, and treat them as unused, we don't need to worry about `UnreachablePropagation` removing all of those statements. This is demonstrated by `tests/coverage/unreachable.rs`. Fixes #116171.
2024-03-26Rollup merge of #123049 - compiler-errors:coroutine-closure-rcvr, r=oli-obkMatthias Krüger-3/+3
In `ConstructCoroutineInClosureShim`, pass receiver by mut ref, not mut pointer The receivers were compatible at codegen time, but did not necessarily have the same layouts due to niches, which was caught by miri. Fixes rust-lang/miri#3400 r? oli-obk
2024-03-26In ConstructCoroutineInClosureShim, pass receiver by ref, not pointerMichael Goulet-3/+3
2024-03-26Rollup merge of #122996 - RalfJung:simplify_branches, r=cjgillotMatthias Krüger-0/+1
simplify_branches: add comment I am not quite sure why this simplification is done here and not in InstSimplify but :shrug: r? `@cjgillot`
2024-03-26coverage: Re-enable `UnreachablePropagation` for coverage buildsZalathar-5/+1
2024-03-25Instance is CopyMichael Goulet-3/+3