Skip to content

Commit c44826f

Browse files
committed
auto merge of #9677 : thestinger/rust/immediate, r=huonw
C-like enums are excluded from this for now, because the code paths specific to them need to be changed. fn foo() -> Option<~int> { Some(~5) } Before: ; Function Attrs: uwtable define void @_ZN3foo18hdec6e36682b87eeaf4v0.0E(%"enum.std::option::Option<~int>[#1]"* noalias nocapture sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 { "function top level": %2 = tail call %"enum.std::libc::types::common::c95::c_void[#1]"* @"_ZN2rt11global_heap10malloc_raw17h56c543b77f9b78aY11v0.9$x2dpreE"({ i64, %tydesc*, i8*, i8*, i8 }* undef, i64 8) %3 = bitcast %"enum.std::libc::types::common::c95::c_void[#1]"* %2 to i64* store i64 5, i64* %3, align 8 %4 = getelementptr inbounds %"enum.std::option::Option<~int>[#1]"* %0, i64 0, i32 0 store i64* %3, i64** %4, align 8 ret void } After: ; Function Attrs: uwtable define %"enum.std::option::Option<~int>[#1]" @_ZN3foo18h2cbf6557a3143edah4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone) #0 { "function top level": %1 = tail call %"enum.std::libc::types::common::c95::c_void[#1]"* @"_ZN2rt11global_heap10malloc_raw18hb1e9dd1beab35edau11v0.9$x2dpreE"({ i64, %tydesc*, i8*, i8*, i8 }* undef, i64 8) %2 = bitcast %"enum.std::libc::types::common::c95::c_void[#1]"* %1 to i64* store i64 5, i64* %2, align 8 %oldret = insertvalue %"enum.std::option::Option<~int>[#1]" undef, i64* %2, 0 ret %"enum.std::option::Option<~int>[#1]" %oldret }
2 parents 1754837 + f2932e4 commit c44826f

File tree

9 files changed

+23
-19
lines changed

9 files changed

+23
-19
lines changed

src/librustc/middle/trans/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
17331733
fcx.alloca_insert_pt = Some(llvm::LLVMGetFirstInstruction(entry_bcx.llbb));
17341734
}
17351735

