Skip to content

Commit

Permalink
Do drop glue for closures.
Browse files Browse the repository at this point in the history
  • Loading branch information
solson committed Feb 10, 2017
1 parent f73f001 commit b755a91
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/terminator/drop.rs
Expand Up @@ -51,7 +51,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
debug!("no need to drop {:?}", ty);
return Ok(());
}
trace!("-need to drop {:?} at {:?}", ty, lval);
trace!("need to drop {:?} at {:?}", ty, lval);

match ty.sty {
// special case `Box` to deallocate the inner allocation
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
// is the same as
// fn drop(&mut self) if Self is Box<T>
drop.push((box_free_fn, val, substs));
},
}

ty::TyAdt(adt_def, substs) => {
// FIXME: some structs are represented as ByValPair
Expand Down Expand Up @@ -165,8 +165,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
ty,
drop,
)?;
},
ty::TyTuple(fields, _) => self.drop_fields(fields.into_iter().cloned(), lval, ty, drop)?,
}

ty::TyTuple(fields, _) =>
self.drop_fields(fields.into_iter().cloned(), lval, ty, drop)?,

ty::TyDynamic(..) => {
let (ptr, vtable) = match lval {
Lvalue::Ptr { ptr, extra: LvalueExtra::Vtable(vtable) } => (ptr, vtable),
Expand All @@ -181,7 +184,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
// just a sanity check
assert_eq!(drop_fn.offset, 0);
}
},
}

ty::TySlice(elem_ty) => {
let (ptr, len) = match lval {
Lvalue::Ptr { ptr, extra: LvalueExtra::Length(len) } => (ptr, len),
Expand All @@ -193,7 +197,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
for i in 0..len {
self.drop(Lvalue::from_ptr(ptr.offset(i * size)), elem_ty, drop)?;
}
},
}

ty::TyArray(elem_ty, len) => {
let lval = self.force_allocation(lval)?;
let (ptr, extra) = match lval {
Expand All @@ -206,10 +211,14 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
for i in 0..(len as u64) {
self.drop(Lvalue::Ptr { ptr: ptr.offset(i * size), extra }, elem_ty, drop)?;
}
},
// FIXME: what about TyClosure and TyAnon?
// other types do not need to process drop
_ => {},
}

ty::TyClosure(def_id, substs) => {
let fields = substs.upvar_tys(def_id, self.tcx);
self.drop_fields(fields, lval, ty, drop)?;
}

_ => bug!(),
}

Ok(())
Expand Down

0 comments on commit b755a91

Please sign in to comment.