1
Fork 0

add a temporary vector_exchange_malloc lang item

This commit is contained in:
Daniel Micay 2013-07-02 19:24:58 -04:00
parent 7bf34c3437
commit 0aedecf96b
6 changed files with 64 additions and 38 deletions

View file

@ -63,33 +63,34 @@ pub enum LangItem {
FailFnLangItem, // 24 FailFnLangItem, // 24
FailBoundsCheckFnLangItem, // 25 FailBoundsCheckFnLangItem, // 25
ExchangeMallocFnLangItem, // 26 ExchangeMallocFnLangItem, // 26
ClosureExchangeMallocFnLangItem, // 27 VectorExchangeMallocFnLangItem, // 27
ExchangeFreeFnLangItem, // 28 ClosureExchangeMallocFnLangItem, // 28
MallocFnLangItem, // 29 ExchangeFreeFnLangItem, // 29
FreeFnLangItem, // 30 MallocFnLangItem, // 30
BorrowAsImmFnLangItem, // 31 FreeFnLangItem, // 31
BorrowAsMutFnLangItem, // 32 BorrowAsImmFnLangItem, // 32
ReturnToMutFnLangItem, // 33 BorrowAsMutFnLangItem, // 33
CheckNotBorrowedFnLangItem, // 34 ReturnToMutFnLangItem, // 34
StrDupUniqFnLangItem, // 35 CheckNotBorrowedFnLangItem, // 35
RecordBorrowFnLangItem, // 36 StrDupUniqFnLangItem, // 36
UnrecordBorrowFnLangItem, // 37 RecordBorrowFnLangItem, // 37
UnrecordBorrowFnLangItem, // 38
StartFnLangItem, // 38 StartFnLangItem, // 39
TyDescStructLangItem, // 39 TyDescStructLangItem, // 40
TyVisitorTraitLangItem, // 40 TyVisitorTraitLangItem, // 41
OpaqueStructLangItem, // 41 OpaqueStructLangItem, // 42
} }
pub struct LanguageItems { pub struct LanguageItems {
items: [Option<def_id>, ..42] items: [Option<def_id>, ..43]
} }
impl LanguageItems { impl LanguageItems {
pub fn new() -> LanguageItems { pub fn new() -> LanguageItems {
LanguageItems { LanguageItems {
items: [ None, ..42 ] items: [ None, ..43 ]
} }
} }
@ -129,23 +130,24 @@ impl LanguageItems {
24 => "fail_", 24 => "fail_",
25 => "fail_bounds_check", 25 => "fail_bounds_check",
26 => "exchange_malloc", 26 => "exchange_malloc",
27 => "closure_exchange_malloc", 27 => "vector_exchange_malloc",
28 => "exchange_free", 28 => "closure_exchange_malloc",
29 => "malloc", 29 => "exchange_free",
30 => "free", 30 => "malloc",
31 => "borrow_as_imm", 31 => "free",
32 => "borrow_as_mut", 32 => "borrow_as_imm",
33 => "return_to_mut", 33 => "borrow_as_mut",
34 => "check_not_borrowed", 34 => "return_to_mut",
35 => "strdup_uniq", 35 => "check_not_borrowed",
36 => "record_borrow", 36 => "strdup_uniq",
37 => "unrecord_borrow", 37 => "record_borrow",
38 => "unrecord_borrow",
38 => "start", 39 => "start",
39 => "ty_desc", 40 => "ty_desc",
40 => "ty_visitor", 41 => "ty_visitor",
41 => "opaque", 42 => "opaque",
_ => "???" _ => "???"
} }
@ -238,6 +240,9 @@ impl LanguageItems {
pub fn exchange_malloc_fn(&self) -> def_id { pub fn exchange_malloc_fn(&self) -> def_id {
self.items[ExchangeMallocFnLangItem as uint].get() self.items[ExchangeMallocFnLangItem as uint].get()
} }
pub fn vector_exchange_malloc_fn(&self) -> def_id {
self.items[VectorExchangeMallocFnLangItem as uint].get()
}
pub fn closure_exchange_malloc_fn(&self) -> def_id { pub fn closure_exchange_malloc_fn(&self) -> def_id {
self.items[ClosureExchangeMallocFnLangItem as uint].get() self.items[ClosureExchangeMallocFnLangItem as uint].get()
} }
@ -331,6 +336,7 @@ impl<'self> LanguageItemCollector<'self> {
item_refs.insert(@"fail_bounds_check", item_refs.insert(@"fail_bounds_check",
FailBoundsCheckFnLangItem as uint); FailBoundsCheckFnLangItem as uint);
item_refs.insert(@"exchange_malloc", ExchangeMallocFnLangItem as uint); item_refs.insert(@"exchange_malloc", ExchangeMallocFnLangItem as uint);
item_refs.insert(@"vector_exchange_malloc", VectorExchangeMallocFnLangItem as uint);
item_refs.insert(@"closure_exchange_malloc", ClosureExchangeMallocFnLangItem as uint); item_refs.insert(@"closure_exchange_malloc", ClosureExchangeMallocFnLangItem as uint);
item_refs.insert(@"exchange_free", ExchangeFreeFnLangItem as uint); item_refs.insert(@"exchange_free", ExchangeFreeFnLangItem as uint);
item_refs.insert(@"malloc", MallocFnLangItem as uint); item_refs.insert(@"malloc", MallocFnLangItem as uint);

View file

@ -296,12 +296,15 @@ pub fn malloc_raw_dyn(bcx: block,
heap_exchange => { heap_exchange => {
(ty::mk_imm_uniq, bcx.tcx().lang_items.exchange_malloc_fn()) (ty::mk_imm_uniq, bcx.tcx().lang_items.exchange_malloc_fn())
} }
heap_exchange_vector => {
(ty::mk_imm_uniq, bcx.tcx().lang_items.vector_exchange_malloc_fn())
}
heap_exchange_closure => { heap_exchange_closure => {
(ty::mk_imm_uniq, bcx.tcx().lang_items.closure_exchange_malloc_fn()) (ty::mk_imm_uniq, bcx.tcx().lang_items.closure_exchange_malloc_fn())
} }
}; };
if heap == heap_exchange { if heap == heap_exchange || heap == heap_exchange_vector {
// Grab the TypeRef type of box_ptr_ty. // Grab the TypeRef type of box_ptr_ty.
let box_ptr_ty = mk_fn(bcx.tcx(), t); let box_ptr_ty = mk_fn(bcx.tcx(), t);
let llty = type_of(ccx, box_ptr_ty); let llty = type_of(ccx, box_ptr_ty);

View file

@ -274,6 +274,7 @@ pub enum heap {
heap_managed, heap_managed,
heap_managed_unique, heap_managed_unique,
heap_exchange, heap_exchange,
heap_exchange_vector,
heap_exchange_closure heap_exchange_closure
} }
@ -395,7 +396,7 @@ pub fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
let f: @fn(block) -> block = |a| glue::trans_free(a, ptr); let f: @fn(block) -> block = |a| glue::trans_free(a, ptr);
f f
} }
heap_exchange | heap_exchange_closure => { heap_exchange | heap_exchange_vector | heap_exchange_closure => {
let f: @fn(block) -> block = |a| glue::trans_exchange_free(a, ptr); let f: @fn(block) -> block = |a| glue::trans_exchange_free(a, ptr);
f f
} }

View file

@ -464,7 +464,7 @@ fn trans_rvalue_datum_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
expr, contents); expr, contents);
} }
ast::expr_vstore(contents, ast::expr_vstore_uniq) => { ast::expr_vstore(contents, ast::expr_vstore_uniq) => {
let heap = heap_for_unique(bcx, expr_ty(bcx, contents)); let heap = tvec::heap_for_unique_vector(bcx, expr_ty(bcx, contents));
return tvec::trans_uniq_or_managed_vstore(bcx, heap, return tvec::trans_uniq_or_managed_vstore(bcx, heap,
expr, contents); expr, contents);
} }

