Skip to content

Commit d206f05

Browse files
committed
remove the closure_exchange_malloc lang item
1 parent 84b3737 commit d206f05

File tree

6 files changed

+14
-39
lines changed

6 files changed

+14
-39
lines changed

src/liballoc/heap.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// FIXME: #13996: mark the `allocate` and `reallocate` return value as `noalias`
1212

13-
#[cfg(not(test))] use core::raw;
13+
#[cfg(stage0, not(test))] use core::raw;
1414
#[cfg(stage0, not(test))] use util;
1515

1616
/// Returns a pointer to `size` bytes of memory.
@@ -111,7 +111,6 @@ unsafe fn exchange_free(ptr: *mut u8, size: uint, align: uint) {
111111
deallocate(ptr, size, align);
112112
}
113113

114-
// FIXME: #7496
115114
#[cfg(stage0, not(test))]
116115
#[lang="closure_exchange_malloc"]
117116
#[inline]
@@ -127,21 +126,6 @@ unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint,
127126
alloc as *mut u8
128127
}
129128

130-
// FIXME: #7496
131-
#[cfg(not(stage0), not(test))]
132-
#[lang="closure_exchange_malloc"]
133-
#[inline]
134-
#[allow(deprecated)]
135-
unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint,
136-
align: uint) -> *mut u8 {
137-
let p = allocate(size, align);
138-
139-
let alloc = p as *mut raw::Box<()>;
140-
(*alloc).drop_glue = drop_glue;
141-
142-
alloc as *mut u8
143-
}
144-
145129
// The minimum alignment guaranteed by the architecture. This value is used to
146130
// add fast paths for low alignment values. In practice, the alignment is a
147131
// constant at the call site and the branch will be optimized out.

src/librustc/middle/lang_items.rs

-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ lets_do_this! {
265265
BeginUnwindLangItem, "begin_unwind", begin_unwind;
266266

267267
ExchangeMallocFnLangItem, "exchange_malloc", exchange_malloc_fn;
268-
ClosureExchangeMallocFnLangItem, "closure_exchange_malloc", closure_exchange_malloc_fn;
269268
ExchangeFreeFnLangItem, "exchange_free", exchange_free_fn;
270269
MallocFnLangItem, "malloc", malloc_fn;
271270
FreeFnLangItem, "free", free_fn;

src/librustc/middle/trans/base.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,10 @@ pub fn malloc_raw_dyn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
383383
Result::new(r.bcx, PointerCast(r.bcx, r.val, llty_ptr))
384384
}
385385

386-
pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
387-
t: ty::t, alloc_fn: LangItem)
388-
-> Result<'blk, 'tcx> {
386+
pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: ty::t) -> Result<'blk, 'tcx> {
389387
let _icx = push_ctxt("malloc_raw_dyn_proc");
390388
let ccx = bcx.ccx();
391389

392-
let langcall = require_alloc_fn(bcx, t, alloc_fn);
393-
394390
// Grab the TypeRef type of ptr_ty.
395391
let ptr_ty = ty::mk_uniq(bcx.tcx(), t);
396392
let ptr_llty = type_of(ccx, ptr_ty);
@@ -399,18 +395,15 @@ pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
399395
let size = llsize_of(bcx.ccx(), llty);
400396
let llalign = C_uint(ccx, llalign_of_min(bcx.ccx(), llty) as uint);
401397

402-
// Allocate space:
403-
let drop_glue = glue::get_drop_glue(ccx, ty::mk_uniq(bcx.tcx(), t));
404-
let r = callee::trans_lang_call(
405-
bcx,
406-
langcall,
407-
[
408-
PointerCast(bcx, drop_glue, Type::glue_fn(ccx, Type::i8p(ccx)).ptr_to()),
409-
size,
410-
llalign
411-
],
412-
None);
413-
Result::new(r.bcx, PointerCast(r.bcx, r.val, ptr_llty))
398+
// Allocate space and store the destructor pointer:
399+
let Result {bcx: bcx, val: llbox} = malloc_raw_dyn(bcx, ptr_llty, t, size, llalign);
400+
let dtor_ptr = GEPi(bcx, llbox, [0u, abi::box_field_drop_glue]);
401+
let drop_glue_field_ty = type_of(ccx, ty::mk_nil_ptr(bcx.tcx()));
402+
let drop_glue = PointerCast(bcx, glue::get_drop_glue(ccx, ty::mk_uniq(bcx.tcx(), t)),
403+
drop_glue_field_ty);
404+
Store(bcx, drop_glue, dtor_ptr);
405+
406+
Result::new(bcx, llbox)
414407
}
415408

416409

src/librustc/middle/trans/closure.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use driver::config::FullDebugInfo;
1515
use llvm::ValueRef;
1616
use middle::def;
1717
use middle::freevars;
18-
use middle::lang_items::ClosureExchangeMallocFnLangItem;
1918
use middle::trans::adt;
2019
use middle::trans::base::*;
2120
use middle::trans::build::*;
@@ -146,7 +145,7 @@ fn allocate_cbox<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
146145
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
147146
match store {
148147
ty::UniqTraitStore => {
149-
malloc_raw_dyn_proc(bcx, cbox_ty, ClosureExchangeMallocFnLangItem)
148+
malloc_raw_dyn_proc(bcx, cbox_ty)
150149
}
151150
ty::RegionTraitStore(..) => {
152151
let llbox = alloc_ty(bcx, cbox_ty, "__closure");

src/librustc/middle/trans/glue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, t: ty::t)
519519
let env_ptr_ty = Type::at_box(bcx.ccx(), Type::i8(bcx.ccx())).ptr_to();
520520
let env = PointerCast(bcx, env, env_ptr_ty);
521521
with_cond(bcx, IsNotNull(bcx, env), |bcx| {
522-
let dtor_ptr = GEPi(bcx, env, [0u, abi::box_field_tydesc]);
522+
let dtor_ptr = GEPi(bcx, env, [0u, abi::box_field_drop_glue]);
523523
let dtor = Load(bcx, dtor_ptr);
524524
Call(bcx, dtor, [PointerCast(bcx, box_cell_v, Type::i8p(bcx.ccx()))], None);
525525
bcx

src/librustc_back/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
pub static box_field_refcnt: uint = 0u;
12-
pub static box_field_tydesc: uint = 1u;
12+
pub static box_field_drop_glue: uint = 1u;
1313
pub static box_field_body: uint = 4u;
1414

1515
pub static tydesc_field_visit_glue: uint = 3u;

0 commit comments

Comments
 (0)