add a closure_exchange_malloc lang item
this makes the exchange allocation header completely unused, and leaves it uninitialized
This commit is contained in:
parent
45e2582e09
commit
4a29d6eb3f
6 changed files with 93 additions and 63 deletions
|
|
@ -33,63 +33,64 @@ use syntax::visit::visit_crate;
|
|||
use core::hashmap::HashMap;
|
||||
|
||||
pub enum LangItem {
|
||||
FreezeTraitLangItem, // 0
|
||||
CopyTraitLangItem, // 1
|
||||
SendTraitLangItem, // 2
|
||||
SizedTraitLangItem, // 3
|
||||
FreezeTraitLangItem, // 0
|
||||
CopyTraitLangItem, // 1
|
||||
SendTraitLangItem, // 2
|
||||
SizedTraitLangItem, // 3
|
||||
|
||||
DropTraitLangItem, // 4
|
||||
DropTraitLangItem, // 4
|
||||
|
||||
AddTraitLangItem, // 5
|
||||
SubTraitLangItem, // 6
|
||||
MulTraitLangItem, // 7
|
||||
DivTraitLangItem, // 8
|
||||
RemTraitLangItem, // 9
|
||||
NegTraitLangItem, // 10
|
||||
NotTraitLangItem, // 11
|
||||
BitXorTraitLangItem, // 11
|
||||
BitAndTraitLangItem, // 13
|
||||
BitOrTraitLangItem, // 14
|
||||
ShlTraitLangItem, // 15
|
||||
ShrTraitLangItem, // 16
|
||||
IndexTraitLangItem, // 17
|
||||
AddTraitLangItem, // 5
|
||||
SubTraitLangItem, // 6
|
||||
MulTraitLangItem, // 7
|
||||
DivTraitLangItem, // 8
|
||||
RemTraitLangItem, // 9
|
||||
NegTraitLangItem, // 10
|
||||
NotTraitLangItem, // 11
|
||||
BitXorTraitLangItem, // 11
|
||||
BitAndTraitLangItem, // 13
|
||||
BitOrTraitLangItem, // 14
|
||||
ShlTraitLangItem, // 15
|
||||
ShrTraitLangItem, // 16
|
||||
IndexTraitLangItem, // 17
|
||||
|
||||
EqTraitLangItem, // 18
|
||||
OrdTraitLangItem, // 19
|
||||
EqTraitLangItem, // 18
|
||||
OrdTraitLangItem, // 19
|
||||
|
||||
StrEqFnLangItem, // 20
|
||||
UniqStrEqFnLangItem, // 21
|
||||
AnnihilateFnLangItem, // 22
|
||||
LogTypeFnLangItem, // 23
|
||||
FailFnLangItem, // 24
|
||||
FailBoundsCheckFnLangItem, // 25
|
||||
ExchangeMallocFnLangItem, // 26
|
||||
ExchangeFreeFnLangItem, // 27
|
||||
MallocFnLangItem, // 28
|
||||
FreeFnLangItem, // 29
|
||||
BorrowAsImmFnLangItem, // 30
|
||||
BorrowAsMutFnLangItem, // 31
|
||||
ReturnToMutFnLangItem, // 32
|
||||
CheckNotBorrowedFnLangItem, // 33
|
||||
StrDupUniqFnLangItem, // 34
|
||||
RecordBorrowFnLangItem, // 35
|
||||
UnrecordBorrowFnLangItem, // 36
|
||||
StrEqFnLangItem, // 20
|
||||
UniqStrEqFnLangItem, // 21
|
||||
AnnihilateFnLangItem, // 22
|
||||
LogTypeFnLangItem, // 23
|
||||
FailFnLangItem, // 24
|
||||
FailBoundsCheckFnLangItem, // 25
|
||||
ExchangeMallocFnLangItem, // 26
|
||||
ClosureExchangeMallocFnLangItem, // 27
|
||||
ExchangeFreeFnLangItem, // 28
|
||||
MallocFnLangItem, // 29
|
||||
FreeFnLangItem, // 30
|
||||
BorrowAsImmFnLangItem, // 31
|
||||
BorrowAsMutFnLangItem, // 32
|
||||
ReturnToMutFnLangItem, // 33
|
||||
CheckNotBorrowedFnLangItem, // 34
|
||||
StrDupUniqFnLangItem, // 35
|
||||
RecordBorrowFnLangItem, // 36
|
||||
UnrecordBorrowFnLangItem, // 37
|
||||
|
||||
StartFnLangItem, // 37
|
||||
StartFnLangItem, // 38
|
||||
|
||||
TyDescStructLangItem, // 38
|
||||
TyVisitorTraitLangItem, // 39
|
||||
OpaqueStructLangItem, // 40
|
||||
TyDescStructLangItem, // 39
|
||||
TyVisitorTraitLangItem, // 40
|
||||
OpaqueStructLangItem, // 41
|
||||
}
|
||||
|
||||
pub struct LanguageItems {
|
||||
items: [Option<def_id>, ..41]
|
||||
items: [Option<def_id>, ..42]
|
||||
}
|
||||
|
||||
impl LanguageItems {
|
||||
pub fn new() -> LanguageItems {
|
||||
LanguageItems {
|
||||
items: [ None, ..41 ]
|
||||
items: [ None, ..42 ]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -129,22 +130,23 @@ impl LanguageItems {
|
|||
24 => "fail_",
|
||||
25 => "fail_bounds_check",
|
||||
26 => "exchange_malloc",
|
||||
27 => "exchange_free",
|
||||
28 => "malloc",
|
||||
29 => "free",
|
||||
30 => "borrow_as_imm",
|
||||
31 => "borrow_as_mut",
|
||||
32 => "return_to_mut",
|
||||
33 => "check_not_borrowed",
|
||||
34 => "strdup_uniq",
|
||||
35 => "record_borrow",
|
||||
36 => "unrecord_borrow",
|
||||
27 => "closure_exchange_malloc",
|
||||
28 => "exchange_free",
|
||||
29 => "malloc",
|
||||
30 => "free",
|
||||
31 => "borrow_as_imm",
|
||||
32 => "borrow_as_mut",
|
||||
33 => "return_to_mut",
|
||||
34 => "check_not_borrowed",
|
||||
35 => "strdup_uniq",
|
||||
36 => "record_borrow",
|
||||
37 => "unrecord_borrow",
|
||||
|
||||
37 => "start",
|
||||
38 => "start",
|
||||
|
||||
38 => "ty_desc",
|
||||
39 => "ty_visitor",
|
||||
40 => "opaque",
|
||||
39 => "ty_desc",
|
||||
40 => "ty_visitor",
|
||||
41 => "opaque",
|
||||
|
||||
_ => "???"
|
||||
}
|
||||
|
|
@ -237,6 +239,9 @@ impl LanguageItems {
|
|||
pub fn exchange_malloc_fn(&self) -> def_id {
|
||||
self.items[ExchangeMallocFnLangItem as uint].get()
|
||||
}
|
||||
pub fn closure_exchange_malloc_fn(&self) -> def_id {
|
||||
self.items[ClosureExchangeMallocFnLangItem as uint].get()
|
||||
}
|
||||
pub fn exchange_free_fn(&self) -> def_id {
|
||||
self.items[ExchangeFreeFnLangItem as uint].get()
|
||||
}
|
||||
|
|
@ -327,6 +332,7 @@ impl<'self> LanguageItemCollector<'self> {
|
|||
item_refs.insert(@"fail_bounds_check",
|
||||
FailBoundsCheckFnLangItem as uint);
|
||||
item_refs.insert(@"exchange_malloc", ExchangeMallocFnLangItem as uint);
|
||||
item_refs.insert(@"closure_exchange_malloc", ClosureExchangeMallocFnLangItem as uint);
|
||||
item_refs.insert(@"exchange_free", ExchangeFreeFnLangItem as uint);
|
||||
item_refs.insert(@"malloc", MallocFnLangItem as uint);
|
||||
item_refs.insert(@"free", FreeFnLangItem as uint);
|
||||
|
|
|
|||
|
|
@ -254,6 +254,9 @@ pub fn malloc_raw_dyn(bcx: block,
|
|||
heap_exchange => {
|
||||
(ty::mk_imm_uniq, bcx.tcx().lang_items.exchange_malloc_fn())
|
||||
}
|
||||
heap_exchange_closure => {
|
||||
(ty::mk_imm_uniq, bcx.tcx().lang_items.closure_exchange_malloc_fn())
|
||||
}
|
||||
};
|
||||
|
||||
// Grab the TypeRef type of box_ptr_ty.
|
||||
|
|
|
|||
|
|
@ -160,6 +160,14 @@ pub fn mk_closure_tys(tcx: ty::ctxt,
|
|||
return cdata_ty;
|
||||
}
|
||||
|
||||
fn heap_for_unique_closure(bcx: block, t: ty::t) -> heap {
|
||||
if ty::type_contents(bcx.tcx(), t).contains_managed() {
|
||||
heap_managed_unique
|
||||
} else {
|
||||
heap_exchange_closure
|
||||
}
|
||||
}
|
||||
|
||||
pub fn allocate_cbox(bcx: block, sigil: ast::Sigil, cdata_ty: ty::t)
|
||||
-> Result {
|
||||
let _icx = push_ctxt("closure::allocate_cbox");
|
||||
|
|
@ -182,7 +190,7 @@ pub fn allocate_cbox(bcx: block, sigil: ast::Sigil, cdata_ty: ty::t)
|
|||
malloc_raw(bcx, cdata_ty, heap_managed)
|
||||
}
|
||||
ast::OwnedSigil => {
|
||||
malloc_raw(bcx, cdata_ty, heap_for_unique(bcx, cdata_ty))
|
||||
malloc_raw(bcx, cdata_ty, heap_for_unique_closure(bcx, cdata_ty))
|
||||
}
|
||||
ast::BorrowedSigil => {
|
||||
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
|
||||
|
|
@ -486,9 +494,6 @@ pub fn make_closure_glue(
|
|||
}
|
||||
}
|
||||
|
||||
// note: unique pointers no longer copy the type descriptor in the take glue,
|
||||
// so we cannot delegate to the unique box take glue here without copying it
|
||||
// ourselves
|
||||
pub fn make_opaque_cbox_take_glue(
|
||||
bcx: block,
|
||||
sigil: ast::Sigil,
|
||||
|
|
@ -530,7 +535,7 @@ pub fn make_opaque_cbox_take_glue(
|
|||
let rval = alloca(bcx, Type::i8p());
|
||||
let bcx = callee::trans_lang_call(
|
||||
bcx,
|
||||
bcx.tcx().lang_items.exchange_malloc_fn(),
|
||||
bcx.tcx().lang_items.closure_exchange_malloc_fn(),
|
||||
[opaque_tydesc, sz],
|
||||
expr::SaveIn(rval));
|
||||
let cbox_out = PointerCast(bcx, Load(bcx, rval), llopaquecboxty);
|
||||
|
|
|
|||
|
|
@ -276,6 +276,7 @@ pub enum heap {
|
|||
heap_managed,
|
||||
heap_managed_unique,
|
||||
heap_exchange,
|
||||
heap_exchange_closure
|
||||
}
|
||||
|
||||
#[deriving(Eq)]
|
||||
|
|
@ -385,7 +386,7 @@ pub fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
|
|||
let f: @fn(block) -> block = |a| glue::trans_free(a, ptr);
|
||||
f
|
||||
}
|
||||
heap_exchange => {
|
||||
heap_exchange | heap_exchange_closure => {
|
||||
let f: @fn(block) -> block = |a| glue::trans_exchange_free(a, ptr);
|
||||
f
|
||||
}
|
||||
|
|
|
|||
|
|
@ -321,6 +321,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
|
|||
_ => {}
|
||||
}
|
||||
}
|
||||
heap_exchange_closure => fail!("vectors are not allocated with closure_exchange_alloc"),
|
||||
heap_managed | heap_managed_unique => {}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,6 +72,20 @@ pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
|
|||
|
||||
assert!(td.is_not_null());
|
||||
|
||||
let total_size = get_box_size(size, (*td).align);
|
||||
malloc_raw(total_size as uint) as *c_char
|
||||
}
|
||||
|
||||
// FIXME: #7496
|
||||
#[cfg(not(test))]
|
||||
#[lang="closure_exchange_malloc"]
|
||||
#[inline]
|
||||
pub unsafe fn closure_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
|
||||
let td = td as *TyDesc;
|
||||
let size = size as uint;
|
||||
|
||||
assert!(td.is_not_null());
|
||||
|
||||
let total_size = get_box_size(size, (*td).align);
|
||||
let p = malloc_raw(total_size as uint);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue