Skip to content

Remove callee_id's from the AST. #12571

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 2 commits into from
Feb 26, 2014
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/librustc/front/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl Visitor<()> for Context {

fn visit_expr(&mut self, e: &ast::Expr, _: ()) {
match e.node {
ast::ExprUnary(_, ast::UnBox, _) => {
ast::ExprUnary(ast::UnBox, _) => {
self.gate_box(e.span);
}
_ => {}
Expand Down
107 changes: 70 additions & 37 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use metadata::tydecode;
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId, TypeParameter,
RegionParameter};
use metadata::tyencode;
use middle::typeck::method_origin;
use middle::typeck::{MethodCallee, MethodOrigin};
use middle::{ty, typeck, moves};
use middle;
use util::ppaux::ty_to_str;
Expand Down Expand Up @@ -50,7 +50,7 @@ use writer = serialize::ebml::writer;
// Auxiliary maps of things to be encoded
pub struct Maps {
root_map: middle::borrowck::root_map,
method_map: middle::typeck::method_map,
method_map: middle::typeck::MethodMap,
vtable_map: middle::typeck::vtable_map,
capture_map: middle::moves::CaptureMap,
}
Expand Down Expand Up @@ -574,30 +574,68 @@ impl tr for moves::CaptureVar {
}

// ______________________________________________________________________
// Encoding and decoding of method_origin
// Encoding and decoding of MethodCallee

impl tr for method_origin {
fn tr(&self, xcx: @ExtendedDecodeContext) -> method_origin {
trait read_method_callee_helper {
fn read_method_callee(&mut self, xcx: @ExtendedDecodeContext) -> MethodCallee;
}

fn encode_method_callee(ecx: &e::EncodeContext,
ebml_w: &mut writer::Encoder,
method: &MethodCallee) {
ebml_w.emit_struct("MethodCallee", 3, |ebml_w| {
ebml_w.emit_struct_field("origin", 0u, |ebml_w| {
method.origin.encode(ebml_w);
});
ebml_w.emit_struct_field("ty", 1u, |ebml_w| {
ebml_w.emit_ty(ecx, method.ty);
});
ebml_w.emit_struct_field("substs", 2u, |ebml_w| {
ebml_w.emit_substs(ecx, &method.substs);
});
})
}

impl<'a> read_method_callee_helper for reader::Decoder<'a> {
fn read_method_callee(&mut self, xcx: @ExtendedDecodeContext) -> MethodCallee {
self.read_struct("MethodCallee", 3, |this| {
MethodCallee {
origin: this.read_struct_field("origin", 0, |this| {
let method_origin: MethodOrigin =
Decodable::decode(this);
method_origin.tr(xcx)
}),
ty: this.read_struct_field("ty", 1, |this| {
this.read_ty(xcx)
}),
substs: this.read_struct_field("substs", 2, |this| {
this.read_substs(xcx)
})
}
})
}
}

impl tr for MethodOrigin {
fn tr(&self, xcx: @ExtendedDecodeContext) -> MethodOrigin {
match *self {
typeck::method_static(did) => {
typeck::method_static(did.tr(xcx))
}
typeck::method_param(ref mp) => {
typeck::method_param(
typeck::method_param {
trait_id: mp.trait_id.tr(xcx),
.. *mp
}
)
}
typeck::method_object(ref mo) => {
typeck::method_object(
typeck::method_object {
trait_id: mo.trait_id.tr(xcx),
.. *mo
}
)
}
typeck::MethodStatic(did) => typeck::MethodStatic(did.tr(xcx)),
typeck::MethodParam(ref mp) => {
typeck::MethodParam(
typeck::MethodParam {
trait_id: mp.trait_id.tr(xcx),
.. *mp
}
)
}
typeck::MethodObject(ref mo) => {
typeck::MethodObject(
typeck::MethodObject {
trait_id: mo.trait_id.tr(xcx),
.. *mo
}
)
}
}
}
}
Expand Down Expand Up @@ -993,17 +1031,13 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
}
}

{
let method_map = maps.method_map.borrow();
let r = method_map.get().find(&id);
for &origin in r.iter() {
ebml_w.tag(c::tag_table_method_map, |ebml_w| {
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| {
origin.encode(ebml_w);
})
for &method in maps.method_map.borrow().get().find(&id).iter() {
ebml_w.tag(c::tag_table_method_map, |ebml_w| {
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| {
encode_method_callee(ecx, ebml_w, method)
})
}
})
}

{
Expand Down Expand Up @@ -1337,9 +1371,8 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
ty_param_defs.get().insert(id, bounds);
}
c::tag_table_method_map => {
let origin: method_origin = Decodable::decode(val_dsr);
let mut method_map = dcx.maps.method_map.borrow_mut();
method_map.get().insert(id, origin.tr(xcx));
let method = val_dsr.read_method_callee(xcx);
dcx.maps.method_map.borrow_mut().get().insert(id, method);
}
c::tag_table_vtable_map => {
let vtable_res =
Expand Down
18 changes: 8 additions & 10 deletions src/librustc/middle/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,6 @@ impl<'a> CheckLoanCtxt<'a> {
pub fn check_call(&self,
_expr: &ast::Expr,
_callee: Option<@ast::Expr>,
_callee_id: ast::NodeId,
_callee_span: Span,
_args: &[@ast::Expr]) {
// NB: This call to check for conflicting loans is not truly
Expand Down Expand Up @@ -828,23 +827,22 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>,
this.check_captured_variables(expr.id, expr.span)
}
ast::ExprAssign(dest, _) |
ast::ExprAssignOp(_, _, dest, _) => {
ast::ExprAssignOp(_, dest, _) => {
this.check_assignment(dest);
}
ast::ExprCall(f, ref args) => {
this.check_call(expr, Some(f), f.id, f.span, *args);
this.check_call(expr, Some(f), f.span, *args);
}
ast::ExprMethodCall(callee_id, _, _, ref args) => {
this.check_call(expr, None, callee_id, expr.span, *args);
ast::ExprMethodCall(_, _, ref args) => {
this.check_call(expr, None, expr.span, *args);
}
ast::ExprIndex(callee_id, _, rval) |
ast::ExprBinary(callee_id, _, _, rval)
ast::ExprIndex(_, rval) | ast::ExprBinary(_, _, rval)
if method_map.get().contains_key(&expr.id) => {
this.check_call(expr, None, callee_id, expr.span, [rval]);
this.check_call(expr, None, expr.span, [rval]);
}
ast::ExprUnary(callee_id, _, _) | ast::ExprIndex(callee_id, _, _)
ast::ExprUnary(_, _) | ast::ExprIndex(_, _)
if method_map.get().contains_key(&expr.id) => {
this.check_call(expr, None, callee_id, expr.span, []);
this.check_call(expr, None, expr.span, []);
}
ast::ExprInlineAsm(ref ia) => {
for &(_, out) in ia.outputs.iter() {
Expand Down
21 changes: 5 additions & 16 deletions src/librustc/middle/borrowck/gather_loans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,9 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,

this.id_range.add(ex.id);

{
let r = ex.get_callee_id();
for callee_id in r.iter() {
this.id_range.add(*callee_id);
}
}

// If this expression is borrowed, have to ensure it remains valid:
{
let adjustments = tcx.adjustments.borrow();
let r = adjustments.get().find(&ex.id);
for &adjustments in r.iter() {
this.guarantee_adjustments(ex, *adjustments);
}
for &adjustments in tcx.adjustments.borrow().get().find(&ex.id).iter() {
this.guarantee_adjustments(ex, *adjustments);
}

// If this expression is a move, gather it:
Expand Down Expand Up @@ -225,7 +214,7 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
visit::walk_expr(this, ex, ());
}

ast::ExprAssign(l, _) | ast::ExprAssignOp(_, _, l, _) => {
ast::ExprAssign(l, _) | ast::ExprAssignOp(_, l, _) => {
let l_cmt = this.bccx.cat_expr(l);
match opt_loan_path(l_cmt) {
Some(l_lp) => {
Expand All @@ -252,8 +241,8 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
visit::walk_expr(this, ex, ());
}

ast::ExprIndex(_, _, arg) |
ast::ExprBinary(_, _, _, arg)
ast::ExprIndex(_, arg) |
ast::ExprBinary(_, _, arg)
if method_map.get().contains_key(&ex.id) => {
// Arguments in method calls are always passed by ref.
//
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Visitor<()> for BorrowckCtxt {
}

pub fn check_crate(tcx: ty::ctxt,
method_map: typeck::method_map,
method_map: typeck::MethodMap,
moves_map: moves::MovesMap,
moved_variables_set: moves::MovedVariablesSet,
capture_map: moves::CaptureMap,
Expand Down Expand Up @@ -156,7 +156,7 @@ fn borrowck_fn(this: &mut BorrowckCtxt,

pub struct BorrowckCtxt {
tcx: ty::ctxt,
method_map: typeck::method_map,
method_map: typeck::MethodMap,
moves_map: moves::MovesMap,
moved_variables_set: moves::MovedVariablesSet,
capture_map: moves::CaptureMap,
Expand Down Expand Up @@ -909,7 +909,7 @@ impl Repr for LoanPath {

struct TcxTyper {
tcx: ty::ctxt,
method_map: typeck::method_map,
method_map: typeck::MethodMap,
}

impl mc::Typer for TcxTyper {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/borrowck/move_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ impl MoveData {
impl FlowedMoveData {
pub fn new(move_data: MoveData,
tcx: ty::ctxt,
method_map: typeck::method_map,
method_map: typeck::MethodMap,
id_range: ast_util::IdRange,
body: &ast::Block)
-> FlowedMoveData {
Expand Down
22 changes: 11 additions & 11 deletions src/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use syntax::opt_vec;

struct CFGBuilder {
tcx: ty::ctxt,
method_map: typeck::method_map,
method_map: typeck::MethodMap,
exit_map: HashMap<ast::NodeId, CFGIndex>,
graph: CFGGraph,
loop_scopes: ~[LoopScope],
Expand All @@ -32,7 +32,7 @@ struct LoopScope {
}

pub fn construct(tcx: ty::ctxt,
method_map: typeck::method_map,
method_map: typeck::MethodMap,
blk: &ast::Block) -> CFG {
let mut cfg_builder = CFGBuilder {
exit_map: HashMap::new(),
Expand Down Expand Up @@ -305,7 +305,7 @@ impl CFGBuilder {
expr_exit
}

ast::ExprBinary(_, op, l, r) if ast_util::lazy_binop(op) => {
ast::ExprBinary(op, l, r) if ast_util::lazy_binop(op) => {
//
// [pred]
// |
Expand Down Expand Up @@ -355,16 +355,16 @@ impl CFGBuilder {
self.call(expr, pred, func, *args)
}

ast::ExprMethodCall(_, _, _, ref args) => {
ast::ExprMethodCall(_, _, ref args) => {
self.call(expr, pred, args[0], args.slice_from(1))
}

ast::ExprIndex(_, l, r) |
ast::ExprBinary(_, _, l, r) if self.is_method_call(expr) => {
ast::ExprIndex(l, r) |
ast::ExprBinary(_, l, r) if self.is_method_call(expr) => {
self.call(expr, pred, l, [r])
}

ast::ExprUnary(_, _, e) if self.is_method_call(expr) => {
ast::ExprUnary(_, e) if self.is_method_call(expr) => {
self.call(expr, pred, e, [])
}

Expand All @@ -384,12 +384,12 @@ impl CFGBuilder {
}

ast::ExprAssign(l, r) |
ast::ExprAssignOp(_, _, l, r) => {
ast::ExprAssignOp(_, l, r) => {
self.straightline(expr, pred, [r, l])
}

ast::ExprIndex(_, l, r) |
ast::ExprBinary(_, _, l, r) => { // NB: && and || handled earlier
ast::ExprIndex(l, r) |
ast::ExprBinary(_, l, r) => { // NB: && and || handled earlier
self.straightline(expr, pred, [l, r])
}

Expand All @@ -399,7 +399,7 @@ impl CFGBuilder {

ast::ExprAddrOf(_, e) |
ast::ExprCast(e, _) |
ast::ExprUnary(_, _, e) |
ast::ExprUnary(_, e) |
ast::ExprParen(e) |
ast::ExprVstore(e, _) |
ast::ExprField(e, _, _) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/cfg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct CFGIndices {

impl CFG {
pub fn new(tcx: ty::ctxt,
method_map: typeck::method_map,
method_map: typeck::MethodMap,
blk: &ast::Block) -> CFG {
construct::construct(tcx, method_map, blk)
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use syntax::visit;
struct CheckCrateVisitor {
sess: Session,
def_map: resolve::DefMap,
method_map: typeck::method_map,
method_map: typeck::MethodMap,
tcx: ty::ctxt,
}

Expand All @@ -43,7 +43,7 @@ impl Visitor<bool> for CheckCrateVisitor {
pub fn check_crate(sess: Session,
krate: &Crate,
def_map: resolve::DefMap,
method_map: typeck::method_map,
method_map: typeck::MethodMap,
tcx: ty::ctxt) {
let mut v = CheckCrateVisitor {
sess: sess,
Expand Down Expand Up @@ -102,14 +102,14 @@ pub fn check_pat(v: &mut CheckCrateVisitor, p: &Pat, _is_const: bool) {
pub fn check_expr(v: &mut CheckCrateVisitor,
sess: Session,
def_map: resolve::DefMap,
method_map: typeck::method_map,
method_map: typeck::MethodMap,
tcx: ty::ctxt,
e: &Expr,
is_const: bool) {
if is_const {
match e.node {
ExprUnary(_, UnDeref, _) => { }
ExprUnary(_, UnBox, _) | ExprUnary(_, UnUniq, _) => {
ExprUnary(UnDeref, _) => { }
ExprUnary(UnBox, _) | ExprUnary(UnUniq, _) => {
sess.span_err(e.span,
"cannot do allocations in constant expressions");
return;
Expand Down
Loading