summary refs log tree commit diff
path: root/src/librustc_mir/dataflow
AgeCommit message (Collapse)AuthorLines
2020-03-10Rollup merge of #69714 - spastorino:place-ref-lifetime, r=oli-obkMazdak Farrokhzad-2/+2
Make PlaceRef take just one lifetime r? @eddyb
2020-03-07Auto merge of #69676 - ecstatic-morse:fix-enum-discr-effect, r=oli-obkbors-20/+28
Pass correct place to `discriminant_switch_effect` PR #69562, which fixed a bug that was causing clippy to ICE, mistakenly passed the place holding the *result* of `Rvalue::Discriminant` instead of the place holding its *operand* to `apply_discriminant_switch_effect` as the enum place. As a result, no effect was applied at all, and we lost the perf benefits from marking inactive enum variants as uninitialized. **edit:** The regression test has been split into #69744. r? @oli-obk
2020-03-06Don't redundantly repeat field names (clippy::redundant_field_names)Matthias Krüger-2/+2
2020-03-05Rollup merge of #69736 - matthiaskrgr:even_more_clippy, r=Dylan-DPCDylan DPC-6/+6
even more clippy cleanups * Don't pass &mut where immutable reference (&) is sufficient (clippy::unnecessary_mut_passed) * Use more efficient &&str to String conversion (clippy::inefficient_to_string) * Don't always eval arguments inside .expect(), use unwrap_or_else and closure. (clippy::expect_fun_call) * Use righthand '&' instead of lefthand "ref". (clippy::toplevel_ref_arg) * Use simple 'for i in x' loops instead of 'while let Some(i) = x.next()' loops on iterators. (clippy::while_let_on_iterator) * Const items have by default a static lifetime, there's no need to annotate it. (clippy::redundant_static_lifetimes) * Remove redundant patterns when matching ( x @ _ to x) (clippy::redundant_pattern)
2020-03-05Don't pass &mut where immutable reference (&) is sufficient ↵Matthias Krüger-4/+4
(clippy::unnecessary_mut_passed)
2020-03-05Const items have by default a static lifetime, there's no need to annotate ↵Matthias Krüger-2/+2
it. (clippy::redundant_static_lifetimes)
2020-03-04PlaceRef<'a, 'tcx> -> PlaceRef<'tcx>Santiago Pastorino-2/+2
2020-03-04Make PlaceRef lifetimes of in_projection be both 'tcxSantiago Pastorino-1/+1
2020-03-04cover some more nearby casesRalf Jung-1/+0
2020-03-03Use correct place for `enum_place`Dylan MacKenzie-20/+28
PR #69562, which fixed a bug that was causing clippy to ICE, passed the place for the *result* of `Rvalue::Discriminant` instead of the *operand* to `apply_discriminant_switch_effect`. As a result, no effect was applied at all, and we lost the perf benefits from marking inactive enum variants as uninitialized.
2020-03-01Auto merge of #69606 - JohnTitor:rollup-i3nrrcf, r=JohnTitorbors-54/+72
Rollup of 7 pull requests Successful merges: - #69397 (bootstrap: Remove commit hash from LLVM version suffix to avoid rebuilds) - #69549 (Improve MinGW detection when cross compiling ) - #69562 (Don't `bug` when taking discriminant of generator during dataflow) - #69579 (parser: Remove `Parser::prev_span`) - #69580 (use .copied() instead of .map(|x| *x) on iterators) - #69583 (Do not ICE on invalid type node after parse recovery) - #69605 (Use `opt_def_id()` over `def_id()`) Failed merges: r? @ghost
2020-03-01Rollup merge of #69562 - ecstatic-morse:dataflow-generator-discriminant, ↵Yuki Okushi-54/+72
r=oli-obk Don't `bug` when taking discriminant of generator during dataflow The proper fix for rust-lang/rust-clippy#5239. `Rvalue::Discriminant` is used on generators as well as `enum`s. This didn't cause a test failure in `rustc` since we don't need to do any dataflow passes until after the generator transform that adds the `Rvalue::Discriminant`. This required a small refactoring. `diff -w` is beneficial. r? @oli-obk cc @JohnTitor
2020-03-01Auto merge of #69295 - ecstatic-morse:unified-dataflow-generators, r=tmandrybors-100/+124
Use new dataflow framework for generators #65672 introduced a new dataflow framework that can handle arbitrarily complex transfer functions as well as ones expressed as a series of gen/kill operations. This PR ports the analyses used to implement generators to the new framework so that we can remove the old one. See #68241 for a prior example of this. The new framework has some superficial API changes, but this shouldn't alter the generator passes in any way. r? @tmandry
2020-03-01Auto merge of #69592 - petrochenkov:nosyntax, r=Centrilbors-2/+2
Rename `libsyntax` to `librustc_ast` This was the last rustc crate that wasn't following the `rustc_*` naming convention. Follow-up to https://github.com/rust-lang/rust/pull/67763.
2020-02-29Rename `syntax` to `rustc_ast` in source codeVadim Petrochenkov-2/+2
2020-02-29use .iter() instead of .into_iter() on references.Matthias Krüger-2/+2
2020-02-28Don't bug when taking discriminant of generatorDylan MacKenzie-54/+72
2020-02-28remove redundant clones, references to operands, explicit boolean ↵Matthias Krüger-5/+1
comparisons and filter(x).next() calls.
2020-02-27Remove now unused `GenKill` impl for old `GenKillSet`Dylan MacKenzie-11/+0
2020-02-27Rename `RequiresStorage` to `MaybeRequiresStorage`Dylan MacKenzie-8/+8
...to be consistent with the naming of other dataflow analyses.
2020-02-27Port `RequiresStorage` to new dataflow frameworkDylan MacKenzie-51/+70
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-33/+31
2020-02-27Auto merge of #68528 - ecstatic-morse:maybe-init-variants, r=oli-obkbors-19/+187
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-24don't explicitly compare against true or falseMatthias Krüger-2/+2
2020-02-19Reorder yield visitation order to match callJonas Schievink-1/+1
2020-02-19Handle resume args in `RequiresStorage` analysisJonas Schievink-11/+46
2020-02-19Use match ergonomics to simplify matchJonas Schievink-5/+5
2020-02-19Match MIR statements exhaustivelyJonas Schievink-1/+8
2020-02-19Auto merge of #69113 - ecstatic-morse:unified-dataflow-borrowed, r=wesleywiserbors-226/+264
Combine `HaveBeenBorrowedLocals` and `IndirectlyMutableLocals` into one dataflow analysis This PR began as an attempt to port `HaveBeenBorrowedLocals` to the new dataflow framework (see #68241 for prior art). Along the way, I noticed that it could share most of its code with `IndirectlyMutableLocals` and then found a few bugs in the two analyses: - Neither one marked locals as borrowed after an `Rvalue::AddressOf`. - `IndirectlyMutableLocals` was missing a minor fix that `HaveBeenBorrowedLocals` got in #61069. This is not a problem today since it is only used during const-checking, where custom drop glue is forbidden. However, this may change some day. I decided to combine the two analyses so that they wouldn't diverge in the future while ensuring that they remain distinct types (called `MaybeBorrowedLocals` and `MaybeMutBorrowedLocals` to be consistent with the `Maybe{Un,}InitializedPlaces` naming scheme). I fixed the bugs and switched to exhaustive matching where possible to make them less likely in the future. Finally, I added comments explaining some of the finer points of the transfer function for these analyses (see #61069 and #65006).
2020-02-17Fix typo in commentDylan MacKenzie-1/+1
2020-02-17Use doc comment for explanation of `shared_borrow_allows_mutation`Dylan MacKenzie-9/+9
2020-02-13Don't print block exit state if unchangedDylan MacKenzie-20/+35
2020-02-13Kill move paths of dead variantsDylan MacKenzie-2/+35
2020-02-13Support effects for particular edges of `SwitchInt`Dylan MacKenzie-7/+110
2020-02-13Use an `Iterator` for `MovePath` traversalDylan MacKenzie-10/+42
2020-02-13Ignore mut borrow from drop terminator in const-evalDylan MacKenzie-12/+33
2020-02-13Rename `MaybeBorrowedLocals` constructorsDylan MacKenzie-2/+5
2020-02-12Use `MaybeBorrowedLocals` for generator analysesDylan MacKenzie-26/+20
It should have the same semantics as `HaveBeenBorrowedLocals`
2020-02-12Remove outdated `IndirectlyMutableLocals`Dylan MacKenzie-138/+0
`MaybeMutBorrowedLocals` serves the same purpose and has a better name.
2020-02-12Implement `Maybe{Mut,}BorrowedLocals` analysesDylan MacKenzie-62/+209
2020-02-12Impl `GenKill` for old dataflow framework's `GenKillSet`Dylan MacKenzie-0/+11
This impl is temporary and will be removed along with the old dataflow framework. It allows us to reuse the transfer function of new dataflow analyses when defining old ones
2020-02-11Clarify why you shouldn't override `Analysis::into_engine`Dylan MacKenzie-3/+11
2020-02-11Skip caching block transfer functions for acyclic MIRDylan MacKenzie-10/+14
2020-02-11Use new dataflow framework for drop elaboration and borrow checkingDylan MacKenzie-7/+1
2020-02-10Use new dataflow interface for initialization/borrows analysesDylan MacKenzie-108/+195
2020-02-10Implement a `find_descendant` method for `MovePath`Dylan MacKenzie-41/+47
2020-02-10Add a `Visitor` for dataflow resultsDylan MacKenzie-0/+275
2020-02-10Add an `into_engine` method to `Analysis`Dylan MacKenzie-0/+30
This makes it more ergonomic to create a dataflow engine and obviates the need to pick between `new_gen_kill` and `new_generic`.
2020-02-10Add a `contains` method to `ResultsCursor`Dylan MacKenzie-0/+7