Skip to content

Commit

Permalink
Revert "don't translate items when monomorphizing foreign-ABI functions"
Browse files Browse the repository at this point in the history
This reverts commit 0c158b4.
  • Loading branch information
spernsteiner committed Aug 12, 2014
1 parent 4bb4a43 commit d5a94c4
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/librustc/middle/trans/base.rs
Expand Up @@ -2066,8 +2066,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
llfn,
&param_substs::empty(),
item.id,
None,
TranslateItems);
None);
} else {
trans_fn(ccx,
&**decl,
Expand Down
11 changes: 4 additions & 7 deletions src/librustc/middle/trans/foreign.rs
Expand Up @@ -577,8 +577,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
llwrapfn: ValueRef,
param_substs: &param_substs,
id: ast::NodeId,
hash: Option<&str>,
handle_items: HandleItemsFlag) {
hash: Option<&str>) {
let _icx = push_ctxt("foreign::build_foreign_fn");

let fnty = ty::node_id_to_type(ccx.tcx(), id);
Expand All @@ -587,8 +586,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,

unsafe { // unsafe because we call LLVM operations
// Build up the Rust function (`foo0` above).
let llrustfn = build_rust_fn(ccx, decl, body, param_substs, attrs, id,
hash, handle_items);
let llrustfn = build_rust_fn(ccx, decl, body, param_substs, attrs, id, hash);

// Build up the foreign wrapper (`foo` above).
return build_wrap_fn(ccx, llrustfn, llwrapfn, &tys, mty);
Expand All @@ -600,8 +598,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
param_substs: &param_substs,
attrs: &[ast::Attribute],
id: ast::NodeId,
hash: Option<&str>,
handle_items: HandleItemsFlag)
hash: Option<&str>)
-> ValueRef {
let _icx = push_ctxt("foreign::foreign::build_rust_fn");
let tcx = ccx.tcx();
Expand Down Expand Up @@ -633,7 +630,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,

let llfn = base::decl_internal_rust_fn(ccx, t, ps.as_slice());
base::set_llvm_fn_attrs(attrs, llfn);
base::trans_fn(ccx, decl, body, llfn, param_substs, id, [], handle_items);
base::trans_fn(ccx, decl, body, llfn, param_substs, id, [], TranslateItems);
llfn
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/monomorphize.rs
Expand Up @@ -164,7 +164,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
if abi != abi::Rust {
foreign::trans_rust_fn_with_foreign_abi(
ccx, &**decl, &**body, [], d, &psubsts, fn_id.node,
Some(hash.as_slice()), IgnoreItems);
Some(hash.as_slice()));
} else {
trans_fn(ccx, &**decl, &**body, d, &psubsts, fn_id.node, [],
IgnoreItems);
Expand Down
6 changes: 3 additions & 3 deletions src/test/run-make/issue-7349/Makefile
Expand Up @@ -2,10 +2,10 @@

# Test to make sure that inner functions within a polymorphic outer function
# don't get re-translated when the outer function is monomorphized. The test
# code monomorphizes the outer functions several times, but the magic constants
# used in the inner functions should each appear only once in the generated IR.
# code monomorphizes the outer function several times, but the magic constant
# `8675309` used in the inner function should appear only once in the generated
# IR.

all:
$(RUSTC) foo.rs --emit=ir
[ "$$(grep -c 8675309 "$(TMPDIR)/foo.ll")" -eq "1" ]
[ "$$(grep -c 11235813 "$(TMPDIR)/foo.ll")" -eq "1" ]
9 changes: 0 additions & 9 deletions src/test/run-make/issue-7349/foo.rs
Expand Up @@ -15,16 +15,7 @@ fn outer<T>() {
}
}

extern "C" fn outer_foreign<T>() {
#[allow(dead_code)]
fn inner() -> uint {
11235813
}
}

fn main() {
outer::<int>();
outer::<uint>();
outer_foreign::<int>();
outer_foreign::<uint>();
}

0 comments on commit d5a94c4

Please sign in to comment.