Skip to content

Commit 2fb1564

Browse files
committed
liveness: Remove redundant fields for a number of live nodes and variables
1 parent 9b5835e commit 2fb1564

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

compiler/rustc_passes/src/liveness.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,6 @@ enum VarKind {
249249
struct IrMaps<'tcx> {
250250
tcx: TyCtxt<'tcx>,
251251
body_owner: LocalDefId,
252-
num_live_nodes: usize,
253-
num_vars: usize,
254252
live_node_map: HirIdMap<LiveNode>,
255253
variable_map: HirIdMap<Variable>,
256254
capture_info_map: HirIdMap<Rc<Vec<CaptureInfo>>>,
@@ -263,8 +261,6 @@ impl IrMaps<'tcx> {
263261
IrMaps {
264262
tcx,
265263
body_owner,
266-
num_live_nodes: 0,
267-
num_vars: 0,
268264
live_node_map: HirIdMap::default(),
269265
variable_map: HirIdMap::default(),
270266
capture_info_map: Default::default(),
@@ -274,9 +270,8 @@ impl IrMaps<'tcx> {
274270
}
275271

276272
fn add_live_node(&mut self, lnk: LiveNodeKind) -> LiveNode {
277-
let ln = LiveNode(self.num_live_nodes as u32);
273+
let ln = LiveNode(self.lnks.len() as u32);
278274
self.lnks.push(lnk);
279-
self.num_live_nodes += 1;
280275

281276
debug!("{:?} is of kind {}", ln, live_node_kind_to_string(lnk, self.tcx));
282277

@@ -291,9 +286,8 @@ impl IrMaps<'tcx> {
291286
}
292287

293288
fn add_variable(&mut self, vk: VarKind) -> Variable {
294-
let v = Variable(self.num_vars as u32);
289+
let v = Variable(self.var_kinds.len() as u32);
295290
self.var_kinds.push(vk);
296-
self.num_vars += 1;
297291

298292
match vk {
299293
Local(LocalInfo { id: node_id, .. }) | Param(node_id, _) | Upvar(node_id, _) => {
@@ -672,8 +666,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
672666
let typeck_results = ir.tcx.typeck(def_id);
673667
let param_env = ir.tcx.param_env(def_id);
674668

675-
let num_live_nodes = ir.num_live_nodes;
676-
let num_vars = ir.num_vars;
669+
let num_live_nodes = ir.lnks.len();
670+
let num_vars = ir.var_kinds.len();
677671

678672
Liveness {
679673
ir,
@@ -719,7 +713,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
719713
}
720714

721715
fn idx(&self, ln: LiveNode, var: Variable) -> usize {
722-
ln.get() * self.ir.num_vars + var.get()
716+
ln.get() * self.ir.var_kinds.len() + var.get()
723717
}
724718

725719
fn live_on_entry(&self, ln: LiveNode, var: Variable) -> Option<LiveNodeKind> {
@@ -756,7 +750,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
756750
{
757751
let node_base_idx = self.idx(ln, Variable(0));
758752
let succ_base_idx = self.idx(succ_ln, Variable(0));
759-
for var_idx in 0..self.ir.num_vars {
753+
for var_idx in 0..self.ir.var_kinds.len() {
760754
op(self, node_base_idx + var_idx, succ_base_idx + var_idx);
761755
}
762756
}
@@ -766,7 +760,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
766760
F: FnMut(usize) -> bool,
767761
{
768762
let node_base_idx = self.idx(ln, Variable(0));
769-
for var_idx in 0..self.ir.num_vars {
763+
for var_idx in 0..self.ir.var_kinds.len() {
770764
let idx = node_base_idx + var_idx;
771765
if test(idx) {
772766
write!(wr, " {:?}", Variable(var_idx as u32))?;
@@ -797,7 +791,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
797791
debug!(
798792
"^^ liveness computation results for body {} (entry={:?})",
799793
{
800-
for ln_idx in 0..self.ir.num_live_nodes {
794+
for ln_idx in 0..self.ir.lnks.len() {
801795
debug!("{:?}", self.ln_str(LiveNode(ln_idx as u32)));
802796
}
803797
hir_id

0 commit comments

Comments
 (0)