summary refs log tree commit diff
path: root/src/librustc_mir/dataflow/mod.rs
AgeCommit message (Collapse)AuthorLines
2018-07-23Simplify 2 functions in rustc_mir/dataflowljedrz-10/+1
2018-07-13Make BitSlice's `Word` properly generic.Nicholas Nethercote-5/+5
Currently `Word` is `usize`, and there are various places in the code that assume this. This patch mostly just changes `usize` occurrences to `Word`. Most of the changes were found as compile errors when I changed `Word` to a type other than `usize`, but there was one non-obvious case in librustc_mir/dataflow/mod.rs that caused bounds check failures before I fixed it.
2018-07-13Inline and remove `DataflowAnalysis::num_bits_overall()`.Nicholas Nethercote-13/+3
It has a single callsite, and duplicates some code from that callsite. The code is more concise and clearer this way.
2018-07-06Rollup merge of #52067 - csmoe:issue-51167, r=nikomatsakisMark Rousskov-1/+2
Visit the mir basic blocks in reverse-postfix order cc #51167 r? @nikomatsakis
2018-07-05reverse_postordercsmoe-1/+2
2018-07-03Address #51813Pramod Bisht-44/+44
2018-06-29Rename `IdxSet::clone_from`.Nicholas Nethercote-1/+1
The current situation is something of a mess. - `IdxSetBuf` derefs to `IdxSet`. - `IdxSetBuf` implements `Clone`, and therefore has a provided `clone_from` method, which does allocation and so is expensive. - `IdxSet` has a `clone_from` method that is non-allocating and therefore cheap, but this method is not from the `Clone` trait. As a result, if you have an `IdxSetBuf` called `b`, if you call `b.clone_from(b2)` you'll get the expensive `IdxSetBuf` method, but if you call `(*b).clone_from(b2)` you'll get the cheap `IdxSetBuf` method. `liveness_of_locals()` does the former, presumably unintentionally, and therefore does lots of unnecessary allocations. Having a `clone_from` method that isn't from the `Clone` trait is a bad idea in general, so this patch renames it as `overwrite`. This avoids the unnecessary allocations in `liveness_of_locals()`, speeding up most NLL benchmarks, the best by 1.5%. It also means that calls of the form `(*b).clone_from(b2)` can be rewritten as `b.overwrite(b2)`.
2018-04-15encapsulate ReserveOrActivateIndex into the borrows dataflowNiko Matsakis-1/+0
2018-04-15relocate `BorrowData` etc into `borrow_check::borrow_set`Niko Matsakis-1/+1
2018-04-06Use `Ident` instead of `Name` in `MetaItem`Vadim Petrochenkov-1/+1
2018-03-15Rollup merge of #48840 - varkor:idxset-cleanup, r=pnkfelixkennytm-2/+1
Remove some unnecessary IdxSet methods This replaces `IdxSet:: reset_to_empty` with `IdxSet:: clear`, and `IdxSet::elems`/`IdxSet::each_bit` with `IdxSet::iter`. Based on some [comments on #rustc](https://botbot.me/mozilla/rustc/2018-01-23/?msg=96063396). r? @pnkfelix
2018-03-09Finally start down the right pathbobtwinkles-20/+21
2018-03-06Remove IdxSet::each_bitvarkor-2/+1
2018-03-02Run Rustfix on librustc_mirManish Goregaokar-1/+1
2018-02-05mir: Add TerminatorKind::FalseUnwindbobtwinkles-0/+8
Sometimes a simple goto misses the cleanup/unwind edges. Specifically, in the case of infinite loops such as those introduced by a loop statement without any other out edges. Analogous to TerminatorKind::FalseEdges; this new terminator kind is used when we want borrowck to consider an unwind path, but real control flow should never actually take it.
2018-02-03Auto merge of #47845 - Zoxc:gen-fixes, r=nikomatsakisbors-0/+1
Generator bugfixes r? @nikomatsakis
2018-01-30Force locals to be live after they are borrowed for immovable generators. ↵John Kåre Alsaker-0/+1
Fixes #47736
2018-01-29rustc: replace "lvalue" terminology with "place" in the code.Eduard-Mihai Burtescu-3/+3
2018-01-03Auto merge of #46984 - arielb1:pre-statement-effect, r=nikomatsakisbors-3/+44
NLL fixes First, introduce pre-statement effects to dataflow to fix #46875. Edge dataflow effects might make that redundant, but I'm not sure of the best way to integrate them with liveness etc., and if this is a hack, this is one of the cleanest hacks I've seen. And I want a small fix to avoid the torrent of bug reports. Second, fix linking of projections to fix #46974 r? @pnkfelix
2017-12-24add pre-statement-effect to dataflowAriel Ben-Yehuda-3/+44
2017-12-21Mir: Add Terminatorkind::AbortDavid Henningsson-0/+1
The Abort Terminatorkind will cause an llvm.trap function call to be emitted. Signed-off-by: David Henningsson <diwic@ubuntu.com>
2017-12-13New `ActiveBorrows` dataflow for two-phase `&mut`; not yet borrowed-checked.Felix S. Klock II-50/+92
High-level picture: The old `Borrows` analysis is now called `Reservations` (implemented as a newtype wrapper around `Borrows`); this continues to compute whether a `Rvalue::Ref` can reach a statement without an intervening `EndRegion`. In addition, we also track what `Place` each such `Rvalue::Ref` was immediately assigned to in a given borrow (yay for MIR-structural properties!). The new `ActiveBorrows` analysis then tracks the initial use of any of those assigned `Places` for a given borrow. I.e. a borrow becomes "active" immediately after it starts being "used" in some way. (This is conservative in the sense that we will treat a copy `x = y;` as a use of `y`; in principle one might further delay activation in such cases.) The new `ActiveBorrows` analysis needs to take the `Reservations` results as an initial input, because the reservation state influences the gen/kill sets for `ActiveBorrows`. In particular, a use of `a` activates a borrow `a = &b` if and only if there exists a path (in the control flow graph) from the borrow to that use. So we need to know if the borrow reaches a given use to know if it really gets a gen-bit or not. * Incorporating the output from one dataflow analysis into the input of another required more changes to the infrastructure than I had expected, and even after those changes, the resulting code is still a bit subtle. * In particular, Since we need to know the intrablock reservation state, we need to dynamically update a bitvector for the reservations as we are also trying to compute the gen/kills bitvector for the active borrows. * The way I ended up deciding to do this (after also toying with at least two other designs) is to put both the reservation state and the active borrow state into a single bitvector. That is why we now have separate (but related) `BorrowIndex` and `ReserveOrActivateIndex`: each borrow index maps to a pair of neighboring reservation and activation indexes. As noted above, these changes are solely adding the active borrows dataflow analysis (and updating the existing code to cope with the switch from `Borrows` to `Reservations`). The code to process the bitvector in the borrow checker currently just skips over all of the active borrow bits. But atop this commit, one *can* observe the analysis results by looking at the graphviz output, e.g. via ```rust #[rustc_mir(borrowck_graphviz_preflow="pre_two_phase.dot", borrowck_graphviz_postflow="post_two_phase.dot")] ``` Includes doc for `FindPlaceUses`, as well as `Reservations` and `ActiveBorrows` structs, which are wrappers are the `Borrows` struct that dictate which flow analysis should be performed.
2017-12-13Refactoring: Allow `BlockSets.on_entry` to denote locally accumulated ↵Felix S. Klock II-0/+30
intrablock state. (Still musing about whether it could make sense to revise the design here to make these constraints on usage explicit.)
2017-12-13Refactoring: pull bitvector initialization out from other parts of dataflow.Felix S. Klock II-12/+9
This is meant to ease development of multi-stage dataflow analyses where the output from one analysis is used to initialize the state for the next; in such a context, you cannot start with `bottom_value` for all the bits.
2017-12-13Revised graphviz rendering API to avoid requiring borrowed state.Felix S. Klock II-13/+32
Made `do_dataflow` and related API `pub(crate)`.
2017-12-10avoid passing the gen/kill bits to `start_block_effects`Ariel Ben-Yehuda-9/+6
If the gen/kill bits are set there, the effects of `start_block_effects` will not be seen when using `FlowAtLocation` etc. to go over the MIR. EverInitializedLvals is the only pass that got this wrong, but this fixes the footgun for everyone.
2017-12-10move FlowAtLocation to be a dataflow abstractionAriel Ben-Yehuda-29/+7
We can now use it in e.g. drop elaboration if we want to.
2017-12-06handle gen/kill sets togetherAriel Ben-Yehuda-0/+30
2017-12-01MIR: s/lv(al(ue)?)?/place in function/variable/module names.Eduard-Mihai Burtescu-3/+3
2017-12-01MIR: s/Lvalue/Place in type names.Eduard-Mihai Burtescu-1/+1
2017-11-27Add initialization info to `MoveData`Matthew Jasper-0/+1
* Used for new dataflow to track if a variable has every been initialized * Used for other dataflows that need to be updated for initializations
2017-11-08restore move out dataflow, add report of move out errorsMikhail Modin-1/+1
2017-11-02add TerminatorKind::FalseEdges and use it in matchesMikhail Modin-0/+6
2017-10-31make the dataflow / mir-borrowck types carry a `'tcx` lifetimeNiko Matsakis-12/+12
Also, factor out `do_mir_borrowck`, which is the code that actually performs the MIR borrowck from within the scope of an inference context. This change should be a pure refactoring.
2017-09-13Analyse storage liveness and preserve it during generator transformationJohn Kåre Alsaker-0/+24
2017-08-21Merge remote-tracking branch 'origin/master' into genAlex Crichton-3/+1
2017-08-19rustc: Remove some dead codeVadim Petrochenkov-3/+1
2017-08-16Merge remote-tracking branch 'origin/master' into genAlex Crichton-34/+237
2017-08-16Merge remote-tracking branch 'origin/master' into genAlex Crichton-4/+4
2017-08-16Cleanup: Every `BitDenotation` is a `DataflowOperator`, so build that in.Felix S. Klock II-20/+11
Post-rebase: ariel confirmed `SetDiscriminant` should indeed be a mutate.
2017-08-16Added some documentation for the `struct BlockSets` in `rustc_mir::dataflow`.Felix S. Klock II-0/+19
2017-08-16MIR based borrow check (opt-in).Felix S. Klock II-4/+112
One can either use `-Z borrowck-mir` or add the `#[rustc_mir_borrowck]` attribute to opt into MIR based borrow checking. Note that regardless of whether one opts in or not, AST-based borrow check will still run as well. The errors emitted from AST-based borrow check will include a "(Ast)" suffix in their error message, while the errors emitted from MIR-based borrow check will include a "(Mir)" suffix. post-rebase: removed check for intra-statement mutual conflict; replaced with assertion checking that at most one borrow is generated per statement. post-rebase: removed dead code: `IdxSet::pairs` and supporting stuff.
2017-08-16Move `DataFlowState::{each_bit,interpret_set}` method definitions to parent ↵Felix S. Klock II-0/+22
module. Refactored `each_bit`, which traverses a `IdxSet`, so that the bulk of its implementation lives in `rustc_data_structures`.
2017-08-16remove now unnecessary constraint on BitDenotation for `fn do_dataflow`.Felix S. Klock II-2/+1
2017-08-16Migrated some code out of `dataflow::drop_flag_effects` and into its parent ↵Felix S. Klock II-4/+69
module. (This code is more general purpose than just supporting drop flag elaboration.)
2017-08-16Added dataflow analysis for `Borrows`.Felix S. Klock II-1/+1
post-rebase: addressed review comment: rename `loc_map`/`location_map` and `rgn_map`/`region_map`. post-rebase: remove now unnecessary `mut` decl. post-rebase: address comments: bind iterator expr, and alpha-rename `loc`/`location` and `idx`/`index`.
2017-08-16Refactor `trait BitDenotation` to take `Location` instead of ↵Felix S. Klock II-8/+7
`BasicBlock`/`usize` argument pairs.
2017-08-15use field init shorthand EVERYWHEREZack M. Davis-4/+4
Like #43008 (f668999), but _much more aggressive_.
2017-08-14Merge remote-tracking branch 'origin/master' into genAlex Crichton-3/+3
2017-08-12Fix some typosBastien Orivel-3/+3