1- use rustc:: mir;
1+ use rustc:: mir:: BasicBlock ;
22use rustc:: ty:: { self , Ty } ;
33use syntax:: codemap:: Span ;
44
5- use interpret:: { EvalResult , EvalContext , StackPopCleanup , Lvalue , LvalueExtra , PrimVal , Value ,
5+ use interpret:: { EvalResult , EvalContext , Lvalue , LvalueExtra , PrimVal , Value ,
66 Machine , ValTy } ;
77
88impl < ' a , ' tcx , M : Machine < ' tcx > > EvalContext < ' a , ' tcx , M > {
@@ -12,6 +12,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
1212 instance : ty:: Instance < ' tcx > ,
1313 ty : Ty < ' tcx > ,
1414 span : Span ,
15+ target : BasicBlock ,
1516 ) -> EvalResult < ' tcx > {
1617 trace ! ( "drop_lvalue: {:#?}" , lval) ;
1718 // We take the address of the object. This may well be unaligned, which is fine for us here.
@@ -32,57 +33,51 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
3233 } => ptr. ptr . to_value ( ) ,
3334 _ => bug ! ( "force_allocation broken" ) ,
3435 } ;
35- self . drop ( val, instance, ty, span)
36+ self . drop ( val, instance, ty, span, target )
3637 }
37- pub ( crate ) fn drop (
38+
39+ fn drop (
3840 & mut self ,
3941 arg : Value ,
40- mut instance : ty:: Instance < ' tcx > ,
42+ instance : ty:: Instance < ' tcx > ,
4143 ty : Ty < ' tcx > ,
4244 span : Span ,
45+ target : BasicBlock ,
4346 ) -> EvalResult < ' tcx > {
4447 trace ! ( "drop: {:#?}, {:?}, {:?}" , arg, ty. sty, instance. def) ;
4548
46- if let ty:: InstanceDef :: DropGlue ( _, None ) = instance. def {
47- trace ! ( "nothing to do, aborting" ) ;
48- // we don't actually need to drop anything
49- return Ok ( ( ) ) ;
50- }
51- let mir = match ty. sty {
49+ let instance = match ty. sty {
5250 ty:: TyDynamic ( ..) => {
5351 let vtable = match arg {
5452 Value :: ByValPair ( _, PrimVal :: Ptr ( vtable) ) => vtable,
5553 _ => bug ! ( "expected fat ptr, got {:?}" , arg) ,
5654 } ;
5755 match self . read_drop_type_from_vtable ( vtable) ? {
58- Some ( func) => {
59- instance = func;
60- self . load_mir ( func. def ) ?
61- }
56+ Some ( func) => func,
6257 // no drop fn -> bail out
63- None => return Ok ( ( ) ) ,
58+ None => {
59+ self . goto_block ( target) ;
60+ return Ok ( ( ) )
61+ } ,
6462 }
6563 }
66- _ => self . load_mir ( instance. def ) ? ,
64+ _ => instance,
6765 } ;
6866
69- self . push_stack_frame (
70- instance,
71- span,
72- mir,
73- Lvalue :: undef ( ) ,
74- StackPopCleanup :: None ,
75- ) ?;
76-
77- let mut arg_locals = self . frame ( ) . mir . args_iter ( ) ;
78- assert_eq ! ( self . frame( ) . mir. arg_count, 1 ) ;
79- let arg_local = arg_locals. next ( ) . unwrap ( ) ;
80- let dest = self . eval_lvalue ( & mir:: Lvalue :: Local ( arg_local) ) ?;
81- let arg_ty = self . tcx . mk_mut_ptr ( ty) ;
67+ // the drop function expects a reference to the value
8268 let valty = ValTy {
8369 value : arg,
84- ty : arg_ty ,
70+ ty : self . tcx . mk_mut_ptr ( ty ) ,
8571 } ;
86- self . write_value ( valty, dest)
72+
73+ let fn_sig = self . tcx . fn_sig ( instance. def_id ( ) ) . skip_binder ( ) . clone ( ) ;
74+
75+ self . eval_fn_call (
76+ instance,
77+ Some ( ( Lvalue :: undef ( ) , target) ) ,
78+ & vec ! [ valty] ,
79+ span,
80+ fn_sig,
81+ )
8782 }
8883}
0 commit comments