about summary refs log tree commit diff
path: root/src/librustc_mir
AgeCommit message (Collapse)AuthorLines
2020-02-29Rollup merge of #69567 - matthiaskrgr:useless_fmt, r=nagisaDylan DPC-12/+12
use .to_string() instead of format!() macro to create strings handles what is left after https://github.com/rust-lang/rust/pull/69541
2020-02-29Rollup merge of #69551 - matthiaskrgr:len_zero, r=Mark-SimulacrumDylan DPC-6/+6
use is_empty() instead of len() == x to determine if structs are empty.
2020-02-29use .to_string() instead of format!() macro to create stringsMatthias Krüger-12/+12
2020-02-28miri engine: turn some debug_assert into assertRalf Jung-14/+12
2020-02-28Don't bug when taking discriminant of generatorDylan MacKenzie-54/+72
2020-02-28Rollup merge of #69547 - matthiaskrgr:more_misc, r=Mark-SimulacrumMazdak Farrokhzad-5/+1
remove redundant clones, references to operands, explicit boolean comparisons and filter(x).next() calls.
2020-02-28Rollup merge of #69541 - dotdash:format, r=Mark-SimulacrumMazdak Farrokhzad-4/+2
Remove unneeded calls to format!()
2020-02-28Rollup merge of #69481 - matthiaskrgr:single_char, r=ecstatic-morseMazdak Farrokhzad-3/+3
use char instead of &str for single char patterns
2020-02-28remove ScalarMaybeUndef::to_bits and make Scalar::to_bits privateRalf Jung-43/+41
2020-02-28use is_empty() instead of len() == x to determine if structs are empty.Matthias Krüger-6/+6
2020-02-28remove redundant clones, references to operands, explicit boolean ↵Matthias Krüger-5/+1
comparisons and filter(x).next() calls.
2020-02-28Auto merge of #68505 - skinny121:canonicalize-const-eval-inputs, r=nikomatsakisbors-5/+1
Canonicalize inputs to const eval where needed Canonicalize inputs to const eval, so that they can contain inference variables. Which enables invoking const eval queries even if the current param env has inference variable within it, which can occur during trait selection. This is a reattempt of #67717, in a far less invasive way. Fixes #68477 r? @nikomatsakis cc @eddyb
2020-02-27don't use .into() to convert types into identical types.Matthias Krüger-6/+5
example: let s: String = format!("hello").into();
2020-02-27- polonius: adapt to the new fact formatAlbin Stjerna-42/+57
- update polonius-engine dependency to 0.12.0 - rustfmt the files failing tidy
2020-02-27Remove now unused `GenKill` impl for old `GenKillSet`Dylan MacKenzie-11/+0
2020-02-27Rename `RequiresStorage` to `MaybeRequiresStorage`Dylan MacKenzie-11/+11
...to be consistent with the naming of other dataflow analyses.
2020-02-27Port `RequiresStorage` to new dataflow frameworkDylan MacKenzie-100/+97
2020-02-27Add inherent `visit_with` method to `dataflow::Results`Dylan MacKenzie-0/+18
This is more ergonomic than importing `dataflow::visit_results`
2020-02-27Port `MaybeStorageLive` to new dataflow frameworkDylan MacKenzie-41/+37
2020-02-27Auto merge of #68528 - ecstatic-morse:maybe-init-variants, r=oli-obkbors-25/+192
Mark other variants as uninitialized after switch on discriminant During drop elaboration, which builds the drop ladder that handles destruction during stack unwinding, we attempt to remove MIR `Drop` terminators that will never be reached in practice. This reduces the number of basic blocks that are passed to LLVM, which should improve performance. In #66753, a user pointed out that unreachable `Drop` terminators are common in functions like `Option::unwrap`, which move out of an `enum`. While discussing possible remedies for that issue, @eddyb suggested moving const-checking after drop elaboration. This would allow the former, which looks for `Drop` terminators and replicates a small amount of drop elaboration to determine whether a dropped local has been moved out, leverage the work done by the latter. However, it turns out that drop elaboration is not as precise as it could be when it comes to eliminating useless drop terminators. For example, let's look at the code for `unwrap_or`. ```rust fn unwrap_or<T>(opt: Option<T>, default: T) -> T { match opt { Some(inner) => inner, None => default, } } ``` `opt` never needs to be dropped, since it is either moved out of (if it is `Some`) or has no drop glue (if it is `None`), and `default` only needs to be dropped if `opt` is `Some`. This is not reflected in the MIR we currently pass to codegen. ![pasted_image](https://user-images.githubusercontent.com/29463364/73384403-109a0d80-4280-11ea-8500-0637b368f2dc.png) @eddyb also suggested the solution to this problem. When we switch on an enum discriminant, we should be marking all fields in other variants as definitely uninitialized. I implemented this on top of alongside a small optimization (split out into #68943) that suppresses drop terminators for enum variants with no fields (e.g. `Option::None`). This is the resulting MIR for `unwrap_or`. ![after](https://user-images.githubusercontent.com/29463364/73384823-e432c100-4280-11ea-84bd-d0bcc3b777b4.png) In concert with #68943, this change speeds up many [optimized and debug builds](https://perf.rust-lang.org/compare.html?start=d55f3e9f1da631c636b54a7c22c1caccbe4bf0db&end=0077a7aa11ebc2462851676f9f464d5221b17d6a). We need to carefully investigate whether I have introduced any miscompilations before merging this. Code that never drops anything would be very fast indeed until memory is exhausted.
2020-02-27Remove unneeded calls to format!()Björn Steinbrink-4/+2
2020-02-27use char instead of &str for single char patternsMatthias Krüger-3/+3
2020-02-27Auto merge of #67332 - matthewjasper:drop-in-place-cgus, r=michaelwoeristerbors-3/+10
Don't instantiate so many copies of drop_in_place Split out from #66703. r? @ghost
2020-02-26Auto merge of #67742 - mark-i-m:describe-it, r=matthewjasperbors-22/+33
Generalized article_and_description r? @matthewjasper The logic of finding the right word and article to print seems to be repeated elsewhere... this is an experimental method to unify this logic...
2020-02-26miri: validity visitor comments and path printing improvementsRalf Jung-22/+45
2020-02-24don't explicitly compare against true or falseMatthias Krüger-2/+2
2020-02-23fmtRalf Jung-4/+1
2020-02-23canonicalize alloc ID before calling tag_static_base_pointerRalf Jung-1/+4
2020-02-23miri/machine: add canonical_alloc_id hook to replace find_foreign_staticRalf Jung-65/+57
2020-02-22add generator_kind queryMark Mansi-8/+10
2020-02-22some fixesMark Mansi-13/+2
2020-02-22minor cleanupMark Mansi-4/+4
2020-02-22Generalized article_and_descriptionMark Mansi-13/+33
2020-02-22Auto merge of #69374 - Dylan-DPC:rollup-x7mjd5z, r=Dylan-DPCbors-1/+1
Rollup of 7 pull requests Successful merges: - #68984 (Make `u8::is_ascii` a stable `const fn`) - #69339 (Add test for #69312) - #69346 (Clean up E0323, E0324, E0325 and E0326 explanations) - #69348 (Wrong error message for move_ref_pattern) - #69349 (MIR is not an experiment anymore) - #69354 (Test `Duration::new` panics on overflow) - #69370 (move const_eval.rs into the module folder) Failed merges: r? @ghost
2020-02-22Rollup merge of #69370 - RalfJung:const-eval-mod, r=oli-obkDylan DPC-0/+0
move const_eval.rs into the module folder This groups the file together with the other `const_eval` files in editors, diff views, etc. r? @oli-obk
2020-02-22Rollup merge of #69349 - spastorino:mir-not-an-experiment, r=Dylan-DPCDylan DPC-1/+1
MIR is not an experiment anymore At least I hope is not :stuck_out_tongue_closed_eyes: r? @oli-obk
2020-02-22move const_eval.rs into the module folderRalf Jung-0/+0
2020-02-22Auto merge of #69333 - ecstatic-morse:revert-simd-shuffle, r=petrochenkovbors-7/+21
Revert #69280 Resolves #69313 by reverting #69280. After #69280, `#[rustc_args_required_const(2)]` is required on the declaration of `simd_shuffle` intrinsics. This is allowed breakage, since you can't define platform intrinsics on stable. However, the latest release of the widely used `packed_simd` crate defines these intrinsics without the requisite attribute. Since there's no urgency to merge #69280, let's revert it. We can reconsider when rust-lang/packed_simd#278 is included in a point release of `packed_simd`. r? @petrochenkov
2020-02-22Auto merge of #69302 - jonas-schievink:yield-needs-storage, r=Zoxcbors-21/+78
Fix generator miscompilations Fixes https://github.com/rust-lang/rust/issues/69039 r? @Zoxc
2020-02-21MIR is not an experiment anymoreSantiago Pastorino-1/+1
2020-02-21Auto merge of #69290 - wesleywiser:speed_up_ctfe_stress_4, r=RalfJungbors-6/+6
Check `RUSTC_CTFE_BACKTRACE` much less by generating fewer errors Before this change, `get_size_and_align()` calls `get_fn_alloc()` *a lot* in CTFE heavy code. This previously returned an `Error` which would check if `RUSTC_CTFE_BACKTRACE` was set on construction. Doing this turned out to be a performance hotspot as @nnethercote discovered in #68792. This is an alternate take on that PR which resolves the performance issue by generating *many* fewer errors. Previously, `ctfe-stress-4` would generate over 5,000,000 errors each of which would check for the presence of the environment variable. With these changes, that number is reduced to 30. r? @RalfJung
2020-02-20Revert "Rollup merge of #69280 - ↵Dylan MacKenzie-7/+21
ecstatic-morse:promote-shuffle-no-special-case, r=petrochenkov" This reverts commit 61d3b6dedb1ec1f3e3cbd3d66b1a3453225bc37c, reversing changes made to c6ad1e2c2a0c7e48537617d36085f866fa6a65a3.
2020-02-20Auto merge of #69072 - ecstatic-morse:associated-items, r=petrochenkovbors-2/+2
O(log n) lookup of associated items by name Resolves #68957, in which compile time is quadratic in the number of associated items. This PR makes name lookup use binary search instead of a linear scan to improve its asymptotic performance. As a result, the pathological case from that issue now runs in 8 seconds on my local machine, as opposed to many minutes on the current stable. Currently, method resolution must do a linear scan through all associated items of a type to find one with a certain name. This PR changes the result of the `associated_items` query to a data structure that preserves the definition order of associated items (which is used, e.g., for the layout of trait object vtables) while adding an index of those items sorted by (unhygienic) name. When doing name lookup, we first find all items with the same `Symbol` using binary search, then run hygienic comparison to find the one we are looking for. Ideally, this would be implemented using an insertion-order preserving, hash-based multi-map, but one is not readily available. Someone who is more familiar with identifier hygiene could probably make this better by auditing the uses of the `AssociatedItems` interface. My goal was to preserve the current behavior exactly, even if it seemed strange (I left at least one FIXME to this effect). For example, some places use comparison with `ident.modern()` and some places use `tcx.hygienic_eq` which requires the `DefId` of the containing `impl`. I don't know whether those approaches are equivalent or which one should be preferred.
2020-02-20Rollup merge of #69185 - RalfJung:const-prop-lints, r=oli-obkMazdak Farrokhzad-91/+86
Unify and improve const-prop lints Add a single helper method for all lints emitted by const-prop, and make that lint different from the CTFE `const_err` lint. Also consistently check overflow on *arithmetic*, not on the assertion, to make behavior the same for debug and release builds. See [this summary comment](https://github.com/rust-lang/rust/pull/69185#issuecomment-587924754) for details and the latest status. In terms of lint formatting, I went for what seems to be the better style: have a general message above the code, and then a specific message at the span: ``` error: this arithmetic operation will overflow --> $DIR/const-err2.rs:21:18 | LL | let a_i128 = -std::i128::MIN; | ^^^^^^^^^^^^^^^ attempt to negate with overflow ``` We could also just have the specific message above and no text at the span if that is preferred. I also converted some of the existing tests to use compiletest revisions, so that the same test can check a bunch of different compile flags. Fixes https://github.com/rust-lang/rust/issues/69020. Helps with https://github.com/rust-lang/rust/issues/69021: debug/release are now consistent, but the assoc-const test in that issue still fails (there is a FIXME in the PR for this). The reason seems to be that const-prop notices the assoc const in `T::N << 42` and does not even bother calling `const_prop` on that operation. Has no effect on https://github.com/rust-lang/rust/issues/61821; the duplication there has entirely different reasons.
2020-02-20Auto merge of #69145 - matthewjasper:mir-typeck-static-ty, r=nikomatsakisbors-29/+41
Fix MIR typeck soundness holes * Check types of static items * Always check lifetime bounds of `Copy` impls r? @nikomatsakis closes #69114
2020-02-20Auto merge of #68847 - ecstatic-morse:const-impl, r=oli-obkbors-56/+102
Allow trait methods to be called on concrete types in a const context This partially implements [RFC 2632](https://github.com/rust-lang/rfcs/pull/2632) by const-checking methods inside an `impl const` block and allowing those methods to be called on concrete types. Calling trait methods on type parameters in a const context is not yet allowed. Implementing this will require much more work. Since we are only concerned with methods on concrete types, we are able to take advantage of the machinery in `Instance::resolve`, which is doing most of the work. This also propagates `#[rustc_const_unstable]` from parent items to child items, making that attribute behave like `#[stable]` and `#[unstable]` do. This allows trait methods to be marked as unstably const. cc #67792 #57563 cc @rust-lang/wg-const-eval r? @oli-obk
2020-02-20Erase regions before before performing const eval, to improve caching.Ben Lewis-5/+1
2020-02-19Check `RUSTC_CTFE_BACKTRACE` much less by generating fewer errorsWesley Wiser-6/+6
Before this change, `get_size_and_align()` calls `get_fn_alloc()` *a lot* in CTFE heavy code. This previously returned an `Error` which would check if `RUSTC_CTFE_BACKTRACE` was set on construction. Doing this turned out to be a performance hotspot as @nnethercote discovered in #68792. This is an alternate take on that PR which resolves the performance issue by generating *many* fewer errors. Previously, `ctfe-stress-4` would generate over 5,000,000 errors each of which would check for the presence of the environment variable. With these changes, that number is reduced to 30.
2020-02-19Add more comments to `SuspensionPoint`Jonas Schievink-3/+9
2020-02-19Remap the resume place if necessaryJonas Schievink-0/+9