Skip to content

Commit

Permalink
auto merge of #6885 : erickt/rust/move-callee_id, r=catamorphism
Browse files Browse the repository at this point in the history
The `callee_id` in `ast::expr` in only used in a couple expression variants. This moves the `callee_id` into those branches to make it more clear when its should be used.

Also, it fixes a bug in a std::run test when there is a symlink in the path rust where was checked out.
  • Loading branch information
bors committed Jun 2, 2013
2 parents 24e85ac + 23808ef commit 63417da
Show file tree
Hide file tree
Showing 41 changed files with 349 additions and 295 deletions.
7 changes: 3 additions & 4 deletions src/libfuzzer/fuzzer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ pub fn common_exprs() -> ~[@ast::expr] {
fn dse(e: ast::expr_) -> @ast::expr {
@ast::expr {
id: 0,
callee_id: -1,
node: e,
span: codemap::dummy_sp(),
}
Expand All @@ -94,9 +93,9 @@ pub fn common_exprs() -> ~[@ast::expr] {
dse(ast::expr_lit(@dsl(ast::lit_nil))),
dse(ast::expr_lit(@dsl(ast::lit_bool(false)))),
dse(ast::expr_lit(@dsl(ast::lit_bool(true)))),
dse(ast::expr_unary(ast::box(ast::m_imm),
dse(ast::expr_unary(-1, ast::box(ast::m_imm),
dse(ast::expr_lit(@dsl(ast::lit_bool(true)))))),
dse(ast::expr_unary(ast::uniq(ast::m_imm),
dse(ast::expr_unary(-1, ast::uniq(ast::m_imm),
dse(ast::expr_lit(@dsl(ast::lit_bool(true))))))
]
}
Expand Down Expand Up @@ -128,7 +127,7 @@ pub fn safe_to_use_expr(e: @ast::expr, tm: test_mode) -> bool {
//ast::expr_cast(_, _) { false }

// https://github.com/mozilla/rust/issues/1458
ast::expr_call(_, _, _) => { false }
ast::expr_call(*) => { false }

_ => { true }
}
Expand Down
4 changes: 0 additions & 4 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,12 @@ fn mk_test_descs(cx: &TestCtxt) -> @ast::expr {
let sess = cx.sess;
let inner_expr = @ast::expr {
id: sess.next_node_id(),
callee_id: sess.next_node_id(),
node: ast::expr_vec(descs, ast::m_imm),
span: dummy_sp(),
};

@ast::expr {
id: sess.next_node_id(),
callee_id: sess.next_node_id(),
node: ast::expr_vstore(inner_expr, ast::expr_vstore_slice),
span: dummy_sp(),
}
Expand All @@ -423,7 +421,6 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::expr {

let name_expr = @ast::expr {
id: cx.sess.next_node_id(),
callee_id: cx.sess.next_node_id(),
node: ast::expr_lit(@name_lit),
span: span
};
Expand All @@ -432,7 +429,6 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::expr {

let fn_expr = @ast::expr {
id: cx.sess.next_node_id(),
callee_id: cx.sess.next_node_id(),
node: ast::expr_path(fn_path),
span: span,
};
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/middle/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,29 +707,29 @@ fn check_loans_in_expr<'a>(expr: @ast::expr,
}
}
ast::expr_assign(dest, _) |
ast::expr_assign_op(_, dest, _) => {
ast::expr_assign_op(_, _, dest, _) => {
this.check_assignment(dest);
}
ast::expr_call(f, ref args, _) => {
this.check_call(expr, Some(f), f.id, f.span, *args);
}
ast::expr_method_call(_, _, _, ref args, _) => {
this.check_call(expr, None, expr.callee_id, expr.span, *args);
ast::expr_method_call(callee_id, _, _, _, ref args, _) => {
this.check_call(expr, None, callee_id, expr.span, *args);
}
ast::expr_index(_, rval) |
ast::expr_binary(_, _, rval)
ast::expr_index(callee_id, _, rval) |
ast::expr_binary(callee_id, _, _, rval)
if this.bccx.method_map.contains_key(&expr.id) => {
this.check_call(expr,
None,
expr.callee_id,
callee_id,
expr.span,
[rval]);
}
ast::expr_unary(*) | ast::expr_index(*)
ast::expr_unary(callee_id, _, _) | ast::expr_index(callee_id, _, _)
if this.bccx.method_map.contains_key(&expr.id) => {
this.check_call(expr,
None,
expr.callee_id,
callee_id,
expr.span,
[]);
}
Expand Down
11 changes: 7 additions & 4 deletions src/librustc/middle/borrowck/gather_loans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ fn gather_loans_in_expr(ex: @ast::expr,
ex.id, pprust::expr_to_str(ex, tcx.sess.intr()));

this.id_range.add(ex.id);
this.id_range.add(ex.callee_id);

for ex.get_callee_id().each |callee_id| {
this.id_range.add(*callee_id);
}

// If this expression is borrowed, have to ensure it remains valid:
for tcx.adjustments.find(&ex.id).each |&adjustments| {
Expand All @@ -201,7 +204,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
visit::visit_expr(ex, this, vt);
}

ast::expr_assign(l, _) | ast::expr_assign_op(_, l, _) => {
ast::expr_assign(l, _) | ast::expr_assign_op(_, _, l, _) => {
let l_cmt = this.bccx.cat_expr(l);
match opt_loan_path(l_cmt) {
Some(l_lp) => {
Expand All @@ -228,8 +231,8 @@ fn gather_loans_in_expr(ex: @ast::expr,
visit::visit_expr(ex, this, vt);
}

ast::expr_index(_, arg) |
ast::expr_binary(_, _, arg)
ast::expr_index(_, _, arg) |
ast::expr_binary(_, _, _, arg)
if this.bccx.method_map.contains_key(&ex.id) => {
// Arguments in method calls are always passed by ref.
//
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ pub fn check_expr(sess: Session,
v: visit::vt<bool>) {
if is_const {
match e.node {
expr_unary(deref, _) => { }
expr_unary(box(_), _) | expr_unary(uniq(_), _) => {
expr_unary(_, deref, _) => { }
expr_unary(_, box(_), _) | expr_unary(_, uniq(_), _) => {
sess.span_err(e.span,
"disallowed operator in constant expression");
return;
}
expr_lit(@codemap::spanned {node: lit_str(_), _}) => { }
expr_binary(_, _, _) | expr_unary(_, _) => {
expr_binary(*) | expr_unary(*) => {
if method_map.contains_key(&e.id) {
sess.span_err(e.span, "user-defined operators are not \
allowed in constant expressions");
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ pub fn classify(e: @expr,
}

ast::expr_copy(inner) |
ast::expr_unary(_, inner) |
ast::expr_unary(_, _, inner) |
ast::expr_paren(inner) => {
classify(inner, tcx)
}

ast::expr_binary(_, a, b) => {
ast::expr_binary(_, _, a, b) => {
join(classify(a, tcx),
classify(b, tcx))
}
Expand Down Expand Up @@ -141,7 +141,7 @@ pub fn classify(e: @expr,
classify(base, tcx)
}

ast::expr_index(base, idx) => {
ast::expr_index(_, base, idx) => {
join(classify(base, tcx),
classify(idx, tcx))
}
Expand Down Expand Up @@ -251,7 +251,7 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
use middle::ty;
fn fromb(b: bool) -> Result<const_val, ~str> { Ok(const_int(b as i64)) }
match e.node {
expr_unary(neg, inner) => {
expr_unary(_, neg, inner) => {
match eval_const_expr_partial(tcx, inner) {
Ok(const_float(f)) => Ok(const_float(-f)),
Ok(const_int(i)) => Ok(const_int(-i)),
Expand All @@ -261,15 +261,15 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: @expr)
ref err => (/*bad*/copy *err)
}
}
expr_unary(not, inner) => {
expr_unary(_, not, inner) => {
match eval_const_expr_partial(tcx, inner) {
Ok(const_int(i)) => Ok(const_int(!i)),
Ok(const_uint(i)) => Ok(const_uint(!i)),
Ok(const_bool(b)) => Ok(const_bool(!b)),
_ => Err(~"Not on float or string")
}
}
expr_binary(op, a, b) => {
expr_binary(_, op, a, b) => {
match (eval_const_expr_partial(tcx, a),
eval_const_expr_partial(tcx, b)) {
(Ok(const_float(a)), Ok(const_float(b))) => {
Expand Down
26 changes: 13 additions & 13 deletions src/librustc/middle/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
}

ast::expr_assign(l, r) |
ast::expr_assign_op(_, l, r) => {
ast::expr_assign_op(_, _, l, r) => {
self.walk_expr(r, in_out, loop_scopes);
self.walk_expr(l, in_out, loop_scopes);
}
Expand All @@ -661,40 +661,40 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
}

ast::expr_call(f, ref args, _) => {
self.walk_call(expr.callee_id, expr.id,
self.walk_call(f.id, expr.id,
f, *args, in_out, loop_scopes);
}

ast::expr_method_call(rcvr, _, _, ref args, _) => {
self.walk_call(expr.callee_id, expr.id,
ast::expr_method_call(callee_id, rcvr, _, _, ref args, _) => {
self.walk_call(callee_id, expr.id,
rcvr, *args, in_out, loop_scopes);
}

ast::expr_index(l, r) |
ast::expr_binary(_, l, r) if self.is_method_call(expr) => {
self.walk_call(expr.callee_id, expr.id,
ast::expr_index(callee_id, l, r) |
ast::expr_binary(callee_id, _, l, r) if self.is_method_call(expr) => {
self.walk_call(callee_id, expr.id,
l, [r], in_out, loop_scopes);
}

ast::expr_unary(_, e) if self.is_method_call(expr) => {
self.walk_call(expr.callee_id, expr.id,
ast::expr_unary(callee_id, _, e) if self.is_method_call(expr) => {
self.walk_call(callee_id, expr.id,
e, [], in_out, loop_scopes);
}

ast::expr_tup(ref exprs) => {
self.walk_exprs(*exprs, in_out, loop_scopes);
}

ast::expr_binary(op, l, r) if ast_util::lazy_binop(op) => {
ast::expr_binary(_, op, l, r) if ast_util::lazy_binop(op) => {
self.walk_expr(l, in_out, loop_scopes);
let temp = reslice(in_out).to_vec();
self.walk_expr(r, in_out, loop_scopes);
join_bits(&self.dfcx.oper, temp, in_out);
}

ast::expr_log(l, r) |
ast::expr_index(l, r) |
ast::expr_binary(_, l, r) => {
ast::expr_index(_, l, r) |
ast::expr_binary(_, _, l, r) => {
self.walk_exprs([l, r], in_out, loop_scopes);
}

Expand All @@ -708,7 +708,7 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
ast::expr_loop_body(e) |
ast::expr_do_body(e) |
ast::expr_cast(e, _) |
ast::expr_unary(_, e) |
ast::expr_unary(_, _, e) |
ast::expr_paren(e) |
ast::expr_vstore(e, _) |
ast::expr_field(e, _, _) => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ pub fn check_crate(tcx: ty::ctxt,

visit_expr: |expr, _, visitor| {
match expr.node {
expr_method_call(*) => {
let base_type = ty::node_id_to_type(tcx, expr.callee_id);
expr_method_call(callee_id, _, _, _, _, _) => {
let base_type = ty::node_id_to_type(tcx, callee_id);
debug!("effect: method call case, base type is %s",
ppaux::ty_to_str(tcx, base_type));
if type_is_unsafe_function(base_type) {
Expand All @@ -128,7 +128,7 @@ pub fn check_crate(tcx: ty::ctxt,
require_unsafe(expr.span, "call to unsafe function")
}
}
expr_unary(deref, base) => {
expr_unary(_, deref, base) => {
let base_type = ty::node_id_to_type(tcx, base.id);
debug!("effect: unary case, base type is %s",
ppaux::ty_to_str(tcx, base_type));
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,9 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
debug!("kind::check_expr(%s)", expr_to_str(e, cx.tcx.sess.intr()));

// Handle any kind bounds on type parameters
let type_parameter_id = match e.node {
expr_index(*)|expr_assign_op(*)|
expr_unary(*)|expr_binary(*)|expr_method_call(*) => e.callee_id,
_ => e.id
let type_parameter_id = match e.get_callee_id() {
Some(callee_id) => callee_id,
None => e.id,
};
for cx.tcx.node_type_substs.find(&type_parameter_id).each |ts| {
let type_param_defs = match e.node {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ fn lint_type_limits() -> visit::vt<@mut Context> {
visit::mk_vt(@visit::Visitor {
visit_expr: |e, cx: @mut Context, vt| {
match e.node {
ast::expr_binary(ref binop, @ref l, @ref r) => {
ast::expr_binary(_, ref binop, @ref l, @ref r) => {
if is_comparison(*binop)
&& !check_limits(cx, *binop, l, r) {
cx.span_lint(type_limits, e.span,
Expand Down
19 changes: 9 additions & 10 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ fn visit_expr(expr: @expr, this: @mut IrMaps, vt: vt<@mut IrMaps>) {
this.add_live_node_for_node(expr.id, ExprNode(expr.span));
visit::visit_expr(expr, this, vt);
}
expr_binary(op, _, _) if ast_util::lazy_binop(op) => {
expr_binary(_, op, _, _) if ast_util::lazy_binop(op) => {
this.add_live_node_for_node(expr.id, ExprNode(expr.span));
visit::visit_expr(expr, this, vt);
}
Expand Down Expand Up @@ -1138,7 +1138,7 @@ impl Liveness {
self.propagate_through_expr(r, succ)
}

expr_assign_op(_, l, r) => {
expr_assign_op(_, _, l, r) => {
// see comment on lvalues in
// propagate_through_lvalue_components()
let succ = self.write_lvalue(l, succ, ACC_WRITE|ACC_READ);
Expand Down Expand Up @@ -1178,11 +1178,10 @@ impl Liveness {
self.propagate_through_expr(f, succ)
}

expr_method_call(rcvr, _, _, ref args, _) => {
expr_method_call(callee_id, rcvr, _, _, ref args, _) => {
// calling a method with bot return type means that the method
// will fail, and hence the successors can be ignored
let t_ret = ty::ty_fn_ret(ty::node_id_to_type(self.tcx,
expr.callee_id));
let t_ret = ty::ty_fn_ret(ty::node_id_to_type(self.tcx, callee_id));
let succ = if ty::type_is_bot(t_ret) {self.s.exit_ln}
else {succ};
let succ = self.propagate_through_exprs(*args, succ);
Expand All @@ -1193,7 +1192,7 @@ impl Liveness {
self.propagate_through_exprs(*exprs, succ)
}

expr_binary(op, l, r) if ast_util::lazy_binop(op) => {
expr_binary(_, op, l, r) if ast_util::lazy_binop(op) => {
let r_succ = self.propagate_through_expr(r, succ);

let ln = self.live_node(expr.id, expr.span);
Expand All @@ -1204,8 +1203,8 @@ impl Liveness {
}

expr_log(l, r) |
expr_index(l, r) |
expr_binary(_, l, r) => {
expr_index(_, l, r) |
expr_binary(_, _, l, r) => {
self.propagate_through_exprs([l, r], succ)
}

Expand All @@ -1214,7 +1213,7 @@ impl Liveness {
expr_loop_body(e) |
expr_do_body(e) |
expr_cast(e, _) |
expr_unary(_, e) |
expr_unary(_, _, e) |
expr_paren(e) => {
self.propagate_through_expr(e, succ)
}
Expand Down Expand Up @@ -1456,7 +1455,7 @@ fn check_expr(expr: @expr, this: @Liveness, vt: vt<@Liveness>) {
visit::visit_expr(expr, this, vt);
}

expr_assign_op(_, l, _) => {
expr_assign_op(_, _, l, _) => {
this.check_lvalue(l, vt);

visit::visit_expr(expr, this, vt);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl mem_categorization_ctxt {

let expr_ty = self.expr_ty(expr);
match expr.node {
ast::expr_unary(ast::deref, e_base) => {
ast::expr_unary(_, ast::deref, e_base) => {
if self.method_map.contains_key(&expr.id) {
return self.cat_rvalue(expr, expr_ty);
}
Expand All @@ -407,7 +407,7 @@ impl mem_categorization_ctxt {
self.cat_field(expr, base_cmt, f_name, self.expr_ty(expr))
}

ast::expr_index(base, _) => {
ast::expr_index(_, base, _) => {
if self.method_map.contains_key(&expr.id) {
return self.cat_rvalue(expr, expr_ty);
}
Expand Down
Loading

0 comments on commit 63417da

Please sign in to comment.