Skip to content

Commit

Permalink
Make drop glue for unsized value pass two arguments instead of *(data…
Browse files Browse the repository at this point in the history
…, meta)
  • Loading branch information
Mark-Simulacrum committed Dec 21, 2016
1 parent 1b38776 commit afc2dcd
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 226 deletions.
3 changes: 2 additions & 1 deletion src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
/// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
unsafe {
assert!(index < LLVMCountParams(llfn));
assert!(index < LLVMCountParams(llfn),
"out of bounds argument access: {} out of {} arguments", index, LLVMCountParams(llfn));
LLVMGetParam(llfn, index)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use base::*;
use common::{
self, CrateContext, FunctionContext, SharedCrateContext
};
use adt::MaybeSizedValue;
use consts;
use declare;
use value::Value;
Expand Down Expand Up @@ -364,7 +365,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(

// Call the by-ref closure body with `self` in a cleanup scope,
// to drop `self` when the body returns, or in case it unwinds.
let self_scope = fcx.schedule_drop_mem(llenv, closure_ty);
let self_scope = fcx.schedule_drop_mem(MaybeSizedValue::sized(llenv), closure_ty);

let llfn = callee.reify(bcx.ccx);
let llret;
Expand Down
16 changes: 6 additions & 10 deletions src/librustc_trans/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
//! corresponds to a normal exit from a block (for example, an expression
//! completing evaluation successfully without panic).
use llvm::{BasicBlockRef, ValueRef};
use llvm::BasicBlockRef;
use base;
use adt::MaybeSizedValue;
use common::{BlockAndBuilder, FunctionContext, Funclet};
use glue;
use type_::Type;
use value::Value;
use rustc::ty::Ty;

pub struct CleanupScope<'tcx> {
Expand All @@ -36,7 +36,7 @@ pub struct CleanupScope<'tcx> {

#[derive(Copy, Clone)]
pub struct DropValue<'tcx> {
val: ValueRef,
val: MaybeSizedValue,
ty: Ty<'tcx>,
skip_dtor: bool,
}
Expand Down Expand Up @@ -94,16 +94,14 @@ impl<'tcx> DropValue<'tcx> {

impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
/// Schedules a (deep) drop of `val`, which is a pointer to an instance of `ty`
pub fn schedule_drop_mem(&self, val: ValueRef, ty: Ty<'tcx>) -> CleanupScope<'tcx> {
pub fn schedule_drop_mem(&self, val: MaybeSizedValue, ty: Ty<'tcx>) -> CleanupScope<'tcx> {
if !self.ccx.shared().type_needs_drop(ty) { return CleanupScope::noop(); }
let drop = DropValue {
val: val,
ty: ty,
skip_dtor: false,
};

debug!("schedule_drop_mem(val={:?}, ty={:?}) skip_dtor={}", Value(val), ty, drop.skip_dtor);

CleanupScope::new(self, drop)
}

Expand All @@ -112,7 +110,8 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
/// `ty`. The scheduled code handles extracting the discriminant
/// and dropping the contents associated with that variant
/// *without* executing any associated drop implementation.
pub fn schedule_drop_adt_contents(&self, val: ValueRef, ty: Ty<'tcx>) -> CleanupScope<'tcx> {
pub fn schedule_drop_adt_contents(&self, val: MaybeSizedValue, ty: Ty<'tcx>)
-> CleanupScope<'tcx> {
// `if` below could be "!contents_needs_drop"; skipping drop
// is just an optimization, so sound to be conservative.
if !self.ccx.shared().type_needs_drop(ty) { return CleanupScope::noop(); }
Expand All @@ -123,9 +122,6 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
skip_dtor: true,
};

debug!("schedule_drop_adt_contents(val={:?}, ty={:?}) skip_dtor={}",
Value(val), ty, drop.skip_dtor);

CleanupScope::new(self, drop)
}
}
Expand Down
Loading

0 comments on commit afc2dcd

Please sign in to comment.