1736-
if !ty::type_is_voidish(substd_output_type) {
1736+
if !ty::type_is_voidish(ccx.tcx, substd_output_type) {
17371737
// If the function returns nil/bot, there is no real return
17381738
// value, so do not set `llretptr`.
17391739
if !skip_retptr || uses_outptr {
@@ -1964,7 +1964,7 @@ pub fn trans_closure(ccx: @mut CrateContext,
19641964
// translation calls that don't have a return value (trans_crate,
19651965
// trans_mod, trans_item, et cetera) and those that do
19661966
// (trans_block, trans_expr, et cetera).
1967-
if body.expr.is_none() || ty::type_is_voidish(block_ty) {
1967+
if body.expr.is_none() || ty::type_is_voidish(bcx.tcx(), block_ty) {
19681968
bcx = controlflow::trans_block(bcx, body, expr::Ignore);
19691969
} else {
19701970
let dest = expr::SaveIn(fcx.llretptr.unwrap());

src/librustc/middle/trans/callee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ pub fn trans_call_inner(in_cx: @mut Block,
660660
}
661661
Some(expr::SaveIn(dst)) => Some(dst),
662662
Some(expr::Ignore) => {
663-
if !ty::type_is_voidish(ret_ty) {
663+
if !ty::type_is_voidish(in_cx.tcx(), ret_ty) {
664664
Some(alloc_ty(bcx, ret_ty, "__llret"))
665665
} else {
666666
unsafe {
@@ -735,7 +735,7 @@ pub fn trans_call_inner(in_cx: @mut Block,
735735
match opt_llretslot {
736736
Some(llretslot) => {
737737
if !type_of::return_uses_outptr(bcx.ccx(), ret_ty) &&
738-
!ty::type_is_voidish(ret_ty)
738+
!ty::type_is_voidish(bcx.tcx(), ret_ty)
739739
{
740740
Store(bcx, llret, llretslot);
741741
}

src/librustc/middle/trans/common.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,13 @@ pub fn type_is_immediate(ccx: &mut CrateContext, ty: ty::t) -> bool {
6969
if simple {
7070
return true;
7171
}
72+
// FIXME: #9651: C-like enums should also be immediate
73+
if ty::type_is_c_like_enum(ccx.tcx, ty) {
74+
return false;
75+
}
7276
match ty::get(ty).sty {
73-
// FIXME: #9651: small `ty_struct` and `ty_enum` should also be immediate
74-
ty::ty_tup(*) => {
77+
// FIXME: #9651: small `ty_struct` should also be immediate
78+
ty::ty_enum(*) | ty::ty_tup(*) => {
7579
let llty = sizing_type_of(ccx, ty);
7680
llsize_of_alloc(ccx, llty) <= llsize_of_alloc(ccx, ccx.int_type)
7781
}

src/librustc/middle/trans/datum.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub fn appropriate_mode(ccx: &mut CrateContext, ty: ty::t) -> DatumMode {
195195
* on whether type is immediate or not.
196196
*/
197197

198-
if ty::type_is_voidish(ty) {
198+
if ty::type_is_voidish(ccx.tcx, ty) {
199199
ByValue
200200
} else if type_is_immediate(ccx, ty) {
201201
ByValue
@@ -271,7 +271,7 @@ impl Datum {
271271

272272
let _icx = push_ctxt("copy_to");
273273

274-
if ty::type_is_voidish(self.ty) {
274+
if ty::type_is_voidish(bcx.tcx(), self.ty) {
275275
return bcx;
276276
}
277277

@@ -343,7 +343,7 @@ impl Datum {
343343
debug2!("move_to(self={}, action={:?}, dst={})",
344344
self.to_str(bcx.ccx()), action, bcx.val_to_str(dst));
345345

346-
if ty::type_is_voidish(self.ty) {
346+
if ty::type_is_voidish(bcx.tcx(), self.ty) {
347347
return bcx;
348348
}
349349

@@ -432,7 +432,7 @@ impl Datum {
432432
*
433433
* Yields the value itself. */
434434

435-
if ty::type_is_voidish(self.ty) {
435+
if ty::type_is_voidish(bcx.tcx(), self.ty) {
436436
C_nil()
437437
} else {
438438
match self.mode {
@@ -469,7 +469,7 @@ impl Datum {
469469
match self.mode {
470470
ByRef(_) => self.val,
471471
ByValue => {
472-
if ty::type_is_voidish(self.ty) {
472+
if ty::type_is_voidish(bcx.tcx(), self.ty) {
473473
C_null(type_of::type_of(bcx.ccx(), self.ty).ptr_to())
474474
} else {
475475
let slot = alloc_ty(bcx, self.ty, "");

src/librustc/middle/trans/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ pub fn trans_into(bcx: @mut Block, expr: &ast::Expr, dest: Dest) -> @mut Block {
440440
debuginfo::set_source_location(bcx.fcx, expr.id, expr.span);
441441

442442
let dest = {
443-
if ty::type_is_voidish(ty) {
443+
if ty::type_is_voidish(bcx.tcx(), ty) {
444444
Ignore
445445
} else {
446446
dest
@@ -531,7 +531,7 @@ fn trans_to_datum_unadjusted(bcx: @mut Block, expr: &ast::Expr) -> DatumBlock {
531531

532532
ty::RvalueDpsExpr => {
533533
let ty = expr_ty(bcx, expr);
534-
if ty::type_is_voidish(ty) {
534+
if ty::type_is_voidish(bcx.tcx(), ty) {
535535
bcx = trans_rvalue_dps_unadjusted(bcx, expr, Ignore);
536536
return nil(bcx, ty);
537537
} else {

src/librustc/middle/trans/foreign.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pub fn trans_native_call(bcx: @mut Block,
177177
_ => ccx.sess.bug("trans_native_call called on non-function type")
178178
};
179179
let llsig = foreign_signature(ccx, &fn_sig);
180-
let ret_def = !ty::type_is_voidish(fn_sig.output);
180+
let ret_def = !ty::type_is_voidish(bcx.tcx(), fn_sig.output);
181181
let fn_type = cabi::compute_abi_info(ccx,
182182
llsig.llarg_tys,
183183
llsig.llret_ty,
@@ -718,7 +718,7 @@ fn foreign_types_for_fn_ty(ccx: &mut CrateContext,
718718
_ => ccx.sess.bug("foreign_types_for_fn_ty called on non-function type")
719719
};
720720
let llsig = foreign_signature(ccx, &fn_sig);
721-
let ret_def = !ty::type_is_voidish(fn_sig.output);
721+
let ret_def = !ty::type_is_voidish(ccx.tcx, fn_sig.output);
722722
let fn_ty = cabi::compute_abi_info(ccx,
723723
llsig.llarg_tys,
724724
llsig.llret_ty,

src/librustc/middle/trans/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
321321
pluralize(out_type_size)));
322322
}
323323

324-
if !ty::type_is_voidish(out_type) {
324+
if !ty::type_is_voidish(ccx.tcx, out_type) {
325325
let llsrcval = get_param(decl, first_real_arg);
326326
if type_is_immediate(ccx, in_type) {
327327
match fcx.llretptr {

src/librustc/middle/trans/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn type_of_rust_fn(cx: &mut CrateContext,
6262
atys.push_all(type_of_explicit_args(cx, inputs));
6363

6464
// Use the output as the actual return value if it's immediate.
65-
if !use_out_pointer && !ty::type_is_voidish(output) {
65+
if !use_out_pointer && !ty::type_is_voidish(cx.tcx, output) {
6666
Type::func(atys, &lloutputtype)
6767
} else {
6868
Type::func(atys, &Type::void())

src/librustc/middle/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1566,9 +1566,9 @@ pub fn subst(cx: ctxt,
15661566

15671567
// Type utilities
15681568

1569-
pub fn type_is_voidish(ty: t) -> bool {
1569+
pub fn type_is_voidish(tcx: ctxt, ty: t) -> bool {
15701570
//! "nil" and "bot" are void types in that they represent 0 bits of information
1571-
type_is_nil(ty) || type_is_bot(ty)
1571+
type_is_nil(ty) || type_is_bot(ty) || type_is_empty(tcx, ty)
15721572
}
15731573

15741574
pub fn type_is_nil(ty: t) -> bool { get(ty).sty == ty_nil }

0 commit comments

Comments
 (0)