Skip to content

Commit 82d8e18

Browse files
committed
---
yaml --- r: 5726 b: refs/heads/master c: 2ff8946 h: refs/heads/master v: v3
1 parent 4dfcaf4 commit 82d8e18

File tree

2 files changed

+50
-32
lines changed

2 files changed

+50
-32
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: 41528dc5438f66c001a521d287be59e9c0d3addf
2+
refs/heads/master: 2ff89469d43a3da326d7da50e4a97fb9c0ba359b

trunk/src/comp/middle/trans.rs

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ fn type_of_explicit_args(cx: @crate_ctxt, sp: span, inputs: [ty::arg]) ->
6262
// FIXME: would be nice to have a constraint on arg
6363
// that would obviate the need for this check
6464
check non_ty_var(cx, arg_ty);
65-
atys += [T_ptr(type_of_inner(cx, sp, arg_ty))];
65+
let llty = type_of_inner(cx, sp, arg_ty);
66+
if arg.mode == ast::by_val { atys += [llty]; }
67+
else { atys += [T_ptr(llty)]; }
6668
}
6769
ret atys;
6870
}
@@ -3424,15 +3426,15 @@ fn trans_bind_thunk(cx: @local_ctxt, sp: span, incoming_fty: ty::t,
34243426
env_ty: ty::t, ty_param_count: uint,
34253427
target_fn: option::t<ValueRef>)
34263428
-> {val: ValueRef, ty: TypeRef} {
3427-
// If we supported constraints on record fields, we could make the
3428-
// constraints for this function:
3429-
/*
3429+
// If we supported constraints on record fields, we could make the
3430+
// constraints for this function:
3431+
/*
34303432
: returns_non_ty_var(ccx, outgoing_fty),
34313433
type_has_static_size(ccx, incoming_fty) ->
3432-
*/
3433-
// but since we don't, we have to do the checks at the beginning.
3434-
let ccx = cx.ccx;
3435-
check type_has_static_size(ccx, incoming_fty);
3434+
*/
3435+
// but since we don't, we have to do the checks at the beginning.
3436+
let ccx = cx.ccx;
3437+
check type_has_static_size(ccx, incoming_fty);
34363438

34373439
// Here we're not necessarily constructing a thunk in the sense of
34383440
// "function with no arguments". The result of compiling 'bind f(foo,
@@ -3566,6 +3568,7 @@ fn trans_bind_thunk(cx: @local_ctxt, sp: span, incoming_fty: ty::t,
35663568
abi::closure_elt_bindings, b]);
35673569
bcx = bound_arg.bcx;
35683570
let val = bound_arg.val;
3571+
if out_arg.mode == ast::by_val { val = Load(bcx, val); }
35693572
// If the type is parameterized, then we need to cast the
35703573
// type we actually have to the parameterized out type.
35713574
if ty::type_contains_params(cx.ccx.tcx, out_arg.ty) {
@@ -3700,21 +3703,24 @@ fn trans_arg_expr(cx: @block_ctxt, arg: ty::arg, lldestty0: TypeRef,
37003703
// to have type lldestty0 (the callee's expected type).
37013704
val = llvm::LLVMGetUndef(lldestty0);
37023705
} else if arg.mode == ast::by_ref || arg.mode == ast::by_val {
3703-
let copied = false;
3704-
if !lv.is_mem && type_is_immediate(ccx, e_ty) {
3706+
let copied = false, imm = type_is_immediate(ccx, e_ty);
3707+
if arg.mode == ast::by_ref && !lv.is_mem && imm {
37053708
val = do_spill_noroot(bcx, val);
37063709
copied = true;
37073710
}
37083711
if ccx.copy_map.contains_key(e.id) && lv.is_mem {
3712+
assert lv.is_mem;
37093713
if !copied {
37103714
let alloc = alloc_ty(bcx, e_ty);
3711-
bcx =
3712-
copy_val(alloc.bcx, INIT, alloc.val,
3713-
load_if_immediate(alloc.bcx, val, e_ty), e_ty);
3715+
bcx = copy_val(alloc.bcx, INIT, alloc.val,
3716+
load_if_immediate(alloc.bcx, val, e_ty), e_ty);
37143717
val = alloc.val;
37153718
} else { bcx = take_ty(bcx, val, e_ty); }
37163719
add_clean(bcx, val, e_ty);
37173720
}
3721+
if arg.mode == ast::by_val && (lv.is_mem || !imm) {
3722+
val = Load(bcx, val);
3723+
}
37183724
} else if type_is_immediate(ccx, e_ty) && !lv.is_mem {
37193725
let r = do_spill(bcx, val, e_ty);
37203726
val = r.val;
@@ -3960,7 +3966,8 @@ fn trans_c_stack_native_call(bcx: @block_ctxt, f: @ast::expr,
39603966

39613967
let r = trans_arg_expr(bcx, ty_arg, llargty, to_zero, to_revoke, arg);
39623968
let llargval = r.val; bcx = r.bcx;
3963-
{ llval: llargval, llty: llargty, static: static }
3969+
{ llval: llargval, llty: llargty, static: static,
3970+
by_val: ty_arg.mode == ast::by_val }
39643971
}, fn_arg_tys, args);
39653972

39663973
// Allocate the argument bundle.
@@ -3976,7 +3983,7 @@ fn trans_c_stack_native_call(bcx: @block_ctxt, f: @ast::expr,
39763983
if llarg.static {
39773984
// FIXME: This load is unfortunate. It won't be necessary once we
39783985
// have reference types again.
3979-
llargval = Load(bcx, llarg.llval);
3986+
llargval = llarg.by_val ? llarg.llval : Load(bcx, llarg.llval);
39803987
} else {
39813988
llargval = llarg.llval;
39823989
}
@@ -5141,27 +5148,38 @@ fn copy_args_to_allocas(fcx: @fn_ctxt, bcx: @block_ctxt, args: [ast::arg],
51415148
arg_tys: [ty::arg], ignore_mut: bool)
51425149
-> @block_ctxt {
51435150
let arg_n: uint = 0u;
5144-
for aarg: ast::arg in args {
5145-
let arg_ty = arg_tys[arg_n].ty;
5146-
alt aarg.mode {
5151+
for arg in arg_tys {
5152+
let id = args[arg_n].id;
5153+
let mutated = !ignore_mut && fcx.lcx.ccx.mut_map.contains_key(id);
5154+
alt arg.mode {
5155+
ast::mode_infer. {
5156+
bcx_ccx(bcx).sess.span_fatal(fcx.sp, "this");
5157+
}
51475158
ast::by_move. {
5148-
add_clean(bcx, fcx.llargs.get(aarg.id), arg_ty);
5159+
add_clean(bcx, fcx.llargs.get(id), arg.ty);
51495160
}
51505161
ast::by_mut_ref. { }
5151-
_ {
5152-
let mutated =
5153-
!ignore_mut && fcx.lcx.ccx.mut_map.contains_key(aarg.id);
5154-
5162+
ast::by_val. {
5163+
let aval = fcx.llargs.get(id);
5164+
let {bcx: cx, val: alloc} = alloc_ty(bcx, arg.ty);
5165+
bcx = cx;
5166+
Store(bcx, aval, alloc);
5167+
if mutated {
5168+
bcx = take_ty(bcx, alloc, arg.ty);
5169+
add_clean(bcx, alloc, arg.ty);
5170+
}
5171+
fcx.llargs.insert(id, alloc);
5172+
}
5173+
ast::by_ref. {
51555174
// Overwrite the llargs entry for locally mutated params
51565175
// with a local alloca.
51575176
if mutated {
5158-
let aptr = fcx.llargs.get(aarg.id);
5159-
let {bcx: bcx, val: alloc} = alloc_ty(bcx, arg_ty);
5160-
bcx =
5161-
copy_val(bcx, INIT, alloc,
5162-
load_if_immediate(bcx, aptr, arg_ty), arg_ty);
5163-
fcx.llargs.insert(aarg.id, alloc);
5164-
add_clean(bcx, alloc, arg_ty);
5177+
let aptr = fcx.llargs.get(id);
5178+
let {bcx: cx, val: alloc} = alloc_ty(bcx, arg.ty);
5179+
bcx = copy_val(cx, INIT, alloc,
5180+
load_if_immediate(cx, aptr, arg.ty), arg.ty);
5181+
fcx.llargs.insert(id, alloc);
5182+
add_clean(bcx, alloc, arg.ty);
51655183
}
51665184
}
51675185
}
@@ -5845,7 +5863,7 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
58455863
let i = arg_n;
58465864
for arg: ty::arg in args {
58475865
let llarg = llvm::LLVMGetParam(fcx.llfn, i);
5848-
if arg.mode == ast::by_ref || arg.mode == ast::by_val {
5866+
if arg.mode == ast::by_ref {
58495867
llarg = load_if_immediate(bcx, llarg, arg.ty);
58505868
}
58515869
assert (llarg as int != 0);

0 commit comments

Comments
 (0)