Cleanup trait callees
This commit is contained in:
@@ -440,39 +440,31 @@ pub fn trans_trait_callee<'a>(
|
|||||||
let _icx = push_ctxt("impl::trans_trait_callee");
|
let _icx = push_ctxt("impl::trans_trait_callee");
|
||||||
let mut bcx = bcx;
|
let mut bcx = bcx;
|
||||||
|
|
||||||
// make a local copy for trait if needed
|
// Translate self_datum and take ownership of the value by
|
||||||
let self_ty = expr_ty_adjusted(bcx, self_expr);
|
// converting to an rvalue.
|
||||||
let self_scratch = match ty::get(self_ty).sty {
|
let self_datum = unpack_datum!(
|
||||||
ty::ty_trait(_, _, ty::RegionTraitStore(..), _, _) => {
|
bcx, expr::trans(bcx, self_expr));
|
||||||
unpack_datum!(bcx, expr::trans(bcx, self_expr))
|
let self_datum = unpack_datum!(
|
||||||
}
|
bcx, self_datum.to_rvalue_datum(bcx, "trait_callee"));
|
||||||
_ => {
|
|
||||||
// Arrange a temporary cleanup for the object in case something
|
// Convert to by-ref since `trans_trait_callee_from_llval` wants it
|
||||||
// should go wrong before the method is actually *invoked*.
|
// that way.
|
||||||
let datum = unpack_datum!(
|
let self_datum = unpack_datum!(
|
||||||
bcx,
|
bcx, self_datum.to_ref_datum(bcx));
|
||||||
lvalue_scratch_datum(
|
|
||||||
bcx, self_ty, "__trait_callee", false, arg_cleanup_scope, (),
|
// Arrange cleanup in case something should go wrong before the
|
||||||
|(), bcx, llval| expr::trans_into(bcx, self_expr,
|
// actual call occurs.
|
||||||
expr::SaveIn(llval))));
|
let llval = self_datum.add_clean(bcx.fcx, arg_cleanup_scope);
|
||||||
datum.to_expr_datum()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let callee_ty = node_id_type(bcx, callee_id);
|
let callee_ty = node_id_type(bcx, callee_id);
|
||||||
assert!(self_scratch.kind.is_by_ref()); // FIXME why special case above??
|
trans_trait_callee_from_llval(bcx, callee_ty, n_method, llval)
|
||||||
trans_trait_callee_from_llval(bcx,
|
|
||||||
callee_ty,
|
|
||||||
n_method,
|
|
||||||
self_scratch.val)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trans_trait_callee_from_llval<'a>(
|
pub fn trans_trait_callee_from_llval<'a>(bcx: &'a Block<'a>,
|
||||||
bcx: &'a Block<'a>,
|
callee_ty: ty::t,
|
||||||
callee_ty: ty::t,
|
n_method: uint,
|
||||||
n_method: uint,
|
llpair: ValueRef)
|
||||||
llpair: ValueRef)
|
-> Callee<'a> {
|
||||||
-> Callee<'a> {
|
|
||||||
/*!
|
/*!
|
||||||
* Same as `trans_trait_callee()` above, except that it is given
|
* Same as `trans_trait_callee()` above, except that it is given
|
||||||
* a by-ref pointer to the object pair.
|
* a by-ref pointer to the object pair.
|
||||||
@@ -641,8 +633,8 @@ pub fn trans_trait_cast<'a>(bcx: &'a Block<'a>,
|
|||||||
/*!
|
/*!
|
||||||
* Generates the code to convert from a pointer (`~T`, `&T`, etc)
|
* Generates the code to convert from a pointer (`~T`, `&T`, etc)
|
||||||
* into an object (`~Trait`, `&Trait`, etc). This means creating a
|
* into an object (`~Trait`, `&Trait`, etc). This means creating a
|
||||||
* pair where the first word is the pointer and the second word is
|
* pair where the first word is the vtable and the second word is
|
||||||
* an appropriate vtable.
|
* the pointer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let mut bcx = bcx;
|
let mut bcx = bcx;
|
||||||
|
|||||||
Reference in New Issue
Block a user