Skip to content

Commit ea6bb5a

Browse files
committed
Remove to_zero/to_revoke kludge
It is much simpler to just move by_move args into a temporary alloca.
1 parent bfff2a8 commit ea6bb5a

File tree

2 files changed

+25
-71
lines changed

2 files changed

+25
-71
lines changed

src/comp/middle/trans/base.rs

Lines changed: 24 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,9 +2731,7 @@ fn trans_cast(cx: @block_ctxt, e: @ast::expr, id: ast::node_id,
27312731
}
27322732

27332733
fn trans_arg_expr(cx: @block_ctxt, arg: ty::arg, lldestty: TypeRef,
2734-
&to_zero: [{v: ValueRef, t: ty::t}],
2735-
&to_revoke: [{v: ValueRef, t: ty::t}], e: @ast::expr) ->
2736-
result {
2734+
e: @ast::expr) -> result {
27372735
let ccx = bcx_ccx(cx);
27382736
let e_ty = expr_ty(cx, e);
27392737
let is_bot = ty::type_is_bot(e_ty);
@@ -2765,19 +2763,20 @@ fn trans_arg_expr(cx: @block_ctxt, arg: ty::arg, lldestty: TypeRef,
27652763
if arg_mode == ast::by_val && (lv.kind == owned || !imm) {
27662764
val = Load(bcx, val);
27672765
}
2768-
} else if arg_mode == ast::by_copy {
2766+
} else if arg_mode == ast::by_copy || arg_mode == ast::by_move {
27692767
let {bcx: cx, val: alloc} = alloc_ty(bcx, e_ty);
2770-
let last_use = ccx.last_uses.contains_key(e.id);
2768+
let move_out = arg_mode == ast::by_move ||
2769+
ccx.last_uses.contains_key(e.id);
27712770
bcx = cx;
27722771
if lv.kind == temporary { revoke_clean(bcx, val); }
27732772
if lv.kind == owned || !ty::type_is_immediate(e_ty) {
27742773
bcx = memmove_ty(bcx, alloc, val, e_ty);
2775-
if last_use && ty::type_needs_drop(ccx.tcx, e_ty) {
2774+
if move_out && ty::type_needs_drop(ccx.tcx, e_ty) {
27762775
bcx = zero_alloca(bcx, val, e_ty);
27772776
}
27782777
} else { Store(bcx, val, alloc); }
27792778
val = alloc;
2780-
if lv.kind != temporary && !last_use {
2779+
if lv.kind != temporary && !move_out {
27812780
bcx = take_ty(bcx, val, e_ty);
27822781
}
27832782
} else if ty::type_is_immediate(e_ty) && lv.kind != owned {
@@ -2789,15 +2788,6 @@ fn trans_arg_expr(cx: @block_ctxt, arg: ty::arg, lldestty: TypeRef,
27892788
if !is_bot && arg.ty != e_ty || ty::type_has_params(arg.ty) {
27902789
val = PointerCast(bcx, val, lldestty);
27912790
}
2792-
2793-
// Collect arg for later if it happens to be one we've moving out.
2794-
if arg_mode == ast::by_move {
2795-
if lv.kind == owned {
2796-
// Use actual ty, not declared ty -- anything else doesn't make
2797-
// sense if declared ty is a ty param
2798-
to_zero += [{v: lv.val, t: e_ty}];
2799-
} else { to_revoke += [{v: lv.val, t: e_ty}]; }
2800-
}
28012791
ret rslt(bcx, val);
28022792
}
28032793

@@ -2813,15 +2803,11 @@ fn trans_args(cx: @block_ctxt, llenv: ValueRef,
28132803
dest: dest)
28142804
-> {bcx: @block_ctxt,
28152805
args: [ValueRef],
2816-
retslot: ValueRef,
2817-
to_zero: [{v: ValueRef, t: ty::t}],
2818-
to_revoke: [{v: ValueRef, t: ty::t}]} {
2806+
retslot: ValueRef} {
28192807

28202808
let args = ty::ty_fn_args(fn_ty);
28212809
let llargs: [ValueRef] = [];
28222810
let lltydescs: [ValueRef] = [];
2823-
let to_zero = [];
2824-
let to_revoke = [];
28252811

28262812
let ccx = bcx_ccx(cx);
28272813
let bcx = cx;
@@ -2899,17 +2885,14 @@ fn trans_args(cx: @block_ctxt, llenv: ValueRef,
28992885
let arg_tys = type_of_explicit_args(ccx, args);
29002886
let i = 0u;
29012887
for e: @ast::expr in es {
2902-
let r = trans_arg_expr(bcx, args[i], arg_tys[i], to_zero, to_revoke,
2903-
e);
2888+
let r = trans_arg_expr(bcx, args[i], arg_tys[i], e);
29042889
bcx = r.bcx;
29052890
llargs += [r.val];
29062891
i += 1u;
29072892
}
29082893
ret {bcx: bcx,
29092894
args: llargs,
2910-
retslot: llretslot,
2911-
to_zero: to_zero,
2912-
to_revoke: to_revoke};
2895+
retslot: llretslot};
29132896
}
29142897

29152898
fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
@@ -2969,8 +2952,7 @@ fn trans_call_inner(in_cx: @block_ctxt, fn_expr_ty: ty::t,
29692952
then one or more of the args has
29702953
type _|_. Since that means it diverges, the code
29712954
for the call itself is unreachable. */
2972-
bcx = invoke_full(bcx, faddr, llargs, args_res.to_zero,
2973-
args_res.to_revoke);
2955+
bcx = invoke_full(bcx, faddr, llargs);
29742956
alt dest {
29752957
ignore {
29762958
if llvm::LLVMIsUndef(llretslot) != lib::llvm::True {
@@ -2982,8 +2964,6 @@ fn trans_call_inner(in_cx: @block_ctxt, fn_expr_ty: ty::t,
29822964
*cell = Load(bcx, llretslot);
29832965
}
29842966
}
2985-
// Forget about anything we moved out.
2986-
bcx = zero_and_revoke(bcx, args_res.to_zero, args_res.to_revoke);
29872967

29882968
bcx = trans_block_cleanups(bcx, cx);
29892969
let next_cx = new_sub_block_ctxt(in_cx, "next");
@@ -2994,65 +2974,43 @@ fn trans_call_inner(in_cx: @block_ctxt, fn_expr_ty: ty::t,
29942974
ret next_cx;
29952975
}
29962976

2997-
fn zero_and_revoke(bcx: @block_ctxt,
2998-
to_zero: [{v: ValueRef, t: ty::t}],
2999-
to_revoke: [{v: ValueRef, t: ty::t}]) -> @block_ctxt {
3000-
let bcx = bcx;
3001-
for {v, t} in to_zero {
3002-
bcx = zero_alloca(bcx, v, t);
3003-
}
3004-
for {v, _} in to_revoke { revoke_clean(bcx, v); }
3005-
ret bcx;
3006-
}
3007-
30082977
fn invoke(bcx: @block_ctxt, llfn: ValueRef,
30092978
llargs: [ValueRef]) -> @block_ctxt {
3010-
ret invoke_(bcx, llfn, llargs, [], [], Invoke);
2979+
ret invoke_(bcx, llfn, llargs, Invoke);
30112980
}
30122981

3013-
fn invoke_full(bcx: @block_ctxt, llfn: ValueRef, llargs: [ValueRef],
3014-
to_zero: [{v: ValueRef, t: ty::t}],
3015-
to_revoke: [{v: ValueRef, t: ty::t}]) -> @block_ctxt {
3016-
ret invoke_(bcx, llfn, llargs, to_zero, to_revoke, Invoke);
2982+
fn invoke_full(bcx: @block_ctxt, llfn: ValueRef, llargs: [ValueRef])
2983+
-> @block_ctxt {
2984+
ret invoke_(bcx, llfn, llargs, Invoke);
30172985
}
30182986

30192987
fn invoke_(bcx: @block_ctxt, llfn: ValueRef, llargs: [ValueRef],
3020-
to_zero: [{v: ValueRef, t: ty::t}],
3021-
to_revoke: [{v: ValueRef, t: ty::t}],
30222988
invoker: fn(@block_ctxt, ValueRef, [ValueRef],
30232989
BasicBlockRef, BasicBlockRef)) -> @block_ctxt {
30242990
// FIXME: May be worth turning this into a plain call when there are no
30252991
// cleanups to run
30262992
if bcx.unreachable { ret bcx; }
30272993
let normal_bcx = new_sub_block_ctxt(bcx, "normal return");
3028-
invoker(bcx, llfn, llargs, normal_bcx.llbb,
3029-
get_landing_pad(bcx, to_zero, to_revoke));
2994+
invoker(bcx, llfn, llargs, normal_bcx.llbb, get_landing_pad(bcx));
30302995
ret normal_bcx;
30312996
}
30322997

3033-
fn get_landing_pad(bcx: @block_ctxt,
3034-
to_zero: [{v: ValueRef, t: ty::t}],
3035-
to_revoke: [{v: ValueRef, t: ty::t}]
3036-
) -> BasicBlockRef {
3037-
let have_zero_or_revoke = vec::is_not_empty(to_zero)
3038-
|| vec::is_not_empty(to_revoke);
3039-
let scope_bcx = find_scope_for_lpad(bcx, have_zero_or_revoke);
3040-
if scope_bcx.lpad_dirty || have_zero_or_revoke {
2998+
fn get_landing_pad(bcx: @block_ctxt) -> BasicBlockRef {
2999+
let scope_bcx = find_scope_for_lpad(bcx);
3000+
if scope_bcx.lpad_dirty {
30413001
let unwind_bcx = new_sub_block_ctxt(bcx, "unwind");
3042-
trans_landing_pad(unwind_bcx, to_zero, to_revoke);
3002+
trans_landing_pad(unwind_bcx);
30433003
scope_bcx.lpad = some(unwind_bcx.llbb);
3044-
scope_bcx.lpad_dirty = have_zero_or_revoke;
3004+
scope_bcx.lpad_dirty = false;
30453005
}
30463006
assert option::is_some(scope_bcx.lpad);
30473007
ret option::get(scope_bcx.lpad);
30483008

3049-
fn find_scope_for_lpad(bcx: @block_ctxt,
3050-
have_zero_or_revoke: bool) -> @block_ctxt {
3009+
fn find_scope_for_lpad(bcx: @block_ctxt) -> @block_ctxt {
30513010
let scope_bcx = bcx;
30523011
while true {
30533012
scope_bcx = find_scope_cx(scope_bcx);
3054-
if vec::is_not_empty(scope_bcx.cleanups)
3055-
|| have_zero_or_revoke {
3013+
if vec::is_not_empty(scope_bcx.cleanups) {
30563014
ret scope_bcx;
30573015
} else {
30583016
scope_bcx = alt scope_bcx.parent {
@@ -3067,9 +3025,7 @@ fn get_landing_pad(bcx: @block_ctxt,
30673025
}
30683026
}
30693027

3070-
fn trans_landing_pad(bcx: @block_ctxt,
3071-
to_zero: [{v: ValueRef, t: ty::t}],
3072-
to_revoke: [{v: ValueRef, t: ty::t}]) -> BasicBlockRef {
3028+
fn trans_landing_pad(bcx: @block_ctxt) -> BasicBlockRef {
30733029
// The landing pad return type (the type being propagated). Not sure what
30743030
// this represents but it's determined by the personality function and
30753031
// this is what the EH proposal example uses.
@@ -3095,7 +3051,7 @@ fn trans_landing_pad(bcx: @block_ctxt,
30953051
// FIXME: This seems like a very naive and redundant way to generate the
30963052
// landing pads, as we're re-generating all in-scope cleanups for each
30973053
// function call. Probably good optimization opportunities here.
3098-
let bcx = zero_and_revoke(bcx, to_zero, to_revoke);
3054+
let bcx = bcx;
30993055
let scope_cx = bcx;
31003056
while true {
31013057
scope_cx = find_scope_cx(scope_cx);

src/comp/middle/trans/impl.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,10 @@ fn trans_impl(ccx: @crate_ctxt, path: path, name: ast::ident,
6060
}
6161

6262
fn trans_self_arg(bcx: @block_ctxt, base: @ast::expr) -> result {
63-
let tz = [], tr = [];
6463
let basety = expr_ty(bcx, base);
6564
let m_by_ref = ast::expl(ast::by_ref);
6665
trans_arg_expr(bcx, {mode: m_by_ref, ty: basety},
67-
T_ptr(type_of_or_i8(bcx_ccx(bcx), basety)), tz,
68-
tr, base)
66+
T_ptr(type_of_or_i8(bcx_ccx(bcx), basety)), base)
6967
}
7068

7169
fn trans_method_callee(bcx: @block_ctxt, callee_id: ast::node_id,

0 commit comments

Comments
 (0)