Skip to content

Commit

Permalink
rustc: keep track of tables everywhere as if they were per-body.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Jan 6, 2017
1 parent a28701a commit 85a4a19
Show file tree
Hide file tree
Showing 68 changed files with 946 additions and 979 deletions.
1 change: 0 additions & 1 deletion src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 19 additions & 5 deletions src/librustc/cfg/construct.rs
Expand Up @@ -18,6 +18,7 @@ use hir::{self, PatKind};

struct CFGBuilder<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
tables: &'a ty::Tables<'tcx>,
graph: CFGGraph,
fn_exit: CFGIndex,
loop_scopes: Vec<LoopScope>,
Expand All @@ -42,10 +43,23 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let fn_exit = graph.add_node(CFGNodeData::Exit);
let body_exit;

// Find the function this expression is from.
let mut node_id = body.id;
loop {
let node = tcx.map.get(node_id);
if hir::map::blocks::FnLikeNode::from_node(node).is_some() {
break;
}
let parent = tcx.map.get_parent_node(node_id);
assert!(node_id != parent);
node_id = parent;
}

let mut cfg_builder = CFGBuilder {
tcx: tcx,
tables: tcx.item_tables(tcx.map.local_def_id(node_id)),
graph: graph,
fn_exit: fn_exit,
tcx: tcx,
loop_scopes: Vec::new()
};
body_exit = cfg_builder.expr(body, entry);
Expand Down Expand Up @@ -310,11 +324,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}

hir::ExprIndex(ref l, ref r) |
hir::ExprBinary(_, ref l, ref r) if self.tcx.tables().is_method_call(expr.id) => {
hir::ExprBinary(_, ref l, ref r) if self.tables.is_method_call(expr.id) => {
self.call(expr, pred, &l, Some(&**r).into_iter())
}

hir::ExprUnary(_, ref e) if self.tcx.tables().is_method_call(expr.id) => {
hir::ExprUnary(_, ref e) if self.tables.is_method_call(expr.id) => {
self.call(expr, pred, &e, None::<hir::Expr>.iter())
}

Expand Down Expand Up @@ -368,9 +382,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
func_or_rcvr: &hir::Expr,
args: I) -> CFGIndex {
let method_call = ty::MethodCall::expr(call_expr.id);
let fn_ty = match self.tcx.tables().method_map.get(&method_call) {
let fn_ty = match self.tables.method_map.get(&method_call) {
Some(method) => method.ty,
None => self.tcx.tables().expr_ty_adjusted(func_or_rcvr)
None => self.tables.expr_ty_adjusted(func_or_rcvr)
};

let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
Expand Down
19 changes: 0 additions & 19 deletions src/librustc/hir/map/blocks.rs
Expand Up @@ -45,15 +45,6 @@ pub struct FnLikeNode<'a> { node: map::Node<'a> }
/// corresponds to some FnLikeNode.
pub trait MaybeFnLike { fn is_fn_like(&self) -> bool; }

/// Components shared by fn-like things (fn items, methods, closures).
pub struct FnParts<'a> {
pub decl: &'a FnDecl,
pub body: ast::BodyId,
pub kind: FnKind<'a>,
pub span: Span,
pub id: NodeId,
}

impl MaybeFnLike for ast::Item {
fn is_fn_like(&self) -> bool {
match self.node { ast::ItemFn(..) => true, _ => false, }
Expand Down Expand Up @@ -165,16 +156,6 @@ impl<'a> FnLikeNode<'a> {
}
}

pub fn to_fn_parts(self) -> FnParts<'a> {
FnParts {
decl: self.decl(),
body: self.body(),
kind: self.kind(),
span: self.span(),
id: self.id(),
}
}

pub fn body(self) -> ast::BodyId {
self.handle(|i: ItemFnParts<'a>| i.body,
|_, _, _: &'a ast::MethodSig, _, body: ast::BodyId, _, _| body,
Expand Down

0 comments on commit 85a4a19

Please sign in to comment.