diff options
| author | Patrick Walton <[email protected]> | 2010-12-13 16:12:45 -0800 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2010-12-13 16:12:45 -0800 |
| commit | 29e6d7a4adb1536d6f51b8d5fd7966113681bbc4 (patch) | |
| tree | a6a81be7f2191cc52732efb56d6ac7e14ce0a1f3 /src | |
| parent | Set the new vec fill-size on the compiler side, as in rustboot. Un-XFAIL firs... (diff) | |
| download | rust-29e6d7a4adb1536d6f51b8d5fd7966113681bbc4.tar.xz rust-29e6d7a4adb1536d6f51b8d5fd7966113681bbc4.zip | |
rustc: Hack to get rid of passing i1 types for unit around in most cases, suggested by Rafael
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp/middle/trans.rs | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index dbf96f34..cbf01735 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -322,7 +322,15 @@ fn type_of_inner(@crate_ctxt cx, @typeck.ty t) -> TypeRef { } atys += t; } - ret T_fn(atys, type_of(cx, out)); + + auto ret_ty; + if (typeck.type_is_nil(out)) { + ret_ty = llvm.LLVMVoidType(); + } else { + ret_ty = type_of(cx, out); + } + + ret T_fn(atys, ret_ty); } case (typeck.ty_var(_)) { // FIXME: implement. @@ -1511,7 +1519,14 @@ impure fn trans_call(@block_ctxt cx, @ast.expr f, auto fn_ty = typeck.expr_ty(f); auto ret_ty = typeck.ann_to_type(ann); auto args_res = trans_args(f_res._0.bcx, args, fn_ty); - auto retval = args_res._0.build.FastCall(f_res._0.val, args_res._1); + + auto real_retval = args_res._0.build.FastCall(f_res._0.val, args_res._1); + auto retval; + if (typeck.type_is_nil(ret_ty)) { + retval = C_nil(); + } else { + retval = real_retval; + } // Structured returns come back as first-class values. This is nice for // LLVM but wrong for us; we treat structured values by pointer in @@ -1795,8 +1810,13 @@ impure fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result { } alt (e) { - case (some[@ast.expr](_)) { - r.val = r.bcx.build.Ret(r.val); + case (some[@ast.expr](?ex)) { + if (typeck.type_is_nil(typeck.expr_ty(ex))) { + r.bcx.build.RetVoid(); + r.val = C_nil(); + } else { + r.val = r.bcx.build.Ret(r.val); + } ret r; } case (_) { /* fall through */ } @@ -1804,7 +1824,8 @@ impure fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result { // FIXME: until LLVM has a unit type, we are moving around // C_nil values rather than their void type. - r.val = r.bcx.build.Ret(C_nil()); + r.bcx.build.RetVoid(); + r.val = C_nil(); ret r; } @@ -2054,7 +2075,7 @@ impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid, if (!is_terminated(res.bcx)) { // FIXME: until LLVM has a unit type, we are moving around // C_nil values rather than their void type. - res.bcx.build.Ret(C_nil()); + res.bcx.build.RetVoid(); } } |