@@ -289,21 +289,25 @@ pub fn malloc_raw_dyn(bcx: block,
289
289
let _icx = push_ctxt ( "malloc_raw" ) ;
290
290
let ccx = bcx. ccx ( ) ;
291
291
292
- let ( mk_fn, langcall) = match heap {
293
- heap_managed | heap_managed_unique => {
294
- ( ty:: mk_imm_box, bcx. tcx ( ) . lang_items . malloc_fn ( ) )
295
- }
296
- heap_exchange => {
297
- ( ty:: mk_imm_uniq, bcx. tcx ( ) . lang_items . exchange_malloc_fn ( ) )
298
- }
299
- heap_exchange_closure => {
300
- ( ty:: mk_imm_uniq, bcx. tcx ( ) . lang_items . closure_exchange_malloc_fn ( ) )
301
- }
302
- } ;
303
-
304
292
if heap == heap_exchange {
293
+ let llty_value = type_of:: type_of ( ccx, t) ;
294
+ let llalign = llalign_of_min ( ccx, llty_value) ;
295
+
296
+ // Allocate space:
297
+ let rval = alloca ( bcx, Type :: i8p ( ) ) ;
298
+ let bcx = callee:: trans_lang_call (
299
+ bcx,
300
+ bcx. tcx ( ) . lang_items . exchange_malloc_fn ( ) ,
301
+ [ C_i32 ( llalign as i32 ) , size] ,
302
+ expr:: SaveIn ( rval) ) ;
303
+ rslt ( bcx, PointerCast ( bcx, Load ( bcx, rval) , llty_value. ptr_to ( ) ) )
304
+ } else if heap == heap_exchange_vector {
305
305
// Grab the TypeRef type of box_ptr_ty.
306
- let box_ptr_ty = mk_fn ( bcx. tcx ( ) , t) ;
306
+ let element_type = match ty:: get ( t) . sty {
307
+ ty:: ty_unboxed_vec( e) => e,
308
+ _ => fail ! ( "not a vector body" )
309
+ } ;
310
+ let box_ptr_ty = ty:: mk_evec ( bcx. tcx ( ) , element_type, ty:: vstore_uniq) ;
307
311
let llty = type_of ( ccx, box_ptr_ty) ;
308
312
309
313
let llty_value = type_of:: type_of ( ccx, t) ;
@@ -313,11 +317,22 @@ pub fn malloc_raw_dyn(bcx: block,
313
317
let rval = alloca ( bcx, Type :: i8p ( ) ) ;
314
318
let bcx = callee:: trans_lang_call (
315
319
bcx,
316
- langcall ,
320
+ bcx . tcx ( ) . lang_items . vector_exchange_malloc_fn ( ) ,
317
321
[ C_i32 ( llalign as i32 ) , size] ,
318
322
expr:: SaveIn ( rval) ) ;
319
323
rslt ( bcx, PointerCast ( bcx, Load ( bcx, rval) , llty) )
320
324
} else {
325
+ // we treat ~fn, @fn and @[] as @ here, which isn't ideal
326
+ let ( mk_fn, langcall) = match heap {
327
+ heap_managed | heap_managed_unique => {
328
+ ( ty:: mk_imm_box, bcx. tcx ( ) . lang_items . malloc_fn ( ) )
329
+ }
330
+ heap_exchange_closure => {
331
+ ( ty:: mk_imm_box, bcx. tcx ( ) . lang_items . closure_exchange_malloc_fn ( ) )
332
+ }
333
+ _ => fail ! ( "heap_exchange/heap_exchange_vector already handled" )
334
+ } ;
335
+
321
336
// Grab the TypeRef type of box_ptr_ty.
322
337
let box_ptr_ty = mk_fn ( bcx. tcx ( ) , t) ;
323
338
let llty = type_of ( ccx, box_ptr_ty) ;
@@ -359,16 +374,17 @@ pub struct MallocResult {
359
374
// and pulls out the body
360
375
pub fn malloc_general_dyn ( bcx : block , t : ty:: t , heap : heap , size : ValueRef )
361
376
-> MallocResult {
377
+ assert ! ( heap != heap_exchange) ;
362
378
let _icx = push_ctxt ( "malloc_general" ) ;
363
379
let Result { bcx : bcx, val : llbox} = malloc_raw_dyn ( bcx, t, heap, size) ;
364
380
let body = GEPi ( bcx, llbox, [ 0 u, abi:: box_field_body] ) ;
365
381
366
382
MallocResult { bcx : bcx, box : llbox, body : body }
367
383
}
368
384
369
- pub fn malloc_general ( bcx : block , t : ty:: t , heap : heap )
370
- -> MallocResult {
371
- let ty = type_of ( bcx . ccx ( ) , t ) ;
385
+ pub fn malloc_general ( bcx : block , t : ty:: t , heap : heap ) -> MallocResult {
386
+ let ty = type_of ( bcx . ccx ( ) , t ) ;
387
+ assert ! ( heap != heap_exchange ) ;
372
388
malloc_general_dyn ( bcx, t, heap, llsize_of ( bcx. ccx ( ) , ty) )
373
389
}
374
390
pub fn malloc_boxed ( bcx : block , t : ty:: t )
@@ -385,6 +401,7 @@ pub fn heap_for_unique(bcx: block, t: ty::t) -> heap {
385
401
}
386
402
387
403
pub fn maybe_set_managed_unique_rc ( bcx : block , bx : ValueRef , heap : heap ) {
404
+ assert ! ( heap != heap_exchange) ;
388
405
if heap == heap_managed_unique {
389
406
// In cases where we are looking at a unique-typed allocation in the
390
407
// managed heap (thus have refcount 1 from the managed allocator),
@@ -396,11 +413,6 @@ pub fn maybe_set_managed_unique_rc(bcx: block, bx: ValueRef, heap: heap) {
396
413
}
397
414
}
398
415
399
- pub fn malloc_unique ( bcx : block , t : ty:: t )
400
- -> MallocResult {
401
- malloc_general ( bcx, t, heap_for_unique ( bcx, t) )
402
- }
403
-
404
416
// Type descriptor and type glue stuff
405
417
406
418
pub fn get_tydesc_simple ( ccx : & mut CrateContext , t : ty:: t ) -> ValueRef {
0 commit comments