about summary refs log tree commit diff
path: root/compiler/rustc_mir/src/transform
AgeCommit message (Collapse)AuthorLines
2020-10-10Refactor how SwitchInt stores jump targetsJonas Schievink-97/+86
2020-10-10Take functions by valueDániel Buga-1/+1
2020-10-10Recognize discriminant reads as no-ops in RemoveNoopLandingPadsTomasz Miąsko-1/+1
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-09Revert calculate_dtor signature changeDániel Buga-1/+1
2020-10-09Add find_map_relevant_implDániel Buga-2/+1
2020-10-07Auto merge of #77597 - simonvandel:uninhabited-hashset, r=jonas-schievinkbors-2/+7
perf: UninhabitedEnumBranching avoid n^2 Avoid n² complexity. This showed up in a profile for match-stress-enum that has 8192 variants I have only profiled locally against `match-stress-enum`, so we should have it perf tested to make sure it does not regress other crates.
2020-10-07perf: UninhabitedEnumBranching void n^2Simon Vandel Sillesen-2/+7
Avoid n² complexity. This showed up in a profile for match-stress-enum that has 8192 variants
2020-10-07Auto merge of #77464 - ecstatic-morse:const-fn-impl-trait, r=oli-obkbors-3/+8
Give `impl Trait` in a `const fn` its own feature gate ...previously it was gated under `#![feature(const_fn)]`. I think we actually want to do this in all const-contexts? If so, this should be `#![feature(const_impl_trait)]` instead. I don't think there's any way to make use of `impl Trait` within a `const` initializer. cc #77463 r? `@oli-obk`
2020-10-07normalize substs during inliningBastian Kauschke-3/+7
2020-10-07Rollup merge of #77582 - ecstatic-morse:disable-early-otherwise-branch, ↵Dylan DPC-1/+1
r=wesleywiser Move `EarlyOtherwiseBranch` to mir-opt-level 2 cc #75119 This didn't have an [effect in most cases](https://perf.rust-lang.org/compare.html?start=81e02708f1f4760244756548981277d5199baa9a&end=2e0edc0f28c5647141bedba02e7a222d3a5dc9c3&stat=instructions:u), and is not trivially sound. Let it bake at `mir-opt-level=2` for a while. Also, this missed the cutoff for beta, so we'll have to backport this. r? @wesleywiser
2020-10-07Rollup merge of #77568 - lcnr:mir-inline-def-id, r=ecstatic-morseDylan DPC-17/+15
inliner: use caller param_env We used the callee param env instead of the caller param env by accident in #77430, this PR fixes that and caches it in the `Inliner` struct. fixes #77564 r? @ecstatic-morse
2020-10-05Make `impl Trait` unstable in all contextsDylan MacKenzie-6/+2
2020-10-05Remove `fn` from feature nameDylan MacKenzie-2/+2
2020-10-05Add `#![feature(const_fn_impl)]`Dylan MacKenzie-2/+11
2020-10-05Move `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-05Updates to experimental coverage counter injectionRich Kadel-217/+1011
This is a combination of 18 commits. Commit #2: Additional examples and some small improvements. Commit #3: fixed mir-opt non-mir extensions and spanview title elements Corrected a fairly recent assumption in runtest.rs that all MIR dump files end in .mir. (It was appending .mir to the graphviz .dot and spanview .html file names when generating blessed output files. That also left outdated files in the baseline alongside the files with the incorrect names, which I've now removed.) Updated spanview HTML title elements to match their content, replacing a hardcoded and incorrect name that was left in accidentally when originally submitted. Commit #4: added more test examples also improved Makefiles with support for non-zero exit status and to force validation of tests unless a specific test overrides it with a specific comment. Commit #5: Fixed rare issues after testing on real-world crate Commit #6: Addressed PR feedback, and removed temporary -Zexperimental-coverage -Zinstrument-coverage once again supports the latest capabilities of LLVM instrprof coverage instrumentation. Also fixed a bug in spanview. Commit #7: Fix closure handling, add tests for closures and inner items And cleaned up other tests for consistency, and to make it more clear where spans start/end by breaking up lines. Commit #8: renamed "typical" test results "expected" Now that the `llvm-cov show` tests are improved to normally expect matching actuals, and to allow individual tests to override that expectation. Commit #9: test coverage of inline generic struct function Commit #10: Addressed review feedback * Removed unnecessary Unreachable filter. * Replaced a match wildcard with remining variants. * Added more comments to help clarify the role of successors() in the CFG traversal Commit #11: refactoring based on feedback * refactored `fn coverage_spans()`. * changed the way I expand an empty coverage span to improve performance * fixed a typo that I had accidently left in, in visit.rs Commit #12: Optimized use of SourceMap and SourceFile Commit #13: Fixed a regression, and synched with upstream Some generated test file names changed due to some new change upstream. Commit #14: Stripping out crate disambiguators from demangled names These can vary depending on the test platform. Commit #15: Ignore llvm-cov show diff on test with generics, expand IO error message Tests with generics produce llvm-cov show results with demangled names that can include an unstable "crate disambiguator" (hex value). The value changes when run in the Rust CI Windows environment. I added a sed filter to strip them out (in a prior commit), but sed also appears to fail in the same environment. Until I can figure out a workaround, I'm just going to ignore this specific test result. I added a FIXME to follow up later, but it's not that critical. I also saw an error with Windows GNU, but the IO error did not specify a path for the directory or file that triggered the error. I updated the error messages to provide more info for next, time but also noticed some other tests with similar steps did not fail. Looks spurious. Commit #16: Modify rust-demangler to strip disambiguators by default Commit #17: Remove std::process::exit from coverage tests Due to Issue #77553, programs that call std::process::exit() do not generate coverage results on Windows MSVC. Commit #18: fix: test file paths exceeding Windows max path len
2020-10-05Auto merge of #77549 - tmiasko:simplify-branch-same-fix, r=oli-obkbors-1/+2
Fix miscompile in SimplifyBranchSame Cherry-picked from #77486, but with a different test case that used to be compiled incorrectly on both master & beta branches.
2020-10-05Auto merge of #77552 - ecstatic-morse:body-def-id, r=lcnrbors-95/+77
Replace `(Body, DefId)` with `Body` where possible Follow-up to #77430. I `grep`-ed for parameter lists in which a `Body` appeared within a few lines of a `DefId`, so it's possible that I missed some cases, but this should be pretty complete. Most of these changes were mechanical, but there's a few places where I started calling things "caller" and "callee" when multiple `DefId`s were in-scope at once. Also, we should probably have a helper function on `Body` that returns a `LocalDefId`. I can do that in this PR or in a follow-up.
2020-10-05inliner: use caller param_envBastian Kauschke-17/+15
2020-10-05query_name_of_opt_const_arg -> query_name_opt_const_argBastian Kauschke-1/+1
2020-10-05Rollup merge of #77512 - ecstatic-morse:const-checking-allow-abort, r=RalfJungDylan DPC-17/+11
Allow `Abort` terminators in all const-contexts We never unwind during const-eval, so we basically have these semantics already. Also I just figured out that these only appear along the cleanup path, which doesn't get const-checked. In other words, this doesn't actually change behavior: the `check-pass` test I added compiles just fine on nightly. r? @RalfJung cc @rust-lang/wg-const-eval
2020-10-04Replace `(Body, WithOptConstParam)` with `Body` where possibleDylan MacKenzie-6/+3
2020-10-04Replace `(Body, DefId)` with `Body` where possibleDylan MacKenzie-89/+74
A `Body` now contains its `MirSource`, which in turn contains the `DefId` of the item associated with the `Body`.
2020-10-04cleanup WithOptConstParam queriesBastian Kauschke-5/+1
2020-10-04Add comment to `Abort` match armecstatic-morse-0/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2020-10-04Remember the `MirSource` for each `Body`Dylan MacKenzie-269/+207
2020-10-04Move `MirSource` to `rustc_middle`Dylan MacKenzie-28/+3
2020-10-04Discuss cleanup blocks and `span_bug` on `Abort`Dylan MacKenzie-6/+11
2020-10-04stop promoting union field accesses in 'const'Ralf Jung-20/+14
2020-10-04Enable RenameReturnPlace MIR optimization on mir-opt-level >= 2Tomasz Miąsko-6/+0
The destination propagation as currently implemented does not supersede the NRVO, e.g., the destination propagation never applies if either local has an address taken, while NRVO might. Additionally, the issue with failing assertions had been already resolved. Continue running both optimizations at mir-opt-level >= 2.
2020-10-04Fix miscompile in SimplifyBranchSameSimon Vandel Sillesen-1/+2
2020-10-03Allow `Abort` terminators in a const-contextDylan MacKenzie-14/+2
These appear along the cleanup path inside functions with `#[unwind(aborts)]`. We don't const-check the cleanup path anyways, since const-eval already has "abort-on-panic" semantics and there's often drops that would otherwise be forbidden, so the check wasn't really preventing anything anyways.
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-01Unify `&mut` and `&raw mut` const-checking errorsDylan MacKenzie-29/+15
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.