summary refs log tree commit diff
path: root/compiler/rustc_mir/src/transform
AgeCommit message (Collapse)AuthorLines
2020-11-06Disable 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-11-06Disable "optimization to avoid load of address" in InstCombineTomasz Miąsko-0/+5
2020-11-06revert #75443 update mir validatorBastian Kauschke-75/+21
2020-10-08Move `EarlyOtherwiseBranch` to mir-opt-level 2Dylan MacKenzie-1/+1
This didn't have an effect in most cases, and is not trivially sound. Let it bake at `mir-opt-level=2` for a while.
2020-10-08Fix miscompile in SimplifyBranchSameSimon Vandel Sillesen-1/+2
2020-10-03Rollup merge of #77251 - dtolnay:drop, r=Aaron1011Jonas Schievink-1/+30
Bypass const_item_mutation if const's type has Drop impl Follow-up to #75573. This PR disables the const_item_mutation lint in cases that the const has a Drop impl which observes the mutation. ```rust struct Log { msg: &'static str } const LOG: Log = Log { msg: "" }; impl Drop for Log { fn drop(&mut self) { println!("{}", self.msg); } } LOG.msg = "wow"; // prints "wow" ``` r? @Aaron1011
2020-10-02Auto merge of #77462 - jonas-schievink:rollup-m0rqdh5, r=jonas-schievinkbors-3/+12
Rollup of 12 pull requests Successful merges: - #76101 (Update RELEASES.md for 1.47.0) - #76739 (resolve: prohibit anon const non-static lifetimes) - #76811 (Doc alias name restriction) - #77405 (Add tracking issue of iter_advance_by feature) - #77409 (Add example for iter chain struct) - #77415 (Better error message for `async` blocks in a const-context) - #77423 (Add `-Zprecise-enum-drop-elaboration`) - #77432 (Use posix_spawn on musl targets) - #77441 (Fix AVR stack corruption bug) - #77442 (Clean up on example doc fixes for ptr::copy) - #77444 (Fix span for incorrect pattern field and add label) - #77453 (Stop running macOS builds on Azure Pipelines) Failed merges: r? `@ghost`
2020-10-02Rollup merge of #77415 - ecstatic-morse:const-checking-async-block, r=oli-obkJonas Schievink-3/+12
Better error message for `async` blocks in a const-context Improves the error message for the case in #77361. r? @oli-obk
2020-10-02validate: skip debuginfoJonas Schievink-15/+14
2020-10-02validate: storage must be allocated on local useJonas Schievink-3/+29
2020-10-01Disable the SimplifyArmIdentity mir-optWesley Wiser-1/+6
The optimization still has some bugs that need to be worked out such as #77359. We can try re-enabling this again after the known issues are resolved.
2020-10-01Fixme with link for re-enabling const mutation lint for Drop constsDavid Tolnay-2/+9
2020-10-01Give better const-checking error for `async` blocksDylan MacKenzie-3/+12
2020-10-01Auto merge of #74839 - alarsyo:multiple_return_terminators, r=oli-obkbors-0/+41
Implement multiple return terminator optimization Closes #72022
2020-10-01Implement multiple return terminators optimizationAntoine Martin-0/+41
2020-10-01Auto merge of #77354 - ecstatic-morse:const-checking-moar-errors, r=oli-obkbors-209/+242
Overhaul const-checking diagnostics The primary purpose of this PR was to remove `NonConstOp::STOPS_CONST_CHECKING`, which causes any additional errors found by the const-checker to be silenced. I used this flag to preserve diagnostic parity with `qualify_min_const_fn.rs`, which has since been removed. However, simply removing the flag caused a deluge of errors in some cases, since an error would be emitted any time a local or temporary had a wrong type. To remedy this, I added an alternative system (`DiagnosticImportance`) to silence additional error messages that were likely to distract the user from the underlying issue. When an error of the highest importance occurs, all less important errors are silenced. When no error of the highest importance occurs, all less important errors are emitted after checking is complete. Following the suggestions from the important error is usually enough to fix the less important errors, so this should lead to better UX most of the time. There's also some unrelated diagnostics improvements in this PR isolated in their own commits. Splitting them out would be possible, but a bit of a pain. This isn't as tidy as some of my other PRs, but it should *only* affect diagnostics, never whether or not something passes const-checking. Note that there are a few trivial exceptions to this, like banning `Yield` in all const-contexts, not just `const fn`. As always, meant to be reviewed commit-by-commit. r? `@oli-obk`
2020-09-30Warn on method call mutating const, even if it has destructorDavid Tolnay-1/+1
2020-09-30Skip dropck::check_drop_impl in is_const_item_without_destructorDavid Tolnay-1/+2
adt_destructor by default also validates the Drop impl using dropck::check_drop_impl, which contains an expect_local(). This leads to ICE in check_const_item_mutation if the const's type is not a local type. thread 'rustc' panicked at 'DefId::expect_local: `DefId(5:4805 ~ alloc[d7e9]::vec::{impl#50})` isn't local', compiler/rustc_span/src/def_id.rs:174:43 stack backtrace: 0: rust_begin_unwind 1: rustc_span::def_id::DefId::expect_local::{{closure}} 2: rustc_typeck::check::dropck::check_drop_impl 3: rustc_middle::ty::util::<impl rustc_middle::ty::context::TyCtxt>::calculate_dtor::{{closure}} 4: rustc_middle::ty::trait_def::<impl rustc_middle::ty::context::TyCtxt>::for_each_relevant_impl 5: rustc_middle::ty::util::<impl rustc_middle::ty::context::TyCtxt>::calculate_dtor 6: rustc_typeck::check::adt_destructor 7: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::adt_destructor>::compute 8: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl 9: rustc_query_system::query::plumbing::get_query_impl 10: rustc_mir::transform::check_const_item_mutation::ConstMutationChecker::is_const_item_without_destructor
2020-09-30Simplify defid destructor checkDavid Tolnay-1/+1
2020-09-30Add justification of the destructor filterDavid Tolnay-0/+12
2020-09-30Bypass const_item_mutation if const's type has Drop implDavid Tolnay-2/+11
2020-10-01Rollup merge of #77343 - varkor:rustc_args_required_const-validation, r=lcnrDylan DPC-1/+1
Validate `rustc_args_required_const` Fixes https://github.com/rust-lang/rust/issues/74608.
2020-10-01Rollup merge of #77324 - Aaron1011:fix/const-item-mutation-ptr, r=petrochenkovDylan DPC-5/+9
Don't fire `const_item_mutation` lint on writes through a pointer Fixes #77321
2020-09-30Rollup merge of #77037 - matthiaskrgr:cl42ppy, r=Dylan-DPCJonas Schievink-1/+1
more tiny clippy cleanups commits stand alone and can be reviewed one by one
2020-09-30Remove E0019, use E0015 for inline assembly in a constDylan MacKenzie-2/+2
2020-09-30Better span for attribute suggestionsDylan MacKenzie-11/+19
`def_span` has the same issues as `body.span`, so do it this way instead.
2020-09-30Validate `rustc_args_required_const`varkor-1/+1
2020-09-29Remove default `build_error` implDylan MacKenzie-29/+12
Now all structured errors must have their own error code
2020-09-29Remove machinery for halting error outputDylan MacKenzie-15/+0
2020-09-29Don't stop const-checking after erroneous trait boundDylan MacKenzie-6/+17
2020-09-29Emit multiple function pointer errors from const-checkerDylan MacKenzie-4/+0
2020-09-29Don't emit duplicate errors for the return placeDylan MacKenzie-1/+2
2020-09-29Priority levelsDylan MacKenzie-10/+74
2020-09-29Bless mut testsDylan MacKenzie-2/+0
2020-09-29Give `MutDeref` a real error messageDylan MacKenzie-0/+9
2020-09-29Remove `ops::non_const`Dylan MacKenzie-58/+55
This helper function was meant to reduce code duplication between const-checking pre- and post-drop-elaboration. Most of the functionality is only relevant for the pre-drop-elaboration pass.
2020-09-29Fix "unstable in stable" errorDylan MacKenzie-1/+6
The "otherwise" note is printed before the suggestion currently.
2020-09-29Return a `DiagnosticBuilder` from structured errorsDylan MacKenzie-75/+64
This ensures that `emit_error` will actually cause compilation to fail.
2020-09-29Forbid generator-specific MIR in all const-contextsDylan MacKenzie-5/+3
2020-09-29`delay_span_bug` if const-checking an `async` functionDylan MacKenzie-2/+17
This errors during AST lowering. Any errors we emit here are just noise.
2020-09-29Continue after `impl Trait` in `const fn`Dylan MacKenzie-2/+0
2020-09-29Continue const-checking after errors when easyDylan MacKenzie-24/+0
This doesn't change any UI test output
2020-09-28Don't fire `const_item_mutation` lint on writes through a pointerAaron Hill-5/+9
Fixes #77321
2020-09-28Auto merge of #77302 - RalfJung:rollup-n8gg3v6, r=RalfJungbors-7/+21
Rollup of 7 pull requests Successful merges: - #76454 (UI to unit test for those using Cell/RefCell/UnsafeCell) - #76474 (Add option to pass a custom codegen backend from a driver) - #76711 (diag: improve closure/generic parameter mismatch) - #77170 (Remove `#[rustc_allow_const_fn_ptr]` and add `#![feature(const_fn_fn_ptr_basics)]`) - #77194 (Add doc alias for iterator fold) - #77288 (fix building libstd for Miri on macOS) - #77295 (Update unstable-book: Fix ABNF in inline assembly docs) Failed merges: r? `@ghost`
2020-09-28Rollup merge of #77170 - ecstatic-morse:const-fn-ptr, r=oli-obkRalf Jung-7/+21
Remove `#[rustc_allow_const_fn_ptr]` and add `#![feature(const_fn_fn_ptr_basics)]` `rustc_allow_const_fn_ptr` was a hack to work around the lack of an escape hatch for the "min `const fn`" checks in const-stable functions. Now that we have co-opted `allow_internal_unstable` for this purpose, we no longer need a bespoke attribute. Now this functionality is gated under `const_fn_fn_ptr_basics` (how concise!), and `#[allow_internal_unstable(const_fn_fn_ptr_basics)]` replaces `#[rustc_allow_const_fn_ptr]`. `const_fn_fn_ptr_basics` allows function pointer types to appear in the arguments and locals of a `const fn` as well as function pointer casts to be performed inside a `const fn`. Both of these were allowed in constants and statics already. Notably, this does **not** allow users to invoke function pointers in a const context. Presumably, we will use a nicer name for that (`const_fn_ptr`?). r? @oli-obk
2020-09-27[mir-opt] Introduce a new flag to enable experimental/unsound mir optsWesley Wiser-1/+3
2020-09-27Add a feature gate for basic function pointer use in `const fn`Dylan MacKenzie-7/+21
2020-09-27Rollup merge of #77203 - ecstatic-morse:const-stability-attr-checks, r=oli-obkJonas Schievink-3/+0
Check for missing const-stability attributes in `rustc_passes` Currently, this happens as a side effect of `is_min_const_fn`, which is non-obvious. Also adds a test for this case, since we didn't seem to have one before.
2020-09-27Rollup merge of #77231 - oli-obk:clippy_const_fn, r=ManishearthJonas Schievink-463/+0
Move helper function for `missing_const_for_fn` out of rustc to clippy cc @rust-lang/clippy @ecstatic-morse #76618 r? @Manishearth I also removed all support for suggesting a function could be `const fn` when that would require feature gates to actually work. This means we'll now have to maintain this ourselves in clippy, but that's how most lints work anyway, so...
2020-09-27Rollup merge of #77107 - bugadani:perf, r=oli-obkJonas Schievink-5/+5
Enable const propagation into operands at mir_opt_level=2 Feature was added in #74507 but gated with `mir_opt_level>=3` because of compile time regressions. Let's see whether the LLVM 11 update solves that. As the [perf results](https://github.com/rust-lang/rust/pull/77107#issuecomment-697668154) show, enabling this optimization results in a lot less regression as before. cc @oli-obk r? @ghost