Skip to content

Commit 85a4a19

Browse files
committed
rustc: keep track of tables everywhere as if they were per-body.
1 parent a28701a commit 85a4a19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+946
-979
lines changed

src/Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustc/cfg/construct.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use hir::{self, PatKind};
1818

1919
struct CFGBuilder<'a, 'tcx: 'a> {
2020
tcx: TyCtxt<'a, 'tcx, 'tcx>,
21+
tables: &'a ty::Tables<'tcx>,
2122
graph: CFGGraph,
2223
fn_exit: CFGIndex,
2324
loop_scopes: Vec<LoopScope>,
@@ -42,10 +43,23 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
4243
let fn_exit = graph.add_node(CFGNodeData::Exit);
4344
let body_exit;
4445

46+
// Find the function this expression is from.
47+
let mut node_id = body.id;
48+
loop {
49+
let node = tcx.map.get(node_id);
50+
if hir::map::blocks::FnLikeNode::from_node(node).is_some() {
51+
break;
52+
}
53+
let parent = tcx.map.get_parent_node(node_id);
54+
assert!(node_id != parent);
55+
node_id = parent;
56+
}
57+
4558
let mut cfg_builder = CFGBuilder {
59+
tcx: tcx,
60+
tables: tcx.item_tables(tcx.map.local_def_id(node_id)),
4661
graph: graph,
4762
fn_exit: fn_exit,
48-
tcx: tcx,
4963
loop_scopes: Vec::new()
5064
};
5165
body_exit = cfg_builder.expr(body, entry);
@@ -310,11 +324,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
310324
}
311325

312326
hir::ExprIndex(ref l, ref r) |
313-
hir::ExprBinary(_, ref l, ref r) if self.tcx.tables().is_method_call(expr.id) => {
327+
hir::ExprBinary(_, ref l, ref r) if self.tables.is_method_call(expr.id) => {
314328
self.call(expr, pred, &l, Some(&**r).into_iter())
315329
}
316330

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

@@ -368,9 +382,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
368382
func_or_rcvr: &hir::Expr,
369383
args: I) -> CFGIndex {
370384
let method_call = ty::MethodCall::expr(call_expr.id);
371-
let fn_ty = match self.tcx.tables().method_map.get(&method_call) {
385+
let fn_ty = match self.tables.method_map.get(&method_call) {
372386
Some(method) => method.ty,
373-
None => self.tcx.tables().expr_ty_adjusted(func_or_rcvr)
387+
None => self.tables.expr_ty_adjusted(func_or_rcvr)
374388
};
375389

376390
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);

src/librustc/hir/map/blocks.rs

-19
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ pub struct FnLikeNode<'a> { node: map::Node<'a> }
4545
/// corresponds to some FnLikeNode.
4646
pub trait MaybeFnLike { fn is_fn_like(&self) -> bool; }
4747

48-
/// Components shared by fn-like things (fn items, methods, closures).
49-
pub struct FnParts<'a> {
50-
pub decl: &'a FnDecl,
51-
pub body: ast::BodyId,
52-
pub kind: FnKind<'a>,
53-
pub span: Span,
54-
pub id: NodeId,
55-
}
56-
5748
impl MaybeFnLike for ast::Item {
5849
fn is_fn_like(&self) -> bool {
5950
match self.node { ast::ItemFn(..) => true, _ => false, }
@@ -165,16 +156,6 @@ impl<'a> FnLikeNode<'a> {
165156
}
166157
}
167158

168-
pub fn to_fn_parts(self) -> FnParts<'a> {
169-
FnParts {
170-
decl: self.decl(),
171-
body: self.body(),
172-
kind: self.kind(),
173-
span: self.span(),
174-
id: self.id(),
175-
}
176-
}
177-
178159
pub fn body(self) -> ast::BodyId {
179160
self.handle(|i: ItemFnParts<'a>| i.body,
180161
|_, _, _: &'a ast::MethodSig, _, body: ast::BodyId, _, _| body,

0 commit comments

Comments
 (0)