about summary refs log tree commit diff
path: root/compiler/rustc_mir/src
AgeCommit message (Collapse)AuthorLines
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-27Show the inline stack of MIR lints that only occur after inliningOliver Scherer-0/+13
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-149/+214
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-26explain why interning is not as trivial as it might seemRalf Jung-0/+11
2020-10-26interning cleanup: we no longer need to distinguish Const and ConstInner; we ↵Ralf Jung-69/+33
no longer need the ignore_interior_mut_in_const hack
2020-10-26move &mut-in-const check from interning to validationRalf Jung-3/+11
2020-10-26move UnsafeCell-in-const check from interning to validationRalf Jung-47/+63
2020-10-26ensure we intern all promoteds as InternKind::PromotedRalf Jung-10/+7
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-25Auto merge of #78179 - RalfJung:miri-comments, r=oli-obkbors-23/+25
Miri engine: entirely skip interning of ZST, and improve some comments r? `@oli-obk`
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-2/+5
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-2/+5
2020-10-22Auto merge of #78212 - JohnTitor:rollup-j5r6xuy, r=JohnTitorbors-29/+15
Rollup of 10 pull requests Successful merges: - #77420 (Unify const-checking structured errors for `&mut` and `&raw mut`) - #77554 (Support signed integers and `char` in v0 mangling) - #77976 (Mark inout asm! operands as used in liveness pass) - #78009 (Haiku: explicitly set CMAKE_SYSTEM_NAME when cross-compiling) - #78084 (Greatly improve display for small mobile devices screens) - #78155 (Fix two small issues in compiler/rustc_lint/src/types.rs) - #78156 (Fixed build failure of `rustfmt`) - #78172 (Add test case for #77062) - #78188 (Add tracking issue number for pin_static_ref) - #78200 (Add `ControlFlow::is_{break,continue}` methods) Failed merges: r? `@ghost`
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-21reviewBastian Kauschke-17/+4
2020-10-21Lift: take self by valueBastian Kauschke-2/+2
2020-10-21switch allow_internal_unstable const fns to rustc_allow_const_fn_unstableFlorian Warzecha-4/+4
2020-10-21Miri engine interning: improve comments, and entirely skip ZSTRalf Jung-11/+17
2020-10-21Miri engine validity check: simplify code with 'matches!'Ralf Jung-12/+8
and improve a comment a bit
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-38/+83
2020-10-21rustc_mir: track inlined callees in SourceScopeData.Eduard-Mihai Burtescu-13/+29
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