-
Notifications
You must be signed in to change notification settings - Fork 13.3k
only compute liveness for variables whose types include regions #52115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bors
merged 16 commits into
rust-lang:master
from
Dylan-DPC-zz:feature/nll-liveness-regions
Jul 21, 2018
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
38c7d1a
add generic parameter
Dylan-DPC f2b5583
add trait structs and other changes from V to local
Dylan-DPC d25231f
use LiveVariableMap as trait bound
Dylan-DPC 4b5f0ba
generic shuffle continues
Dylan-DPC 43b69c2
make liveness generic over set of local variables
nikomatsakis 0d847ec
add LocalWithRegion NllLivenessMap
Dylan-DPC 0819ba9
mir/mod.rs / visit.rs reverted back to using Local
Dylan-DPC 1951a30
convert LocalWithRegion to Local
Dylan-DPC 2255786
left out one field during merge
Dylan-DPC 9910dee
tidy fixes
Dylan-DPC 67685de
always get number of live variables from the map
nikomatsakis 4e3339e
move NllLivenessMap and LocalWithRegion to liveness_map
Dylan-DPC dbb756d
tidy up
Dylan-DPC 7db3324
remove unwanted tests and a reference to it in comments
Dylan-DPC a4c0d36
add docs
Dylan-DPC 0770ff0
delete tests
Dylan-DPC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
//! For the NLL computation, we need to compute liveness, but only for those | ||
//! local variables whose types contain regions. The others are not of interest | ||
//! to us. This file defines a new index type (LocalWithRegion) that indexes into | ||
//! a list of "variables whose type contain regions". It also defines a map from | ||
//! Local to LocalWithRegion and vice versa -- this map can be given to the | ||
//! liveness code so that it only operates over variables with regions in their | ||
//! types, instead of all variables. | ||
|
||
use rustc::ty::TypeFoldable; | ||
use rustc_data_structures::indexed_vec::IndexVec; | ||
use rustc::mir::{Mir, Local}; | ||
use util::liveness::LiveVariableMap; | ||
|
||
use rustc_data_structures::indexed_vec::Idx; | ||
|
||
/// Map between Local and LocalWithRegion indices: this map is supplied to the | ||
/// liveness code so that it will only analyze those variables whose types | ||
/// contain regions. | ||
crate struct NllLivenessMap { | ||
/// For each local variable, contains either None (if the type has no regions) | ||
/// or Some(i) with a suitable index. | ||
pub from_local: IndexVec<Local, Option<LocalWithRegion>>, | ||
/// For each LocalWithRegion, maps back to the original Local index. | ||
pub to_local: IndexVec<LocalWithRegion, Local>, | ||
|
||
} | ||
|
||
impl LiveVariableMap for NllLivenessMap { | ||
|
||
fn from_local(&self, local: Local) -> Option<Self::LiveVar> { | ||
self.from_local[local] | ||
} | ||
|
||
type LiveVar = LocalWithRegion; | ||
|
||
fn from_live_var(&self, local: Self::LiveVar) -> Local { | ||
self.to_local[local] | ||
} | ||
|
||
fn num_variables(&self) -> usize { | ||
self.to_local.len() | ||
} | ||
} | ||
|
||
impl NllLivenessMap { | ||
/// Iterates over the variables in Mir and assigns each Local whose type contains | ||
/// regions a LocalWithRegion index. Returns a map for converting back and forth. | ||
pub fn compute(mir: &Mir) -> Self { | ||
let mut to_local = IndexVec::default(); | ||
let from_local: IndexVec<Local,Option<_>> = mir | ||
.local_decls | ||
.iter_enumerated() | ||
.map(|(local, local_decl)| { | ||
if local_decl.ty.has_free_regions() { | ||
Some(to_local.push(local)) | ||
} | ||
else { | ||
None | ||
} | ||
}).collect(); | ||
|
||
Self { from_local, to_local } | ||
} | ||
} | ||
|
||
/// Index given to each local variable whose type contains a region. | ||
newtype_index!(LocalWithRegion); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a module doc comment here explaining what is going on. Something like this:
For the NLL computation, we need to compute liveness, but only for those local variables whose types contain regions. The others are not of interest to us. This file defines a new index type (
LocalWithRegion
) that indexes into a list of "variables whose type contain regions". It also defines a map fromLocal
toLocalWithRegion
and vice versa -- this map can be given to the liveness code so that it only operates over variables with regions in their types, instead of all variables.