remove filling on drop
This commit is contained in:
parent
8d6d646203
commit
4fff19528b
@ -26,7 +26,7 @@ use glue;
|
||||
use type_::Type;
|
||||
use rustc_data_structures::fnv::FnvHashMap;
|
||||
|
||||
use super::{MirContext, TempRef, drop};
|
||||
use super::{MirContext, TempRef};
|
||||
use super::constant::Const;
|
||||
use super::lvalue::{LvalueRef, load_fat_ptr};
|
||||
use super::operand::OperandRef;
|
||||
@ -168,11 +168,9 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
cleanup_bundle.as_ref());
|
||||
self.bcx(target).at_start(|bcx| {
|
||||
debug_loc.apply_to_bcx(bcx);
|
||||
drop::drop_fill(bcx, lvalue.llval, ty)
|
||||
});
|
||||
} else {
|
||||
bcx.call(drop_fn, &[llvalue], cleanup_bundle.as_ref());
|
||||
drop::drop_fill(&bcx, lvalue.llval, ty);
|
||||
funclet_br(bcx, self.llblock(target));
|
||||
}
|
||||
}
|
||||
@ -215,7 +213,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
let llptr = self.trans_operand(&bcx, &args[0]).immediate();
|
||||
let val = self.trans_operand(&bcx, &args[1]);
|
||||
self.store_operand(&bcx, llptr, val);
|
||||
self.set_operand_dropped(&bcx, &args[1]);
|
||||
funclet_br(bcx, self.llblock(target));
|
||||
return;
|
||||
}
|
||||
@ -226,7 +223,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
this.trans_transmute(&bcx, &args[0], dest);
|
||||
});
|
||||
|
||||
self.set_operand_dropped(&bcx, &args[0]);
|
||||
funclet_br(bcx, self.llblock(target));
|
||||
return;
|
||||
}
|
||||
@ -332,9 +328,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
}
|
||||
|
||||
if let Some((_, target)) = *destination {
|
||||
for op in args {
|
||||
self.set_operand_dropped(&bcx, op);
|
||||
}
|
||||
funclet_br(bcx, self.llblock(target));
|
||||
} else {
|
||||
// trans_intrinsic_call already used Unreachable.
|
||||
@ -363,13 +356,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
cleanup_bundle.as_ref());
|
||||
fn_ty.apply_attrs_callsite(invokeret);
|
||||
|
||||
landingpad.at_start(|bcx| {
|
||||
debug_loc.apply_to_bcx(bcx);
|
||||
for op in args {
|
||||
self.set_operand_dropped(bcx, op);
|
||||
}
|
||||
});
|
||||
|
||||
if destination.is_some() {
|
||||
let ret_bcx = ret_bcx.build();
|
||||
ret_bcx.at_start(|ret_bcx| {
|
||||
@ -379,9 +365,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
ty: sig.output.unwrap()
|
||||
};
|
||||
self.store_return(&ret_bcx, ret_dest, fn_ty.ret, op);
|
||||
for op in args {
|
||||
self.set_operand_dropped(&ret_bcx, op);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@ -393,9 +376,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
ty: sig.output.unwrap()
|
||||
};
|
||||
self.store_return(&bcx, ret_dest, fn_ty.ret, op);
|
||||
for op in args {
|
||||
self.set_operand_dropped(&bcx, op);
|
||||
}
|
||||
funclet_br(bcx, self.llblock(target));
|
||||
} else {
|
||||
// no need to drop args, because the call never returns
|
||||
|
@ -1,27 +0,0 @@
|
||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use llvm::ValueRef;
|
||||
use rustc::ty::Ty;
|
||||
use adt;
|
||||
use base;
|
||||
use common::{self, BlockAndBuilder};
|
||||
use machine;
|
||||
use type_of;
|
||||
use type_::Type;
|
||||
|
||||
pub fn drop_fill<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>, value: ValueRef, ty: Ty<'tcx>) {
|
||||
let llty = type_of::type_of(bcx.ccx(), ty);
|
||||
let llptr = bcx.pointercast(value, Type::i8(bcx.ccx()).ptr_to());
|
||||
let filling = common::C_u8(bcx.ccx(), adt::DTOR_DONE);
|
||||
let size = machine::llsize_of(bcx.ccx(), llty);
|
||||
let align = common::C_u32(bcx.ccx(), machine::llalign_of_min(bcx.ccx(), llty));
|
||||
base::call_memset(&bcx, llptr, filling, size, align, false);
|
||||
}
|
@ -20,7 +20,6 @@ use common::{self, BlockAndBuilder, CrateContext, C_uint, C_undef};
|
||||
use consts;
|
||||
use machine;
|
||||
use type_of::type_of;
|
||||
use mir::drop;
|
||||
use Disr;
|
||||
|
||||
use std::ptr;
|
||||
@ -51,9 +50,6 @@ impl<'tcx> LvalueRef<'tcx> {
|
||||
{
|
||||
assert!(!ty.has_erasable_regions());
|
||||
let lltemp = bcx.with_block(|bcx| base::alloc_ty(bcx, ty, name));
|
||||
if bcx.fcx().type_needs_drop(ty) {
|
||||
drop::drop_fill(bcx, lltemp, ty);
|
||||
}
|
||||
LvalueRef::new_sized(lltemp, LvalueTy::from_ty(ty))
|
||||
}
|
||||
|
||||
|
@ -431,7 +431,6 @@ fn arg_value_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
|
||||
mod analyze;
|
||||
mod block;
|
||||
mod constant;
|
||||
mod drop;
|
||||
mod lvalue;
|
||||
mod operand;
|
||||
mod rvalue;
|
||||
|
@ -15,12 +15,11 @@ use base;
|
||||
use common::{self, Block, BlockAndBuilder};
|
||||
use datum;
|
||||
use value::Value;
|
||||
use glue;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use super::lvalue::load_fat_ptr;
|
||||
use super::{MirContext, TempRef, drop};
|
||||
use super::{MirContext, TempRef};
|
||||
|
||||
/// The representation of a Rust value. The enum variant is in fact
|
||||
/// uniquely determined by the value's type, but is kept as a
|
||||
@ -179,29 +178,4 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_operand_dropped(&mut self,
|
||||
bcx: &BlockAndBuilder<'bcx, 'tcx>,
|
||||
operand: &mir::Operand<'tcx>) {
|
||||
match *operand {
|
||||
mir::Operand::Constant(_) => return,
|
||||
mir::Operand::Consume(ref lvalue) => {
|
||||
if let mir::Lvalue::Temp(idx) = *lvalue {
|
||||
if let TempRef::Operand(..) = self.temps[idx as usize] {
|
||||
// All lvalues which have an associated drop are promoted to an alloca
|
||||
// beforehand. If this is an operand, it is safe to say this is never
|
||||
// dropped and there’s no reason for us to zero this out at all.
|
||||
return
|
||||
}
|
||||
}
|
||||
let lvalue = self.trans_lvalue(bcx, lvalue);
|
||||
let ty = lvalue.ty.to_ty(bcx.tcx());
|
||||
if !glue::type_needs_drop(bcx.tcx(), ty) {
|
||||
return
|
||||
} else {
|
||||
drop::drop_fill(bcx, lvalue.llval, ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ use type_of;
|
||||
use tvec;
|
||||
use value::Value;
|
||||
use Disr;
|
||||
use glue;
|
||||
|
||||
use super::MirContext;
|
||||
use super::operand::{OperandRef, OperandValue};
|
||||
@ -48,7 +47,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
// FIXME: consider not copying constants through stack. (fixable by translating
|
||||
// constants into OperandValue::Ref, why don’t we do that yet if we don’t?)
|
||||
self.store_operand(&bcx, dest.llval, tr_operand);
|
||||
self.set_operand_dropped(&bcx, operand);
|
||||
bcx
|
||||
}
|
||||
|
||||
@ -92,7 +90,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
});
|
||||
self.set_operand_dropped(&bcx, source);
|
||||
bcx
|
||||
}
|
||||
|
||||
@ -107,7 +104,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
block
|
||||
})
|
||||
});
|
||||
self.set_operand_dropped(&bcx, elem);
|
||||
bcx
|
||||
}
|
||||
|
||||
@ -128,7 +124,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
val, disr, i);
|
||||
self.store_operand(&bcx, lldest_i, op);
|
||||
}
|
||||
self.set_operand_dropped(&bcx, operand);
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
@ -167,7 +162,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
let dest = bcx.gepi(dest.llval, &[0, i]);
|
||||
self.store_operand(&bcx, dest, op);
|
||||
}
|
||||
self.set_operand_dropped(&bcx, operand);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -209,9 +203,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
asm::trans_inline_asm(bcx, asm, outputs, input_vals);
|
||||
});
|
||||
|
||||
for input in inputs {
|
||||
self.set_operand_dropped(&bcx, input);
|
||||
}
|
||||
bcx
|
||||
}
|
||||
|
||||
@ -269,7 +260,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
// &'a fmt::Debug+Send => &'a fmt::Debug,
|
||||
// So we need to pointercast the base to ensure
|
||||
// the types match up.
|
||||
self.set_operand_dropped(&bcx, source);
|
||||
let llcast_ty = type_of::fat_ptr_base_ty(bcx.ccx(), cast_ty);
|
||||
let lldata = bcx.pointercast(lldata, llcast_ty);
|
||||
OperandValue::FatPtr(lldata, llextra)
|
||||
@ -280,7 +270,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
base::unsize_thin_ptr(bcx, lldata,
|
||||
operand.ty, cast_ty)
|
||||
});
|
||||
self.set_operand_dropped(&bcx, source);
|
||||
OperandValue::FatPtr(lldata, llextra)
|
||||
}
|
||||
OperandValue::Ref(_) => {
|
||||
@ -569,8 +558,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rvalue_creates_operand<'bcx, 'tcx>(mir: &mir::Mir<'tcx>,
|
||||
bcx: &BlockAndBuilder<'bcx, 'tcx>,
|
||||
pub fn rvalue_creates_operand<'bcx, 'tcx>(_mir: &mir::Mir<'tcx>,
|
||||
_bcx: &BlockAndBuilder<'bcx, 'tcx>,
|
||||
rvalue: &mir::Rvalue<'tcx>) -> bool {
|
||||
match *rvalue {
|
||||
mir::Rvalue::Ref(..) |
|
||||
@ -578,21 +567,14 @@ pub fn rvalue_creates_operand<'bcx, 'tcx>(mir: &mir::Mir<'tcx>,
|
||||
mir::Rvalue::Cast(..) | // (*)
|
||||
mir::Rvalue::BinaryOp(..) |
|
||||
mir::Rvalue::UnaryOp(..) |
|
||||
mir::Rvalue::Box(..) =>
|
||||
mir::Rvalue::Box(..) |
|
||||
mir::Rvalue::Use(..) =>
|
||||
true,
|
||||
mir::Rvalue::Repeat(..) |
|
||||
mir::Rvalue::Aggregate(..) |
|
||||
mir::Rvalue::Slice { .. } |
|
||||
mir::Rvalue::InlineAsm { .. } =>
|
||||
false,
|
||||
mir::Rvalue::Use(ref operand) => {
|
||||
let ty = mir.operand_ty(bcx.tcx(), operand);
|
||||
let ty = bcx.monomorphize(&ty);
|
||||
// Types that don't need dropping can just be an operand,
|
||||
// this allows temporary lvalues, used as rvalues, to
|
||||
// avoid a stack slot when it's unnecessary
|
||||
!glue::type_needs_drop(bcx.tcx(), ty)
|
||||
}
|
||||
}
|
||||
|
||||
// (*) this is only true if the type is suitable
|
||||
|
Loading…
x
Reference in New Issue
Block a user