Skip to content

Shrink LiveNode. #50981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
//! enclosing function. On the way down the tree, it identifies those AST
//! nodes and variable IDs that will be needed for the liveness analysis
//! and assigns them contiguous IDs. The liveness id for an AST node is
//! called a `live_node` (it's a newtype'd usize) and the id for a variable
//! is called a `variable` (another newtype'd usize).
//! called a `live_node` (it's a newtype'd u32) and the id for a variable
//! is called a `variable` (another newtype'd u32).
//!
//! On the way back up the tree, as we are about to exit from a function
//! declaration we allocate a `liveness` instance. Now that we know
Expand Down Expand Up @@ -112,7 +112,7 @@ use lint;
use util::nodemap::{NodeMap, NodeSet};

use std::collections::VecDeque;
use std::{fmt, usize};
use std::{fmt, u32};
use std::io::prelude::*;
use std::io;
use std::rc::Rc;
Expand All @@ -134,23 +134,17 @@ enum LoopKind<'a> {
}

#[derive(Copy, Clone, PartialEq)]
struct Variable(usize);
struct Variable(u32);

#[derive(Copy, PartialEq)]
struct LiveNode(usize);
#[derive(Copy, Clone, PartialEq)]
struct LiveNode(u32);

impl Variable {
fn get(&self) -> usize { let Variable(v) = *self; v }
fn get(&self) -> usize { self.0 as usize }
}

impl LiveNode {
fn get(&self) -> usize { let LiveNode(v) = *self; v }
}

impl Clone for LiveNode {
fn clone(&self) -> LiveNode {
LiveNode(self.get())
}
fn get(&self) -> usize { self.0 as usize }
}

#[derive(Copy, Clone, PartialEq, Debug)]
Expand Down Expand Up @@ -233,11 +227,11 @@ impl fmt::Debug for Variable {

impl LiveNode {
fn is_valid(&self) -> bool {
self.get() != usize::MAX
self.0 != u32::MAX
}
}

fn invalid_node() -> LiveNode { LiveNode(usize::MAX) }
fn invalid_node() -> LiveNode { LiveNode(u32::MAX) }

struct CaptureInfo {
ln: LiveNode,
Expand Down Expand Up @@ -285,7 +279,7 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
}

fn add_live_node(&mut self, lnk: LiveNodeKind) -> LiveNode {
let ln = LiveNode(self.num_live_nodes);
let ln = LiveNode(self.num_live_nodes as u32);
self.lnks.push(lnk);
self.num_live_nodes += 1;

Expand All @@ -303,7 +297,7 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
}

fn add_variable(&mut self, vk: VarKind) -> Variable {
let v = Variable(self.num_vars);
let v = Variable(self.num_vars as u32);
self.var_kinds.push(vk);
self.num_vars += 1;

Expand Down Expand Up @@ -708,7 +702,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
for var_idx in 0..self.ir.num_vars {
let idx = node_base_idx + var_idx;
if test(idx).is_valid() {
write!(wr, " {:?}", Variable(var_idx))?;
write!(wr, " {:?}", Variable(var_idx as u32))?;
}
}
Ok(())
Expand Down Expand Up @@ -848,7 +842,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
debug!("^^ liveness computation results for body {} (entry={:?})",
{
for ln_idx in 0..self.ir.num_live_nodes {
debug!("{:?}", self.ln_str(LiveNode(ln_idx)));
debug!("{:?}", self.ln_str(LiveNode(ln_idx as u32)));
}
body.id
},
Expand Down