2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
2014-11-25 20:17:11 -06:00
|
|
|
//! Handles translation of callees as well as other call-related
|
|
|
|
//! things. Callees are a superset of normal rust values and sometimes
|
|
|
|
//! have different representations. In particular, top-level fn items
|
|
|
|
//! and methods are represented as just a fn ptr and not a full
|
|
|
|
//! closure.
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2014-11-06 02:05:53 -06:00
|
|
|
pub use self::AutorefArg::*;
|
|
|
|
pub use self::CalleeData::*;
|
|
|
|
pub use self::CallArgs::*;
|
|
|
|
|
2014-06-28 14:55:17 -05:00
|
|
|
use arena::TypedArena;
|
2015-01-04 09:50:24 -06:00
|
|
|
use back::link;
|
2014-11-15 19:30:33 -06:00
|
|
|
use session;
|
2015-06-18 13:07:36 -05:00
|
|
|
use llvm::{self, ValueRef, get_params};
|
2013-02-25 13:11:21 -06:00
|
|
|
use metadata::csearch;
|
2014-05-14 14:31:30 -05:00
|
|
|
use middle::def;
|
2014-05-13 10:35:42 -05:00
|
|
|
use middle::subst;
|
2014-11-06 01:24:44 -06:00
|
|
|
use middle::subst::{Subst, Substs};
|
2014-11-15 19:30:33 -06:00
|
|
|
use trans::adt;
|
|
|
|
use trans::base;
|
|
|
|
use trans::base::*;
|
|
|
|
use trans::build::*;
|
|
|
|
use trans::callee;
|
|
|
|
use trans::cleanup;
|
|
|
|
use trans::cleanup::CleanupMethods;
|
|
|
|
use trans::closure;
|
2015-02-04 10:16:59 -06:00
|
|
|
use trans::common::{self, Block, Result, NodeIdAndSpan, ExprId, CrateContext,
|
|
|
|
ExprOrMethodCall, FunctionContext, MethodCallKey};
|
2015-01-04 10:47:58 -06:00
|
|
|
use trans::consts;
|
2014-11-15 19:30:33 -06:00
|
|
|
use trans::datum::*;
|
2014-12-11 06:53:30 -06:00
|
|
|
use trans::debuginfo::{DebugLoc, ToDebugLoc};
|
2015-03-03 17:08:06 -06:00
|
|
|
use trans::declare;
|
2014-11-15 19:30:33 -06:00
|
|
|
use trans::expr;
|
|
|
|
use trans::glue;
|
|
|
|
use trans::inline;
|
|
|
|
use trans::foreign;
|
|
|
|
use trans::intrinsic;
|
|
|
|
use trans::meth;
|
|
|
|
use trans::monomorphize;
|
|
|
|
use trans::type_::Type;
|
|
|
|
use trans::type_of;
|
2015-01-03 21:42:21 -06:00
|
|
|
use middle::ty::{self, Ty};
|
2014-11-25 13:21:20 -06:00
|
|
|
use middle::ty::MethodCall;
|
2015-06-09 18:40:45 -05:00
|
|
|
use rustc::ast_map;
|
2012-12-13 15:05:22 -06:00
|
|
|
|
2014-08-18 10:29:44 -05:00
|
|
|
use syntax::abi as synabi;
|
2012-08-28 17:54:45 -05:00
|
|
|
use syntax::ast;
|
2014-09-07 12:09:06 -05:00
|
|
|
use syntax::ptr::P;
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2015-03-30 08:38:44 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2013-01-29 19:57:02 -06:00
|
|
|
pub struct MethodData {
|
2014-03-28 12:05:27 -05:00
|
|
|
pub llfn: ValueRef,
|
|
|
|
pub llself: ValueRef,
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
pub enum CalleeData<'tcx> {
|
2014-07-10 01:42:08 -05:00
|
|
|
// Constructor for enum variant/tuple-like-struct
|
|
|
|
// i.e. Some, Ok
|
2014-09-29 14:11:30 -05:00
|
|
|
NamedTupleConstructor(subst::Substs<'tcx>, ty::Disr),
|
2014-07-10 01:42:08 -05:00
|
|
|
|
2014-01-27 06:18:36 -06:00
|
|
|
// Represents a (possibly monomorphized) top-level fn item or method
|
|
|
|
// item. Note that this is just the fn-ptr and is not a Rust closure
|
|
|
|
// value (which is a pair).
|
|
|
|
Fn(/* llfn */ ValueRef),
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
Intrinsic(ast::NodeId, subst::Substs<'tcx>),
|
2014-07-09 17:31:45 -05:00
|
|
|
|
2014-08-04 15:56:56 -05:00
|
|
|
TraitItem(MethodData)
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
2014-09-06 11:13:04 -05:00
|
|
|
pub struct Callee<'blk, 'tcx: 'blk> {
|
|
|
|
pub bcx: Block<'blk, 'tcx>,
|
2014-09-29 14:11:30 -05:00
|
|
|
pub data: CalleeData<'tcx>,
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
2014-09-06 11:13:04 -05:00
|
|
|
fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
|
|
|
|
-> Callee<'blk, 'tcx> {
|
2013-06-16 23:23:24 -05:00
|
|
|
let _icx = push_ctxt("trans_callee");
|
2015-06-18 12:25:05 -05:00
|
|
|
debug!("callee::trans(expr={:?})", expr);
|
2012-08-28 17:54:45 -05:00
|
|
|
|
|
|
|
// pick out special kinds of expressions that can be called:
|
2015-01-12 22:02:56 -06:00
|
|
|
match expr.node {
|
2015-02-17 11:29:13 -06:00
|
|
|
ast::ExprPath(..) => {
|
2015-01-12 22:02:56 -06:00
|
|
|
return trans_def(bcx, bcx.def(expr.id), expr);
|
|
|
|
}
|
|
|
|
_ => {}
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// any other expressions are closures:
|
2013-02-27 18:28:37 -06:00
|
|
|
return datum_callee(bcx, expr);
|
|
|
|
|
2014-09-06 11:13:04 -05:00
|
|
|
fn datum_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
|
|
|
|
-> Callee<'blk, 'tcx> {
|
2015-01-05 12:53:39 -06:00
|
|
|
let DatumBlock { bcx, datum, .. } = expr::trans(bcx, expr);
|
2014-10-31 03:51:16 -05:00
|
|
|
match datum.ty.sty {
|
2015-06-11 18:21:46 -05:00
|
|
|
ty::TyBareFn(..) => {
|
2014-01-15 13:39:08 -06:00
|
|
|
let llval = datum.to_llscalarish(bcx);
|
2014-05-29 00:26:56 -05:00
|
|
|
return Callee {
|
|
|
|
bcx: bcx,
|
|
|
|
data: Fn(llval),
|
|
|
|
};
|
2013-02-27 18:28:37 -06:00
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
bcx.tcx().sess.span_bug(
|
|
|
|
expr.span,
|
2015-06-02 18:31:23 -05:00
|
|
|
&format!("type of callee is neither bare-fn nor closure: {}",
|
2015-06-18 12:25:05 -05:00
|
|
|
datum.ty));
|
2013-02-27 18:28:37 -06:00
|
|
|
}
|
|
|
|
}
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
2014-09-06 11:13:04 -05:00
|
|
|
fn fn_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, llfn: ValueRef)
|
|
|
|
-> Callee<'blk, 'tcx> {
|
2014-05-29 00:26:56 -05:00
|
|
|
return Callee {
|
|
|
|
bcx: bcx,
|
|
|
|
data: Fn(llfn),
|
|
|
|
};
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
2014-10-14 19:33:20 -05:00
|
|
|
fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|
|
|
def: def::Def,
|
|
|
|
ref_expr: &ast::Expr)
|
2014-09-06 11:13:04 -05:00
|
|
|
-> Callee<'blk, 'tcx> {
|
2015-06-18 12:25:05 -05:00
|
|
|
debug!("trans_def(def={:?}, ref_expr={:?})", def, ref_expr);
|
2015-02-04 10:16:59 -06:00
|
|
|
let expr_ty = common::node_id_type(bcx, ref_expr.id);
|
2012-08-28 17:54:45 -05:00
|
|
|
match def {
|
2014-10-15 23:44:24 -05:00
|
|
|
def::DefFn(did, _) if {
|
2014-09-05 19:46:05 -05:00
|
|
|
let maybe_def_id = inline::get_local_instance(bcx.ccx(), did);
|
|
|
|
let maybe_ast_node = maybe_def_id.and_then(|def_id| bcx.tcx().map
|
|
|
|
.find(def_id.node));
|
|
|
|
match maybe_ast_node {
|
2014-07-10 02:20:28 -05:00
|
|
|
Some(ast_map::NodeStructCtor(_)) => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
} => {
|
2015-02-04 10:16:59 -06:00
|
|
|
let substs = common::node_id_substs(bcx.ccx(),
|
|
|
|
ExprId(ref_expr.id),
|
|
|
|
bcx.fcx.param_substs);
|
2014-07-10 02:20:28 -05:00
|
|
|
Callee {
|
|
|
|
bcx: bcx,
|
|
|
|
data: NamedTupleConstructor(substs, 0)
|
|
|
|
}
|
|
|
|
}
|
2014-10-31 03:51:16 -05:00
|
|
|
def::DefFn(did, _) if match expr_ty.sty {
|
2015-06-11 18:21:46 -05:00
|
|
|
ty::TyBareFn(_, ref f) => f.abi == synabi::RustIntrinsic,
|
2014-07-09 17:31:45 -05:00
|
|
|
_ => false
|
|
|
|
} => {
|
2015-02-04 10:16:59 -06:00
|
|
|
let substs = common::node_id_substs(bcx.ccx(),
|
|
|
|
ExprId(ref_expr.id),
|
|
|
|
bcx.fcx.param_substs);
|
2014-09-05 19:39:51 -05:00
|
|
|
let def_id = inline::maybe_instantiate_inline(bcx.ccx(), did);
|
2014-07-09 17:31:45 -05:00
|
|
|
Callee { bcx: bcx, data: Intrinsic(def_id.node, substs) }
|
|
|
|
}
|
2015-02-11 01:32:25 -06:00
|
|
|
def::DefFn(did, _) | def::DefMethod(did, def::FromImpl(_)) => {
|
2015-01-04 10:47:58 -06:00
|
|
|
fn_callee(bcx, trans_fn_ref(bcx.ccx(), did, ExprId(ref_expr.id),
|
|
|
|
bcx.fcx.param_substs).val)
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
2015-02-11 01:32:25 -06:00
|
|
|
def::DefMethod(meth_did, def::FromTrait(trait_did)) => {
|
2015-01-04 10:47:58 -06:00
|
|
|
fn_callee(bcx, meth::trans_static_method_callee(bcx.ccx(),
|
|
|
|
meth_did,
|
2012-10-12 19:00:08 -05:00
|
|
|
trait_did,
|
2015-01-04 10:47:58 -06:00
|
|
|
ref_expr.id,
|
|
|
|
bcx.fcx.param_substs).val)
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
2014-05-14 14:31:30 -05:00
|
|
|
def::DefVariant(tid, vid, _) => {
|
2014-07-10 01:42:08 -05:00
|
|
|
let vinfo = ty::enum_variant_with_id(bcx.tcx(), tid, vid);
|
2015-02-04 10:16:59 -06:00
|
|
|
let substs = common::node_id_substs(bcx.ccx(),
|
|
|
|
ExprId(ref_expr.id),
|
|
|
|
bcx.fcx.param_substs);
|
2014-07-10 01:42:08 -05:00
|
|
|
|
|
|
|
// Nullary variants are not callable
|
2015-03-24 18:54:09 -05:00
|
|
|
assert!(!vinfo.args.is_empty());
|
2014-07-10 01:42:08 -05:00
|
|
|
|
|
|
|
Callee {
|
|
|
|
bcx: bcx,
|
2014-07-10 02:20:28 -05:00
|
|
|
data: NamedTupleConstructor(substs, vinfo.disr_val)
|
2014-07-10 01:42:08 -05:00
|
|
|
}
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
2014-07-10 02:20:28 -05:00
|
|
|
def::DefStruct(_) => {
|
2015-02-04 10:16:59 -06:00
|
|
|
let substs = common::node_id_substs(bcx.ccx(),
|
|
|
|
ExprId(ref_expr.id),
|
|
|
|
bcx.fcx.param_substs);
|
2014-07-10 02:20:28 -05:00
|
|
|
Callee {
|
|
|
|
bcx: bcx,
|
|
|
|
data: NamedTupleConstructor(substs, 0)
|
|
|
|
}
|
2012-10-24 16:36:00 -05:00
|
|
|
}
|
2014-05-14 14:31:30 -05:00
|
|
|
def::DefStatic(..) |
|
rustc: Add `const` globals to the language
This change is an implementation of [RFC 69][rfc] which adds a third kind of
global to the language, `const`. This global is most similar to what the old
`static` was, and if you're unsure about what to use then you should use a
`const`.
The semantics of these three kinds of globals are:
* A `const` does not represent a memory location, but only a value. Constants
are translated as rvalues, which means that their values are directly inlined
at usage location (similar to a #define in C/C++). Constant values are, well,
constant, and can not be modified. Any "modification" is actually a
modification to a local value on the stack rather than the actual constant
itself.
Almost all values are allowed inside constants, whether they have interior
mutability or not. There are a few minor restrictions listed in the RFC, but
they should in general not come up too often.
* A `static` now always represents a memory location (unconditionally). Any
references to the same `static` are actually a reference to the same memory
location. Only values whose types ascribe to `Sync` are allowed in a `static`.
This restriction is in place because many threads may access a `static`
concurrently. Lifting this restriction (and allowing unsafe access) is a
future extension not implemented at this time.
* A `static mut` continues to always represent a memory location. All references
to a `static mut` continue to be `unsafe`.
This is a large breaking change, and many programs will need to be updated
accordingly. A summary of the breaking changes is:
* Statics may no longer be used in patterns. Statics now always represent a
memory location, which can sometimes be modified. To fix code, repurpose the
matched-on-`static` to a `const`.
static FOO: uint = 4;
match n {
FOO => { /* ... */ }
_ => { /* ... */ }
}
change this code to:
const FOO: uint = 4;
match n {
FOO => { /* ... */ }
_ => { /* ... */ }
}
* Statics may no longer refer to other statics by value. Due to statics being
able to change at runtime, allowing them to reference one another could
possibly lead to confusing semantics. If you are in this situation, use a
constant initializer instead. Note, however, that statics may reference other
statics by address, however.
* Statics may no longer be used in constant expressions, such as array lengths.
This is due to the same restrictions as listed above. Use a `const` instead.
[breaking-change]
[rfc]: https://github.com/rust-lang/rfcs/pull/246
2014-10-06 10:17:01 -05:00
|
|
|
def::DefConst(..) |
|
2015-03-14 13:05:00 -05:00
|
|
|
def::DefAssociatedConst(..) |
|
2014-05-14 14:31:30 -05:00
|
|
|
def::DefLocal(..) |
|
|
|
|
def::DefUpvar(..) => {
|
2013-02-27 18:28:37 -06:00
|
|
|
datum_callee(bcx, ref_expr)
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
2015-02-23 23:45:34 -06:00
|
|
|
def::DefMod(..) | def::DefForeignMod(..) | def::DefTrait(..) |
|
2014-08-05 21:44:21 -05:00
|
|
|
def::DefTy(..) | def::DefPrimTy(..) | def::DefAssociatedTy(..) |
|
2015-02-05 01:19:07 -06:00
|
|
|
def::DefUse(..) | def::DefRegion(..) | def::DefLabel(..) |
|
2015-02-05 05:20:48 -06:00
|
|
|
def::DefTyParam(..) | def::DefSelfTy(..) => {
|
2012-08-28 17:54:45 -05:00
|
|
|
bcx.tcx().sess.span_bug(
|
|
|
|
ref_expr.span,
|
2015-01-07 10:58:31 -06:00
|
|
|
&format!("cannot translate def {:?} \
|
2015-02-20 13:08:14 -06:00
|
|
|
to a callable thing!", def));
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:17:11 -06:00
|
|
|
/// Translates a reference (with id `ref_id`) to the fn/method with id `def_id` into a function
|
|
|
|
/// pointer. This may require monomorphization or inlining.
|
2015-01-04 10:47:58 -06:00
|
|
|
pub fn trans_fn_ref<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|
|
|
def_id: ast::DefId,
|
|
|
|
node: ExprOrMethodCall,
|
2015-01-29 06:03:34 -06:00
|
|
|
param_substs: &'tcx subst::Substs<'tcx>)
|
2015-01-04 10:47:58 -06:00
|
|
|
-> Datum<'tcx, Rvalue> {
|
2013-06-16 23:23:24 -05:00
|
|
|
let _icx = push_ctxt("trans_fn_ref");
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2015-02-04 10:16:59 -06:00
|
|
|
let substs = common::node_id_substs(ccx, node, param_substs);
|
2015-06-18 12:25:05 -05:00
|
|
|
debug!("trans_fn_ref(def_id={:?}, node={:?}, substs={:?})",
|
|
|
|
def_id,
|
2014-05-07 06:20:15 -05:00
|
|
|
node,
|
2015-06-18 12:25:05 -05:00
|
|
|
substs);
|
2015-01-04 10:47:58 -06:00
|
|
|
trans_fn_ref_with_substs(ccx, def_id, node, param_substs, substs)
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
2014-09-12 10:42:58 -05:00
|
|
|
fn trans_fn_ref_with_substs_to_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|
|
|
def_id: ast::DefId,
|
|
|
|
ref_id: ast::NodeId,
|
2014-09-29 14:11:30 -05:00
|
|
|
substs: subst::Substs<'tcx>)
|
2014-09-12 10:42:58 -05:00
|
|
|
-> Callee<'blk, 'tcx> {
|
2014-05-29 00:26:56 -05:00
|
|
|
Callee {
|
|
|
|
bcx: bcx,
|
2015-01-04 10:47:58 -06:00
|
|
|
data: Fn(trans_fn_ref_with_substs(bcx.ccx(),
|
2014-09-12 10:42:58 -05:00
|
|
|
def_id,
|
|
|
|
ExprId(ref_id),
|
2015-01-04 10:47:58 -06:00
|
|
|
bcx.fcx.param_substs,
|
|
|
|
substs).val),
|
2014-05-29 00:26:56 -05:00
|
|
|
}
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
2014-12-01 08:23:40 -06:00
|
|
|
/// Translates an adapter that implements the `Fn` trait for a fn
|
|
|
|
/// pointer. This is basically the equivalent of something like:
|
|
|
|
///
|
2015-03-12 21:42:38 -05:00
|
|
|
/// ```
|
2014-12-01 08:23:40 -06:00
|
|
|
/// impl<'a> Fn(&'a int) -> &'a int for fn(&int) -> &int {
|
|
|
|
/// extern "rust-abi" fn call(&self, args: (&'a int,)) -> &'a int {
|
|
|
|
/// (*self)(args.0)
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// but for the bare function type given.
|
|
|
|
pub fn trans_fn_pointer_shim<'a, 'tcx>(
|
|
|
|
ccx: &'a CrateContext<'a, 'tcx>,
|
2015-02-15 14:09:26 -06:00
|
|
|
closure_kind: ty::ClosureKind,
|
2014-12-01 08:23:40 -06:00
|
|
|
bare_fn_ty: Ty<'tcx>)
|
|
|
|
-> ValueRef
|
|
|
|
{
|
|
|
|
let _icx = push_ctxt("trans_fn_pointer_shim");
|
|
|
|
let tcx = ccx.tcx();
|
|
|
|
|
2015-02-15 14:09:26 -06:00
|
|
|
// Normalize the type for better caching.
|
2015-02-04 10:16:59 -06:00
|
|
|
let bare_fn_ty = common::erase_regions(tcx, &bare_fn_ty);
|
2015-02-15 14:09:26 -06:00
|
|
|
|
|
|
|
// If this is an impl of `Fn` or `FnMut` trait, the receiver is `&self`.
|
|
|
|
let is_by_ref = match closure_kind {
|
|
|
|
ty::FnClosureKind | ty::FnMutClosureKind => true,
|
|
|
|
ty::FnOnceClosureKind => false,
|
|
|
|
};
|
|
|
|
let bare_fn_ty_maybe_ref = if is_by_ref {
|
|
|
|
ty::mk_imm_rptr(tcx, tcx.mk_region(ty::ReStatic), bare_fn_ty)
|
|
|
|
} else {
|
|
|
|
bare_fn_ty
|
|
|
|
};
|
|
|
|
|
|
|
|
// Check if we already trans'd this shim.
|
|
|
|
match ccx.fn_pointer_shims().borrow().get(&bare_fn_ty_maybe_ref) {
|
2014-12-03 19:23:15 -06:00
|
|
|
Some(&llval) => { return llval; }
|
|
|
|
None => { }
|
|
|
|
}
|
|
|
|
|
2015-06-18 12:25:05 -05:00
|
|
|
debug!("trans_fn_pointer_shim(bare_fn_ty={:?})",
|
|
|
|
bare_fn_ty);
|
2014-12-01 08:23:40 -06:00
|
|
|
|
|
|
|
// Construct the "tuply" version of `bare_fn_ty`. It takes two arguments: `self`,
|
|
|
|
// which is the fn pointer, and `args`, which is the arguments tuple.
|
2015-01-06 04:03:42 -06:00
|
|
|
let (opt_def_id, sig) =
|
2014-12-01 08:23:40 -06:00
|
|
|
match bare_fn_ty.sty {
|
2015-06-11 18:21:46 -05:00
|
|
|
ty::TyBareFn(opt_def_id,
|
2014-12-04 16:52:20 -06:00
|
|
|
&ty::BareFnTy { unsafety: ast::Unsafety::Normal,
|
2015-01-06 04:03:42 -06:00
|
|
|
abi: synabi::Rust,
|
|
|
|
ref sig }) => {
|
|
|
|
(opt_def_id, sig)
|
2014-12-01 08:23:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
_ => {
|
2015-01-07 10:58:31 -06:00
|
|
|
tcx.sess.bug(&format!("trans_fn_pointer_shim invoked on invalid type: {}",
|
2015-06-18 12:25:05 -05:00
|
|
|
bare_fn_ty));
|
2014-12-01 08:23:40 -06:00
|
|
|
}
|
|
|
|
};
|
2015-01-06 04:03:42 -06:00
|
|
|
let sig = ty::erase_late_bound_regions(tcx, sig);
|
|
|
|
let tuple_input_ty = ty::mk_tup(tcx, sig.inputs.to_vec());
|
2014-12-01 08:23:40 -06:00
|
|
|
let tuple_fn_ty = ty::mk_bare_fn(tcx,
|
2014-11-26 05:01:28 -06:00
|
|
|
opt_def_id,
|
2014-12-04 16:52:20 -06:00
|
|
|
tcx.mk_bare_fn(ty::BareFnTy {
|
|
|
|
unsafety: ast::Unsafety::Normal,
|
|
|
|
abi: synabi::RustCall,
|
2014-12-26 05:33:56 -06:00
|
|
|
sig: ty::Binder(ty::FnSig {
|
2015-02-15 14:09:26 -06:00
|
|
|
inputs: vec![bare_fn_ty_maybe_ref,
|
2014-12-04 16:52:20 -06:00
|
|
|
tuple_input_ty],
|
2015-01-06 04:03:42 -06:00
|
|
|
output: sig.output,
|
2014-12-04 16:52:20 -06:00
|
|
|
variadic: false
|
2014-12-26 05:33:56 -06:00
|
|
|
})}));
|
2015-06-18 12:25:05 -05:00
|
|
|
debug!("tuple_fn_ty: {:?}", tuple_fn_ty);
|
2014-12-01 08:23:40 -06:00
|
|
|
|
|
|
|
//
|
2015-03-03 17:08:06 -06:00
|
|
|
let function_name = link::mangle_internal_name_by_type_and_seq(ccx, bare_fn_ty,
|
|
|
|
"fn_pointer_shim");
|
|
|
|
let llfn = declare::declare_internal_rust_fn(ccx, &function_name[..], tuple_fn_ty);
|
2014-12-01 08:23:40 -06:00
|
|
|
|
|
|
|
//
|
2015-01-29 06:03:34 -06:00
|
|
|
let empty_substs = tcx.mk_substs(Substs::trans_empty());
|
2015-01-26 06:38:33 -06:00
|
|
|
let (block_arena, fcx): (TypedArena<_>, FunctionContext);
|
|
|
|
block_arena = TypedArena::new();
|
|
|
|
fcx = new_fn_ctxt(ccx,
|
|
|
|
llfn,
|
|
|
|
ast::DUMMY_NODE_ID,
|
|
|
|
false,
|
|
|
|
sig.output,
|
2015-01-29 06:03:34 -06:00
|
|
|
empty_substs,
|
2015-01-26 06:38:33 -06:00
|
|
|
None,
|
|
|
|
&block_arena);
|
2015-01-06 04:03:42 -06:00
|
|
|
let mut bcx = init_function(&fcx, false, sig.output);
|
2014-12-01 08:23:40 -06:00
|
|
|
|
2015-06-18 13:07:36 -05:00
|
|
|
let llargs = get_params(fcx.llfn);
|
|
|
|
|
Pass fat pointers in two immediate arguments
This has a number of advantages compared to creating a copy in memory
and passing a pointer. The obvious one is that we don't have to put the
data into memory but can keep it in registers. Since we're currently
passing a pointer anyway (instead of using e.g. a known offset on the
stack, which is what the `byval` attribute would achieve), we only use a
single additional register for each fat pointer, but save at least two
pointers worth of stack in exchange (sometimes more because more than
one copy gets eliminated). On archs that pass arguments on the stack, we
save a pointer worth of stack even without considering the omitted
copies.
Additionally, LLVM can optimize the code a lot better, to a large degree
due to the fact that lots of copies are gone or can be optimized away.
Additionally, we can now emit attributes like nonnull on the data and/or
vtable pointers contained in the fat pointer, potentially allowing for
even more optimizations.
This results in LLVM passes being about 3-7% faster (depending on the
crate), and the resulting code is also a few percent smaller, for
example:
text data filename
5671479 3941461 before/librustc-d8ace771.so
5447663 3905745 after/librustc-d8ace771.so
1944425 2394024 before/libstd-d8ace771.so
1896769 2387610 after/libstd-d8ace771.so
I had to remove a call in the backtrace-debuginfo test, because LLVM can
now merge the tails of some blocks when optimizations are turned on,
which can't correctly preserve line info.
Fixes #22924
Cc #22891 (at least for fat pointers the code is good now)
2015-06-18 16:57:40 -05:00
|
|
|
let self_idx = fcx.arg_offset();
|
2014-12-01 08:23:40 -06:00
|
|
|
// the first argument (`self`) will be ptr to the the fn pointer
|
2015-02-15 14:09:26 -06:00
|
|
|
let llfnpointer = if is_by_ref {
|
Pass fat pointers in two immediate arguments
This has a number of advantages compared to creating a copy in memory
and passing a pointer. The obvious one is that we don't have to put the
data into memory but can keep it in registers. Since we're currently
passing a pointer anyway (instead of using e.g. a known offset on the
stack, which is what the `byval` attribute would achieve), we only use a
single additional register for each fat pointer, but save at least two
pointers worth of stack in exchange (sometimes more because more than
one copy gets eliminated). On archs that pass arguments on the stack, we
save a pointer worth of stack even without considering the omitted
copies.
Additionally, LLVM can optimize the code a lot better, to a large degree
due to the fact that lots of copies are gone or can be optimized away.
Additionally, we can now emit attributes like nonnull on the data and/or
vtable pointers contained in the fat pointer, potentially allowing for
even more optimizations.
This results in LLVM passes being about 3-7% faster (depending on the
crate), and the resulting code is also a few percent smaller, for
example:
text data filename
5671479 3941461 before/librustc-d8ace771.so
5447663 3905745 after/librustc-d8ace771.so
1944425 2394024 before/libstd-d8ace771.so
1896769 2387610 after/libstd-d8ace771.so
I had to remove a call in the backtrace-debuginfo test, because LLVM can
now merge the tails of some blocks when optimizations are turned on,
which can't correctly preserve line info.
Fixes #22924
Cc #22891 (at least for fat pointers the code is good now)
2015-06-18 16:57:40 -05:00
|
|
|
Load(bcx, llargs[self_idx])
|
2015-02-15 14:09:26 -06:00
|
|
|
} else {
|
Pass fat pointers in two immediate arguments
This has a number of advantages compared to creating a copy in memory
and passing a pointer. The obvious one is that we don't have to put the
data into memory but can keep it in registers. Since we're currently
passing a pointer anyway (instead of using e.g. a known offset on the
stack, which is what the `byval` attribute would achieve), we only use a
single additional register for each fat pointer, but save at least two
pointers worth of stack in exchange (sometimes more because more than
one copy gets eliminated). On archs that pass arguments on the stack, we
save a pointer worth of stack even without considering the omitted
copies.
Additionally, LLVM can optimize the code a lot better, to a large degree
due to the fact that lots of copies are gone or can be optimized away.
Additionally, we can now emit attributes like nonnull on the data and/or
vtable pointers contained in the fat pointer, potentially allowing for
even more optimizations.
This results in LLVM passes being about 3-7% faster (depending on the
crate), and the resulting code is also a few percent smaller, for
example:
text data filename
5671479 3941461 before/librustc-d8ace771.so
5447663 3905745 after/librustc-d8ace771.so
1944425 2394024 before/libstd-d8ace771.so
1896769 2387610 after/libstd-d8ace771.so
I had to remove a call in the backtrace-debuginfo test, because LLVM can
now merge the tails of some blocks when optimizations are turned on,
which can't correctly preserve line info.
Fixes #22924
Cc #22891 (at least for fat pointers the code is good now)
2015-06-18 16:57:40 -05:00
|
|
|
llargs[self_idx]
|
2015-02-15 14:09:26 -06:00
|
|
|
};
|
2014-12-01 08:23:40 -06:00
|
|
|
|
|
|
|
assert!(!fcx.needs_ret_allocas);
|
|
|
|
|
|
|
|
let dest = fcx.llretslotptr.get().map(|_|
|
2015-01-06 04:03:42 -06:00
|
|
|
expr::SaveIn(fcx.get_ret_slot(bcx, sig.output, "ret_slot"))
|
2014-12-01 08:23:40 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
bcx = trans_call_inner(bcx,
|
2015-02-04 10:16:59 -06:00
|
|
|
DebugLoc::None,
|
2014-12-01 08:23:40 -06:00
|
|
|
bare_fn_ty,
|
|
|
|
|bcx, _| Callee { bcx: bcx, data: Fn(llfnpointer) },
|
Pass fat pointers in two immediate arguments
This has a number of advantages compared to creating a copy in memory
and passing a pointer. The obvious one is that we don't have to put the
data into memory but can keep it in registers. Since we're currently
passing a pointer anyway (instead of using e.g. a known offset on the
stack, which is what the `byval` attribute would achieve), we only use a
single additional register for each fat pointer, but save at least two
pointers worth of stack in exchange (sometimes more because more than
one copy gets eliminated). On archs that pass arguments on the stack, we
save a pointer worth of stack even without considering the omitted
copies.
Additionally, LLVM can optimize the code a lot better, to a large degree
due to the fact that lots of copies are gone or can be optimized away.
Additionally, we can now emit attributes like nonnull on the data and/or
vtable pointers contained in the fat pointer, potentially allowing for
even more optimizations.
This results in LLVM passes being about 3-7% faster (depending on the
crate), and the resulting code is also a few percent smaller, for
example:
text data filename
5671479 3941461 before/librustc-d8ace771.so
5447663 3905745 after/librustc-d8ace771.so
1944425 2394024 before/libstd-d8ace771.so
1896769 2387610 after/libstd-d8ace771.so
I had to remove a call in the backtrace-debuginfo test, because LLVM can
now merge the tails of some blocks when optimizations are turned on,
which can't correctly preserve line info.
Fixes #22924
Cc #22891 (at least for fat pointers the code is good now)
2015-06-18 16:57:40 -05:00
|
|
|
ArgVals(&llargs[(self_idx + 1)..]),
|
2014-12-01 08:23:40 -06:00
|
|
|
dest).bcx;
|
|
|
|
|
2014-12-11 06:53:30 -06:00
|
|
|
finish_fn(&fcx, bcx, sig.output, DebugLoc::None);
|
2014-12-01 08:23:40 -06:00
|
|
|
|
2015-02-15 14:09:26 -06:00
|
|
|
ccx.fn_pointer_shims().borrow_mut().insert(bare_fn_ty_maybe_ref, llfn);
|
2014-12-03 19:23:15 -06:00
|
|
|
|
2014-12-01 08:23:40 -06:00
|
|
|
llfn
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:17:11 -06:00
|
|
|
/// Translates a reference to a fn/method item, monomorphizing and
|
|
|
|
/// inlining as it goes.
|
|
|
|
///
|
|
|
|
/// # Parameters
|
|
|
|
///
|
2015-01-04 10:47:58 -06:00
|
|
|
/// - `ccx`: the crate context
|
2014-11-25 20:17:11 -06:00
|
|
|
/// - `def_id`: def id of the fn or method item being referenced
|
|
|
|
/// - `node`: node id of the reference to the fn/method, if applicable.
|
|
|
|
/// This parameter may be zero; but, if so, the resulting value may not
|
|
|
|
/// have the right type, so it must be cast before being used.
|
2015-01-04 10:47:58 -06:00
|
|
|
/// - `param_substs`: if the `node` is in a polymorphic function, these
|
|
|
|
/// are the substitutions required to monomorphize its type
|
2014-11-25 20:17:11 -06:00
|
|
|
/// - `substs`: values for each of the fn/method's parameters
|
2015-01-04 10:47:58 -06:00
|
|
|
pub fn trans_fn_ref_with_substs<'a, 'tcx>(
|
|
|
|
ccx: &CrateContext<'a, 'tcx>,
|
|
|
|
def_id: ast::DefId,
|
|
|
|
node: ExprOrMethodCall,
|
2015-01-29 06:03:34 -06:00
|
|
|
param_substs: &'tcx subst::Substs<'tcx>,
|
2015-01-04 10:47:58 -06:00
|
|
|
substs: subst::Substs<'tcx>)
|
|
|
|
-> Datum<'tcx, Rvalue>
|
2014-05-31 17:53:13 -05:00
|
|
|
{
|
2014-09-12 10:42:58 -05:00
|
|
|
let _icx = push_ctxt("trans_fn_ref_with_substs");
|
2015-01-04 10:47:58 -06:00
|
|
|
let tcx = ccx.tcx();
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2015-06-18 12:25:05 -05:00
|
|
|
debug!("trans_fn_ref_with_substs(def_id={:?}, node={:?}, \
|
|
|
|
param_substs={:?}, substs={:?})",
|
|
|
|
def_id,
|
2014-03-06 11:24:11 -06:00
|
|
|
node,
|
2015-06-18 12:25:05 -05:00
|
|
|
param_substs,
|
|
|
|
substs);
|
2012-09-10 14:25:45 -05:00
|
|
|
|
2014-05-31 17:53:13 -05:00
|
|
|
assert!(substs.types.all(|t| !ty::type_needs_infer(*t)));
|
2014-11-15 15:50:34 -06:00
|
|
|
assert!(substs.types.all(|t| !ty::type_has_escaping_regions(*t)));
|
|
|
|
let substs = substs.erase_regions();
|
2013-03-21 07:34:18 -05:00
|
|
|
|
2013-08-23 16:34:00 -05:00
|
|
|
// Load the info for the appropriate trait if necessary.
|
2014-08-04 15:56:56 -05:00
|
|
|
match ty::trait_of_item(tcx, def_id) {
|
2013-08-23 16:34:00 -05:00
|
|
|
None => {}
|
|
|
|
Some(trait_id) => {
|
|
|
|
ty::populate_implementations_for_trait_if_necessary(tcx, trait_id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-12 13:05:03 -05:00
|
|
|
// We need to do a bunch of special handling for default methods.
|
|
|
|
// We need to modify the def_id and our substs in order to monomorphize
|
|
|
|
// the function.
|
2014-09-12 10:42:58 -05:00
|
|
|
let (is_default, def_id, substs) = match ty::provided_source(tcx, def_id) {
|
2015-01-29 06:03:34 -06:00
|
|
|
None => {
|
|
|
|
(false, def_id, tcx.mk_substs(substs))
|
|
|
|
}
|
2013-07-15 19:26:56 -05:00
|
|
|
Some(source_id) => {
|
2013-06-12 13:05:03 -05:00
|
|
|
// There are two relevant substitutions when compiling
|
|
|
|
// default methods. First, there is the substitution for
|
|
|
|
// the type parameters of the impl we are using and the
|
|
|
|
// method we are calling. This substitution is the substs
|
|
|
|
// argument we already have.
|
|
|
|
// In order to compile a default method, though, we need
|
|
|
|
// to consider another substitution: the substitution for
|
|
|
|
// the type parameters on trait; the impl we are using
|
|
|
|
// implements the trait at some particular type
|
|
|
|
// parameters, and we need to substitute for those first.
|
|
|
|
// So, what we need to do is find this substitution and
|
|
|
|
// compose it with the one we already have.
|
|
|
|
|
2014-08-04 15:56:56 -05:00
|
|
|
let impl_id = ty::impl_or_trait_item(tcx, def_id).container()
|
|
|
|
.id();
|
|
|
|
let impl_or_trait_item = ty::impl_or_trait_item(tcx, source_id);
|
|
|
|
match impl_or_trait_item {
|
|
|
|
ty::MethodTraitItem(method) => {
|
2014-12-14 06:17:23 -06:00
|
|
|
let trait_ref = ty::impl_trait_ref(tcx, impl_id).unwrap();
|
2014-08-04 15:56:56 -05:00
|
|
|
|
|
|
|
// Compute the first substitution
|
2014-11-15 15:50:34 -06:00
|
|
|
let first_subst =
|
2015-04-21 10:59:58 -05:00
|
|
|
ty::make_substs_for_receiver_types(tcx, &trait_ref, &*method)
|
2014-11-15 15:50:34 -06:00
|
|
|
.erase_regions();
|
2014-08-04 15:56:56 -05:00
|
|
|
|
|
|
|
// And compose them
|
2015-01-29 06:03:34 -06:00
|
|
|
let new_substs = tcx.mk_substs(first_subst.subst(tcx, &substs));
|
2014-08-04 15:56:56 -05:00
|
|
|
|
|
|
|
debug!("trans_fn_with_vtables - default method: \
|
2015-06-18 12:25:05 -05:00
|
|
|
substs = {:?}, trait_subst = {:?}, \
|
|
|
|
first_subst = {:?}, new_subst = {:?}",
|
|
|
|
substs, trait_ref.substs,
|
|
|
|
first_subst, new_substs);
|
2014-08-04 15:56:56 -05:00
|
|
|
|
2014-09-12 10:42:58 -05:00
|
|
|
(true, source_id, new_substs)
|
2014-08-04 15:56:56 -05:00
|
|
|
}
|
2015-03-14 13:05:00 -05:00
|
|
|
_ => {
|
2015-01-04 10:47:58 -06:00
|
|
|
tcx.sess.bug("trans_fn_ref_with_vtables() tried \
|
2015-03-14 13:05:00 -05:00
|
|
|
to translate a non-method?!")
|
2014-08-05 21:44:21 -05:00
|
|
|
}
|
2014-08-04 15:56:56 -05:00
|
|
|
}
|
2013-06-12 13:05:03 -05:00
|
|
|
}
|
2012-10-08 14:39:30 -05:00
|
|
|
};
|
|
|
|
|
2015-01-24 14:15:08 -06:00
|
|
|
// If this is a closure, redirect to it.
|
2015-01-29 06:03:34 -06:00
|
|
|
match closure::get_or_create_declaration_if_closure(ccx, def_id, substs) {
|
2014-05-29 00:26:56 -05:00
|
|
|
None => {}
|
|
|
|
Some(llfn) => return llfn,
|
|
|
|
}
|
|
|
|
|
2012-08-28 17:54:45 -05:00
|
|
|
// Check whether this fn has an inlined copy and, if so, redirect
|
|
|
|
// def_id to the local id of the inlined copy.
|
2014-09-05 19:39:51 -05:00
|
|
|
let def_id = inline::maybe_instantiate_inline(ccx, def_id);
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2014-07-10 12:59:52 -05:00
|
|
|
// We must monomorphise if the fn has type parameters, is a default method,
|
|
|
|
// or is a named tuple constructor.
|
|
|
|
let must_monomorphise = if !substs.types.is_empty() || is_default {
|
|
|
|
true
|
|
|
|
} else if def_id.krate == ast::LOCAL_CRATE {
|
|
|
|
let map_node = session::expect(
|
|
|
|
ccx.sess(),
|
|
|
|
tcx.map.find(def_id.node),
|
|
|
|
|| "local item should be in ast map".to_string());
|
|
|
|
|
|
|
|
match map_node {
|
|
|
|
ast_map::NodeVariant(v) => match v.node.kind {
|
2015-03-24 18:54:09 -05:00
|
|
|
ast::TupleVariantKind(ref args) => !args.is_empty(),
|
2014-07-10 12:59:52 -05:00
|
|
|
_ => false
|
|
|
|
},
|
|
|
|
ast_map::NodeStructCtor(_) => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
};
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2015-06-18 12:25:05 -05:00
|
|
|
debug!("trans_fn_ref_with_substs({:?}) must_monomorphise: {}",
|
|
|
|
def_id, must_monomorphise);
|
2015-06-02 18:31:23 -05:00
|
|
|
|
2014-04-20 23:49:39 -05:00
|
|
|
// Create a monomorphic version of generic functions
|
2012-08-28 17:54:45 -05:00
|
|
|
if must_monomorphise {
|
|
|
|
// Should be either intra-crate or inlined.
|
2014-02-05 15:15:24 -06:00
|
|
|
assert_eq!(def_id.krate, ast::LOCAL_CRATE);
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2014-03-08 10:33:39 -06:00
|
|
|
let opt_ref_id = match node {
|
|
|
|
ExprId(id) => if id != 0 { Some(id) } else { None },
|
2014-12-14 22:03:00 -06:00
|
|
|
MethodCallKey(_) => None,
|
2014-03-06 11:24:11 -06:00
|
|
|
};
|
|
|
|
|
2015-01-04 10:47:58 -06:00
|
|
|
let (val, fn_ty, must_cast) =
|
2015-01-29 06:03:34 -06:00
|
|
|
monomorphize::monomorphic_fn(ccx, def_id, substs, opt_ref_id);
|
2014-03-06 11:24:11 -06:00
|
|
|
if must_cast && node != ExprId(0) {
|
2012-08-28 17:54:45 -05:00
|
|
|
// Monotype of the REFERENCE to the function (type params
|
|
|
|
// are subst'd)
|
2014-03-06 11:24:11 -06:00
|
|
|
let ref_ty = match node {
|
2015-01-04 10:47:58 -06:00
|
|
|
ExprId(id) => ty::node_id_to_type(tcx, id),
|
2014-12-14 22:03:00 -06:00
|
|
|
MethodCallKey(method_call) => {
|
2015-03-21 20:15:47 -05:00
|
|
|
tcx.method_map.borrow().get(&method_call).unwrap().ty
|
2014-03-06 11:24:11 -06:00
|
|
|
}
|
2014-02-26 08:06:45 -06:00
|
|
|
};
|
2015-01-04 10:47:58 -06:00
|
|
|
let ref_ty = monomorphize::apply_param_substs(tcx,
|
|
|
|
param_substs,
|
|
|
|
&ref_ty);
|
|
|
|
let llptrty = type_of::type_of_fn_from_ty(ccx, ref_ty).ptr_to();
|
2015-02-04 10:16:59 -06:00
|
|
|
if llptrty != common::val_ty(val) {
|
2015-01-04 10:47:58 -06:00
|
|
|
let val = consts::ptrcast(val, llptrty);
|
|
|
|
return Datum::new(val, ref_ty, Rvalue::new(ByValue));
|
|
|
|
}
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
2015-01-04 10:47:58 -06:00
|
|
|
return Datum::new(val, fn_ty, Rvalue::new(ByValue));
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
2014-12-23 04:52:47 -06:00
|
|
|
// Type scheme of the function item (may have type params)
|
|
|
|
let fn_type_scheme = ty::lookup_item_type(tcx, def_id);
|
2014-12-17 13:16:28 -06:00
|
|
|
let fn_type = monomorphize::normalize_associated_type(tcx, &fn_type_scheme.ty);
|
2014-05-29 00:26:56 -05:00
|
|
|
|
2012-08-28 17:54:45 -05:00
|
|
|
// Find the actual function pointer.
|
2013-05-21 14:25:44 -05:00
|
|
|
let mut val = {
|
2014-02-05 15:15:24 -06:00
|
|
|
if def_id.krate == ast::LOCAL_CRATE {
|
2012-08-28 17:54:45 -05:00
|
|
|
// Internal reference.
|
|
|
|
get_item_val(ccx, def_id.node)
|
|
|
|
} else {
|
|
|
|
// External reference.
|
2014-12-17 13:16:28 -06:00
|
|
|
trans_external_path(ccx, def_id, fn_type)
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-21 14:25:44 -05:00
|
|
|
// This is subtle and surprising, but sometimes we have to bitcast
|
|
|
|
// the resulting fn pointer. The reason has to do with external
|
|
|
|
// functions. If you have two crates that both bind the same C
|
|
|
|
// library, they may not use precisely the same types: for
|
|
|
|
// example, they will probably each declare their own structs,
|
|
|
|
// which are distinct types from LLVM's point of view (nominal
|
|
|
|
// types).
|
|
|
|
//
|
|
|
|
// Now, if those two crates are linked into an application, and
|
|
|
|
// they contain inlined code, you can wind up with a situation
|
|
|
|
// where both of those functions wind up being loaded into this
|
|
|
|
// application simultaneously. In that case, the same function
|
|
|
|
// (from LLVM's point of view) requires two types. But of course
|
|
|
|
// LLVM won't allow one function to have two types.
|
|
|
|
//
|
|
|
|
// What we currently do, therefore, is declare the function with
|
|
|
|
// one of the two types (whichever happens to come first) and then
|
|
|
|
// bitcast as needed when the function is referenced to make sure
|
|
|
|
// it has the type we expect.
|
|
|
|
//
|
|
|
|
// This can occur on either a crate-local or crate-external
|
|
|
|
// reference. It also occurs when testing libcore and in some
|
|
|
|
// other weird situations. Annoying.
|
2014-12-17 13:16:28 -06:00
|
|
|
let llty = type_of::type_of_fn_from_ty(ccx, fn_type);
|
2013-05-21 14:25:44 -05:00
|
|
|
let llptrty = llty.ptr_to();
|
2015-02-04 10:16:59 -06:00
|
|
|
if common::val_ty(val) != llptrty {
|
2014-05-29 00:26:56 -05:00
|
|
|
debug!("trans_fn_ref_with_vtables(): casting pointer!");
|
2015-01-04 10:47:58 -06:00
|
|
|
val = consts::ptrcast(val, llptrty);
|
2014-05-29 00:26:56 -05:00
|
|
|
} else {
|
|
|
|
debug!("trans_fn_ref_with_vtables(): not casting pointer!");
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
|
2015-01-04 10:47:58 -06:00
|
|
|
Datum::new(val, fn_type, Rvalue::new(ByValue))
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ______________________________________________________________________
|
|
|
|
// Translating calls
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
pub fn trans_call<'a, 'blk, 'tcx>(in_cx: Block<'blk, 'tcx>,
|
2015-02-04 10:16:59 -06:00
|
|
|
call_expr: &ast::Expr,
|
2014-09-29 14:11:30 -05:00
|
|
|
f: &ast::Expr,
|
|
|
|
args: CallArgs<'a, 'tcx>,
|
|
|
|
dest: expr::Dest)
|
|
|
|
-> Block<'blk, 'tcx> {
|
2013-06-16 23:23:24 -05:00
|
|
|
let _icx = push_ctxt("trans_call");
|
2013-04-18 17:53:29 -05:00
|
|
|
trans_call_inner(in_cx,
|
2015-02-04 10:16:59 -06:00
|
|
|
call_expr.debug_loc(),
|
|
|
|
common::expr_ty_adjusted(in_cx, f),
|
2014-01-15 13:39:08 -06:00
|
|
|
|cx, _| trans(cx, f),
|
2013-04-18 17:53:29 -05:00
|
|
|
args,
|
2014-01-27 06:18:36 -06:00
|
|
|
Some(dest)).bcx
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
pub fn trans_method_call<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
2015-02-04 10:16:59 -06:00
|
|
|
call_expr: &ast::Expr,
|
2014-09-29 14:11:30 -05:00
|
|
|
rcvr: &ast::Expr,
|
|
|
|
args: CallArgs<'a, 'tcx>,
|
|
|
|
dest: expr::Dest)
|
|
|
|
-> Block<'blk, 'tcx> {
|
2013-06-16 23:23:24 -05:00
|
|
|
let _icx = push_ctxt("trans_method_call");
|
2015-06-18 12:25:05 -05:00
|
|
|
debug!("trans_method_call(call_expr={:?})", call_expr);
|
2015-02-04 10:16:59 -06:00
|
|
|
let method_call = MethodCall::expr(call_expr.id);
|
2015-03-01 11:19:07 -06:00
|
|
|
let method_ty = match bcx.tcx().method_map.borrow().get(&method_call) {
|
|
|
|
Some(method) => match method.origin {
|
|
|
|
ty::MethodTraitObject(_) => match method.ty.sty {
|
2015-06-11 18:21:46 -05:00
|
|
|
ty::TyBareFn(_, ref fty) => {
|
2015-03-01 11:19:07 -06:00
|
|
|
ty::mk_bare_fn(bcx.tcx(), None, meth::opaque_method_ty(bcx.tcx(), fty))
|
|
|
|
}
|
|
|
|
_ => method.ty
|
|
|
|
},
|
|
|
|
_ => method.ty
|
|
|
|
},
|
|
|
|
None => panic!("method not found in trans_method_call")
|
|
|
|
};
|
2012-11-30 13:18:25 -06:00
|
|
|
trans_call_inner(
|
2014-02-26 08:06:45 -06:00
|
|
|
bcx,
|
2015-02-04 10:16:59 -06:00
|
|
|
call_expr.debug_loc(),
|
|
|
|
common::monomorphize_type(bcx, method_ty),
|
2014-01-15 13:39:08 -06:00
|
|
|
|cx, arg_cleanup_scope| {
|
2014-03-06 11:24:11 -06:00
|
|
|
meth::trans_method_callee(cx, method_call, Some(rcvr), arg_cleanup_scope)
|
2012-11-30 13:18:25 -06:00
|
|
|
},
|
|
|
|
args,
|
2014-01-27 06:18:36 -06:00
|
|
|
Some(dest)).bcx
|
2012-11-30 13:18:25 -06:00
|
|
|
}
|
|
|
|
|
2014-09-06 11:13:04 -05:00
|
|
|
pub fn trans_lang_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|
|
|
did: ast::DefId,
|
|
|
|
args: &[ValueRef],
|
2015-02-04 10:16:59 -06:00
|
|
|
dest: Option<expr::Dest>,
|
|
|
|
debug_loc: DebugLoc)
|
2014-09-06 11:13:04 -05:00
|
|
|
-> Result<'blk, 'tcx> {
|
2014-02-05 15:15:24 -06:00
|
|
|
let fty = if did.krate == ast::LOCAL_CRATE {
|
2014-03-15 15:29:34 -05:00
|
|
|
ty::node_id_to_type(bcx.tcx(), did.node)
|
2012-08-28 17:54:45 -05:00
|
|
|
} else {
|
2014-03-15 15:29:34 -05:00
|
|
|
csearch::get_type(bcx.tcx(), did).ty
|
2012-08-28 17:54:45 -05:00
|
|
|
};
|
2013-04-24 03:29:46 -05:00
|
|
|
callee::trans_call_inner(bcx,
|
2015-02-04 10:16:59 -06:00
|
|
|
debug_loc,
|
2013-04-24 03:29:46 -05:00
|
|
|
fty,
|
2014-01-15 13:39:08 -06:00
|
|
|
|bcx, _| {
|
2014-09-12 10:42:58 -05:00
|
|
|
trans_fn_ref_with_substs_to_callee(bcx,
|
|
|
|
did,
|
|
|
|
0,
|
2014-11-15 15:50:34 -06:00
|
|
|
subst::Substs::trans_empty())
|
2013-04-24 03:29:46 -05:00
|
|
|
},
|
|
|
|
ArgVals(args),
|
2014-01-27 06:18:36 -06:00
|
|
|
dest)
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
2014-11-25 20:17:11 -06:00
|
|
|
/// This behemoth of a function translates function calls. Unfortunately, in order to generate more
|
|
|
|
/// efficient LLVM output at -O0, it has quite a complex signature (refactoring this into two
|
|
|
|
/// functions seems like a good idea).
|
|
|
|
///
|
|
|
|
/// In particular, for lang items, it is invoked with a dest of None, and in that case the return
|
|
|
|
/// value contains the result of the fn. The lang item must not return a structural type or else
|
|
|
|
/// all heck breaks loose.
|
|
|
|
///
|
|
|
|
/// For non-lang items, `dest` is always Some, and hence the result is written into memory
|
|
|
|
/// somewhere. Nonetheless we return the actual return value of the function.
|
2014-12-09 12:44:51 -06:00
|
|
|
pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
|
2015-02-04 10:16:59 -06:00
|
|
|
debug_loc: DebugLoc,
|
2014-12-09 12:44:51 -06:00
|
|
|
callee_ty: Ty<'tcx>,
|
|
|
|
get_callee: F,
|
|
|
|
args: CallArgs<'a, 'tcx>,
|
|
|
|
dest: Option<expr::Dest>)
|
|
|
|
-> Result<'blk, 'tcx> where
|
|
|
|
F: FnOnce(Block<'blk, 'tcx>, cleanup::ScopeId) -> Callee<'blk, 'tcx>,
|
|
|
|
{
|
2014-01-15 13:39:08 -06:00
|
|
|
// Introduce a temporary cleanup scope that will contain cleanups
|
|
|
|
// for the arguments while they are being evaluated. The purpose
|
2014-10-09 14:17:22 -05:00
|
|
|
// this cleanup is to ensure that, should a panic occur while
|
2014-01-15 13:39:08 -06:00
|
|
|
// evaluating argument N, the values for arguments 0...N-1 are all
|
2014-10-09 14:17:22 -05:00
|
|
|
// cleaned up. If no panic occurs, the values are handed off to
|
2014-01-15 13:39:08 -06:00
|
|
|
// the callee, and hence none of the cleanups in this temporary
|
|
|
|
// scope will ever execute.
|
|
|
|
let fcx = bcx.fcx;
|
|
|
|
let ccx = fcx.ccx;
|
|
|
|
let arg_cleanup_scope = fcx.push_custom_cleanup_scope();
|
2013-05-21 14:25:44 -05:00
|
|
|
|
2014-01-15 13:39:08 -06:00
|
|
|
let callee = get_callee(bcx, cleanup::CustomScope(arg_cleanup_scope));
|
|
|
|
let mut bcx = callee.bcx;
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2014-10-31 03:51:16 -05:00
|
|
|
let (abi, ret_ty) = match callee_ty.sty {
|
2015-06-11 18:21:46 -05:00
|
|
|
ty::TyBareFn(_, ref f) => {
|
2015-01-06 04:03:42 -06:00
|
|
|
let output = ty::erase_late_bound_regions(bcx.tcx(), &f.sig.output());
|
|
|
|
(f.abi, output)
|
|
|
|
}
|
2014-10-09 14:17:22 -05:00
|
|
|
_ => panic!("expected bare rust fn or closure in trans_call_inner")
|
2014-07-09 17:31:45 -05:00
|
|
|
};
|
|
|
|
|
2014-01-27 06:18:36 -06:00
|
|
|
let (llfn, llenv, llself) = match callee.data {
|
|
|
|
Fn(llfn) => {
|
|
|
|
(llfn, None, None)
|
|
|
|
}
|
2014-08-04 15:56:56 -05:00
|
|
|
TraitItem(d) => {
|
2014-01-27 06:18:36 -06:00
|
|
|
(d.llfn, None, Some(d.llself))
|
|
|
|
}
|
2014-07-09 17:31:45 -05:00
|
|
|
Intrinsic(node, substs) => {
|
|
|
|
assert!(abi == synabi::RustIntrinsic);
|
|
|
|
assert!(dest.is_some());
|
2014-01-15 13:39:08 -06:00
|
|
|
|
2015-02-04 10:16:59 -06:00
|
|
|
let call_info = match debug_loc {
|
|
|
|
DebugLoc::At(id, span) => NodeIdAndSpan { id: id, span: span },
|
|
|
|
DebugLoc::None => {
|
|
|
|
bcx.sess().bug("No call info for intrinsic call?")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-09 17:31:45 -05:00
|
|
|
return intrinsic::trans_intrinsic_call(bcx, node, callee_ty,
|
|
|
|
arg_cleanup_scope, args,
|
2014-08-05 16:38:14 -05:00
|
|
|
dest.unwrap(), substs,
|
|
|
|
call_info);
|
2014-07-09 17:31:45 -05:00
|
|
|
}
|
2014-07-10 02:20:28 -05:00
|
|
|
NamedTupleConstructor(substs, disr) => {
|
2014-07-10 01:42:08 -05:00
|
|
|
assert!(dest.is_some());
|
|
|
|
fcx.pop_custom_cleanup_scope(arg_cleanup_scope);
|
|
|
|
|
|
|
|
let ctor_ty = callee_ty.subst(bcx.tcx(), &substs);
|
debuginfo: Make sure that all calls to drop glue are associated with debug locations.
This commit makes rustc emit debug locations for all call
and invoke statements in LLVM IR, if they are contained
within a function that debuginfo is enabled for. This is
important because LLVM does not handle the case where a
function body containing debuginfo is inlined into another
function with debuginfo, but the inlined call statement
does not have a debug location. In this case, LLVM will
not know where (in terms of source code coordinates) the
function was inlined to and we end up with some statements
still linked to the source locations in there original,
non-inlined function without any indication that they are
indeed an inline-copy. Later, when generating DWARF from
the IR, LLVM will interpret this as corrupt IR and abort.
Unfortunately, the undesirable case described above can
still occur when using LTO. If there is a crate compiled
without debuginfo calling into a crate compiled with
debuginfo, we again end up with the conditions triggering
the error. This is why some LTO tests still fail with the
dreaded assertion, if the standard library was built with
debuginfo enabled.
That is, `RUSTFLAGS_STAGE2=-g make rustc-stage2` will
succeed but `RUSTFLAGS_STAGE2=-g make check` will still
fail after this commit has been merged. This is a problem
that has to be dealt with separately.
Fixes #17201
Fixes #15816
Fixes #15156
2014-09-24 01:49:38 -05:00
|
|
|
return base::trans_named_tuple_constructor(bcx,
|
|
|
|
ctor_ty,
|
|
|
|
disr,
|
|
|
|
args,
|
|
|
|
dest.unwrap(),
|
2015-02-04 10:16:59 -06:00
|
|
|
debug_loc);
|
2014-07-10 01:42:08 -05:00
|
|
|
}
|
2014-01-15 13:39:08 -06:00
|
|
|
};
|
|
|
|
|
2014-07-09 19:51:05 -05:00
|
|
|
// Intrinsics should not become actual functions.
|
|
|
|
// We trans them in place in `trans_intrinsic_call`
|
|
|
|
assert!(abi != synabi::RustIntrinsic);
|
|
|
|
|
2014-07-28 01:23:16 -05:00
|
|
|
let is_rust_fn = abi == synabi::Rust || abi == synabi::RustCall;
|
|
|
|
|
2014-01-15 13:39:08 -06:00
|
|
|
// Generate a location to store the result. If the user does
|
|
|
|
// not care about the result, just make a stack slot.
|
2014-10-24 14:14:37 -05:00
|
|
|
let opt_llretslot = dest.and_then(|dest| match dest {
|
|
|
|
expr::SaveIn(dst) => Some(dst),
|
|
|
|
expr::Ignore => {
|
|
|
|
let ret_ty = match ret_ty {
|
|
|
|
ty::FnConverging(ret_ty) => ret_ty,
|
2014-11-04 06:57:21 -06:00
|
|
|
ty::FnDiverging => ty::mk_nil(ccx.tcx())
|
2014-10-24 14:14:37 -05:00
|
|
|
};
|
|
|
|
if !is_rust_fn ||
|
|
|
|
type_of::return_uses_outptr(ccx, ret_ty) ||
|
2015-02-25 16:09:58 -06:00
|
|
|
bcx.fcx.type_needs_drop(ret_ty) {
|
2014-10-24 14:14:37 -05:00
|
|
|
// Push the out-pointer if we use an out-pointer for this
|
|
|
|
// return type, otherwise push "undef".
|
2015-02-04 10:16:59 -06:00
|
|
|
if common::type_is_zero_size(ccx, ret_ty) {
|
2014-10-24 14:14:37 -05:00
|
|
|
let llty = type_of::type_of(ccx, ret_ty);
|
2015-02-04 10:16:59 -06:00
|
|
|
Some(common::C_undef(llty.ptr_to()))
|
2014-10-24 14:14:37 -05:00
|
|
|
} else {
|
|
|
|
Some(alloc_ty(bcx, ret_ty, "__llret"))
|
|
|
|
}
|
2014-01-15 13:39:08 -06:00
|
|
|
} else {
|
2014-10-24 14:14:37 -05:00
|
|
|
None
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
2014-01-15 13:39:08 -06:00
|
|
|
}
|
2014-10-24 14:14:37 -05:00
|
|
|
});
|
2013-03-19 13:40:34 -05:00
|
|
|
|
2014-01-15 13:39:08 -06:00
|
|
|
let mut llresult = unsafe {
|
2014-03-15 15:29:34 -05:00
|
|
|
llvm::LLVMGetUndef(Type::nil(ccx).ptr_to().to_ref())
|
2014-01-15 13:39:08 -06:00
|
|
|
};
|
2013-04-18 17:53:29 -05:00
|
|
|
|
2014-01-15 13:39:08 -06:00
|
|
|
// The code below invokes the function, using either the Rust
|
|
|
|
// conventions (if it is a rust fn) or the native conventions
|
2014-09-02 22:31:36 -05:00
|
|
|
// (otherwise). The important part is that, when all is said
|
2014-01-15 13:39:08 -06:00
|
|
|
// and done, either the return value of the function will have been
|
|
|
|
// written in opt_llretslot (if it is Some) or `llresult` will be
|
|
|
|
// set appropriately (otherwise).
|
2014-07-28 01:23:16 -05:00
|
|
|
if is_rust_fn {
|
2014-03-04 12:02:49 -06:00
|
|
|
let mut llargs = Vec::new();
|
2014-01-15 13:39:08 -06:00
|
|
|
|
2015-02-22 05:47:27 -06:00
|
|
|
if let (ty::FnConverging(ret_ty), Some(mut llretslot)) = (ret_ty, opt_llretslot) {
|
2014-10-24 14:14:37 -05:00
|
|
|
if type_of::return_uses_outptr(ccx, ret_ty) {
|
2015-02-22 05:47:27 -06:00
|
|
|
let llformal_ret_ty = type_of::type_of(ccx, ret_ty).ptr_to();
|
|
|
|
let llret_ty = common::val_ty(llretslot);
|
|
|
|
if llformal_ret_ty != llret_ty {
|
|
|
|
// this could happen due to e.g. subtyping
|
|
|
|
debug!("casting actual return type ({}) to match formal ({})",
|
|
|
|
bcx.llty_str(llret_ty), bcx.llty_str(llformal_ret_ty));
|
|
|
|
llretslot = PointerCast(bcx, llretslot, llformal_ret_ty);
|
|
|
|
}
|
2014-10-24 14:14:37 -05:00
|
|
|
llargs.push(llretslot);
|
|
|
|
}
|
2014-01-15 13:39:08 -06:00
|
|
|
}
|
2013-05-21 14:25:44 -05:00
|
|
|
|
2014-01-27 06:18:36 -06:00
|
|
|
// Push the environment (or a trait object's self).
|
|
|
|
match (llenv, llself) {
|
2014-10-24 14:14:37 -05:00
|
|
|
(Some(llenv), None) => llargs.push(llenv),
|
2014-01-27 06:18:36 -06:00
|
|
|
(None, Some(llself)) => llargs.push(llself),
|
|
|
|
_ => {}
|
|
|
|
}
|
2013-04-18 17:53:29 -05:00
|
|
|
|
2014-01-15 13:39:08 -06:00
|
|
|
// Push the arguments.
|
2014-05-29 00:26:56 -05:00
|
|
|
bcx = trans_args(bcx,
|
|
|
|
args,
|
|
|
|
callee_ty,
|
|
|
|
&mut llargs,
|
2014-01-27 06:18:36 -06:00
|
|
|
cleanup::CustomScope(arg_cleanup_scope),
|
2014-05-29 00:26:56 -05:00
|
|
|
llself.is_some(),
|
|
|
|
abi);
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2014-10-13 09:12:38 -05:00
|
|
|
fcx.scopes.borrow_mut().last_mut().unwrap().drop_non_lifetime_clean();
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2014-01-15 13:39:08 -06:00
|
|
|
// Invoke the actual rust fn and update bcx/llresult.
|
2014-03-08 14:36:22 -06:00
|
|
|
let (llret, b) = base::invoke(bcx,
|
|
|
|
llfn,
|
2015-02-18 13:48:57 -06:00
|
|
|
&llargs[..],
|
2014-05-21 14:07:48 -05:00
|
|
|
callee_ty,
|
2015-02-04 10:16:59 -06:00
|
|
|
debug_loc);
|
2014-01-15 13:39:08 -06:00
|
|
|
bcx = b;
|
|
|
|
llresult = llret;
|
|
|
|
|
|
|
|
// If the Rust convention for this type is return via
|
|
|
|
// the return value, copy it into llretslot.
|
2014-10-24 14:14:37 -05:00
|
|
|
match (opt_llretslot, ret_ty) {
|
|
|
|
(Some(llretslot), ty::FnConverging(ret_ty)) => {
|
2014-01-15 13:39:08 -06:00
|
|
|
if !type_of::return_uses_outptr(bcx.ccx(), ret_ty) &&
|
2015-02-04 10:16:59 -06:00
|
|
|
!common::type_is_zero_size(bcx.ccx(), ret_ty)
|
2014-01-15 13:39:08 -06:00
|
|
|
{
|
2014-07-05 14:47:14 -05:00
|
|
|
store_ty(bcx, llret, llretslot, ret_ty)
|
2013-05-21 14:25:44 -05:00
|
|
|
}
|
|
|
|
}
|
2014-10-24 14:14:37 -05:00
|
|
|
(_, _) => {}
|
2012-10-26 20:23:45 -05:00
|
|
|
}
|
2014-01-15 13:39:08 -06:00
|
|
|
} else {
|
|
|
|
// Lang items are the only case where dest is None, and
|
|
|
|
// they are always Rust fns.
|
|
|
|
assert!(dest.is_some());
|
|
|
|
|
2014-03-04 12:02:49 -06:00
|
|
|
let mut llargs = Vec::new();
|
2014-01-15 13:39:08 -06:00
|
|
|
let arg_tys = match args {
|
2015-05-20 13:26:53 -05:00
|
|
|
ArgExprs(a) => a.iter().map(|x| common::expr_ty_adjusted(bcx, &**x)).collect(),
|
2014-10-09 14:17:22 -05:00
|
|
|
_ => panic!("expected arg exprs.")
|
2014-01-15 13:39:08 -06:00
|
|
|
};
|
2014-05-29 00:26:56 -05:00
|
|
|
bcx = trans_args(bcx,
|
|
|
|
args,
|
|
|
|
callee_ty,
|
|
|
|
&mut llargs,
|
|
|
|
cleanup::CustomScope(arg_cleanup_scope),
|
|
|
|
false,
|
|
|
|
abi);
|
2014-10-13 09:12:38 -05:00
|
|
|
fcx.scopes.borrow_mut().last_mut().unwrap().drop_non_lifetime_clean();
|
|
|
|
|
2015-02-04 10:42:32 -06:00
|
|
|
bcx = foreign::trans_native_call(bcx,
|
|
|
|
callee_ty,
|
|
|
|
llfn,
|
|
|
|
opt_llretslot.unwrap(),
|
2015-02-18 13:48:57 -06:00
|
|
|
&llargs[..],
|
2015-02-04 10:42:32 -06:00
|
|
|
arg_tys,
|
|
|
|
debug_loc);
|
2014-01-15 13:39:08 -06:00
|
|
|
}
|
2013-04-18 17:53:29 -05:00
|
|
|
|
2014-10-13 09:12:38 -05:00
|
|
|
fcx.pop_and_trans_custom_cleanup_scope(bcx, arg_cleanup_scope);
|
|
|
|
|
2014-01-15 13:39:08 -06:00
|
|
|
// If the caller doesn't care about the result of this fn call,
|
|
|
|
// drop the temporary slot we made.
|
2014-10-24 14:14:37 -05:00
|
|
|
match (dest, opt_llretslot, ret_ty) {
|
|
|
|
(Some(expr::Ignore), Some(llretslot), ty::FnConverging(ret_ty)) => {
|
2014-01-15 13:39:08 -06:00
|
|
|
// drop the value if it is not being saved.
|
2014-12-11 06:53:30 -06:00
|
|
|
bcx = glue::drop_ty(bcx,
|
|
|
|
llretslot,
|
|
|
|
ret_ty,
|
2015-02-04 10:16:59 -06:00
|
|
|
debug_loc);
|
2014-07-28 01:41:44 -05:00
|
|
|
call_lifetime_end(bcx, llretslot);
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
2014-07-28 01:23:16 -05:00
|
|
|
_ => {}
|
2014-01-15 13:39:08 -06:00
|
|
|
}
|
2013-05-21 14:25:44 -05:00
|
|
|
|
2014-10-28 12:32:05 -05:00
|
|
|
if ret_ty == ty::FnDiverging {
|
|
|
|
Unreachable(bcx);
|
2014-01-15 13:39:08 -06:00
|
|
|
}
|
|
|
|
|
2014-05-03 06:14:56 -05:00
|
|
|
Result::new(bcx, llresult)
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
pub enum CallArgs<'a, 'tcx> {
|
2014-03-08 10:33:39 -06:00
|
|
|
// Supply value of arguments as a list of expressions that must be
|
|
|
|
// translated. This is used in the common case of `foo(bar, qux)`.
|
2014-09-07 12:09:06 -05:00
|
|
|
ArgExprs(&'a [P<ast::Expr>]),
|
2014-03-08 10:33:39 -06:00
|
|
|
|
|
|
|
// Supply value of arguments as a list of LLVM value refs; frequently
|
|
|
|
// used with lang items and so forth, when the argument is an internal
|
|
|
|
// value.
|
|
|
|
ArgVals(&'a [ValueRef]),
|
|
|
|
|
2014-12-01 12:18:18 -06:00
|
|
|
// For overloaded operators: `(lhs, Vec(rhs, rhs_id), autoref)`. `lhs`
|
2014-03-08 10:33:39 -06:00
|
|
|
// is the left-hand-side and `rhs/rhs_id` is the datum/expr-id of
|
2014-12-01 12:18:18 -06:00
|
|
|
// the right-hand-side arguments (if any). `autoref` indicates whether the `rhs`
|
|
|
|
// arguments should be auto-referenced
|
|
|
|
ArgOverloadedOp(Datum<'tcx, Expr>, Vec<(Datum<'tcx, Expr>, ast::NodeId)>, bool),
|
2014-05-29 00:26:56 -05:00
|
|
|
|
|
|
|
// Supply value of arguments as a list of expressions that must be
|
|
|
|
// translated, for overloaded call operators.
|
2014-09-07 12:09:06 -05:00
|
|
|
ArgOverloadedCall(Vec<&'a ast::Expr>),
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
2014-09-06 11:13:04 -05:00
|
|
|
fn trans_args_under_call_abi<'blk, 'tcx>(
|
|
|
|
mut bcx: Block<'blk, 'tcx>,
|
2014-09-07 12:09:06 -05:00
|
|
|
arg_exprs: &[P<ast::Expr>],
|
2014-09-29 14:11:30 -05:00
|
|
|
fn_ty: Ty<'tcx>,
|
2014-05-29 00:26:56 -05:00
|
|
|
llargs: &mut Vec<ValueRef>,
|
|
|
|
arg_cleanup_scope: cleanup::ScopeId,
|
|
|
|
ignore_self: bool)
|
2015-01-06 04:03:42 -06:00
|
|
|
-> Block<'blk, 'tcx>
|
|
|
|
{
|
|
|
|
let args =
|
|
|
|
ty::erase_late_bound_regions(
|
|
|
|
bcx.tcx(), &ty::ty_fn_args(fn_ty));
|
|
|
|
|
2014-05-29 00:26:56 -05:00
|
|
|
// Translate the `self` argument first.
|
|
|
|
if !ignore_self {
|
|
|
|
let arg_datum = unpack_datum!(bcx, expr::trans(bcx, &*arg_exprs[0]));
|
2015-06-18 14:16:47 -05:00
|
|
|
bcx = trans_arg_datum(bcx,
|
|
|
|
args[0],
|
|
|
|
arg_datum,
|
|
|
|
arg_cleanup_scope,
|
|
|
|
DontAutorefArg,
|
|
|
|
llargs);
|
2014-05-29 00:26:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now untuple the rest of the arguments.
|
2014-09-07 12:09:06 -05:00
|
|
|
let tuple_expr = &arg_exprs[1];
|
2015-02-04 10:16:59 -06:00
|
|
|
let tuple_type = common::node_id_type(bcx, tuple_expr.id);
|
2014-05-29 00:26:56 -05:00
|
|
|
|
2014-10-31 03:51:16 -05:00
|
|
|
match tuple_type.sty {
|
2015-06-11 18:21:46 -05:00
|
|
|
ty::TyTuple(ref field_types) => {
|
2014-05-29 00:26:56 -05:00
|
|
|
let tuple_datum = unpack_datum!(bcx,
|
2014-09-07 12:09:06 -05:00
|
|
|
expr::trans(bcx, &**tuple_expr));
|
2014-05-29 00:26:56 -05:00
|
|
|
let tuple_lvalue_datum =
|
|
|
|
unpack_datum!(bcx,
|
|
|
|
tuple_datum.to_lvalue_datum(bcx,
|
|
|
|
"args",
|
|
|
|
tuple_expr.id));
|
|
|
|
let repr = adt::represent_type(bcx.ccx(), tuple_type);
|
|
|
|
let repr_ptr = &*repr;
|
2015-06-18 14:16:47 -05:00
|
|
|
for (i, field_type) in field_types.iter().enumerate() {
|
2014-05-29 00:26:56 -05:00
|
|
|
let arg_datum = tuple_lvalue_datum.get_element(
|
2014-08-06 04:59:40 -05:00
|
|
|
bcx,
|
2015-02-28 14:41:26 -06:00
|
|
|
field_type,
|
2014-05-29 00:26:56 -05:00
|
|
|
|srcval| {
|
|
|
|
adt::trans_field_ptr(bcx, repr_ptr, srcval, 0, i)
|
2015-02-28 14:41:26 -06:00
|
|
|
}).to_expr_datum();
|
2015-06-18 14:16:47 -05:00
|
|
|
bcx = trans_arg_datum(bcx,
|
|
|
|
field_type,
|
|
|
|
arg_datum,
|
|
|
|
arg_cleanup_scope,
|
|
|
|
DontAutorefArg,
|
|
|
|
llargs);
|
|
|
|
}
|
2014-05-29 00:26:56 -05:00
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
bcx.sess().span_bug(tuple_expr.span,
|
|
|
|
"argument to `.call()` wasn't a tuple?!")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bcx
|
|
|
|
}
|
|
|
|
|
2014-09-06 11:13:04 -05:00
|
|
|
fn trans_overloaded_call_args<'blk, 'tcx>(
|
|
|
|
mut bcx: Block<'blk, 'tcx>,
|
2014-09-07 12:09:06 -05:00
|
|
|
arg_exprs: Vec<&ast::Expr>,
|
2014-09-29 14:11:30 -05:00
|
|
|
fn_ty: Ty<'tcx>,
|
2014-05-29 00:26:56 -05:00
|
|
|
llargs: &mut Vec<ValueRef>,
|
|
|
|
arg_cleanup_scope: cleanup::ScopeId,
|
|
|
|
ignore_self: bool)
|
2014-09-06 11:13:04 -05:00
|
|
|
-> Block<'blk, 'tcx> {
|
2014-05-29 00:26:56 -05:00
|
|
|
// Translate the `self` argument first.
|
2015-01-06 04:03:42 -06:00
|
|
|
let arg_tys = ty::erase_late_bound_regions(bcx.tcx(), &ty::ty_fn_args(fn_ty));
|
2014-05-29 00:26:56 -05:00
|
|
|
if !ignore_self {
|
2014-09-07 12:09:06 -05:00
|
|
|
let arg_datum = unpack_datum!(bcx, expr::trans(bcx, arg_exprs[0]));
|
2015-06-18 14:16:47 -05:00
|
|
|
bcx = trans_arg_datum(bcx,
|
|
|
|
arg_tys[0],
|
|
|
|
arg_datum,
|
|
|
|
arg_cleanup_scope,
|
|
|
|
DontAutorefArg,
|
|
|
|
llargs);
|
2014-05-29 00:26:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now untuple the rest of the arguments.
|
2014-10-15 01:05:01 -05:00
|
|
|
let tuple_type = arg_tys[1];
|
2014-10-31 03:51:16 -05:00
|
|
|
match tuple_type.sty {
|
2015-06-11 18:21:46 -05:00
|
|
|
ty::TyTuple(ref field_types) => {
|
2014-05-29 00:26:56 -05:00
|
|
|
for (i, &field_type) in field_types.iter().enumerate() {
|
|
|
|
let arg_datum =
|
2014-09-07 12:09:06 -05:00
|
|
|
unpack_datum!(bcx, expr::trans(bcx, arg_exprs[i + 1]));
|
2015-06-18 14:16:47 -05:00
|
|
|
bcx = trans_arg_datum(bcx,
|
|
|
|
field_type,
|
|
|
|
arg_datum,
|
|
|
|
arg_cleanup_scope,
|
|
|
|
DontAutorefArg,
|
|
|
|
llargs);
|
2014-05-29 00:26:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
bcx.sess().span_bug(arg_exprs[0].span,
|
|
|
|
"argument to `.call()` wasn't a tuple?!")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bcx
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
pub fn trans_args<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>,
|
|
|
|
args: CallArgs<'a, 'tcx>,
|
|
|
|
fn_ty: Ty<'tcx>,
|
|
|
|
llargs: &mut Vec<ValueRef>,
|
|
|
|
arg_cleanup_scope: cleanup::ScopeId,
|
|
|
|
ignore_self: bool,
|
|
|
|
abi: synabi::Abi)
|
|
|
|
-> Block<'blk, 'tcx> {
|
2014-05-29 00:26:56 -05:00
|
|
|
debug!("trans_args(abi={})", abi);
|
|
|
|
|
2013-06-16 23:23:24 -05:00
|
|
|
let _icx = push_ctxt("trans_args");
|
2015-01-06 04:03:42 -06:00
|
|
|
let arg_tys = ty::erase_late_bound_regions(cx.tcx(), &ty::ty_fn_args(fn_ty));
|
2013-10-25 00:56:34 -05:00
|
|
|
let variadic = ty::fn_is_variadic(fn_ty);
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2013-03-19 13:40:34 -05:00
|
|
|
let mut bcx = cx;
|
2012-08-28 17:54:45 -05:00
|
|
|
|
|
|
|
// First we figure out the caller's view of the types of the arguments.
|
|
|
|
// This will be needed if this is a generic call, because the callee has
|
|
|
|
// to cast her view of the arguments to the caller's view.
|
|
|
|
match args {
|
2014-01-27 06:18:36 -06:00
|
|
|
ArgExprs(arg_exprs) => {
|
2014-05-29 00:26:56 -05:00
|
|
|
if abi == synabi::RustCall {
|
|
|
|
// This is only used for direct calls to the `call`,
|
|
|
|
// `call_mut` or `call_once` functions.
|
|
|
|
return trans_args_under_call_abi(cx,
|
|
|
|
arg_exprs,
|
|
|
|
fn_ty,
|
|
|
|
llargs,
|
|
|
|
arg_cleanup_scope,
|
|
|
|
ignore_self)
|
|
|
|
}
|
|
|
|
|
2014-01-27 06:18:36 -06:00
|
|
|
let num_formal_args = arg_tys.len();
|
2014-05-16 12:15:33 -05:00
|
|
|
for (i, arg_expr) in arg_exprs.iter().enumerate() {
|
2014-01-27 06:18:36 -06:00
|
|
|
if i == 0 && ignore_self {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let arg_ty = if i >= num_formal_args {
|
|
|
|
assert!(variadic);
|
2015-02-04 10:16:59 -06:00
|
|
|
common::expr_ty_adjusted(cx, &**arg_expr)
|
2014-01-27 06:18:36 -06:00
|
|
|
} else {
|
2014-10-15 01:05:01 -05:00
|
|
|
arg_tys[i]
|
2014-01-27 06:18:36 -06:00
|
|
|
};
|
2014-03-06 11:24:11 -06:00
|
|
|
|
2014-05-16 12:15:33 -05:00
|
|
|
let arg_datum = unpack_datum!(bcx, expr::trans(bcx, &**arg_expr));
|
2015-06-18 14:16:47 -05:00
|
|
|
bcx = trans_arg_datum(bcx, arg_ty, arg_datum,
|
|
|
|
arg_cleanup_scope,
|
|
|
|
DontAutorefArg,
|
|
|
|
llargs);
|
2014-01-27 06:18:36 -06:00
|
|
|
}
|
|
|
|
}
|
2014-05-29 00:26:56 -05:00
|
|
|
ArgOverloadedCall(arg_exprs) => {
|
|
|
|
return trans_overloaded_call_args(cx,
|
|
|
|
arg_exprs,
|
|
|
|
fn_ty,
|
|
|
|
llargs,
|
|
|
|
arg_cleanup_scope,
|
|
|
|
ignore_self)
|
|
|
|
}
|
2014-12-01 12:18:18 -06:00
|
|
|
ArgOverloadedOp(lhs, rhs, autoref) => {
|
2014-01-27 06:18:36 -06:00
|
|
|
assert!(!variadic);
|
|
|
|
|
2015-06-18 14:16:47 -05:00
|
|
|
bcx = trans_arg_datum(bcx, arg_tys[0], lhs,
|
|
|
|
arg_cleanup_scope,
|
|
|
|
DontAutorefArg,
|
|
|
|
llargs);
|
2014-01-27 06:18:36 -06:00
|
|
|
|
2014-09-15 03:48:58 -05:00
|
|
|
assert_eq!(arg_tys.len(), 1 + rhs.len());
|
2015-01-31 19:03:04 -06:00
|
|
|
for (rhs, rhs_id) in rhs {
|
2015-06-18 14:16:47 -05:00
|
|
|
bcx = trans_arg_datum(bcx, arg_tys[1], rhs,
|
|
|
|
arg_cleanup_scope,
|
|
|
|
if autoref { DoAutorefArg(rhs_id) } else { DontAutorefArg },
|
|
|
|
llargs);
|
2014-01-27 06:18:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ArgVals(vs) => {
|
|
|
|
llargs.push_all(vs);
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-24 17:34:20 -05:00
|
|
|
bcx
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|
|
|
|
|
2015-03-30 08:38:44 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2013-01-29 19:57:02 -06:00
|
|
|
pub enum AutorefArg {
|
2012-09-19 20:00:26 -05:00
|
|
|
DontAutorefArg,
|
2014-03-06 11:24:11 -06:00
|
|
|
DoAutorefArg(ast::NodeId)
|
2012-09-19 20:00:26 -05:00
|
|
|
}
|
|
|
|
|
2014-09-06 11:13:04 -05:00
|
|
|
pub fn trans_arg_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
2014-09-29 14:11:30 -05:00
|
|
|
formal_arg_ty: Ty<'tcx>,
|
|
|
|
arg_datum: Datum<'tcx, Expr>,
|
2014-09-06 11:13:04 -05:00
|
|
|
arg_cleanup_scope: cleanup::ScopeId,
|
2015-06-18 14:16:47 -05:00
|
|
|
autoref_arg: AutorefArg,
|
|
|
|
llargs: &mut Vec<ValueRef>)
|
|
|
|
-> Block<'blk, 'tcx> {
|
2014-03-06 11:24:11 -06:00
|
|
|
let _icx = push_ctxt("trans_arg_datum");
|
2014-01-15 13:39:08 -06:00
|
|
|
let mut bcx = bcx;
|
2012-08-28 17:54:45 -05:00
|
|
|
let ccx = bcx.ccx();
|
|
|
|
|
2015-06-18 12:25:05 -05:00
|
|
|
debug!("trans_arg_datum({:?})",
|
|
|
|
formal_arg_ty);
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2014-01-15 13:39:08 -06:00
|
|
|
let arg_datum_ty = arg_datum.ty;
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2014-06-21 05:39:03 -05:00
|
|
|
debug!(" arg datum: {}", arg_datum.to_string(bcx.ccx()));
|
2012-08-28 17:54:45 -05:00
|
|
|
|
2012-09-18 12:41:05 -05:00
|
|
|
let mut val;
|
2014-10-24 14:14:37 -05:00
|
|
|
// FIXME(#3548) use the adjustments table
|
|
|
|
match autoref_arg {
|
|
|
|
DoAutorefArg(arg_id) => {
|
|
|
|
// We will pass argument by reference
|
|
|
|
// We want an lvalue, so that we can pass by reference and
|
|
|
|
let arg_datum = unpack_datum!(
|
|
|
|
bcx, arg_datum.to_lvalue_datum(bcx, "arg", arg_id));
|
|
|
|
val = arg_datum.val;
|
2013-01-10 23:23:07 -06:00
|
|
|
}
|
Pass fat pointers in two immediate arguments
This has a number of advantages compared to creating a copy in memory
and passing a pointer. The obvious one is that we don't have to put the
data into memory but can keep it in registers. Since we're currently
passing a pointer anyway (instead of using e.g. a known offset on the
stack, which is what the `byval` attribute would achieve), we only use a
single additional register for each fat pointer, but save at least two
pointers worth of stack in exchange (sometimes more because more than
one copy gets eliminated). On archs that pass arguments on the stack, we
save a pointer worth of stack even without considering the omitted
copies.
Additionally, LLVM can optimize the code a lot better, to a large degree
due to the fact that lots of copies are gone or can be optimized away.
Additionally, we can now emit attributes like nonnull on the data and/or
vtable pointers contained in the fat pointer, potentially allowing for
even more optimizations.
This results in LLVM passes being about 3-7% faster (depending on the
crate), and the resulting code is also a few percent smaller, for
example:
text data filename
5671479 3941461 before/librustc-d8ace771.so
5447663 3905745 after/librustc-d8ace771.so
1944425 2394024 before/libstd-d8ace771.so
1896769 2387610 after/libstd-d8ace771.so
I had to remove a call in the backtrace-debuginfo test, because LLVM can
now merge the tails of some blocks when optimizations are turned on,
which can't correctly preserve line info.
Fixes #22924
Cc #22891 (at least for fat pointers the code is good now)
2015-06-18 16:57:40 -05:00
|
|
|
DontAutorefArg if common::type_is_fat_ptr(bcx.tcx(), arg_datum_ty) &&
|
|
|
|
!bcx.fcx.type_needs_drop(arg_datum_ty) => {
|
|
|
|
val = arg_datum.val
|
|
|
|
}
|
2014-10-24 14:14:37 -05:00
|
|
|
DontAutorefArg => {
|
|
|
|
// Make this an rvalue, since we are going to be
|
|
|
|
// passing ownership.
|
|
|
|
let arg_datum = unpack_datum!(
|
|
|
|
bcx, arg_datum.to_rvalue_datum(bcx, "arg"));
|
|
|
|
|
|
|
|
// Now that arg_datum is owned, get it into the appropriate
|
|
|
|
// mode (ref vs value).
|
|
|
|
let arg_datum = unpack_datum!(
|
|
|
|
bcx, arg_datum.to_appropriate_datum(bcx));
|
|
|
|
|
|
|
|
// Technically, ownership of val passes to the callee.
|
2014-10-09 14:17:22 -05:00
|
|
|
// However, we must cleanup should we panic before the
|
2014-10-24 14:14:37 -05:00
|
|
|
// callee is actually invoked.
|
|
|
|
val = arg_datum.add_clean(bcx.fcx, arg_cleanup_scope);
|
2012-09-18 12:41:05 -05:00
|
|
|
}
|
2014-10-24 14:14:37 -05:00
|
|
|
}
|
2012-09-18 12:41:05 -05:00
|
|
|
|
Pass fat pointers in two immediate arguments
This has a number of advantages compared to creating a copy in memory
and passing a pointer. The obvious one is that we don't have to put the
data into memory but can keep it in registers. Since we're currently
passing a pointer anyway (instead of using e.g. a known offset on the
stack, which is what the `byval` attribute would achieve), we only use a
single additional register for each fat pointer, but save at least two
pointers worth of stack in exchange (sometimes more because more than
one copy gets eliminated). On archs that pass arguments on the stack, we
save a pointer worth of stack even without considering the omitted
copies.
Additionally, LLVM can optimize the code a lot better, to a large degree
due to the fact that lots of copies are gone or can be optimized away.
Additionally, we can now emit attributes like nonnull on the data and/or
vtable pointers contained in the fat pointer, potentially allowing for
even more optimizations.
This results in LLVM passes being about 3-7% faster (depending on the
crate), and the resulting code is also a few percent smaller, for
example:
text data filename
5671479 3941461 before/librustc-d8ace771.so
5447663 3905745 after/librustc-d8ace771.so
1944425 2394024 before/libstd-d8ace771.so
1896769 2387610 after/libstd-d8ace771.so
I had to remove a call in the backtrace-debuginfo test, because LLVM can
now merge the tails of some blocks when optimizations are turned on,
which can't correctly preserve line info.
Fixes #22924
Cc #22891 (at least for fat pointers the code is good now)
2015-06-18 16:57:40 -05:00
|
|
|
if type_of::arg_is_indirect(ccx, formal_arg_ty) && formal_arg_ty != arg_datum_ty {
|
2014-10-24 14:14:37 -05:00
|
|
|
// this could happen due to e.g. subtyping
|
|
|
|
let llformal_arg_ty = type_of::type_of_explicit_arg(ccx, formal_arg_ty);
|
|
|
|
debug!("casting actual type ({}) to match formal ({})",
|
|
|
|
bcx.val_to_string(val), bcx.llty_str(llformal_arg_ty));
|
2015-06-18 12:25:05 -05:00
|
|
|
debug!("Rust types: {:?}; {:?}", arg_datum_ty,
|
|
|
|
formal_arg_ty);
|
2014-10-24 14:14:37 -05:00
|
|
|
val = PointerCast(bcx, val, llformal_arg_ty);
|
2012-09-14 14:01:43 -05:00
|
|
|
}
|
2012-09-18 12:41:05 -05:00
|
|
|
|
2014-06-21 05:39:03 -05:00
|
|
|
debug!("--- trans_arg_datum passing {}", bcx.val_to_string(val));
|
2015-06-18 14:16:47 -05:00
|
|
|
|
Pass fat pointers in two immediate arguments
This has a number of advantages compared to creating a copy in memory
and passing a pointer. The obvious one is that we don't have to put the
data into memory but can keep it in registers. Since we're currently
passing a pointer anyway (instead of using e.g. a known offset on the
stack, which is what the `byval` attribute would achieve), we only use a
single additional register for each fat pointer, but save at least two
pointers worth of stack in exchange (sometimes more because more than
one copy gets eliminated). On archs that pass arguments on the stack, we
save a pointer worth of stack even without considering the omitted
copies.
Additionally, LLVM can optimize the code a lot better, to a large degree
due to the fact that lots of copies are gone or can be optimized away.
Additionally, we can now emit attributes like nonnull on the data and/or
vtable pointers contained in the fat pointer, potentially allowing for
even more optimizations.
This results in LLVM passes being about 3-7% faster (depending on the
crate), and the resulting code is also a few percent smaller, for
example:
text data filename
5671479 3941461 before/librustc-d8ace771.so
5447663 3905745 after/librustc-d8ace771.so
1944425 2394024 before/libstd-d8ace771.so
1896769 2387610 after/libstd-d8ace771.so
I had to remove a call in the backtrace-debuginfo test, because LLVM can
now merge the tails of some blocks when optimizations are turned on,
which can't correctly preserve line info.
Fixes #22924
Cc #22891 (at least for fat pointers the code is good now)
2015-06-18 16:57:40 -05:00
|
|
|
if common::type_is_fat_ptr(bcx.tcx(), formal_arg_ty) {
|
|
|
|
llargs.push(Load(bcx, expr::get_dataptr(bcx, val)));
|
|
|
|
llargs.push(Load(bcx, expr::get_len(bcx, val)));
|
|
|
|
} else {
|
|
|
|
llargs.push(val);
|
|
|
|
}
|
2015-06-18 14:16:47 -05:00
|
|
|
|
|
|
|
bcx
|
2012-08-28 17:54:45 -05:00
|
|
|
}
|