Skip to content

Commit 975ac55

Browse files
committed
Lose the by_ref destination style
It's not needed. Issue #667
1 parent babd1ff commit 975ac55

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

src/comp/middle/trans.rs

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,7 +2481,6 @@ fn join_branches(parent_cx: @block_ctxt, ins: [result]) -> @block_ctxt {
24812481

24822482
tag dest {
24832483
by_val(@mutable ValueRef);
2484-
by_ref(@mutable ValueRef);
24852484
save_in(ValueRef);
24862485
ignore;
24872486
}
@@ -2493,7 +2492,6 @@ fn empty_dest_cell() -> @mutable ValueRef {
24932492
fn dup_for_join(dest: dest) -> dest {
24942493
alt dest {
24952494
by_val(_) { by_val(empty_dest_cell()) }
2496-
by_ref(_) { by_ref(empty_dest_cell()) }
24972495
_ { dest }
24982496
}
24992497
}
@@ -2507,7 +2505,7 @@ fn join_returns(parent_cx: @block_ctxt, in_cxs: [@block_ctxt],
25072505
Br(cx, out.llbb);
25082506
reachable = true;
25092507
alt in_ds[i] {
2510-
by_val(cell) | by_ref(cell) {
2508+
by_val(cell) {
25112509
if option::is_none(phi) {
25122510
phi = some(EmptyPhi(out, val_ty(*cell)));
25132511
}
@@ -2522,7 +2520,7 @@ fn join_returns(parent_cx: @block_ctxt, in_cxs: [@block_ctxt],
25222520
Unreachable(out);
25232521
} else {
25242522
alt out_dest {
2525-
by_val(cell) | by_ref(cell) { *cell = option::get(phi); }
2523+
by_val(cell) { *cell = option::get(phi); }
25262524
_ {}
25272525
}
25282526
}
@@ -3333,7 +3331,7 @@ fn trans_lval(cx: @block_ctxt, e: @ast::expr) -> lval_result {
33333331
// A by-ref returning function
33343332
if expr_is_lval(bcx_tcx(cx), e) {
33353333
let cell = empty_dest_cell();
3336-
let bcx = trans_call(cx, f, none, args, e.id, by_ref(cell));
3334+
let bcx = trans_call(cx, f, none, args, e.id, by_val(cell));
33373335
ret lval_mem(bcx, *cell);
33383336
} else { // By-value return
33393337
let {bcx, val} = dps_to_result(cx, {|bcx, dest|
@@ -3799,7 +3797,8 @@ fn trans_args(cx: @block_ctxt, outer_cx: @block_ctxt, llenv: ValueRef,
37993797
args: [ValueRef],
38003798
retslot: ValueRef,
38013799
to_zero: [{v: ValueRef, t: ty::t}],
3802-
to_revoke: [{v: ValueRef, t: ty::t}]} {
3800+
to_revoke: [{v: ValueRef, t: ty::t}],
3801+
ret_ref: bool} {
38033802

38043803
let args: [ty::arg] = ty::ty_fn_args(bcx_tcx(cx), fn_ty);
38053804
let llargs: [ValueRef] = [];
@@ -3825,19 +3824,20 @@ fn trans_args(cx: @block_ctxt, outer_cx: @block_ctxt, llenv: ValueRef,
38253824
}
38263825
// Arg 0: Output pointer.
38273826
let llretty = type_of_or_i8(bcx, full_retty);
3828-
let dest_ref = false;
3829-
let llretslot = alt dest {
3830-
ignore. {
3831-
if ty::type_is_nil(tcx, full_retty) || !option::is_none(lliterbody) {
3832-
llvm::LLVMGetUndef(T_ptr(llretty))
3833-
} else { alloca(cx, llretty) }
3834-
}
3835-
save_in(dst) { dst }
3836-
by_val(_) { alloca(cx, llretty) }
3837-
by_ref(_) { dest_ref = true; alloca(cx, T_ptr(llretty)) }
3827+
let llretslot = if ret_ref {
3828+
alloca(cx, T_ptr(llretty))
3829+
} else {
3830+
alt dest {
3831+
ignore. {
3832+
if ty::type_is_nil(tcx, full_retty) ||
3833+
!option::is_none(lliterbody) {
3834+
llvm::LLVMGetUndef(T_ptr(llretty))
3835+
} else { alloca(cx, llretty) }
3836+
}
3837+
save_in(dst) { dst }
3838+
by_val(_) { alloca(cx, llretty) }
3839+
}
38383840
};
3839-
// FIXME[DSP] does this always hold?
3840-
assert dest_ref == ret_ref;
38413841

38423842
if ty::type_contains_params(tcx, retty) {
38433843
// It's possible that the callee has some generic-ness somewhere in
@@ -3898,7 +3898,8 @@ fn trans_args(cx: @block_ctxt, outer_cx: @block_ctxt, llenv: ValueRef,
38983898
args: llargs,
38993899
retslot: llretslot,
39003900
to_zero: to_zero,
3901-
to_revoke: to_revoke};
3901+
to_revoke: to_revoke,
3902+
ret_ref: ret_ref};
39023903
}
39033904

39043905
fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
@@ -3953,12 +3954,13 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
39533954
args_res.to_revoke);
39543955
alt dest {
39553956
ignore. {
3956-
if llvm::LLVMIsUndef(llretslot) != lib::llvm::True {
3957+
if llvm::LLVMIsUndef(llretslot) != lib::llvm::True &&
3958+
!args_res.ret_ref {
39573959
bcx = drop_ty(bcx, llretslot, ret_ty);
39583960
}
39593961
}
39603962
save_in(_) { } // Already saved by callee
3961-
by_ref(cell) | by_val(cell) {
3963+
by_val(cell) {
39623964
*cell = Load(bcx, llretslot);
39633965
}
39643966
}
@@ -4278,13 +4280,6 @@ fn trans_temp_expr(bcx: @block_ctxt, e: @ast::expr) -> lval_result {
42784280
}
42794281
}
42804282

4281-
// FIXME[DPS] supersede by trans_temp_expr, get rid of by_ref dests
4282-
fn trans_expr_by_ref(bcx: @block_ctxt, e: @ast::expr) -> result {
4283-
let cell = empty_dest_cell();
4284-
bcx = trans_expr_dps(bcx, e, by_ref(cell));
4285-
ret rslt(bcx, *cell);
4286-
}
4287-
42884283
// Invariants:
42894284
// - things returning nil get dest=ignore
42904285
// - any lvalue expr may be given dest=by_ref
@@ -4476,10 +4471,6 @@ fn lval_to_dps(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
44764471
*cell = Load(bcx, val);
44774472
}
44784473
}
4479-
by_ref(cell) {
4480-
assert is_mem;
4481-
*cell = val;
4482-
}
44834474
save_in(loc) { bcx = move_val_if_temp(bcx, INIT, loc, lv, ty); }
44844475
ignore. {}
44854476
}
@@ -4728,7 +4719,8 @@ fn trans_ret(bcx: @block_ctxt, e: option::t<@ast::expr>) -> @block_ctxt {
47284719
alt e {
47294720
some(x) {
47304721
if ast_util::ret_by_ref(bcx.fcx.ret_style) {
4731-
let {bcx: cx, val} = trans_expr_by_ref(bcx, x);
4722+
let {bcx: cx, val, is_mem} = trans_lval(bcx, x);
4723+
assert is_mem;
47324724
Store(cx, val, bcx.fcx.llretptr);
47334725
bcx = cx;
47344726
} else {

0 commit comments

Comments
 (0)