79
79
//! ## Special nodes and variables
80
80
//!
81
81
//! We generate various special nodes for various, well, special purposes.
82
- //! These are described in the `Specials ` struct.
82
+ //! These are described in the `Liveness ` struct.
83
83
84
84
use self :: LiveNodeKind :: * ;
85
85
use self :: VarKind :: * ;
@@ -626,17 +626,6 @@ impl RWUTable {
626
626
}
627
627
}
628
628
629
- #[ derive( Copy , Clone ) ]
630
- struct Specials {
631
- /// A live node representing a point of execution before closure entry &
632
- /// after closure exit. Used to calculate liveness of captured variables
633
- /// through calls to the same closure. Used for Fn & FnMut closures only.
634
- closure_ln : LiveNode ,
635
- /// A live node representing every 'exit' from the function, whether it be
636
- /// by explicit return, panic, or other means.
637
- exit_ln : LiveNode ,
638
- }
639
-
640
629
const ACC_READ : u32 = 1 ;
641
630
const ACC_WRITE : u32 = 2 ;
642
631
const ACC_USE : u32 = 4 ;
@@ -645,10 +634,17 @@ struct Liveness<'a, 'tcx> {
645
634
ir : & ' a mut IrMaps < ' tcx > ,
646
635
typeck_results : & ' a ty:: TypeckResults < ' tcx > ,
647
636
param_env : ty:: ParamEnv < ' tcx > ,
648
- s : Specials ,
649
637
successors : Vec < LiveNode > ,
650
638
rwu_table : RWUTable ,
651
639
640
+ /// A live node representing a point of execution before closure entry &
641
+ /// after closure exit. Used to calculate liveness of captured variables
642
+ /// through calls to the same closure. Used for Fn & FnMut closures only.
643
+ closure_ln : LiveNode ,
644
+ /// A live node representing every 'exit' from the function, whether it be
645
+ /// by explicit return, panic, or other means.
646
+ exit_ln : LiveNode ,
647
+
652
648
// mappings from loop node ID to LiveNode
653
649
// ("break" label should map to loop node ID,
654
650
// it probably doesn't now)
@@ -658,24 +654,23 @@ struct Liveness<'a, 'tcx> {
658
654
659
655
impl < ' a , ' tcx > Liveness < ' a , ' tcx > {
660
656
fn new ( ir : & ' a mut IrMaps < ' tcx > , def_id : LocalDefId ) -> Liveness < ' a , ' tcx > {
661
- let specials = Specials {
662
- closure_ln : ir. add_live_node ( ClosureNode ) ,
663
- exit_ln : ir. add_live_node ( ExitNode ) ,
664
- } ;
665
-
666
657
let typeck_results = ir. tcx . typeck ( def_id) ;
667
658
let param_env = ir. tcx . param_env ( def_id) ;
668
659
660
+ let closure_ln = ir. add_live_node ( ClosureNode ) ;
661
+ let exit_ln = ir. add_live_node ( ExitNode ) ;
662
+
669
663
let num_live_nodes = ir. lnks . len ( ) ;
670
664
let num_vars = ir. var_kinds . len ( ) ;
671
665
672
666
Liveness {
673
667
ir,
674
668
typeck_results,
675
669
param_env,
676
- s : specials,
677
670
successors : vec ! [ invalid_node( ) ; num_live_nodes] ,
678
671
rwu_table : RWUTable :: new ( num_live_nodes * num_vars) ,
672
+ closure_ln,
673
+ exit_ln,
679
674
break_ln : Default :: default ( ) ,
680
675
cont_ln : Default :: default ( ) ,
681
676
}
@@ -935,14 +930,14 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
935
930
match self . typeck_results . upvar_capture ( upvar_id) {
936
931
ty:: UpvarCapture :: ByRef ( _) => {
937
932
let var = self . variable ( var_hir_id, upvar. span ) ;
938
- self . acc ( self . s . exit_ln , var, ACC_READ | ACC_USE ) ;
933
+ self . acc ( self . exit_ln , var, ACC_READ | ACC_USE ) ;
939
934
}
940
935
ty:: UpvarCapture :: ByValue ( _) => { }
941
936
}
942
937
}
943
938
}
944
939
945
- let succ = self . propagate_through_expr ( & body. value , self . s . exit_ln ) ;
940
+ let succ = self . propagate_through_expr ( & body. value , self . exit_ln ) ;
946
941
947
942
match fk {
948
943
FnKind :: Method ( ..) | FnKind :: ItemFn ( ..) => return succ,
@@ -965,19 +960,19 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
965
960
// Propagate through calls to the closure.
966
961
let mut first_merge = true ;
967
962
loop {
968
- self . init_from_succ ( self . s . closure_ln , succ) ;
963
+ self . init_from_succ ( self . closure_ln , succ) ;
969
964
for param in body. params {
970
965
param. pat . each_binding ( |_bm, hir_id, _x, ident| {
971
966
let var = self . variable ( hir_id, ident. span ) ;
972
- self . define ( self . s . closure_ln , var) ;
967
+ self . define ( self . closure_ln , var) ;
973
968
} )
974
969
}
975
970
976
- if !self . merge_from_succ ( self . s . exit_ln , self . s . closure_ln , first_merge) {
971
+ if !self . merge_from_succ ( self . exit_ln , self . closure_ln , first_merge) {
977
972
break ;
978
973
}
979
974
first_merge = false ;
980
- assert_eq ! ( succ, self . propagate_through_expr( & body. value, self . s . exit_ln) ) ;
975
+ assert_eq ! ( succ, self . propagate_through_expr( & body. value, self . exit_ln) ) ;
981
976
}
982
977
983
978
succ
@@ -1099,7 +1094,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
1099
1094
1100
1095
hir:: ExprKind :: Ret ( ref o_e) => {
1101
1096
// ignore succ and subst exit_ln:
1102
- let exit_ln = self . s . exit_ln ;
1097
+ let exit_ln = self . exit_ln ;
1103
1098
self . propagate_through_opt_expr ( o_e. as_ref ( ) . map ( |e| & * * e) , exit_ln)
1104
1099
}
1105
1100
@@ -1174,7 +1169,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
1174
1169
self . typeck_results . expr_ty ( expr) ,
1175
1170
self . param_env ,
1176
1171
) {
1177
- self . s . exit_ln
1172
+ self . exit_ln
1178
1173
} else {
1179
1174
succ
1180
1175
} ;
@@ -1189,7 +1184,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
1189
1184
self . typeck_results . expr_ty ( expr) ,
1190
1185
self . param_env ,
1191
1186
) {
1192
- self . s . exit_ln
1187
+ self . exit_ln
1193
1188
} else {
1194
1189
succ
1195
1190
} ;
@@ -1226,7 +1221,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
1226
1221
hir:: ExprKind :: InlineAsm ( ref asm) => {
1227
1222
// Handle non-returning asm
1228
1223
let mut succ = if asm. options . contains ( InlineAsmOptions :: NORETURN ) {
1229
- self . s . exit_ln
1224
+ self . exit_ln
1230
1225
} else {
1231
1226
succ
1232
1227
} ;
@@ -1696,7 +1691,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
1696
1691
// {ret}`, there is only one node, so asking about
1697
1692
// assigned_on_exit() is not meaningful.
1698
1693
let is_assigned =
1699
- if ln == self . s . exit_ln { false } else { self . assigned_on_exit ( ln, var) . is_some ( ) } ;
1694
+ if ln == self . exit_ln { false } else { self . assigned_on_exit ( ln, var) . is_some ( ) } ;
1700
1695
1701
1696
if is_assigned {
1702
1697
self . ir . tcx . struct_span_lint_hir (
0 commit comments