summary refs log tree commit diff
path: root/compiler/rustc_mir/src/transform
AgeCommit message (Collapse)AuthorLines
2021-02-05Never MIR inline functions with a different instruction setTomasz Miąsko-0/+5
2021-01-31Rollup merge of #80404 - JulianKnodt:arr_ref, r=oli-obkJonas Schievink-63/+3
Remove const_in_array_repeat Fixes #80371. Fixes #81315. Fixes #80767. Fixes #75682. I thought there might be some issue with `Repeats(_, 0)`, but if you increase the items in the array it still ICEs. I'm not sure if this is the best fix but it does fix the given issue.
2021-01-30Remove const_in_array_rep_exprkadmin-64/+5
2021-01-28Avoid memory allocation when removing dead blocksTomasz Miąsko-7/+6
Use `reachable_as_bitset` to reuse a bitset from the traversal rather than allocating it seprately. Additionally check if there are any unreachable blocks before proceeding.
2021-01-27Check that value is explicitly nonekadmin-2/+1
2021-01-25Auto merge of #68828 - oli-obk:inline_cycle, r=wesleywiserbors-18/+254
Prevent query cycles in the MIR inliner r? `@eddyb` `@wesleywiser` cc `@rust-lang/wg-mir-opt` The general design is that we have a new query that is run on the `validated_mir` instead of on the `optimized_mir`. That query is forced before going into the optimization pipeline, so as to not try to read from a stolen MIR. The query should not be cached cross crate, as you should never call it for items from other crates. By its very design calls into other crates can never cause query cycles. This is a pessimistic approach to inlining, since we strictly have more calls in the `validated_mir` than we have in `optimized_mir`, but that's not a problem imo.
2021-01-24Rollup merge of #78578 - oli-obk:const_mut_refs, r=RalfJungJonas Schievink-30/+70
Permit mutable references in all const contexts fixes #71212 cc `@rust-lang/wg-const-eval` `@christianpoveda`
2021-01-23Leave some notes for future changes to the MIR opt level of mir inliningoli-1/+9
2021-01-23Make sure that const prop does not produce unsilenceable lints after inliningoli-1/+9
2021-01-23Prevent query cycles during inliningoli-17/+237
2021-01-23Auto merge of #80579 - RalfJung:no-fallible-promotion, r=oli-obkbors-26/+86
avoid promoting division, modulo and indexing operations that could fail For division, `x / y` will still be promoted if `y` is a non-zero integer literal; however, `1/(1+1)` will not be promoted any more. While at it, also see if we can reject promoting floating-point arithmetic (which are [complicated](https://github.com/rust-lang/unsafe-code-guidelines/issues/237) so maybe we should not promote them). This will need a crater run to see if there's code out there that relies on these things being promoted. If we can land this, promoteds in `fn`/`const fn` cannot fail to evaluate any more, which should let us do some simplifications in codegen/Miri! Cc https://github.com/rust-lang/rfcs/pull/3027 Fixes https://github.com/rust-lang/rust/issues/61821 r? `@oli-obk`
2021-01-23Do not allow arbitrary mutable references in `static mut`, just keep with ↵oli-6/+2
the existing exceptions
2021-01-23Adjust wording of a diagnosticoli-1/+1
2021-01-23Permit mutable references in all const contextsoli-28/+72
2021-01-22Auto merge of #81101 - tmiasko:combine-now, r=nagisabors-284/+77
Combine instructions immediately
2021-01-22do promote array indexing if we know it is in-boundsRalf Jung-15/+49
2021-01-22avoid promoting division, modulo and indexing operations that could failRalf Jung-13/+39
2021-01-21Auto merge of #81122 - tmiasko:no-drop, r=davidtwcobors-41/+20
Visit only terminators when removing unneeded drops No functional changes intended
2021-01-21Rollup merge of #81187 - eltociear:patch-6, r=jonas-schievinkYuki Okushi-1/+1
Fix typo in counters.rs formating -> formatting
2021-01-21Rollup merge of #81178 - tmiasko:no-landing-pads, r=oli-obkYuki Okushi-23/+8
Visit only terminators when removing landing pads No functional changes intended
2021-01-19Fix typo in counters.rsIkko Ashimine-1/+1
formating -> formatting
2021-01-19Auto merge of #81110 - LeSeulArtichaut:fix-unused-unsafe-label, r=RalfJungbors-8/+9
Fix `unused_unsafe` label with `unsafe_block_in_unsafe_fn Previously, the following code: ```rust #![feature(unsafe_block_in_unsafe_fn)] unsafe fn foo() { unsafe { unsf() } } unsafe fn unsf() {} ``` Would give the following warning: ``` warning: unnecessary `unsafe` block --> src/lib.rs:4:5 | 4 | unsafe { unsf() } | ^^^^^^ unnecessary `unsafe` block | = note: `#[warn(unused_unsafe)]` on by default ``` which doesn't point out that the block is in an `unsafe fn`. Tracking issue: #71668 cc #79208
2021-01-18Auto merge of #80707 - oli-obk:stability_hole_const_intrinsics, r=RalfJungbors-8/+18
Stability oddity with const intrinsics cc `@RalfJung` In https://github.com/rust-lang/rust/pull/80699#discussion_r551495670 `@usbalbin` realized we accepted some intrinsics as `const` without a `#[rustc_const_(un)stable]` attribute. I did some digging, and that example works because intrinsics inherit their stability from their parents... including `#[rustc_const_(un)stable]` attributes. While we may want to fix that (not sure, wasn't there just a MCPed PR that caused this on purpose?), we definitely want tests for it, thus this PR adding tests and some fun tracing statements.
2021-01-18Combine instructions immediatelyTomasz Miąsko-147/+79
No functional changes intended
2021-01-18Remove disabled transformation from instcombineTomasz Miąsko-142/+3
2021-01-18Rollup merge of #81121 - tmiasko:simplify-cfg-no-dbg, r=jonas-schievinkAshley Mannix-1/+1
Avoid logging the whole MIR body in SimplifyCfg
2021-01-18Rollup merge of #81116 - bugadani:body-span, r=wesleywiserAshley Mannix-1/+1
ConstProp: Copy body span instead of querying it
2021-01-18Only inherit const stability for methods of `impl const Trait` blocksoli-1/+1
2021-01-18Auto merge of #80865 - oliviacrain:proj_based, r=RalfJungbors-90/+83
Use PlaceRef projection abstractions more consistently in rustc_mir PlaceRef contains abstractions for dealing with the `projections` array. This PR uses these abstractions more consistently within the `rustc_mir` crate. See associated issue: rust-lang/rust#80647. r? `@RalfJung`
2021-01-18Visit only terminators when removing landing padsTomasz Miąsko-23/+8
No functional changes intended
2021-01-17Fix `unused_unsafe` label with `unsafe_block_in_unsafe_fnLeSeulArtichaut-8/+9
2021-01-17Avoid logging the whole MIR body in SimplifyCfgTomasz Miąsko-1/+1
2021-01-17Copy body span instead of querying itDániel Buga-1/+1
2021-01-17Add regression testoli-5/+15
2021-01-17Remove an unnecessary field from a `NonConstOp`oli-3/+3
2021-01-17Visit only terminators when removing unneeded dropsTomasz Miąsko-41/+20
No functional changes intended
2021-01-16Review changesJack Huey-16/+16
2021-01-16Auto merge of #80290 - RalfJung:less-intrinsic-write, r=lcnrbors-8/+0
implement ptr::write without dedicated intrinsic This makes `ptr::write` more consistent with `ptr::write_unaligned`, `ptr::read`, `ptr::read_unaligned`, all of which are implemented in terms of `copy_nonoverlapping`. This means we can also remove `move_val_init` implementations in codegen and Miri, and its special handling in the borrow checker. Also see [this Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/ptr.3A.3Aread.20vs.20ptr.3A.3Awrite).
2021-01-16Use PlaceRef more consistently in rustc_mirOlivia Crain-90/+83
2021-01-15inline: Round word-size cost estimates upTomasz Miąsko-1/+1
2021-01-14Use Option::map_or instead of `.map(..).unwrap_or(..)`LingMan-2/+2
2021-01-12Auto merge of #78407 - oli-obk:ub_checkable_ctfe, r=RalfJung,pnkfelixbors-27/+123
Make CTFE able to check for UB... ... by not doing any optimizations on the `const fn` MIR used in CTFE. This means we duplicate all `const fn`'s MIR now, once for CTFE, once for runtime. This PR is for checking the perf effect, so we have some data when talking about https://github.com/rust-lang/const-eval/blob/master/rfcs/0000-const-ub.md To do this, we now have two queries for obtaining mir: `optimized_mir` and `mir_for_ctfe`. It is now illegal to invoke `optimized_mir` to obtain the MIR of a const/static item's initializer, an array length, an inline const expression or an enum discriminant initializer. For `const fn`, both `optimized_mir` and `mir_for_ctfe` work, the former returning the MIR that LLVM should use if the function is called at runtime. Similarly it is illegal to invoke `mir_for_ctfe` on regular functions. This is all checked via appropriate assertions and I don't think it is easy to get wrong, as there should be no `mir_for_ctfe` calls outside the const evaluator or metadata encoding. Almost all rustc devs should keep using `optimized_mir` (or `instance_mir` for that matter).
2021-01-12Coverage computation needs access to the MIR, toooli-6/+13
2021-01-12Auto merge of #80499 - matthiaskrgr:red_clos, r=estebankbors-6/+6
remove redundant closures (clippy::redundant_closure)
2021-01-10Add ABI argument to `find_mir_or_eval_fn`Nym Seddon-0/+2
Add ABI argument for called function in `find_mir_or_eval_fn` and `call_extra_fn`. Useful for comparing with expected ABI in interpreters. Related to [miri/1631](https://github.com/rust-lang/miri/issues/1631)
2021-01-08Rollup merge of #80521 - richkadel:llvm-coverage-counters-2.4.0, r=wesleywiserYuki Okushi-0/+9
MIR Inline is incompatible with coverage Fixes: #80060 Fixed by disabling inlining if `-Zinstrument-coverage` is set. The PR also adds additional use cases to the coverage test for doctests. r? `@wesleywiser` cc: `@tmandry`
2021-01-07Auto merge of #80648 - Aaron1011:expn-data-private, r=petrochenkovbors-4/+4
Make `ExpnData` fields `krate` and `orig_id` private These fields are only used by hygiene serialized, and should not be accessed by anything outside of `rustc_span`.
2021-01-04Do not run const prop on the `mir_for_ctfe` of `const fn`oli-19/+34
2021-01-04No doc comments on expressionsoli-3/+3
2021-01-04Small comment adjustmentsoli-0/+3