auto merge of #9643 : thestinger/rust/immediate, r=alexcrichton

This commit is contained in:
bors 2013-09-30 21:51:27 -07:00
commit 1dbc467fd9
8 changed files with 84 additions and 49 deletions

View File

@ -1121,13 +1121,13 @@ pub fn do_spill_noroot(cx: @mut Block, v: ValueRef) -> ValueRef {
pub fn spill_if_immediate(cx: @mut Block, v: ValueRef, t: ty::t) -> ValueRef { pub fn spill_if_immediate(cx: @mut Block, v: ValueRef, t: ty::t) -> ValueRef {
let _icx = push_ctxt("spill_if_immediate"); let _icx = push_ctxt("spill_if_immediate");
if ty::type_is_immediate(cx.tcx(), t) { return do_spill(cx, v, t); } if type_is_immediate(cx.tcx(), t) { return do_spill(cx, v, t); }
return v; return v;
} }
pub fn load_if_immediate(cx: @mut Block, v: ValueRef, t: ty::t) -> ValueRef { pub fn load_if_immediate(cx: @mut Block, v: ValueRef, t: ty::t) -> ValueRef {
let _icx = push_ctxt("load_if_immediate"); let _icx = push_ctxt("load_if_immediate");
if ty::type_is_immediate(cx.tcx(), t) { return Load(cx, v); } if type_is_immediate(cx.tcx(), t) { return Load(cx, v); }
return v; return v;
} }

View File

@ -15,7 +15,7 @@ use driver::session;
use driver::session::Session; use driver::session::Session;
use lib::llvm::{ValueRef, BasicBlockRef, BuilderRef}; use lib::llvm::{ValueRef, BasicBlockRef, BuilderRef};
use lib::llvm::{True, False, Bool}; use lib::llvm::{True, False, Bool};
use lib::llvm::{llvm}; use lib::llvm::llvm;
use lib; use lib;
use middle::lang_items::LangItem; use middle::lang_items::LangItem;
use middle::trans::base; use middle::trans::base;
@ -28,17 +28,17 @@ use middle::ty::substs;
use middle::ty; use middle::ty;
use middle::typeck; use middle::typeck;
use middle::borrowck::root_map_key; use middle::borrowck::root_map_key;
use util::ppaux::{Repr}; use util::ppaux::Repr;
use middle::trans::type_::Type; use middle::trans::type_::Type;
use std::c_str::ToCStr; use std::c_str::ToCStr;
use std::cast::transmute; use std::cast::transmute;
use std::cast; use std::cast;
use std::hashmap::{HashMap}; use std::hashmap::HashMap;
use std::libc::{c_uint, c_longlong, c_ulonglong, c_char}; use std::libc::{c_uint, c_longlong, c_ulonglong, c_char};
use std::vec; use std::vec;
use syntax::ast::{Name,Ident}; use syntax::ast::{Name, Ident};
use syntax::ast_map::{path, path_elt, path_pretty_name}; use syntax::ast_map::{path, path_elt, path_pretty_name};
use syntax::codemap::Span; use syntax::codemap::Span;
use syntax::parse::token; use syntax::parse::token;
@ -46,6 +46,25 @@ use syntax::{ast, ast_map};
pub use middle::trans::context::CrateContext; pub use middle::trans::context::CrateContext;
fn type_is_newtype_immediate(cx: ty::ctxt, ty: ty::t) -> bool {
match ty::get(ty).sty {
ty::ty_struct(def_id, ref substs) => {
let fields = ty::struct_fields(cx, def_id, substs);
fields.len() == 1 &&
fields[0].ident.name == token::special_idents::unnamed_field.name &&
type_is_immediate(cx, fields[0].mt.ty)
}
_ => false
}
}
pub fn type_is_immediate(cx: ty::ctxt, ty: ty::t) -> bool {
ty::type_is_scalar(ty) || ty::type_is_boxed(ty) ||
ty::type_is_unique(ty) || ty::type_is_region_ptr(ty) ||
type_is_newtype_immediate(cx, ty) ||
ty::type_is_simd(cx, ty)
}
pub fn gensym_name(name: &str) -> (Ident, path_elt) { pub fn gensym_name(name: &str) -> (Ident, path_elt) {
let name = token::gensym(name); let name = token::gensym(name);
let ident = Ident::new(name); let ident = Ident::new(name);

View File

@ -197,7 +197,7 @@ pub fn appropriate_mode(tcx: ty::ctxt, ty: ty::t) -> DatumMode {
if ty::type_is_voidish(ty) { if ty::type_is_voidish(ty) {
ByValue ByValue
} else if ty::type_is_immediate(tcx, ty) { } else if type_is_immediate(tcx, ty) {
ByValue ByValue
} else { } else {
ByRef(RevokeClean) ByRef(RevokeClean)
@ -667,7 +667,7 @@ impl Datum {
ByValue => { ByValue => {
// Actually, this case cannot happen right // Actually, this case cannot happen right
// now, because enums are never immediate. // now, because enums are never immediate.
assert!(ty::type_is_immediate(bcx.tcx(), ty)); assert!(type_is_immediate(bcx.tcx(), ty));
(Some(Datum {ty: ty, ..*self}), bcx) (Some(Datum {ty: ty, ..*self}), bcx)
} }
}; };
@ -699,7 +699,7 @@ impl Datum {
) )
} }
ByValue => { ByValue => {
assert!(ty::type_is_immediate(bcx.tcx(), ty)); assert!(type_is_immediate(bcx.tcx(), ty));
( (
Some(Datum { Some(Datum {
val: ExtractValue(bcx, self.val, 0), val: ExtractValue(bcx, self.val, 0),

View File

@ -77,19 +77,9 @@ pub fn drop_ty(cx: @mut Block, v: ValueRef, t: ty::t) -> @mut Block {
pub fn drop_ty_immediate(bcx: @mut Block, v: ValueRef, t: ty::t) -> @mut Block { pub fn drop_ty_immediate(bcx: @mut Block, v: ValueRef, t: ty::t) -> @mut Block {
let _icx = push_ctxt("drop_ty_immediate"); let _icx = push_ctxt("drop_ty_immediate");
match ty::get(t).sty { let vp = alloca(bcx, type_of(bcx.ccx(), t), "");
ty::ty_uniq(_) Store(bcx, v, vp);
| ty::ty_evec(_, ty::vstore_uniq) drop_ty(bcx, vp, t)
| ty::ty_estr(ty::vstore_uniq) => {
free_ty_immediate(bcx, v, t)
}
ty::ty_box(_) | ty::ty_opaque_box
| ty::ty_evec(_, ty::vstore_box)
| ty::ty_estr(ty::vstore_box) => {
decr_refcnt_maybe_free(bcx, v, None, t)
}
_ => bcx.tcx().sess.bug("drop_ty_immediate: non-box ty")
}
} }
pub fn free_ty(cx: @mut Block, v: ValueRef, t: ty::t) -> @mut Block { pub fn free_ty(cx: @mut Block, v: ValueRef, t: ty::t) -> @mut Block {

View File

@ -278,7 +278,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
"uninit" => { "uninit" => {
// Do nothing, this is effectively a no-op // Do nothing, this is effectively a no-op
let retty = substs.tys[0]; let retty = substs.tys[0];
if ty::type_is_immediate(ccx.tcx, retty) && !ty::type_is_nil(retty) { if type_is_immediate(ccx.tcx, retty) && !ty::type_is_nil(retty) {
unsafe { unsafe {
Ret(bcx, lib::llvm::llvm::LLVMGetUndef(type_of(ccx, retty).to_ref())); Ret(bcx, lib::llvm::llvm::LLVMGetUndef(type_of(ccx, retty).to_ref()));
} }
@ -316,7 +316,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
if !ty::type_is_voidish(out_type) { if !ty::type_is_voidish(out_type) {
let llsrcval = get_param(decl, first_real_arg); let llsrcval = get_param(decl, first_real_arg);
if ty::type_is_immediate(ccx.tcx, in_type) { if type_is_immediate(ccx.tcx, in_type) {
match fcx.llretptr { match fcx.llretptr {
Some(llretptr) => { Some(llretptr) => {
Store(bcx, llsrcval, PointerCast(bcx, llretptr, llintype.ptr_to())); Store(bcx, llsrcval, PointerCast(bcx, llretptr, llintype.ptr_to()));
@ -335,7 +335,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
} }
} }
} }
} else if ty::type_is_immediate(ccx.tcx, out_type) { } else if type_is_immediate(ccx.tcx, out_type) {
let llsrcptr = PointerCast(bcx, llsrcval, llouttype.ptr_to()); let llsrcptr = PointerCast(bcx, llsrcval, llouttype.ptr_to());
let ll_load = Load(bcx, llsrcptr); let ll_load = Load(bcx, llsrcptr);
Ret(bcx, ll_load); Ret(bcx, ll_load);

View File

@ -21,11 +21,11 @@ use syntax::ast;
use syntax::opt_vec; use syntax::opt_vec;
pub fn arg_is_indirect(ccx: &CrateContext, arg_ty: ty::t) -> bool { pub fn arg_is_indirect(ccx: &CrateContext, arg_ty: ty::t) -> bool {
!ty::type_is_immediate(ccx.tcx, arg_ty) !type_is_immediate(ccx.tcx, arg_ty)
} }
pub fn return_uses_outptr(tcx: ty::ctxt, ty: ty::t) -> bool { pub fn return_uses_outptr(tcx: ty::ctxt, ty: ty::t) -> bool {
!ty::type_is_immediate(tcx, ty) !type_is_immediate(tcx, ty)
} }
pub fn type_of_explicit_arg(ccx: &mut CrateContext, arg_ty: ty::t) -> Type { pub fn type_of_explicit_arg(ccx: &mut CrateContext, arg_ty: ty::t) -> Type {

View File

@ -1752,25 +1752,6 @@ pub fn type_is_scalar(ty: t) -> bool {
} }
} }
fn type_is_newtype_immediate(cx: ctxt, ty: t) -> bool {
match get(ty).sty {
ty_struct(def_id, ref substs) => {
let fields = struct_fields(cx, def_id, substs);
fields.len() == 1 &&
fields[0].ident.name == token::special_idents::unnamed_field.name &&
type_is_immediate(cx, fields[0].mt.ty)
}
_ => false
}
}
pub fn type_is_immediate(cx: ctxt, ty: t) -> bool {
return type_is_scalar(ty) || type_is_boxed(ty) ||
type_is_unique(ty) || type_is_region_ptr(ty) ||
type_is_newtype_immediate(cx, ty) ||
type_is_simd(cx, ty);
}
pub fn type_needs_drop(cx: ctxt, ty: t) -> bool { pub fn type_needs_drop(cx: ctxt, ty: t) -> bool {
type_contents(cx, ty).needs_drop(cx) type_contents(cx, ty).needs_drop(cx)
} }
@ -2538,6 +2519,13 @@ pub fn type_structurally_contains_uniques(cx: ctxt, ty: t) -> bool {
}); });
} }
pub fn type_is_trait(ty: t) -> bool {
match get(ty).sty {
ty_trait(*) => true,
_ => false
}
}
pub fn type_is_integral(ty: t) -> bool { pub fn type_is_integral(ty: t) -> bool {
match get(ty).sty { match get(ty).sty {
ty_infer(IntVar(_)) | ty_int(_) | ty_uint(_) => true, ty_infer(IntVar(_)) | ty_int(_) | ty_uint(_) => true,
@ -3289,10 +3277,10 @@ pub fn expr_kind(tcx: ctxt,
ast::ExprCast(*) => { ast::ExprCast(*) => {
match tcx.node_types.find(&(expr.id as uint)) { match tcx.node_types.find(&(expr.id as uint)) {
Some(&t) => { Some(&t) => {
if ty::type_is_immediate(tcx, t) { if type_is_trait(t) {
RvalueDatumExpr
} else {
RvalueDpsExpr RvalueDpsExpr
} else {
RvalueDatumExpr
} }
} }
None => { None => {

View File

@ -0,0 +1,38 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Wrapper(~str);
impl Wrapper {
pub fn new(wrapped: ~str) -> Wrapper {
Wrapper(wrapped)
}
pub fn say_hi(&self) {
println(fmt!("hello %s", **self));
}
}
impl Drop for Wrapper {
fn drop(&mut self) {}
}
pub fn main() {
{
// This runs without complaint.
let x = Wrapper::new(~"Bob");
x.say_hi();
}
{
// This fails to compile, circa 0.8-89-gc635fba.
// error: internal compiler error: drop_ty_immediate: non-box ty
Wrapper::new(~"Bob").say_hi();
}
}