Skip to content

Commit

Permalink
Remove autoderef for calls
Browse files Browse the repository at this point in the history
We were only using it in a single place, and there for no discernable reason
(probably as part of the bare-fn-vals-are-not-copyable plan). It seems more
surprising than useful.
  • Loading branch information
marijnh committed Sep 16, 2011
1 parent c04490d commit f8a3523
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/comp/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import front::attr;

export modify_for_testing;

type node_id_gen = @fn() -> ast::node_id;
type node_id_gen = fn() -> ast::node_id;

type test = {path: [ast::ident], ignore: bool};

Expand All @@ -29,7 +29,7 @@ fn modify_for_testing(crate: @ast::crate) -> @ast::crate {
// access to the real next node_id.
let next_node_id = @mutable 200000;
let next_node_id_fn =
@bind fn (next_node_id: @mutable ast::node_id) -> ast::node_id {
bind fn (next_node_id: @mutable ast::node_id) -> ast::node_id {
let this_node_id = *next_node_id;
*next_node_id += 1;
ret this_node_id;
Expand Down
4 changes: 2 additions & 2 deletions src/comp/middle/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ fn cant_copy(cx: ctx, b: binding) -> bool {
}

fn check_call(cx: ctx, f: @ast::expr, args: [@ast::expr]) -> [binding] {
let fty = ty::type_autoderef(cx.tcx, ty::expr_ty(cx.tcx, f));
let fty = ty::expr_ty(cx.tcx, f);
let by_ref = alt ty::ty_fn_ret_style(cx.tcx, fty) {
ast::return_ref(_, arg_n) { arg_n } _ { 0u }
};
Expand Down Expand Up @@ -685,7 +685,7 @@ fn expr_root(cx: ctx, ex: @ast::expr, autoderef: bool)
if is_none(path_def_id(cx, base_root.ex)) {
alt base_root.ex.node {
ast::expr_call(f, args) {
let fty = ty::type_autoderef(cx.tcx, ty::expr_ty(cx.tcx, f));
let fty = ty::expr_ty(cx.tcx, f);
alt ty::ty_fn_ret_style(cx.tcx, fty) {
ast::return_ref(mut, arg_n) {
let arg = args[arg_n - 1u];
Expand Down
4 changes: 1 addition & 3 deletions src/comp/middle/mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ fn check_move_rhs(cx: @ctx, src: @expr) {
}

fn check_call(cx: @ctx, f: @expr, args: [@expr]) {
let arg_ts =
ty::ty_fn_args(cx.tcx,
ty::type_autoderef(cx.tcx, ty::expr_ty(cx.tcx, f)));
let arg_ts = ty::ty_fn_args(cx.tcx, ty::expr_ty(cx.tcx, f));
let i = 0u;
for arg_t: ty::arg in arg_ts {
if arg_t.mode != by_ref { check_lval(cx, args[i], msg_mut_ref); }
Expand Down
11 changes: 4 additions & 7 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3676,9 +3676,8 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
// expression because of the hack that allows us to process self-calls
// with trans_call.
let fn_expr_ty = ty::expr_ty(bcx_tcx(in_cx), f);
let fn_ty = ty::type_autoderef(bcx_tcx(in_cx), fn_expr_ty);
let by_ref = ast_util::ret_by_ref(ty::ty_fn_ret_style(bcx_tcx(in_cx),
fn_ty));
fn_expr_ty));
let cx = new_scope_block_ctxt(in_cx, "call");
let f_res = trans_lval_gen(cx, f);
let bcx = f_res.res.bcx;
Expand All @@ -3694,10 +3693,7 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
none. {
// It's a closure. We have to autoderef.
if f_res.is_mem { faddr = load_if_immediate(bcx, faddr, fn_expr_ty); }
let res = autoderef(bcx, faddr, fn_expr_ty);
bcx = res.bcx;

let pair = res.val;
let pair = faddr;
faddr = GEP(bcx, pair, [C_int(0), C_int(abi::fn_field_code)]);
faddr = Load(bcx, faddr);
let llclosure = GEP(bcx, pair, [C_int(0), C_int(abi::fn_field_box)]);
Expand All @@ -3707,7 +3703,8 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,

let ret_ty = ty::node_id_to_type(bcx_tcx(cx), id);
let args_res =
trans_args(bcx, in_cx, llenv, f_res.generic, lliterbody, args, fn_ty);
trans_args(bcx, in_cx, llenv, f_res.generic, lliterbody, args,
fn_expr_ty);
Br(args_res.outer_cx, cx.llbb);
bcx = args_res.bcx;
let llargs = args_res.args;
Expand Down
13 changes: 3 additions & 10 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1488,14 +1488,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
// Get the function type.
let fty = expr_ty(fcx.ccx.tcx, f);

// We want to autoderef calls but not binds
let fty_stripped =
alt call_kind {
kind_call. { do_autoderef(fcx, sp, fty) }
_ { fty }
};

let sty = structure_of(fcx, sp, fty_stripped);
let sty = structure_of(fcx, sp, fty);

// Check that we aren't confusing iter calls and fn calls
alt sty {
Expand Down Expand Up @@ -1620,14 +1613,14 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,

// Pull the return type out of the type of the function.
let rt_1;
let fty = do_autoderef(fcx, sp, ty::expr_ty(fcx.ccx.tcx, f));
let fty = ty::expr_ty(fcx.ccx.tcx, f);
alt structure_of(fcx, sp, fty) {
ty::ty_fn(_, _, rt, cf, _) {
bot |= cf == ast::noreturn;
rt_1 = rt;
}
ty::ty_native_fn(_, _, rt) { rt_1 = rt; }
_ { fail "LHS of call expr didn't have a function type?!"; }
_ { fcx.ccx.tcx.sess.span_fatal(sp, "calling non-function"); }
}
write::ty_only_fixup(fcx, id, rt_1);
ret bot;
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/occurs-check-2.rs

This file was deleted.

10 changes: 0 additions & 10 deletions src/test/run-pass/auto-deref-fn.rs

This file was deleted.

10 changes: 0 additions & 10 deletions src/test/run-pass/call-autoderef-tag.rs

This file was deleted.

12 changes: 6 additions & 6 deletions src/test/run-pass/fixed-point-bind-box.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
fn fix_help<A, @B>(f: @fn(@fn(A) -> B, A) -> B, x: A) -> B {
ret f(@bind fix_help(f, _), x);
fn fix_help<A, @B>(f: fn(fn(A) -> B, A) -> B, x: A) -> B {
ret f(bind fix_help(f, _), x);
}

fn fix<A, @B>(f: @fn(@fn(A) -> B, A) -> B) -> @fn(A) -> B {
ret @bind fix_help(f, _);
fn fix<A, @B>(f: fn(fn(A) -> B, A) -> B) -> fn(A) -> B {
ret bind fix_help(f, _);
}

fn fact_(f: @fn(int) -> int, n: int) -> int {
fn fact_(f: fn(int) -> int, n: int) -> int {
// fun fact 0 = 1
ret if n == 0 { 1 } else { n * f(n - 1) };
}

fn main() {
let fact = fix(@fact_);
let fact = fix(fact_);
assert (fact(5) == 120);
assert (fact(2) == 2);
}

0 comments on commit f8a3523

Please sign in to comment.