Skip to content

Commit 8c64c2e

Browse files
committed
---
yaml --- r: 5684 b: refs/heads/master c: 062aa32 h: refs/heads/master v: v3
1 parent dfd45e7 commit 8c64c2e

File tree

2 files changed

+58
-57
lines changed

2 files changed

+58
-57
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 1f2e9992625219aee8fab5037db64169f0d674e2
2+
refs/heads/master: 062aa3272cec6a4a3bc14a8dd17a22c372d49f7a

trunk/src/comp/middle/trans.rs

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,7 +2470,7 @@ fn trans_binary(cx: @block_ctxt, op: ast::binop, a: @ast::expr, b: @ast::expr,
24702470
}
24712471
}
24722472

2473-
// FIXME remove once all uses have been converted to join_returns
2473+
// FIXME[DPS] remove once all uses have been converted to join_returns
24742474
fn join_branches(parent_cx: @block_ctxt, ins: [result]) -> @block_ctxt {
24752475
let out = new_sub_block_ctxt(parent_cx, "join");
24762476
let branched = false;
@@ -2952,8 +2952,7 @@ fn trans_for_each(cx: @block_ctxt, local: @ast::local, seq: @ast::expr,
29522952
ast::expr_call(f, args) {
29532953
let pair =
29542954
create_real_fn_pair(cx, iter_body_llty, lliterbody, llenv.ptr);
2955-
let r = trans_call(cx, f, some(pair), args, seq.id);
2956-
ret r.res.bcx;
2955+
ret trans_call(cx, f, some(pair), args, seq.id, ignore);
29572956
}
29582957
}
29592958
}
@@ -3300,6 +3299,7 @@ fn expr_is_lval(tcx: ty::ctxt, e: @ast::expr) -> bool {
33003299
// The additional bool returned indicates whether it's mem (that is
33013300
// represented as an alloca or heap, hence needs a 'load' to be used as an
33023301
// immediate).
3302+
// FIXME[DPS] only allow this to be called on actual lvals
33033303
fn trans_lval(cx: @block_ctxt, e: @ast::expr) -> lval_result {
33043304
alt e.node {
33053305
ast::expr_path(p) {
@@ -3340,10 +3340,17 @@ fn trans_lval(cx: @block_ctxt, e: @ast::expr) -> lval_result {
33403340
ret lval_mem(sub.bcx, val);
33413341
}
33423342
ast::expr_call(f, args) {
3343-
let {res: {bcx, val}, by_ref} =
3344-
trans_call(cx, f, none, args, e.id);
3345-
if by_ref { ret lval_mem(bcx, val); }
3346-
else { ret lval_val(bcx, val); }
3343+
// A by-ref returning function
3344+
if expr_is_lval(bcx_tcx(cx), e) {
3345+
let cell = empty_dest_cell();
3346+
let bcx = trans_call(cx, f, none, args, e.id, by_ref(cell));
3347+
ret lval_mem(bcx, *cell);
3348+
} else { // By-value return
3349+
let {bcx, val} = dps_to_result(cx, {|bcx, dest|
3350+
trans_call(bcx, f, none, args, e.id, dest) },
3351+
ty::expr_ty(bcx_tcx(cx), e));
3352+
ret lval_val(bcx, val);
3353+
}
33473354
}
33483355
_ {
33493356
let res = trans_expr(cx, e);
@@ -3797,7 +3804,8 @@ fn trans_arg_expr(cx: @block_ctxt, arg: ty::arg, lldestty0: TypeRef,
37973804
// - trans_args
37983805
fn trans_args(cx: @block_ctxt, outer_cx: @block_ctxt, llenv: ValueRef,
37993806
gen: option::t<generic_info>,
3800-
lliterbody: option::t<ValueRef>, es: [@ast::expr], fn_ty: ty::t)
3807+
lliterbody: option::t<ValueRef>, es: [@ast::expr], fn_ty: ty::t,
3808+
dest: dest)
38013809
-> {bcx: @block_ctxt,
38023810
outer_cx: @block_ctxt,
38033811
args: [ValueRef],
@@ -3813,9 +3821,9 @@ fn trans_args(cx: @block_ctxt, outer_cx: @block_ctxt, llenv: ValueRef,
38133821

38143822
let ccx = bcx_ccx(cx);
38153823
let tcx = ccx.tcx;
3816-
let bcx: @block_ctxt = cx;
3824+
let bcx = cx;
38173825
let ret_style = ty::ty_fn_ret_style(tcx, fn_ty);
3818-
let by_ref = ast_util::ret_by_ref(ret_style);
3826+
let ret_ref = ast_util::ret_by_ref(ret_style);
38193827

38203828
let retty = ty::ty_fn_ret(tcx, fn_ty), full_retty = retty;
38213829
alt gen {
@@ -3828,13 +3836,21 @@ fn trans_args(cx: @block_ctxt, outer_cx: @block_ctxt, llenv: ValueRef,
38283836
_ { }
38293837
}
38303838
// Arg 0: Output pointer.
3831-
let llretslot_res = if ty::type_is_nil(tcx, retty) {
3832-
rslt(cx, llvm::LLVMGetUndef(T_ptr(T_nil())))
3833-
} else if by_ref {
3834-
rslt(cx, alloca(cx, T_ptr(type_of_or_i8(bcx, full_retty))))
3835-
} else { alloc_ty(bcx, full_retty) };
3836-
bcx = llretslot_res.bcx;
3837-
let llretslot = llretslot_res.val;
3839+
let llretty = type_of_or_i8(bcx, full_retty);
3840+
let dest_ref = false;
3841+
let llretslot = alt dest {
3842+
ignore. {
3843+
if ty::type_is_nil(tcx, full_retty) || !option::is_none(lliterbody) {
3844+
llvm::LLVMGetUndef(T_ptr(llretty))
3845+
} else { alloca(cx, llretty) }
3846+
}
3847+
save_in(dst) { dst }
3848+
overwrite(_, _) | by_val(_) { alloca(cx, llretty) }
3849+
by_ref(_) { dest_ref = true; alloca(cx, T_ptr(llretty)) }
3850+
};
3851+
// FIXME[DSP] does this always hold?
3852+
assert dest_ref == ret_ref;
3853+
38383854
if ty::type_contains_params(tcx, retty) {
38393855
// It's possible that the callee has some generic-ness somewhere in
38403856
// its return value -- say a method signature within an obj or a fn
@@ -3843,7 +3859,7 @@ fn trans_args(cx: @block_ctxt, outer_cx: @block_ctxt, llenv: ValueRef,
38433859
// view, for the sake of making a type-compatible call.
38443860
check non_ty_var(ccx, retty);
38453861
let llretty = T_ptr(type_of_inner(ccx, bcx.sp, retty));
3846-
if by_ref { llretty = T_ptr(llretty); }
3862+
if ret_ref { llretty = T_ptr(llretty); }
38473863
llargs += [PointerCast(cx, llretslot, llretty)];
38483864
} else { llargs += [llretslot]; }
38493865

@@ -3899,18 +3915,17 @@ fn trans_args(cx: @block_ctxt, outer_cx: @block_ctxt, llenv: ValueRef,
38993915

39003916
fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
39013917
lliterbody: option::t<ValueRef>, args: [@ast::expr],
3902-
id: ast::node_id) -> {res: result, by_ref: bool} {
3918+
id: ast::node_id, dest: dest) -> @block_ctxt {
39033919
// NB: 'f' isn't necessarily a function; it might be an entire self-call
39043920
// expression because of the hack that allows us to process self-calls
39053921
// with trans_call.
39063922
let tcx = bcx_tcx(in_cx);
39073923
let fn_expr_ty = ty::expr_ty(tcx, f);
39083924

39093925
if check type_is_native_fn_on_c_stack(tcx, fn_expr_ty) {
3910-
ret trans_c_stack_native_call(in_cx, f, args);
3926+
ret trans_c_stack_native_call(in_cx, f, args, dest);
39113927
}
39123928

3913-
let by_ref = ast_util::ret_by_ref(ty::ty_fn_ret_style(tcx, fn_expr_ty));
39143929
let cx = new_scope_block_ctxt(in_cx, "call");
39153930
let f_res = trans_callee(cx, f);
39163931
let bcx = f_res.bcx;
@@ -3936,65 +3951,49 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
39363951
let ret_ty = ty::node_id_to_type(tcx, id);
39373952
let args_res =
39383953
trans_args(bcx, in_cx, llenv, f_res.generic, lliterbody, args,
3939-
fn_expr_ty);
3954+
fn_expr_ty, dest);
39403955
Br(args_res.outer_cx, cx.llbb);
39413956
bcx = args_res.bcx;
39423957
let llargs = args_res.args;
39433958
let llretslot = args_res.retslot;
39443959

3945-
/*
3946-
log_err "calling: " + val_str(bcx_ccx(cx).tn, faddr);
3947-
3948-
for arg: ValueRef in llargs {
3949-
log_err "arg: " + val_str(bcx_ccx(cx).tn, arg);
3950-
}
3951-
*/
3952-
39533960
/* If the block is terminated,
39543961
then one or more of the args has
39553962
type _|_. Since that means it diverges, the code
39563963
for the call itself is unreachable. */
3957-
let retval = C_nil();
39583964
bcx = invoke_full(bcx, faddr, llargs, args_res.to_zero,
39593965
args_res.to_revoke);
3960-
alt lliterbody {
3961-
none. {
3962-
if !ty::type_is_nil(tcx, ret_ty) {
3963-
if by_ref {
3964-
retval = Load(bcx, llretslot);
3965-
} else {
3966-
retval = load_if_immediate(bcx, llretslot, ret_ty);
3967-
// Retval doesn't correspond to anything really tangible
3968-
// in the frame, but it's a ref all the same, so we put a
3969-
// note here to drop it when we're done in this scope.
3970-
add_clean_temp(in_cx, retval, ret_ty);
3971-
}
3966+
alt dest {
3967+
ignore. {
3968+
if llvm::LLVMIsUndef(llretslot) != lib::llvm::True {
3969+
bcx = drop_ty(bcx, llretslot, ret_ty);
39723970
}
39733971
}
3974-
some(_) {
3975-
// If there was an lliterbody, it means we were calling an
3976-
// iter, and we are *not* the party using its 'output' value,
3977-
// we should ignore llretslot.
3972+
save_in(_) { } // Already saved by callee
3973+
overwrite(a, t) {
3974+
bcx = drop_ty(bcx, a, t);
3975+
bcx = memmove_ty(bcx, a, llretslot, ret_ty);
3976+
}
3977+
by_ref(cell) | by_val(cell) {
3978+
*cell = Load(bcx, llretslot);
39783979
}
39793980
}
39803981
// Forget about anything we moved out.
39813982
bcx = zero_and_revoke(bcx, args_res.to_zero, args_res.to_revoke);
39823983

3983-
if !by_ref { bcx = trans_block_cleanups(bcx, cx); }
3984+
bcx = trans_block_cleanups(bcx, cx);
39843985
let next_cx = new_sub_block_ctxt(in_cx, "next");
39853986
if bcx.unreachable || ty::type_is_bot(tcx, ret_ty) {
39863987
Unreachable(next_cx);
39873988
}
39883989
Br(bcx, next_cx.llbb);
3989-
bcx = next_cx;
3990-
ret {res: rslt(bcx, retval), by_ref: by_ref};
3990+
ret next_cx;
39913991
}
39923992

39933993
// Translates a native call on the C stack. Calls into the runtime to perform
39943994
// the stack switching operation.
39953995
fn trans_c_stack_native_call(bcx: @block_ctxt, f: @ast::expr,
3996-
args: [@ast::expr])
3997-
-> {res: result, by_ref: bool} {
3996+
args: [@ast::expr], dest: dest) -> @block_ctxt {
39983997
let ccx = bcx_ccx(bcx);
39993998
let f_res = trans_callee(bcx, f);
40003999
let llfn = f_res.val; bcx = f_res.bcx;
@@ -4061,8 +4060,7 @@ fn trans_c_stack_native_call(bcx: @block_ctxt, f: @ast::expr,
40614060

40624061
// Forget about anything we moved out.
40634062
bcx = zero_and_revoke(bcx, to_zero, to_revoke);
4064-
4065-
ret {res: rslt(bcx, llretval), by_ref: false};
4063+
ret store_in_dest(bcx, llretval, dest);
40664064
}
40674065

40684066
fn zero_and_revoke(bcx: @block_ctxt,
@@ -4359,8 +4357,11 @@ fn trans_expr_dps(bcx: @block_ctxt, e: @ast::expr, dest: dest)
43594357
ast::expr_anon_obj(anon_obj) {
43604358
ret trans_anon_obj(bcx, e.span, anon_obj, e.id, dest);
43614359
}
4362-
// FIXME[DPS] untangle non-lval calls and fields from trans_lval
4363-
ast::expr_call(_, _) | ast::expr_field(_, _) {
4360+
ast::expr_call(f, args) {
4361+
ret trans_call(bcx, f, none, args, e.id, dest);
4362+
}
4363+
// FIXME[DPS] untangle non-lval fields from trans_lval
4364+
ast::expr_field(_, _) {
43644365
ret lval_to_dps(bcx, e, dest);
43654366
}
43664367

0 commit comments

Comments
 (0)