Skip to content

Commit 141b91d

Browse files
committed
liveness: Inline contents of specials struct
1 parent 70f150b commit 141b91d

File tree

1 file changed

+25
-30
lines changed

1 file changed

+25
-30
lines changed

compiler/rustc_passes/src/liveness.rs

+25-30
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
//! ## Special nodes and variables
8080
//!
8181
//! 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.
8383
8484
use self::LiveNodeKind::*;
8585
use self::VarKind::*;
@@ -626,17 +626,6 @@ impl RWUTable {
626626
}
627627
}
628628

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-
640629
const ACC_READ: u32 = 1;
641630
const ACC_WRITE: u32 = 2;
642631
const ACC_USE: u32 = 4;
@@ -645,10 +634,17 @@ struct Liveness<'a, 'tcx> {
645634
ir: &'a mut IrMaps<'tcx>,
646635
typeck_results: &'a ty::TypeckResults<'tcx>,
647636
param_env: ty::ParamEnv<'tcx>,
648-
s: Specials,
649637
successors: Vec<LiveNode>,
650638
rwu_table: RWUTable,
651639

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+
652648
// mappings from loop node ID to LiveNode
653649
// ("break" label should map to loop node ID,
654650
// it probably doesn't now)
@@ -658,24 +654,23 @@ struct Liveness<'a, 'tcx> {
658654

659655
impl<'a, 'tcx> Liveness<'a, 'tcx> {
660656
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-
666657
let typeck_results = ir.tcx.typeck(def_id);
667658
let param_env = ir.tcx.param_env(def_id);
668659

660+
let closure_ln = ir.add_live_node(ClosureNode);
661+
let exit_ln = ir.add_live_node(ExitNode);
662+
669663
let num_live_nodes = ir.lnks.len();
670664
let num_vars = ir.var_kinds.len();
671665

672666
Liveness {
673667
ir,
674668
typeck_results,
675669
param_env,
676-
s: specials,
677670
successors: vec![invalid_node(); num_live_nodes],
678671
rwu_table: RWUTable::new(num_live_nodes * num_vars),
672+
closure_ln,
673+
exit_ln,
679674
break_ln: Default::default(),
680675
cont_ln: Default::default(),
681676
}
@@ -935,14 +930,14 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
935930
match self.typeck_results.upvar_capture(upvar_id) {
936931
ty::UpvarCapture::ByRef(_) => {
937932
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);
939934
}
940935
ty::UpvarCapture::ByValue(_) => {}
941936
}
942937
}
943938
}
944939

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);
946941

947942
match fk {
948943
FnKind::Method(..) | FnKind::ItemFn(..) => return succ,
@@ -965,19 +960,19 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
965960
// Propagate through calls to the closure.
966961
let mut first_merge = true;
967962
loop {
968-
self.init_from_succ(self.s.closure_ln, succ);
963+
self.init_from_succ(self.closure_ln, succ);
969964
for param in body.params {
970965
param.pat.each_binding(|_bm, hir_id, _x, ident| {
971966
let var = self.variable(hir_id, ident.span);
972-
self.define(self.s.closure_ln, var);
967+
self.define(self.closure_ln, var);
973968
})
974969
}
975970

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) {
977972
break;
978973
}
979974
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));
981976
}
982977

983978
succ
@@ -1099,7 +1094,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10991094

11001095
hir::ExprKind::Ret(ref o_e) => {
11011096
// ignore succ and subst exit_ln:
1102-
let exit_ln = self.s.exit_ln;
1097+
let exit_ln = self.exit_ln;
11031098
self.propagate_through_opt_expr(o_e.as_ref().map(|e| &**e), exit_ln)
11041099
}
11051100

@@ -1174,7 +1169,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
11741169
self.typeck_results.expr_ty(expr),
11751170
self.param_env,
11761171
) {
1177-
self.s.exit_ln
1172+
self.exit_ln
11781173
} else {
11791174
succ
11801175
};
@@ -1189,7 +1184,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
11891184
self.typeck_results.expr_ty(expr),
11901185
self.param_env,
11911186
) {
1192-
self.s.exit_ln
1187+
self.exit_ln
11931188
} else {
11941189
succ
11951190
};
@@ -1226,7 +1221,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
12261221
hir::ExprKind::InlineAsm(ref asm) => {
12271222
// Handle non-returning asm
12281223
let mut succ = if asm.options.contains(InlineAsmOptions::NORETURN) {
1229-
self.s.exit_ln
1224+
self.exit_ln
12301225
} else {
12311226
succ
12321227
};
@@ -1696,7 +1691,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
16961691
// {ret}`, there is only one node, so asking about
16971692
// assigned_on_exit() is not meaningful.
16981693
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() };
17001695

17011696
if is_assigned {
17021697
self.ir.tcx.struct_span_lint_hir(

0 commit comments

Comments
 (0)