1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 * Handles translation of callees as well as other call-related
13 * things. Callees are a superset of normal rust values and sometimes
14 * have different representations. In particular, top-level fn items
15 * and methods are represented as just a fn ptr and not a full
23 use lib::llvm::{ValueRef, NoAliasAttribute, StructRetAttribute};
25 use metadata::csearch;
26 use middle::trans::base;
27 use middle::trans::base::*;
28 use middle::trans::build::*;
29 use middle::trans::callee;
30 use middle::trans::common;
31 use middle::trans::common::*;
32 use middle::trans::datum::*;
33 use middle::trans::datum::Datum;
34 use middle::trans::expr;
35 use middle::trans::glue;
36 use middle::trans::inline;
37 use middle::trans::meth;
38 use middle::trans::monomorphize;
39 use middle::trans::type_of;
40 use middle::trans::foreign;
42 use middle::subst::Subst;
44 use middle::typeck::coherence::make_substs_for_receiver_types;
45 use util::ppaux::Repr;
47 use middle::trans::type_::Type;
50 use syntax::abi::AbiSet;
53 use syntax::visit::Visitor;
55 // Represents a (possibly monomorphized) top-level fn item or method
56 // item. Note that this is just the fn-ptr and is not a Rust closure
57 // value (which is a pair).
62 pub struct MethodData {
65 temp_cleanup: Option<ValueRef>,
66 self_mode: ty::SelfMode,
80 pub fn trans(bcx: @mut Block, expr: &ast::Expr) -> Callee {
81 let _icx = push_ctxt("trans_callee");
82 debug!("callee::trans(expr={})", expr.repr(bcx.tcx()));
84 // pick out special kinds of expressions that can be called:
87 return trans_def(bcx, bcx.def(expr.id), expr);
92 // any other expressions are closures:
93 return datum_callee(bcx, expr);
95 fn datum_callee(bcx: @mut Block, expr: &ast::Expr) -> Callee {
96 let DatumBlock {bcx, datum} = expr::trans_to_datum(bcx, expr);
97 match ty::get(datum.ty).sty {
98 ty::ty_bare_fn(*) => {
99 let llval = datum.to_appropriate_llval(bcx);
100 return Callee {bcx: bcx, data: Fn(FnData {llfn: llval})};
102 ty::ty_closure(*) => {
103 return Callee {bcx: bcx, data: Closure(datum)};
106 bcx.tcx().sess.span_bug(
108 format!("Type of callee is neither bare-fn nor closure: {}",
109 bcx.ty_to_str(datum.ty)));
114 fn fn_callee(bcx: @mut Block, fd: FnData) -> Callee {
115 return Callee {bcx: bcx, data: Fn(fd)};
118 fn trans_def(bcx: @mut Block, def: ast::Def, ref_expr: &ast::Expr) -> Callee {
121 ast::DefStaticMethod(did, ast::FromImpl(_), _) => {
122 fn_callee(bcx, trans_fn_ref(bcx, did, ref_expr.id))
124 ast::DefStaticMethod(impl_did,
125 ast::FromTrait(trait_did),
127 fn_callee(bcx, meth::trans_static_method_callee(bcx, impl_did,
131 ast::DefVariant(tid, vid, _) => {
132 // nullary variants are not callable
133 assert!(ty::enum_variant_with_id(bcx.tcx(),
135 vid).args.len() > 0u);
136 fn_callee(bcx, trans_fn_ref(bcx, vid, ref_expr.id))
138 ast::DefStruct(def_id) => {
139 fn_callee(bcx, trans_fn_ref(bcx, def_id, ref_expr.id))
147 datum_callee(bcx, ref_expr)
149 ast::DefMod(*) | ast::DefForeignMod(*) | ast::DefTrait(*) |
150 ast::DefTy(*) | ast::DefPrimTy(*) |
151 ast::DefUse(*) | ast::DefTyParamBinder(*) |
152 ast::DefRegion(*) | ast::DefLabel(*) | ast::DefTyParam(*) |
153 ast::DefSelfTy(*) | ast::DefMethod(*) => {
154 bcx.tcx().sess.span_bug(
156 format!("Cannot translate def {:?} \
157 to a callable thing!", def));
163 pub fn trans_fn_ref_to_callee(bcx: @mut Block,
165 ref_id: ast::NodeId) -> Callee {
167 data: Fn(trans_fn_ref(bcx, def_id, ref_id))}
170 pub fn trans_fn_ref(bcx: @mut Block,
172 ref_id: ast::NodeId) -> FnData {
175 * Translates a reference (with id `ref_id`) to the fn/method
176 * with id `def_id` into a function pointer. This may require
177 * monomorphization or inlining. */
179 let _icx = push_ctxt("trans_fn_ref");
181 let type_params = node_id_type_params(bcx, ref_id);
182 let vtables = node_vtables(bcx, ref_id);
183 debug!("trans_fn_ref(def_id={}, ref_id={:?}, type_params={}, vtables={})",
184 def_id.repr(bcx.tcx()), ref_id, type_params.repr(bcx.tcx()),
185 vtables.repr(bcx.tcx()));
186 trans_fn_ref_with_vtables(bcx, def_id, ref_id, type_params, vtables)
189 pub fn trans_fn_ref_with_vtables_to_callee(
193 type_params: &[ty::t],
194 vtables: Option<typeck::vtable_res>)
197 data: Fn(trans_fn_ref_with_vtables(bcx, def_id, ref_id,
198 type_params, vtables))}
201 fn resolve_default_method_vtables(bcx: @mut Block,
205 impl_vtables: Option<typeck::vtable_res>)
206 -> (typeck::vtable_res, typeck::vtable_param_res) {
208 // Get the vtables that the impl implements the trait at
209 let impl_res = ty::lookup_impl_vtables(bcx.tcx(), impl_id);
211 // Build up a param_substs that we are going to resolve the
212 // trait_vtables under.
213 let param_substs = Some(@param_substs {
214 tys: substs.tps.clone(),
215 self_ty: substs.self_ty,
216 vtables: impl_vtables,
220 let trait_vtables_fixed = resolve_vtables_under_param_substs(
221 bcx.tcx(), param_substs, impl_res.trait_vtables);
223 // Now we pull any vtables for parameters on the actual method.
224 let num_method_vtables = method.generics.type_param_defs.len();
225 let method_vtables = match impl_vtables {
227 let num_impl_type_parameters =
228 vtables.len() - num_method_vtables;
229 vtables.tailn(num_impl_type_parameters).to_owned()
231 None => vec::from_elem(num_method_vtables, @~[])
234 let param_vtables = @(*trait_vtables_fixed + method_vtables);
236 let self_vtables = resolve_param_vtables_under_param_substs(
237 bcx.tcx(), param_substs, impl_res.self_vtables);
239 (param_vtables, self_vtables)
243 pub fn trans_fn_ref_with_vtables(
245 def_id: ast::DefId, // def id of fn
246 ref_id: ast::NodeId, // node id of use of fn; may be zero if N/A
247 type_params: &[ty::t], // values for fn's ty params
248 vtables: Option<typeck::vtable_res>) // vtables for the call
251 * Translates a reference to a fn/method item, monomorphizing and
252 * inlining as it goes.
256 * - `bcx`: the current block where the reference to the fn occurs
257 * - `def_id`: def id of the fn or method item being referenced
258 * - `ref_id`: node id of the reference to the fn/method, if applicable.
259 * This parameter may be zero; but, if so, the resulting value may not
260 * have the right type, so it must be cast before being used.
261 * - `type_params`: values for each of the fn/method's type parameters
262 * - `vtables`: values for each bound on each of the type parameters
265 let _icx = push_ctxt("trans_fn_ref_with_vtables");
269 debug!("trans_fn_ref_with_vtables(bcx={}, def_id={}, ref_id={:?}, \
270 type_params={}, vtables={})",
272 def_id.repr(bcx.tcx()),
274 type_params.repr(bcx.tcx()),
275 vtables.repr(bcx.tcx()));
277 assert!(type_params.iter().all(|t| !ty::type_needs_infer(*t)));
279 // Polytype of the function item (may have type params)
280 let fn_tpt = ty::lookup_item_type(tcx, def_id);
282 let substs = ty::substs { regions: ty::ErasedRegions,
284 tps: /*bad*/ type_params.to_owned() };
286 // Load the info for the appropriate trait if necessary.
287 match ty::trait_of_method(tcx, def_id) {
290 ty::populate_implementations_for_trait_if_necessary(tcx, trait_id)
294 // We need to do a bunch of special handling for default methods.
295 // We need to modify the def_id and our substs in order to monomorphize
297 let (is_default, def_id, substs, self_vtables, vtables) =
298 match ty::provided_source(tcx, def_id) {
299 None => (false, def_id, substs, None, vtables),
301 // There are two relevant substitutions when compiling
302 // default methods. First, there is the substitution for
303 // the type parameters of the impl we are using and the
304 // method we are calling. This substitution is the substs
305 // argument we already have.
306 // In order to compile a default method, though, we need
307 // to consider another substitution: the substitution for
308 // the type parameters on trait; the impl we are using
309 // implements the trait at some particular type
310 // parameters, and we need to substitute for those first.
311 // So, what we need to do is find this substitution and
312 // compose it with the one we already have.
314 let impl_id = ty::method(tcx, def_id).container_id();
315 let method = ty::method(tcx, source_id);
316 let trait_ref = ty::impl_trait_ref(tcx, impl_id)
317 .expect("could not find trait_ref for impl with \
320 // Compute the first substitution
321 let first_subst = make_substs_for_receiver_types(
322 tcx, impl_id, trait_ref, method);
325 let new_substs = first_subst.subst(tcx, &substs);
328 let (param_vtables, self_vtables) =
329 resolve_default_method_vtables(bcx, impl_id,
330 method, &substs, vtables);
332 debug!("trans_fn_with_vtables - default method: \
333 substs = {}, trait_subst = {}, \
334 first_subst = {}, new_subst = {}, \
336 self_vtable = {}, param_vtables = {}",
337 substs.repr(tcx), trait_ref.substs.repr(tcx),
338 first_subst.repr(tcx), new_substs.repr(tcx),
340 self_vtables.repr(tcx), param_vtables.repr(tcx));
343 new_substs, Some(self_vtables), Some(param_vtables))
347 // Check whether this fn has an inlined copy and, if so, redirect
348 // def_id to the local id of the inlined copy.
350 if def_id.crate != ast::LOCAL_CRATE {
351 inline::maybe_instantiate_inline(ccx, def_id)
357 // We must monomorphise if the fn has type parameters, is a rust
358 // intrinsic, or is a default method. In particular, if we see an
359 // intrinsic that is inlined from a different crate, we want to reemit the
360 // intrinsic instead of trying to call it in the other crate.
361 let must_monomorphise;
362 if type_params.len() > 0 || is_default {
363 must_monomorphise = true;
364 } else if def_id.crate == ast::LOCAL_CRATE {
365 let map_node = session::expect(
367 ccx.tcx.items.find(&def_id.node),
368 || format!("local item should be in ast map"));
371 ast_map::node_foreign_item(_, abis, _, _) => {
372 must_monomorphise = abis.is_intrinsic()
375 must_monomorphise = false;
379 must_monomorphise = false;
382 // Create a monomorphic verison of generic functions
383 if must_monomorphise {
384 // Should be either intra-crate or inlined.
385 assert_eq!(def_id.crate, ast::LOCAL_CRATE);
387 let (val, must_cast) =
388 monomorphize::monomorphic_fn(ccx, def_id, &substs,
389 vtables, self_vtables,
392 if must_cast && ref_id != 0 {
393 // Monotype of the REFERENCE to the function (type params
395 let ref_ty = common::node_id_type(bcx, ref_id);
398 bcx, val, type_of::type_of_fn_from_ty(ccx, ref_ty).ptr_to());
400 return FnData {llfn: val};
403 // Find the actual function pointer.
405 if def_id.crate == ast::LOCAL_CRATE {
406 // Internal reference.
407 get_item_val(ccx, def_id.node)
409 // External reference.
410 trans_external_path(ccx, def_id, fn_tpt.ty)
414 // This is subtle and surprising, but sometimes we have to bitcast
415 // the resulting fn pointer. The reason has to do with external
416 // functions. If you have two crates that both bind the same C
417 // library, they may not use precisely the same types: for
418 // example, they will probably each declare their own structs,
419 // which are distinct types from LLVM's point of view (nominal
422 // Now, if those two crates are linked into an application, and
423 // they contain inlined code, you can wind up with a situation
424 // where both of those functions wind up being loaded into this
425 // application simultaneously. In that case, the same function
426 // (from LLVM's point of view) requires two types. But of course
427 // LLVM won't allow one function to have two types.
429 // What we currently do, therefore, is declare the function with
430 // one of the two types (whichever happens to come first) and then
431 // bitcast as needed when the function is referenced to make sure
432 // it has the type we expect.
434 // This can occur on either a crate-local or crate-external
435 // reference. It also occurs when testing libcore and in some
436 // other weird situations. Annoying.
437 let llty = type_of::type_of_fn_from_ty(ccx, fn_tpt.ty);
438 let llptrty = llty.ptr_to();
439 if val_ty(val) != llptrty {
440 val = BitCast(bcx, val, llptrty);
443 return FnData {llfn: val};
446 // ______________________________________________________________________
449 pub fn trans_call(in_cx: @mut Block,
456 let _icx = push_ctxt("trans_call");
457 trans_call_inner(in_cx,
460 node_id_type(in_cx, id),
467 pub fn trans_method_call(in_cx: @mut Block,
469 callee_id: ast::NodeId,
474 let _icx = push_ctxt("trans_method_call");
475 debug!("trans_method_call(call_ex={}, rcvr={})",
476 call_ex.repr(in_cx.tcx()),
477 rcvr.repr(in_cx.tcx()));
481 node_id_type(in_cx, callee_id),
482 expr_ty(in_cx, call_ex),
484 match cx.ccx().maps.method_map.find_copy(&call_ex.id) {
486 debug!("origin for {}: {}",
487 call_ex.repr(in_cx.tcx()),
488 origin.repr(in_cx.tcx()));
490 meth::trans_method_callee(cx,
496 cx.tcx().sess.span_bug(call_ex.span, "method call expr wasn't in method map")
505 pub fn trans_lang_call(bcx: @mut Block,
508 dest: Option<expr::Dest>)
510 let fty = if did.crate == ast::LOCAL_CRATE {
511 ty::node_id_to_type(bcx.ccx().tcx, did.node)
513 csearch::get_type(bcx.ccx().tcx, did).ty
515 let rty = ty::ty_fn_ret(fty);
516 callee::trans_call_inner(bcx,
521 trans_fn_ref_with_vtables_to_callee(bcx,
532 pub fn trans_lang_call_with_type_params(bcx: @mut Block,
535 type_params: &[ty::t],
539 if did.crate == ast::LOCAL_CRATE {
540 fty = ty::node_id_to_type(bcx.tcx(), did.node);
542 fty = csearch::get_type(bcx.tcx(), did).ty;
545 let rty = ty::ty_fn_ret(fty);
546 return callee::trans_call_inner(
550 trans_fn_ref_with_vtables_to_callee(bcx, did, 0,
557 let substituted = ty::subst_tps(callee.bcx.tcx(),
561 let llfnty = type_of::type_of(callee.bcx.ccx(),
563 new_llval = PointerCast(callee.bcx, fn_data.llfn, llfnty);
567 Callee { bcx: callee.bcx, data: Fn(FnData { llfn: new_llval }) }
569 ArgVals(args), Some(dest), DontAutorefArg).bcx;
573 struct CalleeTranslationVisitor {
577 impl Visitor<()> for CalleeTranslationVisitor {
579 fn visit_item(&mut self, _:@ast::item, _:()) { }
581 fn visit_expr(&mut self, e:@ast::Expr, _:()) {
585 ast::ExprRet(_) => self.flag = true,
586 _ => visit::walk_expr(self, e, ()),
593 pub fn body_contains_ret(body: &ast::Block) -> bool {
594 let mut v = CalleeTranslationVisitor{ flag: false };
595 visit::walk_block(&mut v, body, ());
599 pub fn trans_call_inner(in_cx: @mut Block,
600 call_info: Option<NodeInfo>,
603 get_callee: &fn(@mut Block) -> Callee,
605 dest: Option<expr::Dest>,
606 autoref_arg: AutorefArg)
609 * This behemoth of a function translates function calls.
610 * Unfortunately, in order to generate more efficient LLVM
611 * output at -O0, it has quite a complex signature (refactoring
612 * this into two functions seems like a good idea).
614 * In particular, for lang items, it is invoked with a dest of
619 do base::with_scope_result(in_cx, call_info, "call") |cx| {
620 let callee = get_callee(cx);
621 let mut bcx = callee.bcx;
624 let (llfn, llenv) = unsafe {
627 (d.llfn, llvm::LLVMGetUndef(Type::opaque_box(ccx).ptr_to().to_ref()))
630 // Weird but true: we pass self in the *environment* slot!
634 // Closures are represented as (llfn, llclosure) pair:
635 // load the requisite values out.
636 let pair = d.to_ref_llval(bcx);
637 let llfn = GEPi(bcx, pair, [0u, abi::fn_field_code]);
638 let llfn = Load(bcx, llfn);
639 let llenv = GEPi(bcx, pair, [0u, abi::fn_field_box]);
640 let llenv = Load(bcx, llenv);
646 let abi = match ty::get(callee_ty).sty {
647 ty::ty_bare_fn(ref f) => f.abis,
654 // Generate a location to store the result. If the user does
655 // not care about the result, just make a stack slot.
656 let opt_llretslot = match dest {
658 assert!(!type_of::return_uses_outptr(in_cx.ccx(), ret_ty));
661 Some(expr::SaveIn(dst)) => Some(dst),
662 Some(expr::Ignore) => {
663 if !ty::type_is_voidish(in_cx.tcx(), ret_ty) {
664 Some(alloc_ty(bcx, ret_ty, "__llret"))
667 Some(llvm::LLVMGetUndef(Type::nil().ptr_to().to_ref()))
673 let mut llresult = unsafe {
674 llvm::LLVMGetUndef(Type::nil().ptr_to().to_ref())
677 // The code below invokes the function, using either the Rust
678 // conventions (if it is a rust fn) or the native conventions
679 // (otherwise). The important part is that, when all is sad
680 // and done, either the return value of the function will have been
681 // written in opt_llretslot (if it is Some) or `llresult` will be
682 // set appropriately (otherwise).
684 let mut llargs = ~[];
686 // Push the out-pointer if we use an out-pointer for this
687 // return type, otherwise push "undef".
688 if type_of::return_uses_outptr(in_cx.ccx(), ret_ty) {
689 llargs.push(opt_llretslot.unwrap());
692 // Push the environment.
695 // Push the arguments.
696 bcx = trans_args(bcx, args, callee_ty,
697 autoref_arg, &mut llargs);
699 // Now that the arguments have finished evaluating, we
700 // need to revoke the cleanup for the self argument
703 for &v in d.temp_cleanup.iter() {
704 revoke_clean(bcx, v);
710 // A function pointer is called without the declaration available, so we have to apply
711 // any attributes with ABI implications directly to the call instruction. Right now, the
712 // only attribute we need to worry about is `sret`.
714 if type_of::return_uses_outptr(in_cx.ccx(), ret_ty) {
715 attrs.push((1, StructRetAttribute));
718 // The `noalias` attribute on the return value is useful to a function ptr caller.
719 match ty::get(ret_ty).sty {
720 // `~` pointer return values never alias because ownership is transferred
722 ty::ty_evec(_, ty::vstore_uniq) => {
723 attrs.push((0, NoAliasAttribute));
728 // Invoke the actual rust fn and update bcx/llresult.
729 let (llret, b) = base::invoke(bcx, llfn, llargs, attrs);
733 // If the Rust convention for this type is return via
734 // the return value, copy it into llretslot.
735 match opt_llretslot {
737 if !type_of::return_uses_outptr(bcx.ccx(), ret_ty) &&
738 !ty::type_is_voidish(bcx.tcx(), ret_ty)
740 Store(bcx, llret, llretslot);
746 // Lang items are the only case where dest is None, and
747 // they are always Rust fns.
748 assert!(dest.is_some());
750 let mut llargs = ~[];
751 bcx = trans_args(bcx, args, callee_ty,
752 autoref_arg, &mut llargs);
753 let arg_tys = match args {
754 ArgExprs(a) => a.iter().map(|x| expr_ty(bcx, *x)).collect(),
755 ArgVals(_) => fail!("expected arg exprs.")
757 bcx = foreign::trans_native_call(bcx, callee_ty,
758 llfn, opt_llretslot.unwrap(), llargs, arg_tys);
761 // If the caller doesn't care about the result of this fn call,
762 // drop the temporary slot we made.
765 assert!(!type_of::return_uses_outptr(bcx.ccx(), ret_ty));
767 Some(expr::Ignore) => {
768 // drop the value if it is not being saved.
769 bcx = glue::drop_ty(bcx, opt_llretslot.unwrap(), ret_ty);
771 Some(expr::SaveIn(_)) => { }
774 if ty::type_is_bot(ret_ty) {
782 pub enum CallArgs<'self> {
783 ArgExprs(&'self [@ast::Expr]),
784 ArgVals(&'self [ValueRef])
787 pub fn trans_args(cx: @mut Block,
790 autoref_arg: AutorefArg,
791 llargs: &mut ~[ValueRef]) -> @mut Block
793 let _icx = push_ctxt("trans_args");
794 let mut temp_cleanups = ~[];
795 let arg_tys = ty::ty_fn_args(fn_ty);
796 let variadic = ty::fn_is_variadic(fn_ty);
800 // First we figure out the caller's view of the types of the arguments.
801 // This will be needed if this is a generic call, because the callee has
802 // to cast her view of the arguments to the caller's view.
804 ArgExprs(arg_exprs) => {
805 let num_formal_args = arg_tys.len();
806 for (i, arg_expr) in arg_exprs.iter().enumerate() {
807 let arg_ty = if i >= num_formal_args {
809 expr_ty_adjusted(cx, *arg_expr)
813 let arg_val = unpack_result!(bcx, {
821 llargs.push(arg_val);
829 // now that all arguments have been successfully built, we can revoke any
830 // temporary cleanups, as they are only needed if argument construction
831 // should fail (for example, cleanup of copy mode args).
832 for c in temp_cleanups.iter() {
833 revoke_clean(bcx, *c)
839 pub enum AutorefArg {
844 // temp_cleanups: cleanups that should run only if failure occurs before the
846 pub fn trans_arg_expr(bcx: @mut Block,
847 formal_arg_ty: ty::t,
848 self_mode: ty::SelfMode,
849 arg_expr: &ast::Expr,
850 temp_cleanups: &mut ~[ValueRef],
851 autoref_arg: AutorefArg) -> Result {
852 let _icx = push_ctxt("trans_arg_expr");
855 debug!("trans_arg_expr(formal_arg_ty=({}), self_mode={:?}, arg_expr={})",
856 formal_arg_ty.repr(bcx.tcx()),
858 arg_expr.repr(bcx.tcx()));
860 // translate the arg expr to a datum
861 let arg_datumblock = expr::trans_to_datum(bcx, arg_expr);
862 let arg_datum = arg_datumblock.datum;
863 let bcx = arg_datumblock.bcx;
865 debug!(" arg datum: {}", arg_datum.to_str(bcx.ccx()));
868 if ty::type_is_bot(arg_datum.ty) {
869 // For values of type _|_, we generate an
870 // "undef" value, as such a value should never
871 // be inspected. It's important for the value
872 // to have type lldestty (the callee's expected type).
873 let llformal_arg_ty = type_of::type_of(ccx, formal_arg_ty);
875 val = llvm::LLVMGetUndef(llformal_arg_ty.to_ref());
878 // FIXME(#3548) use the adjustments table
881 val = arg_datum.to_ref_llval(bcx);
884 let need_scratch = ty::type_needs_drop(bcx.tcx(), arg_datum.ty) ||
885 (bcx.expr_is_lval(arg_expr) &&
886 arg_datum.appropriate_mode(bcx.ccx()).is_by_ref());
888 let arg_datum = if need_scratch {
889 let scratch = scratch_datum(bcx, arg_datum.ty, "__self", false);
890 arg_datum.store_to_datum(bcx, INIT, scratch);
892 // Technically, ownership of val passes to the callee.
893 // However, we must cleanup should we fail before the
894 // callee is actually invoked.
895 scratch.add_clean(bcx);
896 temp_cleanups.push(scratch.val);
903 val = match self_mode {
905 debug!("by ref arg with type {}", bcx.ty_to_str(arg_datum.ty));
906 arg_datum.to_ref_llval(bcx)
909 debug!("by copy arg with type {}", bcx.ty_to_str(arg_datum.ty));
910 arg_datum.to_appropriate_llval(bcx)
916 if formal_arg_ty != arg_datum.ty {
917 // this could happen due to e.g. subtyping
918 let llformal_arg_ty = type_of::type_of_explicit_arg(ccx, formal_arg_ty);
919 debug!("casting actual type ({}) to match formal ({})",
920 bcx.val_to_str(val), bcx.llty_str(llformal_arg_ty));
921 val = PointerCast(bcx, val, llformal_arg_ty);
925 debug!("--- trans_arg_expr passing {}", bcx.val_to_str(val));
926 return rslt(bcx, val);