Skip to content

Commit e821671

Browse files
committed
Refactor trans_call to separate out the translation of the arguments, environment, and return pointer
1 parent e67448d commit e821671

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

Diff for: src/librustc/middle/trans/callee.rs

+26-34
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,14 @@ pub fn trans_call_inner(
491491
}
492492
};
493493

494-
let args_res = trans_args(bcx, llenv, args, fn_expr_ty,
495-
dest, ret_flag, autoref_arg);
496-
bcx = args_res.bcx;
497-
let mut llargs = /*bad*/copy args_res.args;
494+
let llretslot = trans_ret_slot(bcx, fn_expr_ty, dest);
495+
496+
let mut llargs = ~[];
497+
llargs.push(llretslot);
498+
llargs.push(llenv);
499+
bcx = trans_args(bcx, args, fn_expr_ty,
500+
ret_flag, autoref_arg, &mut llargs);
498501

499-
let llretslot = args_res.retslot;
500502

501503
// Now that the arguments have finished evaluating, we need to revoke
502504
// the cleanup for the self argument, if it exists
@@ -554,30 +556,12 @@ pub enum CallArgs {
554556
ArgVals(&'self [ValueRef])
555557
}
556558

557-
pub struct Args {
558-
bcx: block,
559-
args: ~[ValueRef],
560-
retslot: ValueRef
561-
}
562-
563-
pub fn trans_args(cx: block,
564-
llenv: ValueRef,
565-
+args: CallArgs,
566-
fn_ty: ty::t,
567-
dest: expr::Dest,
568-
ret_flag: Option<ValueRef>,
569-
+autoref_arg: AutorefArg) -> Args {
570-
let _icx = cx.insn_ctxt("trans_args");
571-
let mut temp_cleanups = ~[];
572-
let arg_tys = ty::ty_fn_args(fn_ty);
573-
let mut llargs: ~[ValueRef] = ~[];
574-
575-
let mut bcx = cx;
576-
559+
pub fn trans_ret_slot(+bcx: block,
560+
+fn_ty: ty::t,
561+
+dest: expr::Dest) -> ValueRef
562+
{
577563
let retty = ty::ty_fn_ret(fn_ty);
578-
579-
// Arg 0: Output pointer.
580-
let llretslot = match dest {
564+
match dest {
581565
expr::SaveIn(dst) => dst,
582566
expr::Ignore => {
583567
if ty::type_is_nil(retty) {
@@ -588,13 +572,21 @@ pub fn trans_args(cx: block,
588572
alloc_ty(bcx, retty)
589573
}
590574
}
591-
};
592-
llargs.push(llretslot);
575+
}
576+
}
593577

594-
// Arg 1: Env (closure-bindings / self value)
595-
llargs.push(llenv);
578+
pub fn trans_args(+cx: block,
579+
+args: CallArgs,
580+
+fn_ty: ty::t,
581+
+ret_flag: Option<ValueRef>,
582+
+autoref_arg: AutorefArg,
583+
+llargs: &mut ~[ValueRef]) -> block
584+
{
585+
let _icx = cx.insn_ctxt("trans_args");
586+
let mut temp_cleanups = ~[];
587+
let arg_tys = ty::ty_fn_args(fn_ty);
596588

597-
// ... then explicit args.
589+
let mut bcx = cx;
598590

599591
// First we figure out the caller's view of the types of the arguments.
600592
// This will be needed if this is a generic call, because the callee has
@@ -623,7 +615,7 @@ pub fn trans_args(cx: block,
623615
revoke_clean(bcx, *c)
624616
}
625617

626-
Args { bcx: bcx, args: llargs, retslot: llretslot }
618+
return bcx;
627619
}
628620

629621
pub enum AutorefArg {

0 commit comments

Comments
 (0)