Skip to content

Commit c83d61d

Browse files
committed
Mangle exported names using node IDs rather than types
Use node IDs rather than types to ensure exported names are unique. duplicate symbol. Closes #2074.
1 parent fc7fc90 commit c83d61d

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/rustc/back/link.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -485,15 +485,14 @@ fn mangle(ss: path) -> str {
485485
n
486486
}
487487

488-
fn exported_name(path: path, hash: str, _vers: str) -> str {
488+
fn exported_name(path: path, id: ast::node_id, _vers: str) -> str {
489489
// FIXME: versioning isn't working yet
490-
ret mangle(path + [path_name(hash)]); // + "@" + vers;
491-
490+
ret mangle(path + [path_name(int::str(id))]); // + "@" + vers;
492491
}
493492

494-
fn mangle_exported_name(ccx: @crate_ctxt, path: path, t: ty::t) -> str {
495-
let hash = get_symbol_hash(ccx, t);
496-
ret exported_name(path, hash, ccx.link_meta.vers);
493+
fn mangle_exported_name(ccx: @crate_ctxt, path: path, id: ast::node_id)
494+
-> str {
495+
ret exported_name(path, id, ccx.link_meta.vers);
497496
}
498497

499498
fn mangle_internal_name_by_type_only(ccx: @crate_ctxt, t: ty::t, name: str) ->

src/rustc/middle/trans/base.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, real_substs: [ty::t],
19441944
let llfty = type_of_fn_from_ty(ccx, mono_ty);
19451945

19461946
let pt = *pt + [path_name(ccx.names(name))];
1947-
let s = mangle_exported_name(ccx, pt, mono_ty);
1947+
let s = mangle_exported_name(ccx, pt, fn_id.node);
19481948
let lldecl = decl_internal_cdecl_fn(ccx.llmod, s, llfty);
19491949
ccx.monomorphized.insert(hash_id, lldecl);
19501950
ccx.item_symbols.insert(fn_id.node, s);
@@ -4454,7 +4454,7 @@ fn register_fn_full(ccx: @crate_ctxt, sp: span, path: path,
44544454
fn register_fn_fuller(ccx: @crate_ctxt, sp: span, path: path,
44554455
node_id: ast::node_id, node_type: ty::t,
44564456
cc: lib::llvm::CallConv, llfty: TypeRef) -> ValueRef {
4457-
let ps: str = mangle_exported_name(ccx, path, node_type);
4457+
let ps: str = mangle_exported_name(ccx, path, node_id);
44584458
let llfn: ValueRef = decl_fn(ccx.llmod, ps, cc, llfty);
44594459
ccx.item_symbols.insert(node_id, ps);
44604460

@@ -4583,7 +4583,7 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
45834583
alt check i.node {
45844584
ast::item_const(_, _) {
45854585
let typ = ty::node_id_to_type(ccx.tcx, i.id);
4586-
let s = mangle_exported_name(ccx, my_path, typ);
4586+
let s = mangle_exported_name(ccx, my_path, i.id);
45874587
let g = str::as_c_str(s, {|buf|
45884588
llvm::LLVMAddGlobal(ccx.llmod, type_of(ccx, typ), buf)
45894589
});
@@ -4670,7 +4670,7 @@ fn trans_constant(ccx: @crate_ctxt, it: @ast::item) {
46704670
for vec::each(variants) {|variant|
46714671
let p = path + [path_name(variant.node.name),
46724672
path_name("discrim")];
4673-
let s = mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
4673+
let s = mangle_exported_name(ccx, p, it.id);
46744674
let disr_val = vi[i].disr_val;
46754675
note_unique_llvm_symbol(ccx, s);
46764676
let discrim_gvar = str::as_c_str(s, {|buf|

src/test/run-pass/issue-2074.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn main(args: [str]) {
2+
let one = fn@() -> uint {
3+
enum r { a };
4+
ret a as uint;
5+
};
6+
let two = fn@() -> uint {
7+
enum r { a };
8+
ret a as uint;
9+
};
10+
one(); two();
11+
}

0 commit comments

Comments
 (0)