1414
1515use std;
1616
17- use back:: symbol_names;
1817use llvm;
1918use llvm:: { ValueRef , get_param} ;
2019use middle:: lang_items:: ExchangeFreeFnLangItem ;
2120use rustc:: ty:: subst:: { Substs } ;
2221use rustc:: traits;
2322use rustc:: ty:: { self , Ty , TyCtxt } ;
24- use abi:: { Abi , FnType } ;
2523use adt;
2624use adt:: GetDtorType ; // for tcx.dtor_type()
2725use base:: * ;
@@ -32,7 +30,6 @@ use cleanup::CleanupMethods;
3230use collector;
3331use common:: * ;
3432use debuginfo:: DebugLoc ;
35- use declare;
3633use expr;
3734use machine:: * ;
3835use monomorphize;
@@ -233,56 +230,28 @@ impl<'tcx> DropGlueKind<'tcx> {
233230
234231fn get_drop_glue_core < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > ,
235232 g : DropGlueKind < ' tcx > ) -> ValueRef {
236- debug ! ( "make drop glue for {:?}" , g) ;
237233 let g = g. map_ty ( |t| get_drop_glue_type ( ccx. tcx ( ) , t) ) ;
238- debug ! ( "drop glue type {:?}" , g) ;
239234 match ccx. drop_glues ( ) . borrow ( ) . get ( & g) {
240- Some ( & glue) => return glue,
241- _ => { }
235+ Some ( & ( glue, _) ) => glue,
236+ None => { bug ! ( "Could not find drop glue for {:?} -- {} -- {}" ,
237+ g,
238+ TransItem :: DropGlue ( g) . to_raw_string( ) ,
239+ ccx. codegen_unit( ) . name) }
242240 }
243- let t = g . ty ( ) ;
241+ }
244242
243+ pub fn implement_drop_glue < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > ,
244+ g : DropGlueKind < ' tcx > ) {
245245 let tcx = ccx. tcx ( ) ;
246- let sig = ty:: FnSig {
247- inputs : vec ! [ tcx. mk_mut_ptr( tcx. types. i8 ) ] ,
248- output : ty:: FnOutput :: FnConverging ( tcx. mk_nil ( ) ) ,
249- variadic : false ,
250- } ;
251- // Create a FnType for fn(*mut i8) and substitute the real type in
252- // later - that prevents FnType from splitting fat pointers up.
253- let mut fn_ty = FnType :: new ( ccx, Abi :: Rust , & sig, & [ ] ) ;
254- fn_ty. args [ 0 ] . original_ty = type_of ( ccx, t) . ptr_to ( ) ;
255- let llfnty = fn_ty. llvm_type ( ccx) ;
256-
257- // To avoid infinite recursion, don't `make_drop_glue` until after we've
258- // added the entry to the `drop_glues` cache.
259- if let Some ( old_sym) = ccx. available_drop_glues ( ) . borrow ( ) . get ( & g) {
260- let llfn = declare:: declare_cfn ( ccx, & old_sym, llfnty) ;
261- ccx. drop_glues ( ) . borrow_mut ( ) . insert ( g, llfn) ;
262- return llfn;
263- } ;
264-
265- let suffix = match g {
266- DropGlueKind :: Ty ( _) => "drop" ,
267- DropGlueKind :: TyContents ( _) => "drop_contents" ,
268- } ;
269-
270- let fn_nm = symbol_names:: internal_name_from_type_and_suffix ( ccx, t, suffix) ;
271- assert ! ( declare:: get_defined_value( ccx, & fn_nm) . is_none( ) ) ;
272- let llfn = declare:: declare_cfn ( ccx, & fn_nm, llfnty) ;
273- ccx. available_drop_glues ( ) . borrow_mut ( ) . insert ( g, fn_nm) ;
274- ccx. drop_glues ( ) . borrow_mut ( ) . insert ( g, llfn) ;
275-
276- let _s = StatRecorder :: new ( ccx, format ! ( "drop {:?}" , t) ) ;
246+ assert_eq ! ( g. ty( ) , get_drop_glue_type( tcx, g. ty( ) ) ) ;
247+ let ( llfn, fn_ty) = ccx. drop_glues ( ) . borrow ( ) . get ( & g) . unwrap ( ) . clone ( ) ;
277248
278249 let ( arena, fcx) : ( TypedArena < _ > , FunctionContext ) ;
279250 arena = TypedArena :: new ( ) ;
280251 fcx = FunctionContext :: new ( ccx, llfn, fn_ty, None , & arena) ;
281252
282253 let bcx = fcx. init ( false , None ) ;
283254
284- update_linkage ( ccx, llfn, None ) ;
285-
286255 ccx. stats ( ) . n_glues_created . set ( ccx. stats ( ) . n_glues_created . get ( ) + 1 ) ;
287256 // All glue functions take values passed *by alias*; this is a
288257 // requirement since in many contexts glue is invoked indirectly and
@@ -294,10 +263,9 @@ fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
294263
295264 let bcx = make_drop_glue ( bcx, get_param ( llfn, 0 ) , g) ;
296265 fcx. finish ( bcx, DebugLoc :: None ) ;
297-
298- llfn
299266}
300267
268+
301269fn trans_struct_drop_flag < ' blk , ' tcx > ( mut bcx : Block < ' blk , ' tcx > ,
302270 t : Ty < ' tcx > ,
303271 struct_data : ValueRef )
0 commit comments