add a temporary vector_exchange_malloc lang item
This commit is contained in:
parent
7bf34c3437
commit
0aedecf96b
6 changed files with 64 additions and 38 deletions
|
@ -63,33 +63,34 @@ pub enum LangItem {
|
|||
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
|
||||
VectorExchangeMallocFnLangItem, // 27
|
||||
ClosureExchangeMallocFnLangItem, // 28
|
||||
ExchangeFreeFnLangItem, // 29
|
||||
MallocFnLangItem, // 30
|
||||
FreeFnLangItem, // 31
|
||||
BorrowAsImmFnLangItem, // 32
|
||||
BorrowAsMutFnLangItem, // 33
|
||||
ReturnToMutFnLangItem, // 34
|
||||
CheckNotBorrowedFnLangItem, // 35
|
||||
StrDupUniqFnLangItem, // 36
|
||||
RecordBorrowFnLangItem, // 37
|
||||
UnrecordBorrowFnLangItem, // 38
|
||||
|
||||
StartFnLangItem, // 38
|
||||
StartFnLangItem, // 39
|
||||
|
||||
TyDescStructLangItem, // 39
|
||||
TyVisitorTraitLangItem, // 40
|
||||
OpaqueStructLangItem, // 41
|
||||
TyDescStructLangItem, // 40
|
||||
TyVisitorTraitLangItem, // 41
|
||||
OpaqueStructLangItem, // 42
|
||||
}
|
||||
|
||||
pub struct LanguageItems {
|
||||
items: [Option<def_id>, ..42]
|
||||
items: [Option<def_id>, ..43]
|
||||
}
|
||||
|
||||
impl LanguageItems {
|
||||
pub fn new() -> LanguageItems {
|
||||
LanguageItems {
|
||||
items: [ None, ..42 ]
|
||||
items: [ None, ..43 ]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,23 +130,24 @@ impl LanguageItems {
|
|||
24 => "fail_",
|
||||
25 => "fail_bounds_check",
|
||||
26 => "exchange_malloc",
|
||||
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",
|
||||
27 => "vector_exchange_malloc",
|
||||
28 => "closure_exchange_malloc",
|
||||
29 => "exchange_free",
|
||||
30 => "malloc",
|
||||
31 => "free",
|
||||
32 => "borrow_as_imm",
|
||||
33 => "borrow_as_mut",
|
||||
34 => "return_to_mut",
|
||||
35 => "check_not_borrowed",
|
||||
36 => "strdup_uniq",
|
||||
37 => "record_borrow",
|
||||
38 => "unrecord_borrow",
|
||||
|
||||
38 => "start",
|
||||
39 => "start",
|
||||
|
||||
39 => "ty_desc",
|
||||
40 => "ty_visitor",
|
||||
41 => "opaque",
|
||||
40 => "ty_desc",
|
||||
41 => "ty_visitor",
|
||||
42 => "opaque",
|
||||
|
||||
_ => "???"
|
||||
}
|
||||
|
@ -238,6 +240,9 @@ impl LanguageItems {
|
|||
pub fn exchange_malloc_fn(&self) -> def_id {
|
||||
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 {
|
||||
self.items[ClosureExchangeMallocFnLangItem as uint].get()
|
||||
}
|
||||
|
@ -331,6 +336,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(@"vector_exchange_malloc", VectorExchangeMallocFnLangItem 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);
|
||||
|
|
|
@ -296,12 +296,15 @@ pub fn malloc_raw_dyn(bcx: block,
|
|||
heap_exchange => {
|
||||
(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 => {
|
||||
(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.
|
||||
let box_ptr_ty = mk_fn(bcx.tcx(), t);
|
||||
let llty = type_of(ccx, box_ptr_ty);
|
||||
|
|
|
@ -274,6 +274,7 @@ pub enum heap {
|
|||
heap_managed,
|
||||
heap_managed_unique,
|
||||
heap_exchange,
|
||||
heap_exchange_vector,
|
||||
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);
|
||||
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);
|
||||
f
|
||||
}
|
||||
|
|
|
@ -464,7 +464,7 @@ fn trans_rvalue_datum_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
|
|||
expr, contents);
|
||||
}
|
||||
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,
|
||||
expr, contents);
|
||||
}
|
||||
|
|
|
@ -95,9 +95,17 @@ pub fn alloc_raw(bcx: block, unit_ty: ty::t,
|
|||
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,
|
||||
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,
|
||||
|
@ -298,7 +306,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
|
|||
|
||||
// Handle ~"".
|
||||
match heap {
|
||||
heap_exchange => {
|
||||
heap_exchange_vector => {
|
||||
match content_expr.node {
|
||||
ast::expr_lit(@codemap::spanned {
|
||||
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 => {}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
#[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
|
||||
#[cfg(not(test))]
|
||||
#[lang="closure_exchange_malloc"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue