rustc: Anti-copy police
This commit is contained in:
parent
dd2c7f61a9
commit
39d45b75cc
4 changed files with 22 additions and 27 deletions
|
@ -63,7 +63,7 @@ pub struct EncodeParams {
|
|||
reachable: reachable::map,
|
||||
reexports2: middle::resolve::ExportMap2,
|
||||
item_symbols: @mut HashMap<ast::node_id, ~str>,
|
||||
discrim_symbols: @mut HashMap<ast::node_id, ~str>,
|
||||
discrim_symbols: @mut HashMap<ast::node_id, @~str>,
|
||||
link_meta: LinkMeta,
|
||||
cstore: @mut cstore::CStore,
|
||||
encode_inlined_item: encode_inlined_item
|
||||
|
@ -90,7 +90,7 @@ pub struct EncodeContext {
|
|||
reachable: reachable::map,
|
||||
reexports2: middle::resolve::ExportMap2,
|
||||
item_symbols: @mut HashMap<ast::node_id, ~str>,
|
||||
discrim_symbols: @mut HashMap<ast::node_id, ~str>,
|
||||
discrim_symbols: @mut HashMap<ast::node_id, @~str>,
|
||||
link_meta: LinkMeta,
|
||||
cstore: @mut cstore::CStore,
|
||||
encode_inlined_item: encode_inlined_item,
|
||||
|
@ -285,7 +285,7 @@ fn encode_symbol(ecx: @EncodeContext, ebml_w: writer::Encoder, id: node_id) {
|
|||
fn encode_discriminant(ecx: @EncodeContext, ebml_w: writer::Encoder,
|
||||
id: node_id) {
|
||||
ebml_w.start_tag(tag_items_data_item_symbol);
|
||||
ebml_w.writer.write(str::to_bytes(*ecx.discrim_symbols.get(&id)));
|
||||
ebml_w.writer.write(str::to_bytes(**ecx.discrim_symbols.get(&id)));
|
||||
ebml_w.end_tag();
|
||||
}
|
||||
|
||||
|
|
|
@ -468,11 +468,9 @@ pub fn set_glue_inlining(f: ValueRef, t: ty::t) {
|
|||
|
||||
// Double-check that we never ask LLVM to declare the same symbol twice. It
|
||||
// silently mangles such symbols, breaking our linkage model.
|
||||
pub fn note_unique_llvm_symbol(ccx: @CrateContext, +sym: ~str) {
|
||||
// XXX: this should not be necessary
|
||||
use core::container::Set;
|
||||
pub fn note_unique_llvm_symbol(ccx: @CrateContext, sym: @~str) {
|
||||
if ccx.all_llvm_symbols.contains(&sym) {
|
||||
ccx.sess.bug(~"duplicate LLVM symbol: " + sym);
|
||||
ccx.sess.bug(~"duplicate LLVM symbol: " + *sym);
|
||||
}
|
||||
ccx.all_llvm_symbols.insert(sym);
|
||||
}
|
||||
|
@ -2576,11 +2574,10 @@ pub fn trans_constant(ccx: @CrateContext, it: @ast::item) {
|
|||
path_name(variant.node.name),
|
||||
path_name(special_idents::descrim)
|
||||
]);
|
||||
let s = mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
|
||||
let s = @mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
|
||||
let disr_val = vi[i].disr_val;
|
||||
// XXX: Bad copy.
|
||||
note_unique_llvm_symbol(ccx, copy s);
|
||||
let discrim_gvar = str::as_c_str(s, |buf| {
|
||||
note_unique_llvm_symbol(ccx, s);
|
||||
let discrim_gvar = str::as_c_str(*s, |buf| {
|
||||
unsafe {
|
||||
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ pub struct CrateContext {
|
|||
link_meta: LinkMeta,
|
||||
enum_sizes: @mut HashMap<ty::t, uint>,
|
||||
discrims: @mut HashMap<ast::def_id, ValueRef>,
|
||||
discrim_symbols: @mut HashMap<ast::node_id, ~str>,
|
||||
discrim_symbols: @mut HashMap<ast::node_id, @~str>,
|
||||
tydescs: @mut HashMap<ty::t, @mut tydesc_info>,
|
||||
// Set when running emit_tydescs to enforce that no more tydescs are
|
||||
// created.
|
||||
|
@ -215,7 +215,7 @@ pub struct CrateContext {
|
|||
symbol_hasher: @hash::State,
|
||||
type_hashcodes: @mut HashMap<ty::t, @str>,
|
||||
type_short_names: @mut HashMap<ty::t, ~str>,
|
||||
all_llvm_symbols: @mut HashSet<~str>,
|
||||
all_llvm_symbols: @mut HashSet<@~str>,
|
||||
tcx: ty::ctxt,
|
||||
maps: astencode::Maps,
|
||||
stats: @mut Stats,
|
||||
|
|
|
@ -684,15 +684,14 @@ pub fn declare_tydesc(ccx: @CrateContext, t: ty::t) -> @mut tydesc_info {
|
|||
let llalign = llalign_of(ccx, llty);
|
||||
let addrspace = declare_tydesc_addrspace(ccx, t);
|
||||
//XXX this triggers duplicate LLVM symbols
|
||||
let name = if false /*ccx.sess.opts.debuginfo*/ {
|
||||
let name = @(if false /*ccx.sess.opts.debuginfo*/ {
|
||||
mangle_internal_name_by_type_only(ccx, t, ~"tydesc")
|
||||
} else {
|
||||
mangle_internal_name_by_seq(ccx, ~"tydesc")
|
||||
};
|
||||
// XXX: Bad copy.
|
||||
note_unique_llvm_symbol(ccx, copy name);
|
||||
debug!("+++ declare_tydesc %s %s", ppaux::ty_to_str(ccx.tcx, t), name);
|
||||
let gvar = str::as_c_str(name, |buf| {
|
||||
});
|
||||
note_unique_llvm_symbol(ccx, name);
|
||||
debug!("+++ declare_tydesc %s %s", ppaux::ty_to_str(ccx.tcx, t), *name);
|
||||
let gvar = str::as_c_str(*name, |buf| {
|
||||
unsafe {
|
||||
llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type, buf)
|
||||
}
|
||||
|
@ -718,17 +717,16 @@ pub fn declare_generic_glue(ccx: @CrateContext, t: ty::t, llfnty: TypeRef,
|
|||
+name: ~str) -> ValueRef {
|
||||
let _icx = ccx.insn_ctxt("declare_generic_glue");
|
||||
let name = name;
|
||||
let mut fn_nm;
|
||||
//XXX this triggers duplicate LLVM symbols
|
||||
if false /*ccx.sess.opts.debuginfo*/ {
|
||||
fn_nm = mangle_internal_name_by_type_only(ccx, t, (~"glue_" + name));
|
||||
let fn_nm = @(if false /*ccx.sess.opts.debuginfo*/ {
|
||||
mangle_internal_name_by_type_only(ccx, t, (~"glue_" + name))
|
||||
} else {
|
||||
fn_nm = mangle_internal_name_by_seq(ccx, (~"glue_" + name));
|
||||
}
|
||||
debug!("%s is for type %s", fn_nm, ppaux::ty_to_str(ccx.tcx, t));
|
||||
mangle_internal_name_by_seq(ccx, (~"glue_" + name))
|
||||
});
|
||||
debug!("%s is for type %s", *fn_nm, ppaux::ty_to_str(ccx.tcx, t));
|
||||
// XXX: Bad copy.
|
||||
note_unique_llvm_symbol(ccx, copy fn_nm);
|
||||
let llfn = decl_cdecl_fn(ccx.llmod, fn_nm, llfnty);
|
||||
note_unique_llvm_symbol(ccx, fn_nm);
|
||||
let llfn = decl_cdecl_fn(ccx.llmod, *fn_nm, llfnty);
|
||||
set_glue_inlining(llfn, t);
|
||||
return llfn;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue