/// and should not leak any information about desugarings.
#[derive(Clone, Copy)]
pub struct AbstractConst<'tcx> {
- pub inner: &'tcx [Node<'tcx>],
- pub substs: SubstsRef<'tcx>,
+ // FIXME: Consider adding something like `IndexSlice`
+ // and use this here.
+ inner: &'tcx [Node<'tcx>],
+ substs: SubstsRef<'tcx>,
}
impl AbstractConst<'tcx> {
#[inline]
pub fn subtree(self, node: NodeId) -> AbstractConst<'tcx> {
- AbstractConst { inner: &self.inner[..=node], substs: self.substs }
+ AbstractConst { inner: &self.inner[..=node.index()], substs: self.substs }
}
#[inline]
struct AbstractConstBuilder<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
body: &'a mir::Body<'tcx>,
- nodes: Vec<Node<'tcx>>,
+ nodes: IndexVec<NodeId, Node<'tcx>>,
locals: IndexVec<mir::Local, NodeId>,
checked_op_locals: BitSet<mir::Local>,
}
Some(AbstractConstBuilder {
tcx,
body,
- nodes: vec![],
+ nodes: IndexVec::new(),
locals: IndexVec::from_elem(NodeId::MAX, &body.local_decls),
checked_op_locals: BitSet::new_empty(body.local_decls.len()),
})
}
- fn add_node(&mut self, n: Node<'tcx>) -> NodeId {
- let len = self.nodes.len();
- self.nodes.push(n);
- len
- }
-
fn operand_to_node(&mut self, op: &mir::Operand<'tcx>) -> Option<NodeId> {
debug!("operand_to_node: op={:?}", op);
const ZERO_FIELD: mir::Field = mir::Field::from_usize(0);
None
}
}
- mir::Operand::Constant(ct) => Some(self.add_node(Node::Leaf(ct.literal))),
+ mir::Operand::Constant(ct) => Some(self.nodes.push(Node::Leaf(ct.literal))),
}
}
Rvalue::BinaryOp(op, ref lhs, ref rhs) if Self::check_binop(op) => {
let lhs = self.operand_to_node(lhs)?;
let rhs = self.operand_to_node(rhs)?;
- self.locals[local] = self.add_node(Node::Binop(op, lhs, rhs));
+ self.locals[local] = self.nodes.push(Node::Binop(op, lhs, rhs));
if op.is_checkable() {
bug!("unexpected unchecked checkable binary operation");
}
Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) if Self::check_binop(op) => {
let lhs = self.operand_to_node(lhs)?;
let rhs = self.operand_to_node(rhs)?;
- self.locals[local] = self.add_node(Node::Binop(op, lhs, rhs));
+ self.locals[local] = self.nodes.push(Node::Binop(op, lhs, rhs));
self.checked_op_locals.insert(local);
}
_ => return None,