1616//! liveness code so that it only operates over variables with regions in their
1717//! types, instead of all variables.
1818
19- use borrow_check:: nll:: escaping_locals:: EscapingLocals ;
20- use rustc:: mir:: { Local , Mir } ;
2119use rustc:: ty:: TypeFoldable ;
2220use rustc_data_structures:: indexed_vec:: IndexVec ;
21+ use rustc:: mir:: { Mir , Local } ;
2322use util:: liveness:: LiveVariableMap ;
2423
2524use rustc_data_structures:: indexed_vec:: Idx ;
@@ -30,13 +29,14 @@ use rustc_data_structures::indexed_vec::Idx;
3029crate struct NllLivenessMap {
3130 /// For each local variable, contains either None (if the type has no regions)
3231 /// or Some(i) with a suitable index.
33- from_local : IndexVec < Local , Option < LocalWithRegion > > ,
34-
32+ pub from_local : IndexVec < Local , Option < LocalWithRegion > > ,
3533 /// For each LocalWithRegion, maps back to the original Local index.
36- to_local : IndexVec < LocalWithRegion , Local > ,
34+ pub to_local : IndexVec < LocalWithRegion , Local > ,
35+
3736}
3837
3938impl LiveVariableMap for NllLivenessMap {
39+
4040 fn from_local ( & self , local : Local ) -> Option < Self :: LiveVar > {
4141 self . from_local [ local]
4242 }
@@ -55,43 +55,21 @@ impl LiveVariableMap for NllLivenessMap {
5555impl NllLivenessMap {
5656 /// Iterates over the variables in Mir and assigns each Local whose type contains
5757 /// regions a LocalWithRegion index. Returns a map for converting back and forth.
58- crate fn compute ( mir : & Mir < ' tcx > ) -> Self {
59- let mut escaping_locals = EscapingLocals :: compute ( mir) ;
60-
58+ pub fn compute ( mir : & Mir ) -> Self {
6159 let mut to_local = IndexVec :: default ( ) ;
62- let mut escapes_into_return = 0 ;
63- let mut no_regions = 0 ;
64- let from_local: IndexVec < Local , Option < _ > > = mir
60+ let from_local: IndexVec < Local , Option < _ > > = mir
6561 . local_decls
6662 . iter_enumerated ( )
6763 . map ( |( local, local_decl) | {
68- if escaping_locals. escapes_into_return ( local) {
69- // If the local escapes into the return value,
70- // then the return value will force all of the
71- // regions in its type to outlive free regions
72- // (e.g., `'static`) and hence liveness is not
73- // needed. This is particularly important for big
74- // statics.
75- escapes_into_return += 1 ;
76- None
77- } else if local_decl. ty . has_free_regions ( ) {
78- let l = to_local. push ( local) ;
79- debug ! ( "liveness_map: {:?} = {:?}" , local, l) ;
80- Some ( l)
81- } else {
82- no_regions += 1 ;
83- None
64+ if local_decl. ty . has_free_regions ( ) {
65+ Some ( to_local. push ( local) )
8466 }
67+ else {
68+ None
69+ }
8570 } ) . collect ( ) ;
8671
87- debug ! ( "liveness_map: {} variables need liveness" , to_local. len( ) ) ;
88- debug ! ( "liveness_map: {} escapes into return" , escapes_into_return) ;
89- debug ! ( "liveness_map: {} no regions" , no_regions) ;
90-
91- Self {
92- from_local,
93- to_local,
94- }
72+ Self { from_local, to_local }
9573 }
9674}
9775
0 commit comments