Skip to content

Commit 4a29d6e

Browse files
committed
add a closure_exchange_malloc lang item
this makes the exchange allocation header completely unused, and leaves it uninitialized
1 parent 45e2582 commit 4a29d6e

File tree

6 files changed

+101
-71
lines changed

6 files changed

+101
-71
lines changed

src/librustc/middle/lang_items.rs

Lines changed: 71 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -33,63 +33,64 @@ use syntax::visit::visit_crate;
3333
use core::hashmap::HashMap;
3434

3535
pub enum LangItem {
36-
FreezeTraitLangItem, // 0
37-
CopyTraitLangItem, // 1
38-
SendTraitLangItem, // 2
39-
SizedTraitLangItem, // 3
40-
41-
DropTraitLangItem, // 4
42-
43-
AddTraitLangItem, // 5
44-
SubTraitLangItem, // 6
45-
MulTraitLangItem, // 7
46-
DivTraitLangItem, // 8
47-
RemTraitLangItem, // 9
48-
NegTraitLangItem, // 10
49-
NotTraitLangItem, // 11
50-
BitXorTraitLangItem, // 11
51-
BitAndTraitLangItem, // 13
52-
BitOrTraitLangItem, // 14
53-
ShlTraitLangItem, // 15
54-
ShrTraitLangItem, // 16
55-
IndexTraitLangItem, // 17
56-
57-
EqTraitLangItem, // 18
58-
OrdTraitLangItem, // 19
59-
60-
StrEqFnLangItem, // 20
61-
UniqStrEqFnLangItem, // 21
62-
AnnihilateFnLangItem, // 22
63-
LogTypeFnLangItem, // 23
64-
FailFnLangItem, // 24
65-
FailBoundsCheckFnLangItem, // 25
66-
ExchangeMallocFnLangItem, // 26
67-
ExchangeFreeFnLangItem, // 27
68-
MallocFnLangItem, // 28
69-
FreeFnLangItem, // 29
70-
BorrowAsImmFnLangItem, // 30
71-
BorrowAsMutFnLangItem, // 31
72-
ReturnToMutFnLangItem, // 32
73-
CheckNotBorrowedFnLangItem, // 33
74-
StrDupUniqFnLangItem, // 34
75-
RecordBorrowFnLangItem, // 35
76-
UnrecordBorrowFnLangItem, // 36
77-
78-
StartFnLangItem, // 37
79-
80-
TyDescStructLangItem, // 38
81-
TyVisitorTraitLangItem, // 39
82-
OpaqueStructLangItem, // 40
36+
FreezeTraitLangItem, // 0
37+
CopyTraitLangItem, // 1
38+
SendTraitLangItem, // 2
39+
SizedTraitLangItem, // 3
40+
41+
DropTraitLangItem, // 4
42+
43+
AddTraitLangItem, // 5
44+
SubTraitLangItem, // 6
45+
MulTraitLangItem, // 7
46+
DivTraitLangItem, // 8
47+
RemTraitLangItem, // 9
48+
NegTraitLangItem, // 10
49+
NotTraitLangItem, // 11
50+
BitXorTraitLangItem, // 11
51+
BitAndTraitLangItem, // 13
52+
BitOrTraitLangItem, // 14
53+
ShlTraitLangItem, // 15
54+
ShrTraitLangItem, // 16
55+
IndexTraitLangItem, // 17
56+
57+
EqTraitLangItem, // 18
58+
OrdTraitLangItem, // 19
59+
60+
StrEqFnLangItem, // 20
61+
UniqStrEqFnLangItem, // 21
62+
AnnihilateFnLangItem, // 22
63+
LogTypeFnLangItem, // 23
64+
FailFnLangItem, // 24
65+
FailBoundsCheckFnLangItem, // 25
66+
ExchangeMallocFnLangItem, // 26
67+
ClosureExchangeMallocFnLangItem, // 27
68+
ExchangeFreeFnLangItem, // 28
69+
MallocFnLangItem, // 29
70+
FreeFnLangItem, // 30
71+
BorrowAsImmFnLangItem, // 31
72+
BorrowAsMutFnLangItem, // 32
73+
ReturnToMutFnLangItem, // 33
74+
CheckNotBorrowedFnLangItem, // 34
75+
StrDupUniqFnLangItem, // 35
76+
RecordBorrowFnLangItem, // 36
77+
UnrecordBorrowFnLangItem, // 37
78+
79+
StartFnLangItem, // 38
80+
81+
TyDescStructLangItem, // 39
82+
TyVisitorTraitLangItem, // 40
83+
OpaqueStructLangItem, // 41
8384
}
8485

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

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

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

