Skip to content

Commit 3bc3f96

Browse files
committed
Make trans_lval lval-only
Call trans_temp_lval if you want the old fallback-to-temporary behaviour. Issue #667
1 parent 2cc0008 commit 3bc3f96

File tree

3 files changed

+15
-59
lines changed

3 files changed

+15
-59
lines changed

src/comp/middle/trans.rs

Lines changed: 14 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,27 +2541,6 @@ fn get_dest_addr(dest: dest) -> ValueRef {
25412541
alt dest { save_in(a) { a } }
25422542
}
25432543

2544-
// Wrapper through which legacy non-DPS code can use DPS functions
2545-
fn dps_to_result(bcx: @block_ctxt,
2546-
work: block(@block_ctxt, dest) -> @block_ctxt,
2547-
ty: ty::t) -> result {
2548-
let tcx = bcx_tcx(bcx);
2549-
if ty::type_is_nil(tcx, ty) || ty::type_is_bot(tcx, ty) {
2550-
ret rslt(work(bcx, ignore), C_nil());
2551-
} else if type_is_immediate(bcx_ccx(bcx), ty) {
2552-
let cell = empty_dest_cell();
2553-
bcx = work(bcx, by_val(cell));
2554-
add_clean_temp(bcx, *cell, ty);
2555-
ret rslt(bcx, *cell);
2556-
} else {
2557-
let {bcx, val: alloca} = alloc_ty(bcx, ty);
2558-
bcx = zero_alloca(bcx, alloca, ty);
2559-
bcx = work(bcx, save_in(alloca));
2560-
add_clean_temp(bcx, alloca, ty);
2561-
ret rslt(bcx, alloca);
2562-
}
2563-
}
2564-
25652544
fn trans_if(cx: @block_ctxt, cond: @ast::expr, thn: ast::blk,
25662545
els: option::t<@ast::expr>, dest: dest)
25672546
-> @block_ctxt {
@@ -3244,7 +3223,7 @@ fn trans_callee(bcx: @block_ctxt, e: @ast::expr) -> lval_maybe_callee {
32443223
alt e.node {
32453224
ast::expr_path(p) { ret trans_path(bcx, p, e.id); }
32463225
ast::expr_field(base, ident) {
3247-
// Lval means record field, so not a method
3226+
// Lval means this is a record field, so not a method
32483227
if !expr_is_lval(bcx_tcx(bcx), e) {
32493228
let of = trans_object_field(bcx, base, ident);
32503229
ret {bcx: of.bcx, val: of.mthptr, is_mem: true,
@@ -3262,7 +3241,7 @@ fn trans_callee(bcx: @block_ctxt, e: @ast::expr) -> lval_maybe_callee {
32623241
}
32633242
_ {}
32643243
}
3265-
let lv = trans_lval(bcx, e);
3244+
let lv = trans_temp_lval(bcx, e);
32663245
ret lval_no_env(lv.bcx, lv.val, lv.is_mem);
32673246
}
32683247

@@ -3288,7 +3267,6 @@ fn expr_is_lval(tcx: ty::ctxt, e: @ast::expr) -> bool {
32883267
// The additional bool returned indicates whether it's mem (that is
32893268
// represented as an alloca or heap, hence needs a 'load' to be used as an
32903269
// immediate).
3291-
// FIXME[DPS] only allow this to be called on actual lvals
32923270
fn trans_lval(cx: @block_ctxt, e: @ast::expr) -> lval_result {
32933271
alt e.node {
32943272
ast::expr_path(p) {
@@ -3327,25 +3305,13 @@ fn trans_lval(cx: @block_ctxt, e: @ast::expr) -> lval_result {
33273305
};
33283306
ret lval_mem(sub.bcx, val);
33293307
}
3308+
// This is a by-ref returning call. Regular calls are not lval
33303309
ast::expr_call(f, args) {
3331-
// A by-ref returning function
3332-
if expr_is_lval(bcx_tcx(cx), e) {
3333-
let cell = empty_dest_cell();
3334-
let bcx = trans_call(cx, f, none, args, e.id, by_val(cell));
3335-
ret lval_mem(bcx, *cell);
3336-
} else { // By-value return
3337-
// FIXME[DPS] this will disappear when trans_lval only handles
3338-
// lvals
3339-
let {bcx, val} = dps_to_result(cx, {|bcx, dest|
3340-
trans_call(bcx, f, none, args, e.id, dest) },
3341-
ty::expr_ty(bcx_tcx(cx), e));
3342-
ret lval_val(bcx, val);
3343-
}
3344-
}
3345-
_ {
3346-
let res = trans_temp_expr(cx, e);
3347-
ret lval_val(res.bcx, res.val);
3310+
let cell = empty_dest_cell();
3311+
let bcx = trans_call(cx, f, none, args, e.id, by_val(cell));
3312+
ret lval_mem(bcx, *cell);
33483313
}
3314+
_ { bcx_ccx(cx).sess.span_bug(e.span, "non-lval in trans_lval"); }
33493315
}
33503316
}
33513317

@@ -3736,7 +3702,7 @@ fn trans_arg_expr(cx: @block_ctxt, arg: ty::arg, lldestty0: TypeRef,
37363702
let ccx = bcx_ccx(cx);
37373703
let e_ty = ty::expr_ty(ccx.tcx, e);
37383704
let is_bot = ty::type_is_bot(ccx.tcx, e_ty);
3739-
let lv = trans_lval(cx, e);
3705+
let lv = trans_temp_lval(cx, e);
37403706
let bcx = lv.bcx;
37413707
let val = lv.val;
37423708
if is_bot {
@@ -5331,27 +5297,18 @@ fn trans_closure(cx: @local_ctxt, sp: span, f: ast::_fn, llfndecl: ValueRef,
53315297
finish_fn(fcx, lltop);
53325298
}
53335299

5334-
fn trans_fn_inner(cx: @local_ctxt, sp: span, f: ast::_fn, llfndecl: ValueRef,
5335-
ty_self: option::t<ty::t>, ty_params: [ast::ty_param],
5336-
id: ast::node_id) {
5337-
trans_closure(cx, sp, f, llfndecl, ty_self, ty_params, id, {|_fcx|});
5338-
}
5339-
5340-
53415300
// trans_fn: creates an LLVM function corresponding to a source language
53425301
// function.
53435302
fn trans_fn(cx: @local_ctxt, sp: span, f: ast::_fn, llfndecl: ValueRef,
53445303
ty_self: option::t<ty::t>, ty_params: [ast::ty_param],
53455304
id: ast::node_id) {
5346-
if !cx.ccx.sess.get_opts().stats {
5347-
trans_fn_inner(cx, sp, f, llfndecl, ty_self, ty_params, id);
5348-
ret;
5305+
let do_time = cx.ccx.sess.get_opts().stats;
5306+
let start = do_time ? time::get_time() : {sec: 0u32, usec: 0u32};
5307+
trans_closure(cx, sp, f, llfndecl, ty_self, ty_params, id, {|_fcx|});
5308+
if do_time {
5309+
let end = time::get_time();
5310+
log_fn_time(cx.ccx, str::connect(cx.path, "::"), start, end);
53495311
}
5350-
5351-
let start = time::get_time();
5352-
trans_fn_inner(cx, sp, f, llfndecl, ty_self, ty_params, id);
5353-
let end = time::get_time();
5354-
log_fn_time(cx.ccx, str::connect(cx.path, "::"), start, end);
53555312
}
53565313

53575314
fn trans_res_ctor(cx: @local_ctxt, sp: span, dtor: ast::_fn,

src/comp/middle/trans_uniq.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import trans::{
77
type_of_inner,
88
size_of,
99
node_id_type,
10-
trans_lval,
1110
INIT,
1211
trans_shared_free,
1312
drop_ty,

src/comp/middle/trans_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import back::abi;
66
import trans::{call_memmove, trans_shared_malloc, llsize_of, type_of_or_i8,
77
INIT, copy_val, load_if_immediate, alloca, size_of,
88
llderivedtydescs_block_ctxt, lazily_emit_tydesc_glue,
9-
get_tydesc, load_inbounds, trans_lval,
9+
get_tydesc, load_inbounds,
1010
node_id_type, new_sub_block_ctxt, tps_normal, do_spill_noroot,
1111
GEPi, alloc_ty, dest};
1212
import trans_build::*;

0 commit comments

Comments
 (0)