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.
This commit is contained in:
Tim Chevalier 2012-04-05 18:22:53 -07:00
parent fc7fc90adf
commit c83d61de93
3 changed files with 20 additions and 10 deletions

View File

@ -485,15 +485,14 @@ fn mangle(ss: path) -> str {
n
}
fn exported_name(path: path, hash: str, _vers: str) -> str {
fn exported_name(path: path, id: ast::node_id, _vers: str) -> str {
// FIXME: versioning isn't working yet
ret mangle(path + [path_name(hash)]); // + "@" + vers;
ret mangle(path + [path_name(int::str(id))]); // + "@" + vers;
}
fn mangle_exported_name(ccx: @crate_ctxt, path: path, t: ty::t) -> str {
let hash = get_symbol_hash(ccx, t);
ret exported_name(path, hash, ccx.link_meta.vers);
fn mangle_exported_name(ccx: @crate_ctxt, path: path, id: ast::node_id)
-> str {
ret exported_name(path, id, ccx.link_meta.vers);
}
fn mangle_internal_name_by_type_only(ccx: @crate_ctxt, t: ty::t, name: str) ->

View File

@ -1944,7 +1944,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, real_substs: [ty::t],
let llfty = type_of_fn_from_ty(ccx, mono_ty);
let pt = *pt + [path_name(ccx.names(name))];
let s = mangle_exported_name(ccx, pt, mono_ty);
let s = mangle_exported_name(ccx, pt, fn_id.node);
let lldecl = decl_internal_cdecl_fn(ccx.llmod, s, llfty);
ccx.monomorphized.insert(hash_id, lldecl);
ccx.item_symbols.insert(fn_id.node, s);
@ -4454,7 +4454,7 @@ fn register_fn_full(ccx: @crate_ctxt, sp: span, path: path,
fn register_fn_fuller(ccx: @crate_ctxt, sp: span, path: path,
node_id: ast::node_id, node_type: ty::t,
cc: lib::llvm::CallConv, llfty: TypeRef) -> ValueRef {
let ps: str = mangle_exported_name(ccx, path, node_type);
let ps: str = mangle_exported_name(ccx, path, node_id);
let llfn: ValueRef = decl_fn(ccx.llmod, ps, cc, llfty);
ccx.item_symbols.insert(node_id, ps);
@ -4583,7 +4583,7 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
alt check i.node {
ast::item_const(_, _) {
let typ = ty::node_id_to_type(ccx.tcx, i.id);
let s = mangle_exported_name(ccx, my_path, typ);
let s = mangle_exported_name(ccx, my_path, i.id);
let g = str::as_c_str(s, {|buf|
llvm::LLVMAddGlobal(ccx.llmod, type_of(ccx, typ), buf)
});
@ -4670,7 +4670,7 @@ fn trans_constant(ccx: @crate_ctxt, it: @ast::item) {
for vec::each(variants) {|variant|
let p = path + [path_name(variant.node.name),
path_name("discrim")];
let s = mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
let s = mangle_exported_name(ccx, p, it.id);
let disr_val = vi[i].disr_val;
note_unique_llvm_symbol(ccx, s);
let discrim_gvar = str::as_c_str(s, {|buf|

View File

@ -0,0 +1,11 @@
fn main(args: [str]) {
let one = fn@() -> uint {
enum r { a };
ret a as uint;
};
let two = fn@() -> uint {
enum r { a };
ret a as uint;
};
one(); two();
}