summary refs log tree commit diff
path: root/src/librustc_mir/dataflow/impls
AgeCommit message (Collapse)AuthorLines
2019-07-02Auto merge of #61922 - tmandry:moar-generator-optimization, r=matthewjasperbors-1/+129
Don't store locals that have been moved from in generators This avoids reserving storage in generators for locals that are moved out of (and not re-initialized) prior to yield points. Fixes #59123. This adds a new dataflow analysis, `RequiresStorage`, to determine whether the storage of a local can be destroyed without being observed by the program. The rules are: 1. StorageLive(x) => mark x live 2. StorageDead(x) => mark x dead 3. If a local is moved from, _and has never had its address taken_, mark it dead 4. If (any part of) a local is initialized, mark it live' This is used to determine whether to save a local in the generator object at all, as well as which locals can be overlapped in the generator layout. Here's the size in bytes of all testcases included in the change, before and after the change: async fn test |Size before |Size after -----------------|------------|---------- single | 1028 | 1028 single_with_noop | 2056 | 1032 joined | 5132 | 3084 joined_with_noop | 8208 | 3084 generator test |Size before |Size after ----------------------------|------------|---------- move_before_yield | 1028 | 1028 move_before_yield_with_noop | 2056 | 1032 overlap_move_points | 3080 | 2056 ## Future work Note that there is a possible extension to this optimization, which modifies rule 3 to read: "If a local is moved from, _**and either has never had its address taken, or is Freeze and has never been mutably borrowed**_, mark it dead." This was discussed at length in #59123 and then #61849. Because this would cause some behavior to be UB which was not UB before, it's a step that needs to be taken carefully. A more immediate priority for me is inlining `std::mem::size_of_val(&x)` so it becomes apparent that the address of `x` is not taken. This way, using `size_of_val` to look at the size of your inner futures does not affect the size of your outer future. cc @cramertj @eddyb @Matthias247 @nikomatsakis @RalfJung @Zoxc
2019-07-01Clean up extra lifetime, add assertionsTyler Mandry-12/+16
2019-06-28Use RequiresStorage to determine which locals can overlapTyler Mandry-4/+0
2019-06-28Remove Clone requirementTyler Mandry-1/+0
2019-06-25Add RequiresStorage pass to decide which locals to save in generatorsTyler Mandry-0/+129
This avoids reserving storage in generators for locals that are moved out of (and not re-initialized) prior to yield points.
2019-06-25Implement From<Local> for Place and PlaceBaseSantiago Pastorino-1/+1
2019-06-22Merge `BitSetOperator` and `InitialFlow` into one trait.Dylan MacKenzie-98/+25
Since the value of `InitialFlow` defines the semantics of the `join` operation, there's no reason to have seperate traits for each. We can add a default impl of `join` which branches based on `BOTTOM_VALUE`. This should get optimized away.
2019-06-22rustc_mir: don't pass `on_entry` when building transfer functions.Dylan MacKenzie-66/+75
This commit makes `sets.on_entry` inaccessible in `{before_,}{statement,terminator}_effect`. This field was meant to allow implementors of `BitDenotation` to access the initial state for each block (optionally with the effect of all previous statements applied via `accumulates_intrablock_state`) while defining transfer functions. However, the ability to set the initial value for the entry set of each basic block (except for START_BLOCK) no longer exists. As a result, this functionality is mostly useless, and when it *was* used it was used erroneously (see #62007). Since `on_entry` is now useless, we can also remove `BlockSets`, which held the `gen`, `kill`, and `on_entry` bitvectors and replace it with a `GenKill` struct. Variables of this type are called `trans` since they represent a transfer function. `GenKill`s are stored contiguously in `AllSets`, which reduces the number of bounds checks and may improve cache performance: one is almost never accessed without the other. Replacing `BlockSets` with `GenKill` allows us to define some new helper functions which streamline dataflow iteration and the dataflow-at-location APIs. Notably, `state_for_location` used a subtle side-effect of the `kill`/`kill_all` setters to apply the transfer function, and could be incorrect if a transfer function depended on effects of previous statements in the block on `gen_set`.
2019-06-20Kill conflicting borrows of places with projections.Dylan MacKenzie-30/+25
Resolves #62007. Due to a bug, the previous version of this check did not actually kill any conflicting borrows unless the borrowed place had no projections. Specifically, `entry_set` will always be empty when `statement_effect` is called. It does not contain the set of borrows which are live at this point in the program.
2019-06-18rustc: remove 'x: 'y bounds (except from comments/strings).Eduard-Mihai Burtescu-13/+13
2019-06-14Run `rustfmt --file-lines ...` for changes from previous commits.Eduard-Mihai Burtescu-21/+4
2019-06-14Unify all uses of 'gcx and 'tcx.Eduard-Mihai Burtescu-50/+50
2019-06-12Run `rustfmt --file-lines ...` for changes from previous commits.Eduard-Mihai Burtescu-20/+20
2019-06-12rustc: replace `TyCtxt<'tcx, 'gcx, 'tcx>` with `TyCtxt<'gcx, 'tcx>`.Eduard-Mihai Burtescu-10/+10
2019-06-12rustc: replace `TyCtxt<'a, 'gcx, 'tcx>` with `TyCtxt<'tcx, 'gcx, 'tcx>`.Eduard-Mihai Burtescu-10/+10
2019-06-09Changed usages of `mir` in librustc::mir and librustc_mir to `body`Jad Ghalayini-56/+56
2019-06-06Auto merge of #61373 - tmandry:emit-storagedead-along-unwind, r=eddybbors-10/+3
Emit StorageDead along unwind paths for generators Completion of the work done in #60840. That PR made a change to implicitly consider a local `StorageDead` after Drop, but that was incorrect for DropAndReplace (see also #61060 which tried to fix this in a different way). This finally enables the optimization implemented in #60187. r? @eddyb cc @Zoxc @cramertj @RalfJung
2019-06-04Revert "Make MaybeStorageLive drop-aware"Tyler Mandry-10/+3
This reverts commit dd2eabc49d415dd30cea0953df5d7659d4d9440f.
2019-06-04Rollup merge of #61069 - Zoxc:drop-borrow-fix, r=pnkfelixPietro Albini-1/+12
Make MIR drop terminators borrow the dropped location r? @eddyb cc @tmandry
2019-05-29Rollup merge of #61249 - spastorino:local-or-deref-local, r=oli-obk,CentrilMazdak Farrokhzad-2/+4
Rename Place::local to Place::local_or_deref_local r? @oli-obk
2019-05-28Changes the type `mir::Mir` into `mir::Body`Claude-Alban RANÉLY-VERGÉ-DÉPRÉ-19/+19
The commit should have changed comments as well. At the time of writting, it passes the tidy and check tool. Revisions asked by eddyb : - Renamed of all the occurences of {visit/super}_mir - Renamed test structures `CachedMir` to `Cached` Fixing the missing import on `AggregateKind`
2019-05-28Rename Place::local to Place::local_or_deref_localSantiago Pastorino-2/+4
2019-05-23Make find_local iterate instead of recurseSantiago Pastorino-8/+11
2019-05-23Auto merge of #60174 - matthewjasper:add-match-arm-scopes, r=pnkfelixbors-31/+8
Add match arm scopes and other scope fixes * Add drop and lint scopes for match arms. * Lint attributes are now respected on match arms. * Make sure we emit a StorageDead if we diverge when initializing a temporary. * Adjust MIR pretty printing of scopes for locals. * Don't generate duplicate lint scopes for `let statements`. * Add some previously missing fake borrows for matches. closes #46525 cc @rust-lang/compiler
2019-05-23Make MIR drop terminators borrow the dropped locationJohn Kåre Alsaker-1/+12
2019-05-21Remove MIR borrowck hack for old match scopesMatthew Jasper-31/+8
2019-05-14Make MaybeStorageLive drop-awareTyler Mandry-3/+8
2019-04-26Remove BasicBlock parameter from mir visitor methodsMatthew Jasper-2/+2
2019-04-13Auto merge of #59612 - matthewjasper:dataflow-usual-newtype-index, r=estebankbors-1/+6
Use normal newtype_index macro for MIR dataflows * Makes the definition of these structs contain `struct IndexName` * Avoids having an offset by removing high values, rather than 0 * Implements some traits for us.
2019-04-03Shrink `mir::Statement`.Nicholas Nethercote-2/+2
The `InlineAsm` variant is extremely rare, and `mir::Statement` often contributes significantly to peak memory usage.
2019-04-01Use normal newtype_index macro for MIR dataflowMatthew Jasper-1/+6
2019-03-18promoted is still left in 2 placesSaleem Jaffer-1/+0
2019-03-01Put Local, Static and Promoted as one Base variant of PlaceSantiago Pastorino-7/+8
2019-02-10rustc: doc commentsAlexander Regueiro-7/+0
2019-02-08librustc_mir => 2018Taiki Endo-31/+31
2019-01-30Pass correct arguments to places_conflictMatthew Jasper-1/+1
The borrow place *must* be a place that we track borrows for, otherwise we will likely ICE.
2018-12-28Remove unnecessary borrow generationMatthew Jasper-14/+0
2018-12-25Remove licensesMark Rousskov-40/+0
2018-12-20Auto merge of #56741 - RalfJung:retag-to-raw, r=oli-obkbors-1/+0
treat ref-to-raw cast like a reborrow: do a special kind of retag r? @oli-obk Cc @nikomatsakis
2018-12-20Auto merge of #56649 - davidtwco:issue-46589, r=pnkfelixbors-74/+106
MIR borrowck doesn't accept the example of iterating and updating a mutable reference Fixes #46589. r? @pnkfelix or @nikomatsakis
2018-12-18treat ref-to-raw cast like a reborrow: do a special kind of retagRalf Jung-1/+0
2018-12-17Add required lifetime parameter to BitDenotation.David Wood-64/+65
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-17Kill borrows from a projection after assignment.David Wood-23/+54
This commit extends previous work to kill borrows from a local after assignment into that local to kill borrows from a projection after assignment into a prefix of that place.
2018-12-07Various minor/cosmetic improvements to codeAlexander Regueiro-2/+2
2018-11-30Remove the `region_map` field from `BorrowSet`Matthew Jasper-8/+1
2018-11-18Only handle ReVar regions in NLL borrowckMatthew Jasper-82/+9
Now that lexical MIR borrowck is gone, there's no need to store Regions unnecessarily.
2018-11-18Remove mir::StatementKind::EndRegionMatthew Jasper-5/+1
Since lexical MIR borrow check is gone, and validation no longer uses these, they can be removed.
2018-11-15Auto merge of #55716 - RalfJung:escape-to-raw, r=oli-obkbors-0/+1
Add escape-to-raw MIR statement Add a new MIR "ghost state statement": Escaping a ptr to permit raw accesses. ~~This includes #55549, [click here](https://github.com/RalfJung/rust/compare/miri-visitor...RalfJung:escape-to-raw) for just the new commits.~~
2018-11-07no more action on ref or cast, but add new MIR statement for escaping a ptr ↵Ralf Jung-0/+1
to raw
2018-11-07Rollup merge of #55734 - teresy:shorthand-fields, r=davidtwcokennytm-2/+2
refactor: use shorthand fields refactor: use shorthand for single fields everywhere (excluding tests).