16
16
//! liveness code so that it only operates over variables with regions in their
17
17
//! types, instead of all variables.
18
18
19
- use borrow_check:: nll:: escaping_locals:: EscapingLocals ;
20
- use rustc:: mir:: { Local , Mir } ;
21
19
use rustc:: ty:: TypeFoldable ;
22
20
use rustc_data_structures:: indexed_vec:: IndexVec ;
21
+ use rustc:: mir:: { Mir , Local } ;
23
22
use util:: liveness:: LiveVariableMap ;
24
23
25
24
use rustc_data_structures:: indexed_vec:: Idx ;
@@ -30,13 +29,14 @@ use rustc_data_structures::indexed_vec::Idx;
30
29
crate struct NllLivenessMap {
31
30
/// For each local variable, contains either None (if the type has no regions)
32
31
/// or Some(i) with a suitable index.
33
- from_local : IndexVec < Local , Option < LocalWithRegion > > ,
34
-
32
+ pub from_local : IndexVec < Local , Option < LocalWithRegion > > ,
35
33
/// For each LocalWithRegion, maps back to the original Local index.
36
- to_local : IndexVec < LocalWithRegion , Local > ,
34
+ pub to_local : IndexVec < LocalWithRegion , Local > ,
35
+
37
36
}
38
37
39
38
impl LiveVariableMap for NllLivenessMap {
39
+
40
40
fn from_local ( & self , local : Local ) -> Option < Self :: LiveVar > {
41
41
self . from_local [ local]
42
42
}
@@ -55,43 +55,21 @@ impl LiveVariableMap for NllLivenessMap {
55
55
impl NllLivenessMap {
56
56
/// Iterates over the variables in Mir and assigns each Local whose type contains
57
57
/// 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 {
61
59
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
65
61
. local_decls
66
62
. iter_enumerated ( )
67
63
. 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) )
84
66
}
67
+ else {
68
+ None
69
+ }
85
70
} ) . collect ( ) ;
86
71
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 }
95
73
}
96
74
}
97
75
0 commit comments