1313// Code relating to drop glue.
1414
1515use std;
16+ use std:: iter;
1617
1718use llvm;
1819use llvm:: { ValueRef , get_param} ;
19- use middle:: lang_items:: ExchangeFreeFnLangItem ;
20+ use middle:: lang_items:: BoxFreeFnLangItem ;
2021use rustc:: ty:: subst:: { Substs } ;
2122use rustc:: traits;
2223use rustc:: ty:: { self , AdtKind , Ty , TypeFoldable } ;
24+ use rustc:: ty:: subst:: Kind ;
2325use adt:: { self , MaybeSizedValue } ;
2426use base:: * ;
2527use callee:: Callee ;
@@ -36,38 +38,22 @@ use cleanup::CleanupScope;
3638
3739use syntax_pos:: DUMMY_SP ;
3840
39- pub fn trans_exchange_free_dyn < ' a , ' tcx > (
41+ pub fn trans_exchange_free_ty < ' a , ' tcx > (
4042 bcx : & BlockAndBuilder < ' a , ' tcx > ,
41- v : ValueRef ,
42- size : ValueRef ,
43- align : ValueRef
43+ ptr : MaybeSizedValue ,
44+ content_ty : Ty < ' tcx >
4445) {
45- let def_id = langcall ( bcx. tcx ( ) , None , "" , ExchangeFreeFnLangItem ) ;
46- let args = [ bcx. pointercast ( v , Type :: i8p ( bcx . ccx ) ) , size , align ] ;
47- let callee = Callee :: def ( bcx. ccx , def_id, bcx . tcx ( ) . intern_substs ( & [ ] ) ) ;
46+ let def_id = langcall ( bcx. tcx ( ) , None , "" , BoxFreeFnLangItem ) ;
47+ let substs = bcx. tcx ( ) . mk_substs ( iter :: once ( Kind :: from ( content_ty ) ) ) ;
48+ let callee = Callee :: def ( bcx. ccx , def_id, substs ) ;
4849
49- let ccx = bcx. ccx ;
50- let fn_ty = callee. direct_fn_type ( ccx, & [ ] ) ;
50+ let fn_ty = callee. direct_fn_type ( bcx. ccx , & [ ] ) ;
5151
52- let llret = bcx. call ( callee. reify ( ccx) , & args[ ..] , None ) ;
52+ let llret = bcx. call ( callee. reify ( bcx. ccx ) ,
53+ & [ ptr. value , ptr. meta ] [ ..1 + ptr. has_meta ( ) as usize ] , None ) ;
5354 fn_ty. apply_attrs_callsite ( llret) ;
5455}
5556
56- pub fn trans_exchange_free_ty < ' a , ' tcx > (
57- bcx : & BlockAndBuilder < ' a , ' tcx > , ptr : ValueRef , content_ty : Ty < ' tcx >
58- ) {
59- assert ! ( bcx. ccx. shared( ) . type_is_sized( content_ty) ) ;
60- let sizing_type = sizing_type_of ( bcx. ccx , content_ty) ;
61- let content_size = llsize_of_alloc ( bcx. ccx , sizing_type) ;
62-
63- // `Box<ZeroSizeType>` does not allocate.
64- if content_size != 0 {
65- let content_align = align_of ( bcx. ccx , content_ty) ;
66- let ccx = bcx. ccx ;
67- trans_exchange_free_dyn ( bcx, ptr, C_uint ( ccx, content_size) , C_uint ( ccx, content_align) ) ;
68- }
69- }
70-
7157pub fn get_drop_glue_type < ' a , ' tcx > ( scx : & SharedCrateContext < ' a , ' tcx > , t : Ty < ' tcx > ) -> Ty < ' tcx > {
7258 assert ! ( t. is_normalized_for_trans( ) ) ;
7359
@@ -224,30 +210,16 @@ pub fn implement_drop_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, g: DropGlueKi
224210 // special. It may move to library and have Drop impl. As
225211 // a safe-guard, assert TyBox not used with TyContents.
226212 assert ! ( !skip_dtor) ;
227- if !bcx. ccx . shared ( ) . type_is_sized ( content_ty) {
213+ let ptr = if !bcx. ccx . shared ( ) . type_is_sized ( content_ty) {
228214 let llbox = bcx. load ( get_dataptr ( & bcx, ptr. value ) ) ;
229215 let info = bcx. load ( get_meta ( & bcx, ptr. value ) ) ;
230- drop_ty ( & bcx, MaybeSizedValue :: unsized_ ( llbox, info) , content_ty) ;
231- let ( llsize, llalign) = size_and_align_of_dst ( & bcx, content_ty, info) ;
232-
233- // `Box<ZeroSizeType>` does not allocate.
234- let needs_free = bcx. icmp ( llvm:: IntNE , llsize, C_uint ( bcx. ccx , 0u64 ) ) ;
235- if const_to_opt_uint ( needs_free) == Some ( 0 ) {
236- bcx
237- } else {
238- let next_cx = bcx. fcx ( ) . build_new_block ( "next" ) ;
239- let cond_cx = bcx. fcx ( ) . build_new_block ( "cond" ) ;
240- bcx. cond_br ( needs_free, cond_cx. llbb ( ) , next_cx. llbb ( ) ) ;
241- trans_exchange_free_dyn ( & cond_cx, llbox, llsize, llalign) ;
242- cond_cx. br ( next_cx. llbb ( ) ) ;
243- next_cx
244- }
216+ MaybeSizedValue :: unsized_ ( llbox, info)
245217 } else {
246- let llbox = bcx. load ( ptr. value ) ;
247- drop_ty ( & bcx , MaybeSizedValue :: sized ( llbox ) , content_ty ) ;
248- trans_exchange_free_ty ( & bcx, llbox , content_ty) ;
249- bcx
250- }
218+ MaybeSizedValue :: sized ( bcx. load ( ptr. value ) )
219+ } ;
220+ drop_ty ( & bcx, ptr , content_ty) ;
221+ trans_exchange_free_ty ( & bcx , ptr , content_ty ) ;
222+ bcx
251223 }
252224 ty:: TyDynamic ( ..) => {
253225 // No support in vtable for distinguishing destroying with
0 commit comments