149151
_ => "???"
150152
}
@@ -237,6 +239,9 @@ impl LanguageItems {
237239
pub fn exchange_malloc_fn(&self) -> def_id {
238240
self.items[ExchangeMallocFnLangItem as uint].get()
239241
}
242+
pub fn closure_exchange_malloc_fn(&self) -> def_id {
243+
self.items[ClosureExchangeMallocFnLangItem as uint].get()
244+
}
240245
pub fn exchange_free_fn(&self) -> def_id {
241246
self.items[ExchangeFreeFnLangItem as uint].get()
242247
}
@@ -327,6 +332,7 @@ impl<'self> LanguageItemCollector<'self> {
327332
item_refs.insert(@"fail_bounds_check",
328333
FailBoundsCheckFnLangItem as uint);
329334
item_refs.insert(@"exchange_malloc", ExchangeMallocFnLangItem as uint);
335+
item_refs.insert(@"closure_exchange_malloc", ClosureExchangeMallocFnLangItem as uint);
330336
item_refs.insert(@"exchange_free", ExchangeFreeFnLangItem as uint);
331337
item_refs.insert(@"malloc", MallocFnLangItem as uint);
332338
item_refs.insert(@"free", FreeFnLangItem as uint);

src/librustc/middle/trans/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ pub fn malloc_raw_dyn(bcx: block,
254254
heap_exchange => {
255255
(ty::mk_imm_uniq, bcx.tcx().lang_items.exchange_malloc_fn())
256256
}
257+
heap_exchange_closure => {
258+
(ty::mk_imm_uniq, bcx.tcx().lang_items.closure_exchange_malloc_fn())
259+
}
257260
};
258261

259262
// Grab the TypeRef type of box_ptr_ty.

src/librustc/middle/trans/closure.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ pub fn mk_closure_tys(tcx: ty::ctxt,
160160
return cdata_ty;
161161
}
162162

163+
fn heap_for_unique_closure(bcx: block, t: ty::t) -> heap {
164+
if ty::type_contents(bcx.tcx(), t).contains_managed() {
165+
heap_managed_unique
166+
} else {
167+
heap_exchange_closure
168+
}
169+
}
170+
163171
pub fn allocate_cbox(bcx: block, sigil: ast::Sigil, cdata_ty: ty::t)
164172
-> Result {
165173
let _icx = push_ctxt("closure::allocate_cbox");
@@ -182,7 +190,7 @@ pub fn allocate_cbox(bcx: block, sigil: ast::Sigil, cdata_ty: ty::t)
182190
malloc_raw(bcx, cdata_ty, heap_managed)
183191
}
184192
ast::OwnedSigil => {
185-
malloc_raw(bcx, cdata_ty, heap_for_unique(bcx, cdata_ty))
193+
malloc_raw(bcx, cdata_ty, heap_for_unique_closure(bcx, cdata_ty))
186194
}
187195
ast::BorrowedSigil => {
188196
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
@@ -486,9 +494,6 @@ pub fn make_closure_glue(
486494
}
487495
}
488496

489-
// note: unique pointers no longer copy the type descriptor in the take glue,
490-
// so we cannot delegate to the unique box take glue here without copying it
491-
// ourselves
492497
pub fn make_opaque_cbox_take_glue(
493498
bcx: block,
494499
sigil: ast::Sigil,
@@ -530,7 +535,7 @@ pub fn make_opaque_cbox_take_glue(
530535
let rval = alloca(bcx, Type::i8p());
531536
let bcx = callee::trans_lang_call(
532537
bcx,
533-
bcx.tcx().lang_items.exchange_malloc_fn(),
538+
bcx.tcx().lang_items.closure_exchange_malloc_fn(),
534539
[opaque_tydesc, sz],
535540
expr::SaveIn(rval));
536541
let cbox_out = PointerCast(bcx, Load(bcx, rval), llopaquecboxty);

src/librustc/middle/trans/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ pub enum heap {
276276
heap_managed,
277277
heap_managed_unique,
278278
heap_exchange,
279+
heap_exchange_closure
279280
}
280281

281282
#[deriving(Eq)]
@@ -385,7 +386,7 @@ pub fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
385386
let f: @fn(block) -> block = |a| glue::trans_free(a, ptr);
386387
f
387388
}
388-
heap_exchange => {
389+
heap_exchange | heap_exchange_closure => {
389390
let f: @fn(block) -> block = |a| glue::trans_exchange_free(a, ptr);
390391
f
391392
}

src/librustc/middle/trans/tvec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
321321
_ => {}
322322
}
323323
}
324+
heap_exchange_closure => fail!("vectors are not allocated with closure_exchange_alloc"),
324325
heap_managed | heap_managed_unique => {}
325326
}
326327

src/libstd/rt/global_heap.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
7272

7373
assert!(td.is_not_null());
7474

75+
let total_size = get_box_size(size, (*td).align);
76+
malloc_raw(total_size as uint) as *c_char
77+
}
78+
79+
// FIXME: #7496
80+
#[cfg(not(test))]
81+
#[lang="closure_exchange_malloc"]
82+
#[inline]
83+
pub unsafe fn closure_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
84+
let td = td as *TyDesc;
85+
let size = size as uint;
86+
87+
assert!(td.is_not_null());
88+
7589
let total_size = get_box_size(size, (*td).align);
7690
let p = malloc_raw(total_size as uint);
7791

0 commit comments

Comments
 (0)