about summary refs log tree commit diff
path: root/compiler/rustc_mir/src/transform
AgeCommit message (Collapse)AuthorLines
2020-10-31Assert that locals have storage when usedTomasz Miąsko-12/+21
The validator in visit_local asserts that local has a stroage when used, but visit_local is never called so validation is ineffective. Use super_statement and super_terminator to ensure that locals are visited.
2020-10-30validator: Extend aliasing check to a call terminatorTomasz Miąsko-5/+40
2020-10-29Link to pass docs from NRVO module docsCamelid-0/+2
2020-10-28Rollup merge of #78351 - RalfJung:validity-unsafe-cell, r=oli-obkDylan DPC-7/+7
Move "mutable thing in const" check from interning to validity This moves the check for mutable things (such as `UnsafeCell` or `&mut`) in a`const` from interning to validity. That means we can give more targeted error messages (pointing out *where* the problem lies), and we can simplify interning a bit. Also fix the interning mode used for promoteds in statics. r? @oli-obk
2020-10-27Auto merge of #76269 - ayrtonm:function-reference-lint, r=oli-obkbors-0/+207
added a lint against function references this lint suggests casting function references to `*const ()` closes #75239 r? `@RalfJung`
2020-10-27Added suggestion to `function_item_references` lint and fixed warning messageAyrton-10/+17
Also updated tests accordingly and tweaked some wording in the lint declaration.
2020-10-27Added documentation for `function_item_references` lintAyrton-44/+52
Added documentation for `function_item_references` lint to the rustc book and fixed comments in the lint checker itself.
2020-10-27Fixed compiler error in lint checker triggered by associated typesAyrton-53/+65
When a function argument bound by `Pointer` is an associated type, we only perform substitutions using the parameters from the callsite but don't attempt to normalize since it may not succeed. A simplified version of the scenario that triggered this error was added as a test case. Also fixed `Pointer::fmt` which was being double-counted when called outside of macros and added a test case for this.
2020-10-27Removed test for unhandled case in function_item_references lintAyrton-1/+1
Removed test for the unhandled case of calls to `fn f<T>(x: &T)` where `x` is a function reference and is formatted as a pointer in `f`. This compiles since `&T` implements `Pointer`, but is unlikely to occur in practice. Also tweaked the lint's wording and modified tests accordingly.
2020-10-27Changed lint to check for `std::fmt::Pointer` and `transmute`Ayrton-93/+113
The lint checks arguments in calls to `transmute` or functions that have `Pointer` as a trait bound and displays a warning if the argument is a function reference. Also checks for `std::fmt::Pointer::fmt` to handle formatting macros although it doesn't depend on the exact expansion of the macro or formatting internals. `std::fmt::Pointer` and `std::fmt::Pointer::fmt` were also added as diagnostic items and symbols.
2020-10-27modified lint to work with MIRAyrton-0/+160
Working with MIR let's us exclude expressions like `&fn_name as &dyn Something` and `(&fn_name)()`. Also added ABI, unsafety and whether a function is variadic in the lint suggestion, included the `&` in the span of the lint and updated the test.
2020-10-27Disable "optimization to avoid load of address" in InstCombineJonas Schievink-0/+5
2020-10-26Auto merge of #77876 - tmiasko:simplify-locals, r=wesleywiserbors-143/+110
Remove unused set-discriminant statements and assignments regardless of rvalue * Represent use counts with u32 * Unify use count visitors * Change RemoveStatements visitor into a function * Remove unused set-discriminant statements * Use exhaustive match to clarify what is being optimized * Remove unused assignments regardless of rvalue kind
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