Skip to content

Commit 99ac243

Browse files
committed
auto merge of #5445 : nikomatsakis/rust/issue-3678-refactor-trans_call, r=graydon
Refactor trans_call to separate out the translation of the arguments, environment, and return pointer. Towards #3678. r? @brson
2 parents 0847d52 + e821671 commit 99ac243

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

src/librustc/middle/trans/callee.rs

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,14 @@ pub fn trans_call_inner(
492492
}
493493
};
494494

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

500-
let llretslot = args_res.retslot;
501503

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

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

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

598-
// ... then explicit args.
590+
let mut bcx = cx;
599591

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

627-
Args { bcx: bcx, args: llargs, retslot: llretslot }
619+
return bcx;
628620
}
629621

630622
pub enum AutorefArg {

0 commit comments

Comments
 (0)