diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index dd5809730d6..295d09f83bb 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -55,7 +55,7 @@ use trans::cleanup::CleanupMethods; use trans::cleanup; use trans::closure; use trans::common::{Block, C_bool, C_bytes_in_context, C_i32, C_integral}; -use trans::common::{C_null, C_struct_in_context, C_u64, C_u8, C_uint, C_undef}; +use trans::common::{C_null, C_struct_in_context, C_u64, C_u8, C_undef}; use trans::common::{CrateContext, ExternMap, FunctionContext}; use trans::common::{NodeInfo, Result}; use trans::common::{node_id_type, return_type_is_void}; @@ -73,7 +73,7 @@ use trans::glue; use trans::inline; use trans::intrinsic; use trans::machine; -use trans::machine::{llsize_of, llsize_of_real, llalign_of_min}; +use trans::machine::{llsize_of, llsize_of_real}; use trans::meth; use trans::monomorphize; use trans::tvec; @@ -394,30 +394,6 @@ pub fn malloc_raw_dyn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, Result::new(r.bcx, PointerCast(r.bcx, r.val, llty_ptr)) } -pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>) - -> Result<'blk, 'tcx> { - let _icx = push_ctxt("malloc_raw_dyn_proc"); - let ccx = bcx.ccx(); - - // Grab the TypeRef type of ptr_ty. - let ptr_ty = ty::mk_uniq(bcx.tcx(), t); - let ptr_llty = type_of(ccx, ptr_ty); - - let llty = type_of(bcx.ccx(), t); - let size = llsize_of(bcx.ccx(), llty); - let llalign = C_uint(ccx, llalign_of_min(bcx.ccx(), llty)); - - // Allocate space and store the destructor pointer: - let Result {bcx, val: llbox} = malloc_raw_dyn(bcx, ptr_llty, t, size, llalign); - let dtor_ptr = GEPi(bcx, llbox, &[0u, abi::BOX_FIELD_DROP_GLUE]); - let drop_glue_field_ty = type_of(ccx, ty::mk_nil_ptr(bcx.tcx())); - let drop_glue = PointerCast(bcx, glue::get_drop_glue(ccx, ty::mk_uniq(bcx.tcx(), t)), - drop_glue_field_ty); - Store(bcx, drop_glue, dtor_ptr); - - Result::new(bcx, llbox) -} - // Type descriptor and type glue stuff pub fn get_tydesc<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, diff --git a/src/librustc_trans/trans/closure.rs b/src/librustc_trans/trans/closure.rs index 0ae9de8c891..f3f8be4efb2 100644 --- a/src/librustc_trans/trans/closure.rs +++ b/src/librustc_trans/trans/closure.rs @@ -137,26 +137,6 @@ fn tuplify_box_ty<'tcx>(tcx: &ty::ctxt<'tcx>, t: Ty<'tcx>) -> Ty<'tcx> { ty::mk_tup(tcx, vec!(ty::mk_uint(), ty::mk_nil_ptr(tcx), ptr, ptr, t)) } -fn allocate_cbox<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - store: ty::TraitStore, - cdata_ty: Ty<'tcx>) - -> Result<'blk, 'tcx> { - let _icx = push_ctxt("closure::allocate_cbox"); - let tcx = bcx.tcx(); - - // Allocate and initialize the box: - let cbox_ty = tuplify_box_ty(tcx, cdata_ty); - match store { - ty::UniqTraitStore => { - malloc_raw_dyn_proc(bcx, cbox_ty) - } - ty::RegionTraitStore(..) => { - let llbox = alloc_ty(bcx, cbox_ty, "__closure"); - Result::new(bcx, llbox) - } - } -} - pub struct ClosureResult<'blk, 'tcx: 'blk> { llbox: ValueRef, // llvalue of ptr to closure cdata_ty: Ty<'tcx>, // type of the closure data @@ -168,8 +148,7 @@ pub struct ClosureResult<'blk, 'tcx: 'blk> { // heap allocated closure that copies the upvars into environment. // Otherwise, it is stack allocated and copies pointers to the upvars. pub fn store_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, - bound_values: Vec> , - store: ty::TraitStore) + bound_values: Vec>) -> ClosureResult<'blk, 'tcx> { let _icx = push_ctxt("closure::store_environment"); let ccx = bcx.ccx(); @@ -193,7 +172,7 @@ pub fn store_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } // allocate closure in the heap - let Result {bcx, val: llbox} = allocate_cbox(bcx, store, cdata_ty); + let llbox = alloc_ty(bcx, cbox_ty, "__closure"); let llbox = PointerCast(bcx, llbox, llboxptr_ty); debug!("tuplify_box_ty = {}", ty_to_string(tcx, cbox_ty)); @@ -227,8 +206,7 @@ pub fn store_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // collects the upvars and packages them up for store_environment. fn build_closure<'blk, 'tcx>(bcx0: Block<'blk, 'tcx>, freevar_mode: ast::CaptureClause, - freevars: &Vec, - store: ty::TraitStore) + freevars: &Vec) -> ClosureResult<'blk, 'tcx> { let _icx = push_ctxt("closure::build_closure"); @@ -242,7 +220,7 @@ fn build_closure<'blk, 'tcx>(bcx0: Block<'blk, 'tcx>, env_vals.push(EnvValue {action: freevar_mode, datum: datum}); } - store_environment(bcx, env_vals, store) + store_environment(bcx, env_vals) } // Given an enclosing block context, a new function context, a closure type, @@ -456,7 +434,7 @@ pub fn trans_expr_fn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, llbox, cdata_ty, bcx - } = build_closure(bcx, freevar_mode, &freevars, store); + } = build_closure(bcx, freevar_mode, &freevars); trans_closure(ccx, decl,