about summary refs log tree commit diff
path: root/src/librustc_mir/dataflow
AgeCommit message (Collapse)AuthorLines
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
2020-02-09Use nicer alignment when printing state vectorsDylan MacKenzie-15/+29
2020-02-09Don't break first lineDylan MacKenzie-12/+12
2020-02-09Remove unnecessary allowsDylan MacKenzie-3/+0
2020-02-09Add option to `dot::render` for monospace fontDylan MacKenzie-1/+1
2020-02-09Print `after` effect in default graphviz formatterDylan MacKenzie-4/+4
Now the line for each statement will show the diff resulting from the combination of `before_statement_effect` and `statement_effect`. It's still possible to observe each in isolation via `borrowck_graphviz_format = "two_phase"`.
2020-02-02Add resume arg place to `Yield` MIR terminatorJonas Schievink-1/+3
2020-02-02Add a resume type parameter to `Generator`Jonas Schievink-8/+12
2020-02-01syntax::print -> new crate rustc_ast_prettyMazdak Farrokhzad-1/+1
2020-01-28Place::ty_from takes local by valueSantiago Pastorino-2/+2
2020-01-28Local field on PlaceRef and RootPlace is not a reference anymoreSantiago Pastorino-2/+2
2020-01-27don't clone types that are copy, round two.Matthias Krüger-8/+6
2020-01-19Document all methodsDylan MacKenzie-4/+15
2020-01-19Explain motivation for `GenKill` traitDylan MacKenzie-4/+12
2020-01-15Use trailing underscore for helper methodsDylan MacKenzie-4/+4
2020-01-14Fix testDylan MacKenzie-11/+14
2020-01-14Improve docs for `GenKill` and `GenKillSet`Dylan MacKenzie-6/+8
2020-01-14Improve docs for new frameworkDylan MacKenzie-3/+35
2020-01-14Add test for `ResultsCursor`Dylan MacKenzie-0/+331
This is a unit test that ensures the `seek` functions work correctly.