Synthesize calls to box_free language item

This gets rid of Drop(Free, _) MIR construct by synthesizing a call to language item which
takes care of dropping instead.
This commit is contained in:
Simonas Kazlauskas 2016-01-28 23:59:00 +02:00
parent 7b9d6d3bc8
commit 432460a6fc
20 changed files with 127 additions and 69 deletions

View file

@ -82,13 +82,13 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
constant: &mir::Constant<'tcx>)
-> OperandRef<'tcx>
{
let ty = bcx.monomorphize(&constant.ty);
match constant.literal {
mir::Literal::Item { def_id, kind, substs } => {
let substs = bcx.tcx().mk_substs(bcx.monomorphize(&substs));
self.trans_item_ref(bcx, ty, kind, substs, def_id)
self.trans_item_ref(bcx, constant.ty, kind, substs, def_id)
}
mir::Literal::Value { ref value } => {
let ty = bcx.monomorphize(&constant.ty);
self.trans_constval(bcx, value, ty)
}
}

View file

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use rustc::middle::ty::LvaluePreference;
use rustc::mir::repr as mir;
use trans::common::Block;
use trans::debuginfo::DebugLoc;
@ -52,19 +51,11 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
}
}
mir::StatementKind::Drop(mir::DropKind::Deep, ref lvalue) => {
mir::StatementKind::Drop(ref lvalue) => {
let tr_lvalue = self.trans_lvalue(bcx, lvalue);
let ty = tr_lvalue.ty.to_ty(bcx.tcx());
glue::drop_ty(bcx, tr_lvalue.llval, ty, DebugLoc::None)
}
mir::StatementKind::Drop(mir::DropKind::Free, ref lvalue) => {
let tr_lvalue = self.trans_lvalue(bcx, lvalue);
let ty = tr_lvalue.ty.to_ty(bcx.tcx());
let content_ty = ty.builtin_deref(true, LvaluePreference::NoPreference);
let content_ty = content_ty.unwrap().ty;
glue::trans_exchange_free_ty(bcx, tr_lvalue.llval, content_ty, DebugLoc::None)
}
}
}
}