Skip to content

Commit 351cc4f

Browse files
committed
auto merge of #16359 : epdtry/rust/mono-item-dedup-foreign, r=alexcrichton
Extend the changes from #16059 to the new generic foreign functions introduced by #15831.
2 parents 4136d5f + 0c158b4 commit 351cc4f

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

src/librustc/middle/trans/base.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,8 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
19321932
llfn,
19331933
&param_substs::empty(),
19341934
item.id,
1935-
None);
1935+
None,
1936+
TranslateItems);
19361937
} else {
19371938
trans_fn(ccx,
19381939
&**decl,

src/librustc/middle/trans/foreign.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,8 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
577577
llwrapfn: ValueRef,
578578
param_substs: &param_substs,
579579
id: ast::NodeId,
580-
hash: Option<&str>) {
580+
hash: Option<&str>,
581+
handle_items: HandleItemsFlag) {
581582
let _icx = push_ctxt("foreign::build_foreign_fn");
582583

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

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

591593
// Build up the foreign wrapper (`foo` above).
592594
return build_wrap_fn(ccx, llrustfn, llwrapfn, &tys, mty);
@@ -598,7 +600,8 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
598600
param_substs: &param_substs,
599601
attrs: &[ast::Attribute],
600602
id: ast::NodeId,
601-
hash: Option<&str>)
603+
hash: Option<&str>,
604+
handle_items: HandleItemsFlag)
602605
-> ValueRef {
603606
let _icx = push_ctxt("foreign::foreign::build_rust_fn");
604607
let tcx = ccx.tcx();
@@ -630,7 +633,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
630633

631634
let llfn = base::decl_internal_rust_fn(ccx, t, ps.as_slice());
632635
base::set_llvm_fn_attrs(attrs, llfn);
633-
base::trans_fn(ccx, decl, body, llfn, param_substs, id, [], TranslateItems);
636+
base::trans_fn(ccx, decl, body, llfn, param_substs, id, [], handle_items);
634637
llfn
635638
}
636639

src/librustc/middle/trans/monomorphize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
164164
if abi != abi::Rust {
165165
foreign::trans_rust_fn_with_foreign_abi(
166166
ccx, &**decl, &**body, [], d, &psubsts, fn_id.node,
167-
Some(hash.as_slice()));
167+
Some(hash.as_slice()), IgnoreItems);
168168
} else {
169169
trans_fn(ccx, &**decl, &**body, d, &psubsts, fn_id.node, [],
170170
IgnoreItems);

src/test/run-make/issue-7349/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

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

98
all:
109
$(RUSTC) foo.rs --emit=ir
1110
[ "$$(grep -c 8675309 "$(TMPDIR)/foo.ll")" -eq "1" ]
11+
[ "$$(grep -c 11235813 "$(TMPDIR)/foo.ll")" -eq "1" ]

src/test/run-make/issue-7349/foo.rs

+9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ fn outer<T>() {
1515
}
1616
}
1717

18+
extern "C" fn outer_foreign<T>() {
19+
#[allow(dead_code)]
20+
fn inner() -> uint {
21+
11235813
22+
}
23+
}
24+
1825
fn main() {
1926
outer::<int>();
2027
outer::<uint>();
28+
outer_foreign::<int>();
29+
outer_foreign::<uint>();
2130
}

0 commit comments

Comments
 (0)