@@ -16,7 +16,7 @@ use rustc_index::vec::Idx;
1616use rustc_middle:: mir:: { self , AssertKind , SwitchTargets } ;
1717use rustc_middle:: ty:: layout:: { HasTyCtxt , LayoutOf } ;
1818use rustc_middle:: ty:: print:: { with_no_trimmed_paths, with_no_visible_paths} ;
19- use rustc_middle:: ty:: { self , Instance , Ty , TypeVisitable } ;
19+ use rustc_middle:: ty:: { self , Instance , Ty , TypeVisitable , TraitObjectRepresentation } ;
2020use rustc_span:: source_map:: Span ;
2121use rustc_span:: { sym, Symbol } ;
2222use rustc_symbol_mangling:: typeid:: typeid_for_fnabi;
@@ -367,6 +367,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
367367 bx. ret ( llval) ;
368368 }
369369
370+ #[ tracing:: instrument( level = "debug" , skip( self , helper, bx) ) ]
370371 fn codegen_drop_terminator (
371372 & mut self ,
372373 helper : TerminatorCodegenHelper < ' tcx > ,
@@ -397,20 +398,61 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
397398 let ( drop_fn, fn_abi) = match ty. kind ( ) {
398399 // FIXME(eddyb) perhaps move some of this logic into
399400 // `Instance::resolve_drop_in_place`?
400- ty:: Dynamic ( ..) => {
401+ ty:: Dynamic ( _, _, TraitObjectRepresentation :: Unsized ) => {
402+ // IN THIS ARM, WE HAVE:
403+ // ty = *mut (dyn Trait)
404+ // which is: exists<T> ( *mut T, Vtable<T: Trait> )
405+ // args[0] args[1]
406+ //
407+ // args = ( Data, Vtable )
408+ // |
409+ // v
410+ // /-------\
411+ // | ... |
412+ // \-------/
413+ //
401414 let virtual_drop = Instance {
402415 def : ty:: InstanceDef :: Virtual ( drop_fn. def_id ( ) , 0 ) ,
403416 substs : drop_fn. substs ,
404417 } ;
418+ debug ! ( "ty = {:?}" , ty) ;
419+ debug ! ( "drop_fn = {:?}" , drop_fn) ;
420+ debug ! ( "args = {:?}" , args) ;
405421 let fn_abi = bx. fn_abi_of_instance ( virtual_drop, ty:: List :: empty ( ) ) ;
406422 let vtable = args[ 1 ] ;
423+ // Truncate vtable off of args list
407424 args = & args[ ..1 ] ;
408425 (
409426 meth:: VirtualIndex :: from_index ( ty:: COMMON_VTABLE_ENTRIES_DROPINPLACE )
410427 . get_fn ( & mut bx, vtable, ty, & fn_abi) ,
411428 fn_abi,
412429 )
413430 }
431+ ty:: Dynamic ( _, _, TraitObjectRepresentation :: Sized ) => {
432+ // IN THIS ARM, WE HAVE:
433+ // ty = *mut (dyn* Trait)
434+ // which is: *mut exists<T: sizeof(T) == sizeof(usize)> (T, Vtable<T: Trait>)
435+ //
436+ // args = [ * ]
437+ // |
438+ // v
439+ // ( Data, Vtable )
440+ // |
441+ // v
442+ // /-------\
443+ // | ... |
444+ // \-------/
445+ //
446+ //
447+ // WE CAN CONVERT THIS INTO THE ABOVE LOGIC BY DOING
448+ //
449+ // data = &(*args[0]).0 // gives a pointer to Data above (really the same pointer)
450+ // vtable = (*args[0]).1 // loads the vtable out
451+ // (data, vtable) // an equivalent Rust `*mut dyn Trait`
452+ //
453+ // SO THEN WE CAN USE THE ABOVE CODE.
454+ todo ! ( )
455+ }
414456 _ => ( bx. get_fn_addr ( drop_fn) , bx. fn_abi_of_instance ( drop_fn, ty:: List :: empty ( ) ) ) ,
415457 } ;
416458 helper. do_call (
0 commit comments