summary refs log tree commit diff
path: root/src/librustc_mir/dataflow/mod.rs
AgeCommit message (Collapse)AuthorLines
2019-03-24Rollup merge of #59251 - matthewjasper:fix-graphviz, r=petrochenkovkennytm-6/+6
Use a valid name for graphviz graphs Hiridification has broken graphviz output because `HirId` has a more complex display implemetation than `NodeId`. Since the id was just used to generate a distinct identifier, we just pull out the various constituent indexed.
2019-03-17Use a valid name for graphviz graphsMatthew Jasper-6/+6
2019-03-16Rename `MetaItem::ident` to `MetaItem::path`Vadim Petrochenkov-1/+1
2019-03-07HirIdification: replace NodeId method callsljedrz-5/+6
2019-02-10rustc: doc commentsAlexander Regueiro-13/+13
2019-02-08librustc_mir => 2018Taiki Endo-6/+6
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-20Auto merge of #56649 - davidtwco:issue-46589, r=pnkfelixbors-33/+38
MIR borrowck doesn't accept the example of iterating and updating a mutable reference Fixes #46589. r? @pnkfelix or @nikomatsakis
2018-12-17Add required lifetime parameter to BitDenotation.David Wood-33/+38
This avoids all sorts of confusing issues with using both `dest_place` and `self` in the `propagate_call_return` function in the `BitDenotation` implementation for `Borrows`.
2018-12-07Various minor/cosmetic improvements to codeAlexander Regueiro-4/+4
2018-10-22Replace the `run_passes!` macro with a regular functionWesley Wiser-14/+0
As suggested in the feedback for #55244. When I replaced the macro with a function, rustc started complaining that there were two unused functions so I also removed those.
2018-10-03Record whether a Call in MIR corresponds to a call in HIRMatthew Jasper-1/+1
2018-09-18Eliminate `BitwiseOperator`.Nicholas Nethercote-6/+4
`BitwiseOperator` is an unnecessarily low-level thing. This commit replaces it with `BitSetOperator`, which works on `BitSet`s instead of words. Within `bit_set.rs`, the commit eliminates `Intersect`, `Union`, and `Subtract` by instead passing a function to `bitwise()`.
2018-09-18Merge indexed_set.rs into bitvec.rs, and rename it bit_set.rs.Nicholas Nethercote-36/+35
Currently we have two files implementing bitsets (and 2D bit matrices). This commit combines them into one, taking the best features from each. This involves renaming a lot of things. The high level changes are as follows. - bitvec.rs --> bit_set.rs - indexed_set.rs --> (removed) - BitArray + IdxSet --> BitSet (merged, see below) - BitVector --> GrowableBitSet - {,Sparse,Hybrid}IdxSet --> {,Sparse,Hybrid}BitSet - BitMatrix --> BitMatrix - SparseBitMatrix --> SparseBitMatrix The changes within the bitset types themselves are as follows. ``` OLD OLD NEW BitArray<C> IdxSet<T> BitSet<T> -------- ------ ------ grow - grow new - (remove) new_empty new_empty new_empty new_filled new_filled new_filled - to_hybrid to_hybrid clear clear clear set_up_to set_up_to set_up_to clear_above - clear_above count - count contains(T) contains(&T) contains(T) contains_all - superset is_empty - is_empty insert(T) add(&T) insert(T) insert_all - insert_all() remove(T) remove(&T) remove(T) words words words words_mut words_mut words_mut - overwrite overwrite merge union union - subtract subtract - intersect intersect iter iter iter ``` In general, when choosing names I went with: - names that are more obvious (e.g. `BitSet` over `IdxSet`). - names that are more like the Rust libraries (e.g. `T` over `C`, `insert` over `add`); - names that are more set-like (e.g. `union` over `merge`, `superset` over `contains_all`, `domain_size` over `num_bits`). Also, using `T` for index arguments seems more sensible than `&T` -- even though the latter is standard in Rust collection types -- because indices are always copyable. It also results in fewer `&` and `*` sigils in practice.
2018-09-13Remove bitslice.rs.Nicholas Nethercote-1/+1
This requires the following changes. - It moves parts of bitslice.rs into bitvec.rs: `bitwise()`, `BitwiseOperator`, `bits_to_string()`. - It changes `IdxSet` to just be a wrapper around `BitArray`. - It changes `BitArray` and `BitVec` to use `usize` words instead of `u128` words. (`BitSlice` and `IdxSet` already use `usize`.) Local profiling showed `usize` was better. - It moves some operations from `IdxSet` into `BitArray`: `new_filled()`, `clear()`, `set_up_to()`, `trim_to()` (renamed `clear_above()`), `words()` and `words_mut()`, `encode()` and `decode(). The `IdxSet` operations now just call the `BitArray` operations. - It replaces `BitArray`'s iterator implementation with `IdxSet`'s, because the latter is more concise. It also removes the buggy `size_hint` function from `BitArray`'s iterator, which counted the number of *words* rather than the number of *bits*. `IdxSet`'s iterator is now just a thin wrapper around `BitArray`'s iterator. - It moves some unit tests from `indexed_set.rs` to `bitvec.rs`.
2018-09-05A few cleanups and minor improvements to mir/dataflowljedrz-5/+4
2018-08-30Make move out computation lazySantiago Pastorino-14/+2
2018-08-27update comment in the interest of precisionNiko Matsakis-6/+10
2018-08-24Introduce `UnionIntoIdxSet` and `SubtractFromIdxSet` traits.Nicholas Nethercote-4/+4
They let `union()`, `union_sparse()` and `union_hybrid()` be merged. Likewise for subtract()`, `subtract_sparse()` and `subtract_hybrid()`.
2018-08-23Auto merge of #53520 - nnethercote:merge-IdxSet-IdxSetBuf, r=nikomatsakisbors-49/+23
Merge `IdxSet` and `IdxSetBuf` Because it simplifies things. @r? nikomatsakis
2018-08-20Remove IdxSet typedef and Rename {,Hybrid}IdxSetBuf as {,Hybrid}IdxSet.Nicholas Nethercote-15/+15
Now that the `Buf` vs. non-`Buf` distinction has been removed, it makes sense to drop the `Buf` suffix and use the shorter names everywhere.
2018-08-20Convert `AllSets::on_entry_sets` to a `Vec<IdxSetBuf<E>>`.Nicholas Nethercote-40/+14
This makes it more like `AllSets::{gen,kill}_set`, removes the need for a bunch of bitset range computations, and removes the need for `Bits`. It's marginally less efficient, because we have to allocate one bitset per basic block instead of one large shared bitset, but the difference is negligible in practice.
2018-08-19Fix typos found by codespell.Matthias Krüger-1/+1
2018-08-16Speed up NLL with `HybridIdxSetBuf`.Nicholas Nethercote-42/+48
`HybridIdxSetBuf` is a sparse-when-small but dense-when-large index set that is very efficient for sets that (a) have few elements, (b) have large `universe_size` values, and (c) are cleared frequently. Which makes it perfect for the `gen_set` and `kill_set` sets used by the new borrow checker. This patch reduces the execution time of the five slowest NLL benchmarks by 55%, 21%, 16%, 10% and 9%. It also reduces the max-rss of three benchmarks by 53%, 33%, and 9%.
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.