]> git.lizzy.rs Git - rust.git/commitdiff
remove the closure_exchange_malloc lang item
authorDaniel Micay <danielmicay@gmail.com>
Mon, 15 Sep 2014 20:31:32 +0000 (16:31 -0400)
committerDaniel Micay <danielmicay@gmail.com>
Mon, 15 Sep 2014 22:16:33 +0000 (18:16 -0400)
src/liballoc/heap.rs
src/librustc/middle/lang_items.rs
src/librustc/middle/trans/base.rs
src/librustc/middle/trans/closure.rs
src/librustc/middle/trans/glue.rs
src/librustc_back/abi.rs

index b6c255e79306644b667b1bdedc518ec291c000f9..f1780b07271ec93d563c7eeca601229fffcf2b70 100644 (file)
@@ -10,7 +10,7 @@
 
 // FIXME: #13996: mark the `allocate` and `reallocate` return value as `noalias`
 
-#[cfg(not(test))] use core::raw;
+#[cfg(stage0, not(test))] use core::raw;
 #[cfg(stage0, not(test))] use util;
 
 /// Returns a pointer to `size` bytes of memory.
@@ -111,7 +111,6 @@ unsafe fn exchange_free(ptr: *mut u8, size: uint, align: uint) {
     deallocate(ptr, size, align);
 }
 
-// FIXME: #7496
 #[cfg(stage0, not(test))]
 #[lang="closure_exchange_malloc"]
 #[inline]
@@ -127,21 +126,6 @@ unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint,
     alloc as *mut u8
 }
 
-// FIXME: #7496
-#[cfg(not(stage0), not(test))]
-#[lang="closure_exchange_malloc"]
-#[inline]
-#[allow(deprecated)]
-unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint,
-                                  align: uint) -> *mut u8 {
-    let p = allocate(size, align);
-
-    let alloc = p as *mut raw::Box<()>;
-    (*alloc).drop_glue = drop_glue;
-
-    alloc as *mut u8
-}
-
 // The minimum alignment guaranteed by the architecture. This value is used to
 // add fast paths for low alignment values. In practice, the alignment is a
 // constant at the call site and the branch will be optimized out.
index 24782240f06c4d3a58b30a24e11bfcf8188f4837..507ba3e9d5bf6132f1014718b3d47b8750c309d3 100644 (file)
@@ -265,7 +265,6 @@ pub fn collect_language_items(krate: &ast::Crate,
     BeginUnwindLangItem,             "begin_unwind",            begin_unwind;
 
     ExchangeMallocFnLangItem,        "exchange_malloc",         exchange_malloc_fn;
-    ClosureExchangeMallocFnLangItem, "closure_exchange_malloc", closure_exchange_malloc_fn;
     ExchangeFreeFnLangItem,          "exchange_free",           exchange_free_fn;
     MallocFnLangItem,                "malloc",                  malloc_fn;
     FreeFnLangItem,                  "free",                    free_fn;
index e86df8651187062424549effdec85d27e1f9b621..5187ecb8b3bc8ca47d0d8f8f137e295a9a2701ff 100644 (file)
@@ -383,14 +383,10 @@ 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::t, alloc_fn: LangItem)
-                                       -> Result<'blk, 'tcx> {
+pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: ty::t) -> Result<'blk, 'tcx> {
     let _icx = push_ctxt("malloc_raw_dyn_proc");
     let ccx = bcx.ccx();
 
-    let langcall = require_alloc_fn(bcx, t, alloc_fn);
-
     // Grab the TypeRef type of ptr_ty.
     let ptr_ty = ty::mk_uniq(bcx.tcx(), t);
     let ptr_llty = type_of(ccx, ptr_ty);
@@ -399,18 +395,15 @@ pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
     let size = llsize_of(bcx.ccx(), llty);
     let llalign = C_uint(ccx, llalign_of_min(bcx.ccx(), llty) as uint);
 
-    // Allocate space:
-    let drop_glue = glue::get_drop_glue(ccx, ty::mk_uniq(bcx.tcx(), t));
-    let r = callee::trans_lang_call(
-        bcx,
-        langcall,
-        [
-            PointerCast(bcx, drop_glue, Type::glue_fn(ccx, Type::i8p(ccx)).ptr_to()),
-            size,
-            llalign
-        ],
-        None);
-    Result::new(r.bcx, PointerCast(r.bcx, r.val, ptr_llty))
+    // Allocate space and store the destructor pointer:
+    let Result {bcx: 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)
 }
 
 
index 7bbdf332fe11f20b843062c003d394bb14b8b9d7..2fac6e80ba085b83b8649b72ec7b4d77a4ec9501 100644 (file)
@@ -15,7 +15,6 @@
 use llvm::ValueRef;
 use middle::def;
 use middle::freevars;
-use middle::lang_items::ClosureExchangeMallocFnLangItem;
 use middle::trans::adt;
 use middle::trans::base::*;
 use middle::trans::build::*;
@@ -146,7 +145,7 @@ fn allocate_cbox<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
     let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
     match store {
         ty::UniqTraitStore => {
-            malloc_raw_dyn_proc(bcx, cbox_ty, ClosureExchangeMallocFnLangItem)
+            malloc_raw_dyn_proc(bcx, cbox_ty)
         }
         ty::RegionTraitStore(..) => {
             let llbox = alloc_ty(bcx, cbox_ty, "__closure");
index 259f85098afee14ff9feec007d8f8b569c5c3b51..fa2b192615d878990dfdf1c40ca54ec1085668df 100644 (file)
@@ -519,7 +519,7 @@ fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, t: ty::t)
             let env_ptr_ty = Type::at_box(bcx.ccx(), Type::i8(bcx.ccx())).ptr_to();
             let env = PointerCast(bcx, env, env_ptr_ty);
             with_cond(bcx, IsNotNull(bcx, env), |bcx| {
-                let dtor_ptr = GEPi(bcx, env, [0u, abi::box_field_tydesc]);
+                let dtor_ptr = GEPi(bcx, env, [0u, abi::box_field_drop_glue]);
                 let dtor = Load(bcx, dtor_ptr);
                 Call(bcx, dtor, [PointerCast(bcx, box_cell_v, Type::i8p(bcx.ccx()))], None);
                 bcx
index e859a5d21d7e75095a8520ac975cf2855bc67644..72acba542460cc94280db8c246f5ddcf3ac75c69 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 pub static box_field_refcnt: uint = 0u;
-pub static box_field_tydesc: uint = 1u;
+pub static box_field_drop_glue: uint = 1u;
 pub static box_field_body: uint = 4u;
 
 pub static tydesc_field_visit_glue: uint = 3u;