about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
AgeCommit message (Collapse)AuthorLines
2023-03-25Refactor: `VariantIdx::from_u32(0)` -> `FIRST_VARIANT`Scott McMurray-8/+5
Since structs are always `VariantIdx(0)`, there's a bunch of files where the only reason they had `VariantIdx` or `vec::Idx` imported at all was to get the first variant. So this uses a constant for that, and adds some doc-comments to `VariantIdx` while I'm there, since it doesn't have any today.
2023-03-25Explain how we get to skip checking for cleanup blocks in the visitorBen Kimock-0/+2
2023-03-24Skip checks for common types with alignment 1Ben Kimock-0/+7
2023-03-24Use Vec::split_offBen Kimock-1/+1
2023-03-24Clarify that we are doing ptr.addr() internallyBen Kimock-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-03-23A MIR transform that checks pointers are alignedBen Kimock-0/+222
2023-03-22Add `CastKind::Transmute` to MIRScott McMurray-0/+35
Updates `interpret`, `codegen_ssa`, and `codegen_cranelift` to consume the new cast instead of the intrinsic. Includes `CastTransmute` for custom MIR building, to be able to test the extra UB.
2023-03-23Rollup merge of #109435 - oli-obk:🇨🇭🥚_copy_op, r=RalfJungDylan DPC-2/+3
Detect uninhabited types early in const eval r? `@RalfJung` implements https://github.com/rust-lang/rust/pull/108442#discussion_r1143003840 this is a breaking change, as some UB during const eval is now detected instead of silently being ignored. Users can see this and other UB that may cause future breakage with `-Zextra-const-ub-checks` or just by running miri on their code, which sets that flag by default.
2023-03-23Rollup merge of #109179 - llogiq:intrinsically-option-as-slice, r=eholkDylan DPC-0/+30
move Option::as_slice to intrinsic ````@scottmcm```` suggested on #109095 I use a direct approach of unpacking the operation in MIR lowering, so here's the implementation. cc ````@nikic```` as this should hopefully unblock #107224 (though perhaps other changes to the prior implementation, which I left for bootstrapping, are needed).
2023-03-22Auto merge of #109087 - cjgillot:sparse-bb-clear, r=davidtwcobors-22/+61
Only clear written-to locals in ConstProp This aims to revert the regression in https://github.com/rust-lang/rust/pull/108872 Clearing all locals at the end of each bb is very costly. This PR goes back to the original implementation of recording which locals are modified.
2023-03-21LocalCrate keyMichael Goulet-1/+2
2023-03-21Use local key in providersMichael Goulet-23/+14
2023-03-21Add a layout argument to `enforce_validity`.Oli Scherer-2/+3
This is in preparation of checking the validity only of certain types.
2023-03-19Prefer if cfg!.Camille GILLOT-12/+14
2023-03-19Only clear locals that are known to be written to.Camille GILLOT-16/+53
2023-03-18Enable inlining of diverging functionsBen Kimock-7/+0
2023-03-18Remove duplicate switch targetsBen Kimock-1/+15
2023-03-18Remove duplicate unreachable blocksBen Kimock-1/+43
2023-03-18move Option::as_slice to intrinsicAndre Bogus-0/+30
2023-03-16Auto merge of #108944 - cjgillot:clear-local-info, r=oli-obkbors-10/+22
Wrap the whole LocalInfo in ClearCrossCrate. MIR contains a lot of information about locals. The primary purpose of this information is the quality of borrowck diagnostics. This PR aims to drop this information after MIR analyses are finished, ie. starting from post-cleanup runtime MIR.
2023-03-16Auto merge of #107270 - cjgillot:remove-zst, r=oli-obkbors-29/+107
Replace ZST operands and debuginfo by constants. This is work that ConstProp will not have to do. Split from https://github.com/rust-lang/rust/pull/107267
2023-03-15Auto merge of #109035 - scottmcm:ptr-read-should-know-undef, ↵bors-0/+29
r=WaffleLapkin,JakobDegen Ensure `ptr::read` gets all the same LLVM `load` metadata that dereferencing does I was looking into `array::IntoIter` optimization, and noticed that it wasn't annotating the loads with `noundef` for simple things like `array::IntoIter<i32, N>`. Trying to narrow it down, it seems that was because `MaybeUninit::assume_init_read` isn't marking the load as initialized (<https://rust.godbolt.org/z/Mxd8TPTnv>), which is unfortunate since that's basically its reason to exist. The root cause is that `ptr::read` is currently implemented via the *untyped* `copy_nonoverlapping`, and thus the `load` doesn't get any type-aware metadata: no `noundef`, no `!range`. This PR solves that by lowering `ptr::read(p)` to `copy *p` in MIR, for which the backends already do the right thing. Fortuitiously, this also improves the IR we give to LLVM for things like `mem::replace`, and fixes a couple of long-standing bugs where `ptr::read` on `Copy` types was worse than `*`ing them. Zulip conversation: <https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Move.20array.3A.3AIntoIter.20to.20ManuallyDrop/near/341189936> cc `@erikdesjardins` `@JakobDegen` `@workingjubilee` `@the8472` Fixes #106369 Fixes #73258
2023-03-14Improved implementation and comments after code review feedbackScott McMurray-13/+18
2023-03-14ICE when checking LocalInfo on runtime MIR.Camille GILLOT-3/+9
2023-03-14Remove LocalKind::Var.Camille GILLOT-2/+2
2023-03-14Wrap the whole LocalInfo in ClearCrossCrate.Camille GILLOT-5/+11
2023-03-13Generalize operation.Camille GILLOT-14/+27
2023-03-13Rename method.Camille GILLOT-7/+7
2023-03-13Replace ZST operands and debuginfo by constants.Camille GILLOT-28/+93
2023-03-13Auto merge of #108471 - clubby789:unbox-the-syntax, r=Nilstrieb,est31bors-21/+25
Remove `box_syntax` r? `@Nilstrieb` This removes the feature `box_syntax`, which allows the use of `box <expr>` to create a Box, and finalises removing use of the feature from the compiler. `box_patterns` (allowing the use of `box <pat>` in a pattern) is unaffected. It also removes `ast::ExprKind::Box` - the only way to create a 'box' expression now is with the rustc-internal `#[rustc_box]` attribute. As a temporary measure to help users move away, `box <expr>` now parses the inner expression, and emits a `MachineApplicable` lint to replace it with `Box::new` Closes #49733
2023-03-12Auto merge of #108872 - cjgillot:simp-const-prop, r=oli-obkbors-277/+195
Strengthen state tracking in const-prop Some/many of the changes are replicated between both the const-prop lint and the const-prop optimization. Behaviour changes: - const-prop opt does not give a span to propagated values. This was useless as that span's primary purpose is to diagnose evaluation failure in codegen. - we remove the `OnlyPropagateInto` mode. It was only used for function arguments, which are better modeled by a write before entry. - the tracking of assignments and discriminants make clearer that we do nothing in `NoPropagation` mode or on indirect places.
2023-03-12Auto merge of #108820 - cjgillot:ensure-on-disk, r=oli-obkbors-6/+6
Ensure value is on the on-disk cache before returning from `ensure()`. The current logic for `ensure()` a query just checks that the node is green in the dependency graph. However, a lot of places use `ensure()` to prevent the query from being called later. This is the case before stealing a query result. If the query is actually green but the value is not available in the on-disk cache, `ensure` would return, but a subsequent call to the full query would run the code, and attempt to read from a stolen value. This PR conforms the query system to the usage by checking whether the queried value is loadable from disk before returning. Sadly, I can't manage to craft a proper test... Should fix all instances of "attempted to read from stolen value".
2023-03-12Remove uses of `box_syntax` in rustc and toolsclubby789-21/+25
2023-03-12Auto merge of #108794 - nnethercote:avoid-unnecessary-hashing, r=cjgillotbors-1/+1
Avoid unnecessary hashing I noticed some stable hashing being done in a non-incremental build. It turns out that some of this is necessary to compute the crate hash, but some of it is not. Removing the unnecessary hashing is a perf win. r? `@cjgillot`
2023-03-11`MaybeUninit::assume_init_read` should have `noundef` load metadataScott McMurray-0/+24
I was looking into `array::IntoIter` optimization, and noticed that it wasn't annotating the loads with `noundef` for simple things like `array::IntoIter<i32, N>`. Turned out to be a more general problem as `MaybeUninit::assume_init_read` isn't marking the load as initialized (<https://rust.godbolt.org/z/Mxd8TPTnv>), which is unfortunate since that's basically its reason to exist. This PR lowers `ptr::read(p)` to `copy *p` in MIR, which fortuitiously also improves the IR we give to LLVM for things like `mem::replace`.
2023-03-11Use ensure_with_value in a few more places.Camille GILLOT-1/+1
2023-03-11Make the check for cache opt-in.Camille GILLOT-5/+5
2023-03-10Rollup merge of #108902 - lcnr:do-while-sus, r=davidtwco,NilstriebMatthias Krüger-20/+20
no more do while :<
2023-03-09Bug on PlaceMention in dest-prop.Camille GILLOT-2/+3
2023-03-09Pacify tidy.Camille GILLOT-2/+2
2023-03-09Ignore AscribeUserType in unsafeck to avoid duplicate diagnostics.Camille GILLOT-1/+3
2023-03-09Introduce a no-op PlaceMention statement for `let _ =`.Camille GILLOT-1/+12
2023-03-09no more do whilelcnr-20/+20
2023-03-09Auto merge of #108920 - matthiaskrgr:rollup-qrr9a0u, r=matthiaskrgrbors-159/+16
Rollup of 8 pull requests Successful merges: - #108754 (Retry `pred_known_to_hold_modulo_regions` with fulfillment if ambiguous) - #108759 (1.41.1 supported 32-bit Apple targets) - #108839 (Canonicalize root var when making response from new solver) - #108856 (Remove DropAndReplace terminator) - #108882 (Tweak E0740) - #108898 (Set `LIBC_CHECK_CFG=1` when building Rust code in bootstrap) - #108911 (Improve rustdoc-gui/tester.js code a bit) - #108916 (Remove an unused return value in `rustc_hir_typeck`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-03-09Auto merge of #108178 - cjgillot:ssa-deref, r=oli-obkbors-16/+40
Do not consider `&mut *x` as mutating `x` in `CopyProp` This PR removes an unfortunate overly cautious case from the current implementation. Found by https://github.com/rust-lang/rust/pull/105274 cc `@saethlin`
2023-03-08Rollup merge of #108856 - Zeegomo:remove-drop-and-rep, r=tmiaskoMatthias Krüger-159/+16
Remove DropAndReplace terminator #107844 made DropAndReplace unused, let's remove it completely from the codebase.
2023-03-08Remove useless parameter to operand_from_scalar.Camille GILLOT-14/+5
2023-03-08Make comment more explicit.Camille GILLOT-2/+4
2023-03-08Separate checking rvalue from evaluation.Camille GILLOT-113/+104
2023-03-08Recurse into statement before applying its effect.Camille GILLOT-4/+8