@@ -37,7 +37,6 @@ use lib;
3737use metadata:: { csearch, encoder} ;
3838use middle:: astencode;
3939use middle:: lang_items:: { LangItem , ExchangeMallocFnLangItem , StartFnLangItem } ;
40- use middle:: lang_items:: { MallocFnLangItem , ClosureExchangeMallocFnLangItem } ;
4140use middle:: trans:: _match;
4241use middle:: trans:: adt;
4342use middle:: trans:: build:: * ;
@@ -336,111 +335,64 @@ pub fn at_box_body(bcx: &Block, body_t: ty::t, boxptr: ValueRef) -> ValueRef {
336335 GEPi ( bcx, boxptr, [ 0 u, abi:: box_field_body] )
337336}
338337
339- // malloc_raw_dyn: allocates a box to contain a given type, but with a
340- // potentially dynamic size.
341- pub fn malloc_raw_dyn < ' a > (
342- bcx : & ' a Block < ' a > ,
343- t : ty:: t ,
344- heap : heap ,
345- size : ValueRef )
346- -> Result < ' a > {
347- let _icx = push_ctxt ( "malloc_raw" ) ;
348- let ccx = bcx. ccx ( ) ;
349-
350- fn require_alloc_fn ( bcx : & Block , t : ty:: t , it : LangItem ) -> ast:: DefId {
351- let li = & bcx. tcx ( ) . lang_items ;
352- match li. require ( it) {
353- Ok ( id) => id,
354- Err ( s) => {
355- bcx. sess ( ) . fatal ( format ! ( "allocation of `{}` {}" ,
356- bcx. ty_to_str( t) , s) ) ;
357- }
338+ fn require_alloc_fn ( bcx : & Block , info_ty : ty:: t , it : LangItem ) -> ast:: DefId {
339+ match bcx. tcx ( ) . lang_items . require ( it) {
340+ Ok ( id) => id,
341+ Err ( s) => {
342+ bcx. sess ( ) . fatal ( format ! ( "allocation of `{}` {}" ,
343+ bcx. ty_to_str( info_ty) , s) ) ;
358344 }
359345 }
346+ }
360347
361- if heap == heap_exchange {
362- let llty_value = type_of:: type_of ( ccx, t) ;
363-
364- // Allocate space:
365- let r = callee:: trans_lang_call (
366- bcx,
367- require_alloc_fn ( bcx, t, ExchangeMallocFnLangItem ) ,
368- [ size] ,
369- None ) ;
370- rslt ( r. bcx , PointerCast ( r. bcx , r. val , llty_value. ptr_to ( ) ) )
371- } else {
372- // we treat ~fn as @ here, which isn't ideal
373- let langcall = match heap {
374- heap_managed => {
375- require_alloc_fn ( bcx, t, MallocFnLangItem )
376- }
377- heap_exchange_closure => {
378- require_alloc_fn ( bcx, t, ClosureExchangeMallocFnLangItem )
379- }
380- _ => fail ! ( "heap_exchange already handled" )
381- } ;
348+ // The following malloc_raw_dyn* functions allocate a box to contain
349+ // a given type, but with a potentially dynamic size.
382350
383- // Grab the TypeRef type of box_ptr_ty.
384- let box_ptr_ty = ty:: mk_box ( bcx. tcx ( ) , t) ;
385- let llty = type_of ( ccx, box_ptr_ty) ;
386- let llalign = C_uint ( ccx, llalign_of_min ( ccx, llty) as uint ) ;
387-
388- // Allocate space:
389- let drop_glue = glue:: get_drop_glue ( ccx, t) ;
390- let r = callee:: trans_lang_call (
391- bcx,
392- langcall,
393- [
394- PointerCast ( bcx, drop_glue, Type :: glue_fn ( ccx, Type :: i8p ( ccx) ) . ptr_to ( ) ) ,
395- size,
396- llalign
397- ] ,
398- None ) ;
399- rslt ( r. bcx , PointerCast ( r. bcx , r. val , llty) )
400- }
401- }
402-
403- // malloc_raw: expects an unboxed type and returns a pointer to
404- // enough space for a box of that type. This includes a rust_opaque_box
405- // header.
406- pub fn malloc_raw < ' a > ( bcx : & ' a Block < ' a > , t : ty:: t , heap : heap )
407- -> Result < ' a > {
408- let ty = type_of ( bcx. ccx ( ) , t) ;
409- let size = llsize_of ( bcx. ccx ( ) , ty) ;
410- malloc_raw_dyn ( bcx, t, heap, size)
411- }
412-
413- pub struct MallocResult < ' a > {
414- pub bcx : & ' a Block < ' a > ,
415- pub smart_ptr : ValueRef ,
416- pub body : ValueRef
417- }
418-
419- // malloc_general_dyn: usefully wraps malloc_raw_dyn; allocates a smart
420- // pointer, and pulls out the body
421- pub fn malloc_general_dyn < ' a > (
422- bcx : & ' a Block < ' a > ,
423- t : ty:: t ,
424- heap : heap ,
351+ pub fn malloc_raw_dyn < ' a > ( bcx : & ' a Block < ' a > ,
352+ ptr_ty : ty:: t ,
425353 size : ValueRef )
426- -> MallocResult < ' a > {
427- assert ! ( heap != heap_exchange) ;
428- let _icx = push_ctxt ( "malloc_general" ) ;
429- let Result { bcx : bcx, val : llbox} = malloc_raw_dyn ( bcx, t, heap, size) ;
430- let body = GEPi ( bcx, llbox, [ 0 u, abi:: box_field_body] ) ;
354+ -> Result < ' a > {
355+ let _icx = push_ctxt ( "malloc_raw_exchange" ) ;
356+ let ccx = bcx. ccx ( ) ;
431357
432- MallocResult {
433- bcx : bcx,
434- smart_ptr : llbox,
435- body : body,
436- }
358+ // Allocate space:
359+ let r = callee:: trans_lang_call ( bcx,
360+ require_alloc_fn ( bcx, ptr_ty, ExchangeMallocFnLangItem ) ,
361+ [ size] ,
362+ None ) ;
363+
364+ let llty_ptr = type_of:: type_of ( ccx, ptr_ty) ;
365+ rslt ( r. bcx , PointerCast ( r. bcx , r. val , llty_ptr) )
437366}
438367
439- pub fn malloc_general < ' a > ( bcx : & ' a Block < ' a > , t : ty:: t , heap : heap )
440- -> MallocResult < ' a > {
441- let ty = type_of ( bcx. ccx ( ) , t) ;
442- assert ! ( heap != heap_exchange) ;
443- malloc_general_dyn ( bcx, t, heap, llsize_of ( bcx. ccx ( ) , ty) )
368+ pub fn malloc_raw_dyn_managed < ' a > (
369+ bcx : & ' a Block < ' a > ,
370+ t : ty:: t ,
371+ alloc_fn : LangItem ,
372+ size : ValueRef )
373+ -> Result < ' a > {
374+ let _icx = push_ctxt ( "malloc_raw_managed" ) ;
375+ let ccx = bcx. ccx ( ) ;
376+
377+ let langcall = require_alloc_fn ( bcx, t, alloc_fn) ;
378+
379+ // Grab the TypeRef type of box_ptr_ty.
380+ let box_ptr_ty = ty:: mk_box ( bcx. tcx ( ) , t) ;
381+ let llty = type_of ( ccx, box_ptr_ty) ;
382+ let llalign = C_uint ( ccx, llalign_of_min ( ccx, llty) as uint ) ;
383+
384+ // Allocate space:
385+ let drop_glue = glue:: get_drop_glue ( ccx, t) ;
386+ let r = callee:: trans_lang_call (
387+ bcx,
388+ langcall,
389+ [
390+ PointerCast ( bcx, drop_glue, Type :: glue_fn ( ccx, Type :: i8p ( ccx) ) . ptr_to ( ) ) ,
391+ size,
392+ llalign
393+ ] ,
394+ None ) ;
395+ rslt ( r. bcx , PointerCast ( r. bcx , r. val , llty) )
444396}
445397
446398// Type descriptor and type glue stuff
@@ -708,7 +660,8 @@ pub fn iter_structural_ty<'r,
708660 ty:: ty_str( ty:: vstore_fixed( _) ) |
709661 ty:: ty_vec( _, ty:: vstore_fixed( _) ) => {
710662 let ( base, len) = tvec:: get_base_and_byte_len ( cx, av, t) ;
711- cx = tvec:: iter_vec_raw ( cx, base, t, len, f) ;
663+ let unit_ty = ty:: sequence_element_type ( cx. tcx ( ) , t) ;
664+ cx = tvec:: iter_vec_raw ( cx, base, unit_ty, len, f) ;
712665 }
713666 ty:: ty_tup( ref args) => {
714667 let repr = adt:: represent_type ( cx. ccx ( ) , t) ;
0 commit comments