Skip to content

Commit fb05d91

Browse files
committed
rustc: Make copy_args_to_allocas not insist on a function type so it's easier to make it work with tag constructors
1 parent 9f6a630 commit fb05d91

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/comp/middle/trans.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,19 +1817,13 @@ fn new_fn_ctxt(@crate_ctxt cx,
18171817
// allocas immediately upon entry; this permits us to GEP into structures we
18181818
// were passed and whatnot. Apparently mem2reg will mop up.
18191819

1820-
fn copy_args_to_allocas(@block_ctxt cx, vec[ast.arg] args, &ast.ann ann) {
1821-
1822-
let vec[typeck.arg] arg_ts = vec();
1823-
let @typeck.ty fty = node_ann_type(cx.fcx.ccx, ann);
1824-
alt (fty.struct) {
1825-
case (typeck.ty_fn(?a, _)) { arg_ts += a; }
1826-
}
1820+
fn copy_args_to_allocas(@block_ctxt cx, vec[ast.arg] args,
1821+
vec[typeck.arg] arg_tys) {
18271822

18281823
let uint arg_n = 0u;
18291824

18301825
for (ast.arg aarg in args) {
1831-
auto arg = arg_ts.(arg_n);
1832-
auto arg_t = type_of(cx.fcx.ccx, arg.ty);
1826+
auto arg_t = type_of(cx.fcx.ccx, arg_tys.(arg_n).ty);
18331827
auto alloca = cx.build.Alloca(arg_t);
18341828
auto argval = cx.fcx.llargs.get(aarg.id);
18351829
cx.build.Store(argval, alloca);
@@ -1844,13 +1838,22 @@ fn is_terminated(@block_ctxt cx) -> bool {
18441838
ret llvm.LLVMIsATerminatorInst(inst) as int != 0;
18451839
}
18461840

1841+
fn arg_tys_of_fn(ast.ann ann) -> vec[typeck.arg] {
1842+
alt (typeck.ann_to_type(ann).struct) {
1843+
case (typeck.ty_fn(?arg_tys, _)) {
1844+
ret arg_tys;
1845+
}
1846+
}
1847+
fail;
1848+
}
1849+
18471850
impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
18481851
&ast.ann ann) {
18491852

18501853
auto fcx = new_fn_ctxt(cx, cx.path, f.inputs, fid);
18511854
auto bcx = new_top_block_ctxt(fcx);
18521855

1853-
copy_args_to_allocas(bcx, f.inputs, ann);
1856+
copy_args_to_allocas(bcx, f.inputs, arg_tys_of_fn(ann));
18541857

18551858
auto res = trans_block(bcx, f.body);
18561859
if (!is_terminated(res.bcx)) {

0 commit comments

Comments
 (0)