Skip to content

Commit 0aedecf

Browse files
committed
add a temporary vector_exchange_malloc lang item
1 parent 7bf34c3 commit 0aedecf

File tree

6 files changed

+68
-42
lines changed

6 files changed

+68
-42
lines changed

src/librustc/middle/lang_items.rs

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -63,33 +63,34 @@ pub enum LangItem {
6363
FailFnLangItem, // 24
6464
FailBoundsCheckFnLangItem, // 25
6565
ExchangeMallocFnLangItem, // 26
66-
ClosureExchangeMallocFnLangItem, // 27
67-
ExchangeFreeFnLangItem, // 28
68-
MallocFnLangItem, // 29
69-
FreeFnLangItem, // 30
70-
BorrowAsImmFnLangItem, // 31
71-
BorrowAsMutFnLangItem, // 32
72-
ReturnToMutFnLangItem, // 33
73-
CheckNotBorrowedFnLangItem, // 34
74-
StrDupUniqFnLangItem, // 35
75-
RecordBorrowFnLangItem, // 36
76-
UnrecordBorrowFnLangItem, // 37
77-
78-
StartFnLangItem, // 38
79-
80-
TyDescStructLangItem, // 39
81-
TyVisitorTraitLangItem, // 40
82-
OpaqueStructLangItem, // 41
66+
VectorExchangeMallocFnLangItem, // 27
67+
ClosureExchangeMallocFnLangItem, // 28
68+
ExchangeFreeFnLangItem, // 29
69+
MallocFnLangItem, // 30
70+
FreeFnLangItem, // 31
71+
BorrowAsImmFnLangItem, // 32
72+
BorrowAsMutFnLangItem, // 33
73+
ReturnToMutFnLangItem, // 34
74+
CheckNotBorrowedFnLangItem, // 35
75+
StrDupUniqFnLangItem, // 36
76+
RecordBorrowFnLangItem, // 37
77+
UnrecordBorrowFnLangItem, // 38
78+
79+
StartFnLangItem, // 39
80+
81+
TyDescStructLangItem, // 40
82+
TyVisitorTraitLangItem, // 41
83+
OpaqueStructLangItem, // 42
8384
}
8485

8586
pub struct LanguageItems {
86-
items: [Option<def_id>, ..42]
87+
items: [Option<def_id>, ..43]
8788
}
8889