View file

@ -95,9 +95,17 @@ pub fn alloc_raw(bcx: block, unit_ty: ty::t,
return rslt(bcx, bx); return rslt(bcx, bx);
} }
pub fn heap_for_unique_vector(bcx: block, t: ty::t) -> heap {
if ty::type_contents(bcx.tcx(), t).contains_managed() {
heap_managed_unique
} else {
heap_exchange_vector
}
}
pub fn alloc_uniq_raw(bcx: block, unit_ty: ty::t, pub fn alloc_uniq_raw(bcx: block, unit_ty: ty::t,
fill: ValueRef, alloc: ValueRef) -> Result { fill: ValueRef, alloc: ValueRef) -> Result {
alloc_raw(bcx, unit_ty, fill, alloc, base::heap_for_unique(bcx, unit_ty)) alloc_raw(bcx, unit_ty, fill, alloc, heap_for_unique_vector(bcx, unit_ty))
} }
pub fn alloc_vec(bcx: block, pub fn alloc_vec(bcx: block,
@ -298,7 +306,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
// Handle ~"". // Handle ~"".
match heap { match heap {
heap_exchange => { heap_exchange_vector => {
match content_expr.node { match content_expr.node {
ast::expr_lit(@codemap::spanned { ast::expr_lit(@codemap::spanned {
node: ast::lit_str(s), _ node: ast::lit_str(s), _
@ -321,7 +329,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_exchange | heap_exchange_closure => fail!("vectors use vector_exchange_alloc"),
heap_managed | heap_managed_unique => {} heap_managed | heap_managed_unique => {}
} }

View file

@ -85,6 +85,14 @@ pub unsafe fn exchange_malloc(align: u32, size: uintptr_t) -> *c_char {
malloc_raw(total_size as uint) as *c_char malloc_raw(total_size as uint) as *c_char
} }
#[cfg(not(test))]
#[lang="vector_exchange_malloc"]
#[inline]
pub unsafe fn vector_exchange_malloc(align: u32, size: uintptr_t) -> *c_char {
let total_size = get_box_size(size as uint, align as uint);
malloc_raw(total_size as uint) as *c_char
}
// FIXME: #7496 // FIXME: #7496
#[cfg(not(test))] #[cfg(not(test))]
#[lang="closure_exchange_malloc"] #[lang="closure_exchange_malloc"]