Skip to content

Commit 928364b

Browse files
committed
Only make symbols external when they are actually externally accessible
Closes #2030
1 parent ade1207 commit 928364b

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

src/rustc/middle/trans/base.rs

+15-24
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, real_substs: [ty::t],
18981898

18991899
let pt = *pt + [path_name(ccx.names(name))];
19001900
let s = mangle_exported_name(ccx, pt, mono_ty);
1901-
let lldecl = decl_cdecl_fn(ccx.llmod, s, llfty);
1901+
let lldecl = decl_internal_cdecl_fn(ccx.llmod, s, llfty);
19021902
ccx.monomorphized.insert(hash_id, lldecl);
19031903
ccx.item_symbols.insert(fn_id.node, s);
19041904

@@ -1982,12 +1982,14 @@ fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id)
19821982
}
19831983
csearch::found(ast::ii_method(impl_did, mth)) {
19841984
ccx.external.insert(fn_id, some(mth.id));
1985-
compute_ii_method_info(ccx, impl_did, mth) {|ty, bounds, path|
1986-
if bounds.len() == 0u {
1987-
let llfn = get_item_val(ccx, mth.id);
1988-
trans_fn(ccx, path, mth.decl, mth.body,
1989-
llfn, impl_self(ty), none, mth.id, none);
1990-
}
1985+
let {bounds: impl_bnds, ty: impl_ty} =
1986+
ty::lookup_item_type(ccx.tcx, impl_did);
1987+
if (*impl_bnds).len() + mth.tps.len() == 0u {
1988+
let llfn = get_item_val(ccx, mth.id);
1989+
let path = ty::item_path(ccx.tcx, impl_did) +
1990+
[path_name(mth.ident)];
1991+
trans_fn(ccx, path, mth.decl, mth.body,
1992+
llfn, impl_self(impl_ty), none, mth.id, none);
19911993
}
19921994
local_def(mth.id)
19931995
}
@@ -4173,18 +4175,6 @@ fn trans_mod(ccx: @crate_ctxt, m: ast::_mod) {
41734175
for item in m.items { trans_item(ccx, *item); }
41744176
}
41754177

4176-
fn compute_ii_method_info(ccx: @crate_ctxt,
4177-
impl_did: ast::def_id,
4178-
m: @ast::method,
4179-
f: fn(ty::t, [ty::param_bounds], ast_map::path)) {
4180-
let {bounds: impl_bnds, ty: impl_ty} =
4181-
ty::lookup_item_type(ccx.tcx, impl_did);
4182-
let m_bounds = *impl_bnds + param_bounds(ccx, m.tps);
4183-
let impl_path = ty::item_path(ccx.tcx, impl_did);
4184-
let m_path = impl_path + [path_name(m.ident)];
4185-
f(impl_ty, m_bounds, m_path);
4186-
}
4187-
41884178
fn get_pair_fn_ty(llpairty: TypeRef) -> TypeRef {
41894179
// Bit of a kludge: pick the fn typeref out of the pair.
41904180
ret struct_elt(llpairty, 0u);
@@ -4196,11 +4186,6 @@ fn register_fn(ccx: @crate_ctxt, sp: span, path: path, flav: str,
41964186
register_fn_full(ccx, sp, path, flav, node_id, t)
41974187
}
41984188

4199-
fn param_bounds(ccx: @crate_ctxt, tps: [ast::ty_param])
4200-
-> [ty::param_bounds] {
4201-
vec::map(tps) {|tp| ccx.tcx.ty_param_bounds.get(tp.id) }
4202-
}
4203-
42044189
fn register_fn_full(ccx: @crate_ctxt, sp: span, path: path, flav: str,
42054190
node_id: ast::node_id, node_type: ty::t) -> ValueRef {
42064191
let llfty = type_of_fn_from_ty(ccx, node_type);
@@ -4333,6 +4318,7 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
43334318
alt ccx.item_vals.find(id) {
43344319
some(v) { v }
43354320
none {
4321+
let exprt = false;
43364322
let val = alt check ccx.tcx.items.get(id) {
43374323
ast_map::node_item(i, pth) {
43384324
let my_path = *pth + [path_name(i.ident)];
@@ -4368,6 +4354,7 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
43684354
}
43694355
}
43704356
ast_map::node_method(m, impl_id, pth) {
4357+
exprt = true;
43714358
let mty = ty::node_id_to_type(ccx.tcx, id);
43724359
let pth = *pth + [path_name(int::str(impl_id.node)),
43734360
path_name(m.ident)];
@@ -4377,6 +4364,7 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
43774364
llfn
43784365
}
43794366
ast_map::node_native_item(ni, _, pth) {
4367+
exprt = true;
43804368
native::decl_native_fn(ccx, ni, *pth + [path_name(ni.ident)])
43814369
}
43824370
ast_map::node_ctor(i, _) {
@@ -4405,6 +4393,9 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
44054393
llfn
44064394
}
44074395
};
4396+
if !(exprt || ccx.reachable.contains_key(id)) {
4397+
lib::llvm::SetLinkage(val, lib::llvm::InternalLinkage);
4398+
}
44084399
ccx.item_vals.insert(id, val);
44094400
val
44104401
}

src/rustc/middle/trans/reachable.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,24 @@ fn traverse_public_item(cx: ctx, item: @item) {
9898
}
9999
}
100100
}
101-
item_class(_tps, _items, _) {} // FIXME handle these when stable
101+
item_class(tps, items, ctor) {
102+
cx.rmap.insert(ctor.node.id, ());
103+
for item in items {
104+
alt item.node.decl {
105+
class_method(i) {
106+
cx.rmap.insert(i.id, ());
107+
if tps.len() > 0u ||
108+
attr::find_inline_attr(i.attrs) != attr::ia_none {
109+
alt i.node {
110+
item_fn(_, _, blk) { traverse_inline_body(cx, blk); }
111+
_ {}
112+
}
113+
}
114+
}
115+
_ {}
116+
}
117+
}
118+
}
102119
item_const(_, _) | item_ty(_, _) | item_enum(_, _) | item_iface(_, _) {}
103120
}
104121
}

0 commit comments

Comments
 (0)