about summary refs log tree commit diff
path: root/compiler/rustc_mir/src/transform
AgeCommit message (Collapse)AuthorLines
2020-10-26Auto merge of #68965 - eddyb:mir-inline-scope, r=nagisa,oli-obkbors-118/+126
rustc_mir: track inlined callees in SourceScopeData. We now record which MIR scopes are the roots of *other* (inlined) functions's scope trees, which allows us to generate the correct debuginfo in codegen, similar to what LLVM inlining generates. This PR makes the `ui` test `backtrace-debuginfo` pass, if the MIR inliner is turned on by default. Also, `#[track_caller]` is now correct in the face of MIR inlining (cc `@anp).` Fixes #76997. r? `@rust-lang/wg-mir-opt`
2020-10-26simplify-locals: Remove unused assignments regardless of rvalue kindTomasz Miąsko-25/+1
2020-10-26simplify-locals: Remove unused set-discriminant statementsTomasz Miąsko-5/+9
Update affected ui & incremental tests to use a user declared variable bindings instead of temporaries. The former are preserved because of debuginfo, the latter are not.
2020-10-26simplify-locals: Change RemoveStatements visitor into a functionTomasz Miąsko-42/+31
No functionl changes intended.
2020-10-26simplify-locals: Unify use count visitorsTomasz Miąsko-113/+111
The simplify locals implementation uses two different visitors to update the locals use counts. The DeclMarker calculates the initial use counts. The StatementDeclMarker updates the use counts as statements are being removed from the block. Replace them with a single visitor that can operate in either mode, ensuring consistency of behaviour. Additionally use exhaustive match to clarify what is being optimized. No functional changes intended.
2020-10-26simplify-locals: Represent use counts with u32Tomasz Miąsko-6/+6
2020-10-26interning cleanup: we no longer need to distinguish Const and ConstInner; we ↵Ralf Jung-2/+1
no longer need the ignore_interior_mut_in_const hack
2020-10-26move UnsafeCell-in-const check from interning to validationRalf Jung-5/+6
2020-10-26Rollup merge of #78247 - simonvandel:fix-78192, r=oli-obkDylan DPC-6/+14
Fix #78192 Check which places are marked dead. Fixes #78192
2020-10-25Rollup merge of #78208 - liketechnik:issue-69399, r=oli-obkYuki Okushi-7/+15
replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s `#[allow_internal_unstable]` is currently used to side-step feature gate and stability checks. While it was originally only meant to be used only on macros, its use was expanded to `const fn`s. This pr adds stricter checks for the usage of `#[allow_internal_unstable]` (only on macros) and introduces the `#[rustc_allow_const_fn_unstable]` attribute for usage on `const fn`s. This pr does not change any of the functionality associated with the use of `#[allow_internal_unstable]` on macros or the usage of `#[rustc_allow_const_fn_unstable]` (instead of `#[allow_internal_unstable]`) on `const fn`s (see https://github.com/rust-lang/rust/issues/69399#issuecomment-712911540). Note: The check for `#[rustc_allow_const_fn_unstable]` currently only validates that the attribute is used on a function, because I don't know how I would check if the function is a `const fn` at the place of the check. I therefore openend this as a 'draft pull request'. Closes rust-lang/rust#69399 r? @oli-obk
2020-10-25Rollup merge of #78085 - wesleywiser:mir_validation_switch_int, r=oli-obkYuki Okushi-2/+24
MIR validation should check `SwitchInt` values are valid for the type Fixes #75440
2020-10-25Auto merge of #77526 - RalfJung:dont-promote-unions, r=lcnrbors-20/+14
stop promoting union field accesses in 'const' Turns out that promotion of union field accesses is the only difference between "promotion in `const`/`static` bodies" and "explicit promotion". So if we can remove this, we have finally achieved what I thought to already be the case -- that the bodies of `const`/`static` initializers behave the same as explicit promotion contexts. The reason we do not want to promote union field accesses is that they can introduce UB, i.e., they can go wrong. We want to [minimize the ways promoteds can fail to evaluate](https://github.com/rust-lang/const-eval/issues/53). Also this change makes things more consistent overall, removing a special case that was added without much consideration (as far as I can tell). Cc `@rust-lang/wg-const-eval`
2020-10-24Rollup merge of #78191 - tmiasko:temp-match-branch-simplification, r=oli-obkJonas Schievink-8/+22
Introduce a temporary for discriminant value in MatchBranchSimplification The optimization introduces additional uses of the discriminant operand, but does not ensure that it is still valid to evaluate it or that it still evaluates to the same value. Evaluate it once at original position, and store the result in a new temporary. Follow up on #78151. The optimization remains disabled by default. Closes #78239.
2020-10-24Rollup merge of #78069 - fusion-engineering-forks:core-const-panic-str, ↵Jonas Schievink-1/+3
r=RalfJung Fix const core::panic!(non_literal_str). Invocations of `core::panic!(x)` where `x` is not a string literal expand to `panic!("{}", x)`, which is not understood by the const panic logic right now. This adds `panic_str` as a lang item, and modifies the const eval implementation to hook into this item as well. This fixes the issue mentioned here: https://github.com/rust-lang/rust/issues/51999#issuecomment-687604248 r? `@RalfJung` `@rustbot` modify labels: +A-const-eval
2020-10-24MIR validation should check `SwitchInt` values are valid for the typeWesley Wiser-2/+24
2020-10-24Rollup merge of #78198 - tmiasko:assert, r=davidtwcoJonas Schievink-3/+4
Simplify assert terminator only if condition evaluates to expected value
2020-10-23rename allow_internal_unstable() to rustc_allow_const_fn_unstable() in rustc_mirFlorian Warzecha-3/+11
Followup rename from 05f4a9a42abbbdb64d3ec4ed0ae6883c10c66e3f, which introduced `#[rustc_allow_const_fn_unstable]` for `const fn`s.
2020-10-22Check which places are deadSimon Vandel Sillesen-6/+14
Fixes #78192
2020-10-22Fix const core::panic!(non_literal_str).Mara Bos-1/+3
2020-10-22Rollup merge of #77420 - ecstatic-morse:const-checking-raw-mut-ref, r=davidtwcoYuki Okushi-29/+15
Unify const-checking structured errors for `&mut` and `&raw mut` Resolves #77414 as well as a FIXME.
2020-10-21switch allow_internal_unstable const fns to rustc_allow_const_fn_unstableFlorian Warzecha-4/+4
2020-10-21rustc_mir: run the MIR inlining Integrator on the whole callee body at once.Eduard-Mihai Burtescu-70/+65
2020-10-21rustc_mir: create the Integrator as soon as possible in MIR inlining.Eduard-Mihai Burtescu-45/+44
2020-10-21rustc_mir: don't throw away inlined locals' spans.Eduard-Mihai Burtescu-1/+0
2020-10-21rustc_mir: properly map scope parent chains into the caller when inlining.Eduard-Mihai Burtescu-0/+5
2020-10-21rustc_mir: support MIR-inlining #[track_caller] functions.Eduard-Mihai Burtescu-5/+13
2020-10-21rustc_mir: track inlined callees in SourceScopeData.Eduard-Mihai Burtescu-10/+6
2020-10-21rustc_mir: use Instance more in the inliner.Eduard-Mihai Burtescu-25/+28
2020-10-21rustc_mir: rename `location: SourceInfo` to `source_info`.Eduard-Mihai Burtescu-12/+15
2020-10-21Introduce a temporary for discriminant value in MatchBranchSimplificationTomasz Miąsko-8/+22
The optimization introduces additional uses of the discriminant operand, but does not ensure that it is still valid to evaluate it or that it still evaluates to the same value. Evaluate it once at original position, and store the result in a new temporary.
2020-10-21Simplify assert terminator only if condition evaluates to expected valueTomasz Miąsko-3/+4
2020-10-21Rollup merge of #78101 - RalfJung:foreign-static, r=oli-obkYuki Okushi-0/+3
fix static_ptr_ty for foreign statics Cc https://github.com/rust-lang/rust/issues/74840 This does not fix that issue but fixes a problem in `static_ptr_ty` that we noticed while discussing that issue. I also added and updated a few comments. The one about `internal` locals being ignored does not seem to have been true [even in the commit that introduced it](https://github.com/rust-lang/rust/pull/44700/files#diff-ae2f3c7e2f9744f7ef43e96072b10e98d4e3fe74a3a399a3ad8a810fbe56c520R139). r? @oli-obk
2020-10-21Disable "optimization to avoid load of address" in InstCombineTomasz Miąsko-0/+5
2020-10-20Disable MatchBranchSimplificationTomasz Miąsko-0/+7
This optimization can result in unsoundness, because it introduces additional uses of a place holding the discriminant value without ensuring that it is valid to do so.
2020-10-19fix static_ptr_ty for foreign statics, and more comments in check_unsafetyRalf Jung-0/+3
2020-10-18Auto merge of #77306 - lcnr:inline-ok, r=eddybbors-3/+7
normalize substs while inlining fixes #68347 or more precisely, this fixes the same ICE in rust analyser as veloren is pinned to a specific nightly and had an error with the current one. I didn't look into creating an MVCE here as that seems fairly annoying, will spend a few minutes doing so rn. (failed) r? `@eddyb` cc `@bjorn3`
2020-10-17Auto merge of #77373 - jonas-schievink:rm-rf-copy-prop, r=oli-obkbors-387/+1
Remove the old copy propagation pass This pass was added a long time ago, and has not really seen much improvement since (apart from some great work in https://github.com/rust-lang/rust/pull/76569 that unfortunately ran into preexisting soundness issues). It is slow and unsound, and we now have a destination propagation pass that performs a related optimization and could be extended. Closes https://github.com/rust-lang/rust/issues/36673 Closes https://github.com/rust-lang/rust/issues/73717 Closes https://github.com/rust-lang/rust/issues/76740
2020-10-17Remove the old copy propagation passJonas Schievink-387/+1
2020-10-17Rollup merge of #77992 - nagisa:thaw-coverage-instrumentation, r=wesleywiserYuki Okushi-10/+2
instrument-coverage: try our best to not ICE instrument-coverage was ICEing for me on some code, in particular code that had devirtualized paths from standard library. Instrument coverage probably has no bussiness dictating which paths are valid and which aren't so just feed it everything and whatever and let tooling deal with other stuff. For example, with this commit we can generate coverage hitpoints for these interesting paths: * `/rustc/.../library/core/lib.rs` – non-devirtualized path for libcore * `/home/.../src/library/core/lib.rs` – devirtualized version of above * `<inline asm>`, `<anon>` and many similar synthetic paths Even if those paths somehow get to the instrumentation pass, I'd much rather get hits for these weird paths and hope some of them work (as would be the case for devirtualized path to libcore), rather than have compilation fail entirely.
2020-10-16instrument-coverage: try our best to not ICESimonas Kazlauskas-10/+2
instrument-coverage was ICEing for me on some code, in particular code that had devirtualized paths from standard library. Instrument coverage probably has no bussiness dictating which paths are valid and which aren't so just feed it everything and whatever and let tooling deal with other stuff. For example, with this commit we can generate coverage hitpoints for these interesting paths: * `/rustc/.../library/core/lib.rs` – non-devirtualized path for libcore * `/home/.../src/library/core/lib.rs` – devirtualized version of above * `<inline asm>`, `<anon>` and many similar synthetic paths Even if those paths somehow get to the instrumentation pass, I'd much rather get hits for these weird paths and hope some of them work (as would be the case for devirtualized path to libcore), rather than have compilation fail entirely.
2020-10-16Auto merge of #77947 - tmiasko:promoted-scope, r=oli-obkbors-3/+14
Create a single source scope for promoteds A promoted inherits all scopes from the parent body. At the same time, almost all statements and terminators inside the promoted body so far refer only to one of those scopes: the outermost one. Instead of inheriting all scopes, inherit only a single scope corresponding to the location of the promoted, making sure that there are no references to other scopes.
2020-10-14Create a single source scope for promotedsTomasz Miąsko-3/+14
A promoted inherits all scopes from the parent body. At the same time, almost all statements and terminators inside the promoted body so far refer only to one of those scopes: the outermost one. Instead of inheriting all scopes, inherit only a single scope corresponding to the location of the promoted, making sure that there are no references to other scopes.
2020-10-14Validate references to source scopesTomasz Miąsko-2/+15
2020-10-14Rollup merge of #77892 - est31:remove_redundant_absolute_paths, r=lcnrYuki Okushi-1/+1
Replace absolute paths with relative ones Modern compilers allow reaching external crates like std or core via relative paths in modules outside of lib.rs and main.rs.
2020-10-13Replace absolute paths with relative onesest31-1/+1
Modern compilers allow reaching external crates like std or core via relative paths in modules outside of lib.rs and main.rs.
2020-10-13Auto merge of #77755 - bugadani:perf-calc-dtor, r=ecstatic-morsebors-1/+1
Monomorphize `calculate_dtor` instead of using function pointers Change `calculate_dtor` to avoid dynamic dispatching. This change allows the empty functions to be optimized away. Based on the discussion in https://github.com/rust-lang/rust/pull/77754#discussion_r502498970, the performance impact of this change was measured. Perf run results: https://perf.rust-lang.org/compare.html?start=7bc5839e99411aad9061a632b62075d1346cbb3b&end=ffec759ae9bbc4d6d2235ff40ade6723a85bc7cc
2020-10-13Auto merge of #77796 - jonas-schievink:switchint-refactor, r=oli-obkbors-97/+86
Refactor how SwitchInt stores jump targets Closes https://github.com/rust-lang/rust/issues/65693
2020-10-13Rollup merge of #77550 - lcnr:ty-dep-path-ct-cleanup, r=ecstatic-morseYuki Okushi-5/+1
add shims for WithOptConstParam query calls r? @ecstatic-morse @eddyb
2020-10-11Auto merge of #77793 - tmiasko:no-op-discriminant, r=ecstatic-morsebors-1/+1
Recognize discriminant reads as no-ops in RemoveNoopLandingPads The cleanup blocks often contain read of discriminants. Teach RemoveNoopLandingPads to recognize them as no-ops to remove additional no-op landing pads.
2020-10-11Use SmallVec in SwitchTargetsJonas Schievink-1/+1
This allows building common SwitchTargets (eg. for `if`s) without allocation.