Skip to content

Commit f8a3523

Browse files
committed
Remove autoderef for calls
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.
1 parent c04490d commit f8a3523

File tree

9 files changed

+18
-52
lines changed

9 files changed

+18
-52
lines changed

src/comp/front/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import front::attr;
1010

1111
export modify_for_testing;
1212

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

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

@@ -29,7 +29,7 @@ fn modify_for_testing(crate: @ast::crate) -> @ast::crate {
2929
// access to the real next node_id.
3030
let next_node_id = @mutable 200000;
3131
let next_node_id_fn =
32-
@bind fn (next_node_id: @mutable ast::node_id) -> ast::node_id {
32+
bind fn (next_node_id: @mutable ast::node_id) -> ast::node_id {
3333
let this_node_id = *next_node_id;
3434
*next_node_id += 1;
3535
ret this_node_id;

src/comp/middle/alias.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ fn cant_copy(cx: ctx, b: binding) -> bool {
222222
}
223223

224224
fn check_call(cx: ctx, f: @ast::expr, args: [@ast::expr]) -> [binding] {
225-
let fty = ty::type_autoderef(cx.tcx, ty::expr_ty(cx.tcx, f));
225+
let fty = ty::expr_ty(cx.tcx, f);
226226
let by_ref = alt ty::ty_fn_ret_style(cx.tcx, fty) {
227227
ast::return_ref(_, arg_n) { arg_n } _ { 0u }
228228
};
@@ -685,7 +685,7 @@ fn expr_root(cx: ctx, ex: @ast::expr, autoderef: bool)
685685
if is_none(path_def_id(cx, base_root.ex)) {
686686
alt base_root.ex.node {
687687
ast::expr_call(f, args) {
688-
let fty = ty::type_autoderef(cx.tcx, ty::expr_ty(cx.tcx, f));
688+
let fty = ty::expr_ty(cx.tcx, f);
689689
alt ty::ty_fn_ret_style(cx.tcx, fty) {
690690
ast::return_ref(mut, arg_n) {
691691
let arg = args[arg_n - 1u];

src/comp/middle/mut.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ fn check_move_rhs(cx: @ctx, src: @expr) {
219219
}
220220

221221
fn check_call(cx: @ctx, f: @expr, args: [@expr]) {
222-
let arg_ts =
223-
ty::ty_fn_args(cx.tcx,
224-
ty::type_autoderef(cx.tcx, ty::expr_ty(cx.tcx, f)));
222+
let arg_ts = ty::ty_fn_args(cx.tcx, ty::expr_ty(cx.tcx, f));
225223
let i = 0u;
226224
for arg_t: ty::arg in arg_ts {
227225
if arg_t.mode != by_ref { check_lval(cx, args[i], msg_mut_ref); }

src/comp/middle/trans.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3676,9 +3676,8 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
36763676
// expression because of the hack that allows us to process self-calls
36773677
// with trans_call.
36783678
let fn_expr_ty = ty::expr_ty(bcx_tcx(in_cx), f);
3679-
let fn_ty = ty::type_autoderef(bcx_tcx(in_cx), fn_expr_ty);
36803679
let by_ref = ast_util::ret_by_ref(ty::ty_fn_ret_style(bcx_tcx(in_cx),
3681-
fn_ty));
3680+
fn_expr_ty));
36823681
let cx = new_scope_block_ctxt(in_cx, "call");
36833682
let f_res = trans_lval_gen(cx, f);
36843683
let bcx = f_res.res.bcx;
@@ -3694,10 +3693,7 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
36943693
none. {
36953694
// It's a closure. We have to autoderef.
36963695
if f_res.is_mem { faddr = load_if_immediate(bcx, faddr, fn_expr_ty); }
3697-
let res = autoderef(bcx, faddr, fn_expr_ty);
3698-
bcx = res.bcx;
3699-
3700-
let pair = res.val;
3696+
let pair = faddr;
37013697
faddr = GEP(bcx, pair, [C_int(0), C_int(abi::fn_field_code)]);
37023698
faddr = Load(bcx, faddr);
37033699
let llclosure = GEP(bcx, pair, [C_int(0), C_int(abi::fn_field_box)]);
@@ -3707,7 +3703,8 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
37073703

37083704
let ret_ty = ty::node_id_to_type(bcx_tcx(cx), id);
37093705
let args_res =
3710-
trans_args(bcx, in_cx, llenv, f_res.generic, lliterbody, args, fn_ty);
3706+
trans_args(bcx, in_cx, llenv, f_res.generic, lliterbody, args,
3707+
fn_expr_ty);
37113708
Br(args_res.outer_cx, cx.llbb);
37123709
bcx = args_res.bcx;
37133710
let llargs = args_res.args;

src/comp/middle/typeck.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,14 +1488,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
14881488
// Get the function type.
14891489
let fty = expr_ty(fcx.ccx.tcx, f);
14901490

1491-
// We want to autoderef calls but not binds
1492-
let fty_stripped =
1493-
alt call_kind {
1494-
kind_call. { do_autoderef(fcx, sp, fty) }
1495-
_ { fty }
1496-
};
1497-
1498-
let sty = structure_of(fcx, sp, fty_stripped);
1491+
let sty = structure_of(fcx, sp, fty);
14991492

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

16211614
// Pull the return type out of the type of the function.
16221615
let rt_1;
1623-
let fty = do_autoderef(fcx, sp, ty::expr_ty(fcx.ccx.tcx, f));
1616+
let fty = ty::expr_ty(fcx.ccx.tcx, f);
16241617
alt structure_of(fcx, sp, fty) {
16251618
ty::ty_fn(_, _, rt, cf, _) {
16261619
bot |= cf == ast::noreturn;
16271620
rt_1 = rt;
16281621
}
16291622
ty::ty_native_fn(_, _, rt) { rt_1 = rt; }
1630-
_ { fail "LHS of call expr didn't have a function type?!"; }
1623+
_ { fcx.ccx.tcx.sess.span_fatal(sp, "calling non-function"); }
16311624
}
16321625
write::ty_only_fixup(fcx, id, rt_1);
16331626
ret bot;

src/test/compile-fail/occurs-check-2.rs

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/test/run-pass/auto-deref-fn.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/test/run-pass/call-autoderef-tag.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
fn fix_help<A, @B>(f: @fn(@fn(A) -> B, A) -> B, x: A) -> B {
2-
ret f(@bind fix_help(f, _), x);
1+
fn fix_help<A, @B>(f: fn(fn(A) -> B, A) -> B, x: A) -> B {
2+
ret f(bind fix_help(f, _), x);
33
}
44

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

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

1414
fn main() {
15-
let fact = fix(@fact_);
15+
let fact = fix(fact_);
1616
assert (fact(5) == 120);
1717
assert (fact(2) == 2);
1818
}

0 commit comments

Comments
 (0)