8990
impl LanguageItems {
9091
pub fn new() -> LanguageItems {
9192
LanguageItems {
92-
items: [ None, ..42 ]
93+
items: [ None, ..43 ]
9394
}
9495
}
9596

@@ -129,23 +130,24 @@ impl LanguageItems {
129130
24 => "fail_",
130131
25 => "fail_bounds_check",
131132
26 => "exchange_malloc",
132-
27 => "closure_exchange_malloc",
133-
28 => "exchange_free",
134-
29 => "malloc",
135-
30 => "free",
136-
31 => "borrow_as_imm",
137-
32 => "borrow_as_mut",
138-
33 => "return_to_mut",
139-
34 => "check_not_borrowed",
140-
35 => "strdup_uniq",
141-
36 => "record_borrow",
142-
37 => "unrecord_borrow",
143-
144-
38 => "start",
145-
146-
39 => "ty_desc",
147-
40 => "ty_visitor",
148-
41 => "opaque",
133+
27 => "vector_exchange_malloc",
134+
28 => "closure_exchange_malloc",
135+
29 => "exchange_free",
136+
30 => "malloc",
137+
31 => "free",
138+
32 => "borrow_as_imm",
139+
33 => "borrow_as_mut",
140+
34 => "return_to_mut",
141+
35 => "check_not_borrowed",
142+
36 => "strdup_uniq",
143+
37 => "record_borrow",
144+
38 => "unrecord_borrow",
145+
146+
39 => "start",
147+
148+
40 => "ty_desc",
149+
41 => "ty_visitor",
150+
42 => "opaque",
149151

150152
_ => "???"
151153
}
@@ -238,6 +240,9 @@ impl LanguageItems {
238240
pub fn exchange_malloc_fn(&self) -> def_id {
239241
self.items[ExchangeMallocFnLangItem as uint].get()
240242
}
243+
pub fn vector_exchange_malloc_fn(&self) -> def_id {
244+
self.items[VectorExchangeMallocFnLangItem as uint].get()
245+
}
241246
pub fn closure_exchange_malloc_fn(&self) -> def_id {
242247
self.items[ClosureExchangeMallocFnLangItem as uint].get()
243248
}
@@ -331,6 +336,7 @@ impl<'self> LanguageItemCollector<'self> {
331336
item_refs.insert(@"fail_bounds_check",
332337
FailBoundsCheckFnLangItem as uint);
333338
item_refs.insert(@"exchange_malloc", ExchangeMallocFnLangItem as uint);
339+
item_refs.insert(@"vector_exchange_malloc", VectorExchangeMallocFnLangItem as uint);
334340
item_refs.insert(@"closure_exchange_malloc", ClosureExchangeMallocFnLangItem as uint);
335341
item_refs.insert(@"exchange_free", ExchangeFreeFnLangItem as uint);
336342
item_refs.insert(@"malloc", MallocFnLangItem as uint);

src/librustc/middle/trans/base.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,15 @@ pub fn malloc_raw_dyn(bcx: block,
296296
heap_exchange => {
297297
(ty::mk_imm_uniq, bcx.tcx().lang_items.exchange_malloc_fn())
298298
}
299+
heap_exchange_vector => {
300+
(ty::mk_imm_uniq, bcx.tcx().lang_items.vector_exchange_malloc_fn())
301+
}
299302
heap_exchange_closure => {
300303
(ty::mk_imm_uniq, bcx.tcx().lang_items.closure_exchange_malloc_fn())
301304
}
302305
};
303306

304-
if heap == heap_exchange {
307+
if heap == heap_exchange || heap == heap_exchange_vector {
305308
// Grab the TypeRef type of box_ptr_ty.
306309
let box_ptr_ty = mk_fn(bcx.tcx(), t);
307310
let llty = type_of(ccx, box_ptr_ty);

src/librustc/middle/trans/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ pub enum heap {
274274
heap_managed,
275275
heap_managed_unique,
276276
heap_exchange,
277+
heap_exchange_vector,
277278
heap_exchange_closure
278279
}
279280

@@ -395,7 +396,7 @@ pub fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
395396
let f: @fn(block) -> block = |a| glue::trans_free(a, ptr);
396397
f
397398
}
398-
heap_exchange | heap_exchange_closure => {
399+
heap_exchange | heap_exchange_vector | heap_exchange_closure => {
399400
let f: @fn(block) -> block = |a| glue::trans_exchange_free(a, ptr);
400401
f
401402
}

src/librustc/middle/trans/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ fn trans_rvalue_datum_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
464464
expr, contents);
465465
}
466466
ast::expr_vstore(contents, ast::expr_vstore_uniq) => {
467-
let heap = heap_for_unique(bcx, expr_ty(bcx, contents));
467+
let heap = tvec::heap_for_unique_vector(bcx, expr_ty(bcx, contents));
468468
return tvec::trans_uniq_or_managed_vstore(bcx, heap,
469469
expr, contents);
470470
}

src/librustc/middle/trans/tvec.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,17 @@ pub fn alloc_raw(bcx: block, unit_ty: ty::t,
9595
return rslt(bcx, bx);
9696
}
9797

98+
pub fn heap_for_unique_vector(bcx: block, t: ty::t) -> heap {
99+
if ty::type_contents(bcx.tcx(), t).contains_managed() {
100+
heap_managed_unique
101+
} else {
102+
heap_exchange_vector
103+
}
104+
}
105+
98106
pub fn alloc_uniq_raw(bcx: block, unit_ty: ty::t,
99107
fill: ValueRef, alloc: ValueRef) -> Result {
100-
alloc_raw(bcx, unit_ty, fill, alloc, base::heap_for_unique(bcx, unit_ty))
108+
alloc_raw(bcx, unit_ty, fill, alloc, heap_for_unique_vector(bcx, unit_ty))
101109
}
102110

103111
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
298306

299307
// Handle ~"".
300308
match heap {
301-
heap_exchange => {
309+
heap_exchange_vector => {
302310
match content_expr.node {
303311
ast::expr_lit(@codemap::spanned {
304312
node: ast::lit_str(s), _
@@ -321,7 +329,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
321329
_ => {}
322330
}
323331
}
324-
heap_exchange_closure => fail!("vectors are not allocated with closure_exchange_alloc"),
332+
heap_exchange | heap_exchange_closure => fail!("vectors use vector_exchange_alloc"),
325333
heap_managed | heap_managed_unique => {}
326334
}
327335

src/libstd/rt/global_heap.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ pub unsafe fn exchange_malloc(align: u32, size: uintptr_t) -> *c_char {
8585
malloc_raw(total_size as uint) as *c_char
8686
}
8787

88+
#[cfg(not(test))]
89+
#[lang="vector_exchange_malloc"]
90+
#[inline]
91+
pub unsafe fn vector_exchange_malloc(align: u32, size: uintptr_t) -> *c_char {
92+
let total_size = get_box_size(size as uint, align as uint);
93+
malloc_raw(total_size as uint) as *c_char
94+
}
95+
8896
// FIXME: #7496
8997
#[cfg(not(test))]
9098
#[lang="closure_exchange_malloc"]

0 commit comments

Comments
 (0)