Fix cross-crate inlining of static functions

This commit is contained in:
Brian Anderson 2012-12-02 15:45:20 -08:00
parent 5bf9e6f58b
commit 4f3cc01487
3 changed files with 36 additions and 9 deletions

View File

@ -13,7 +13,7 @@ use syntax::ast;
use syntax::ast_util::local_def;
use syntax::ast_map::{path, path_mod, path_name};
use base::{trans_item, get_item_val, self_arg, trans_fn, impl_owned_self,
impl_self, get_insn_ctxt};
impl_self, no_self, get_insn_ctxt};
// `translate` will be true if this function is allowed to translate the
// item and false otherwise. Currently, this parameter is set to false when
@ -83,14 +83,18 @@ fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id,
let path = vec::append(
ty::item_path(ccx.tcx, impl_did),
~[path_name(mth.ident)]);
let self_ty = ty::node_id_to_type(ccx.tcx, mth.self_id);
debug!("calling inline trans_fn with self_ty %s",
ty_to_str(ccx.tcx, self_ty));
let self_kind;
match mth.self_ty.node {
ast::sty_value => self_kind = impl_owned_self(self_ty),
_ => self_kind = impl_self(self_ty),
}
let self_kind = match mth.self_ty.node {
ast::sty_static => no_self,
_ => {
let self_ty = ty::node_id_to_type(ccx.tcx, mth.self_id);
debug!("calling inline trans_fn with self_ty %s",
ty_to_str(ccx.tcx, self_ty));
match mth.self_ty.node {
ast::sty_value => impl_owned_self(self_ty),
_ => impl_self(self_ty),
}
}
};
trans_fn(ccx,
path,
mth.decl,

View File

@ -0,0 +1,14 @@
pub mod num {
pub trait Num2 {
static pure fn from_int2(n: int) -> self;
}
}
pub mod float {
impl float: num::Num2 {
#[inline]
static pure fn from_int2(n: int) -> float { return n as float; }
}
}

View File

@ -0,0 +1,9 @@
// aux-build:static_fn_inline_xc_aux.rs
extern mod mycore(name ="static_fn_inline_xc_aux");
use mycore::num;
fn main() {
let _1:float = num::from_int2(1i);
}