Skip to content

Commit 39d45b7

Browse files
committed
rustc: Anti-copy police
1 parent dd2c7f6 commit 39d45b7

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

src/librustc/metadata/encoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub struct EncodeParams {
6363
reachable: reachable::map,
6464
reexports2: middle::resolve::ExportMap2,
6565
item_symbols: @mut HashMap<ast::node_id, ~str>,
66-
discrim_symbols: @mut HashMap<ast::node_id, ~str>,
66+
discrim_symbols: @mut HashMap<ast::node_id, @~str>,
6767
link_meta: LinkMeta,
6868
cstore: @mut cstore::CStore,
6969
encode_inlined_item: encode_inlined_item
@@ -90,7 +90,7 @@ pub struct EncodeContext {
9090
reachable: reachable::map,
9191
reexports2: middle::resolve::ExportMap2,
9292
item_symbols: @mut HashMap<ast::node_id, ~str>,
93-
discrim_symbols: @mut HashMap<ast::node_id, ~str>,
93+
discrim_symbols: @mut HashMap<ast::node_id, @~str>,
9494
link_meta: LinkMeta,
9595
cstore: @mut cstore::CStore,
9696
encode_inlined_item: encode_inlined_item,
@@ -285,7 +285,7 @@ fn encode_symbol(ecx: @EncodeContext, ebml_w: writer::Encoder, id: node_id) {
285285
fn encode_discriminant(ecx: @EncodeContext, ebml_w: writer::Encoder,
286286
id: node_id) {
287287
ebml_w.start_tag(tag_items_data_item_symbol);
288-
ebml_w.writer.write(str::to_bytes(*ecx.discrim_symbols.get(&id)));
288+
ebml_w.writer.write(str::to_bytes(**ecx.discrim_symbols.get(&id)));
289289
ebml_w.end_tag();
290290
}
291291

src/librustc/middle/trans/base.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,9 @@ pub fn set_glue_inlining(f: ValueRef, t: ty::t) {
468468

469469
// Double-check that we never ask LLVM to declare the same symbol twice. It
470470
// silently mangles such symbols, breaking our linkage model.
471-
pub fn note_unique_llvm_symbol(ccx: @CrateContext, +sym: ~str) {
472-
// XXX: this should not be necessary
473-
use core::container::Set;
471+
pub fn note_unique_llvm_symbol(ccx: @CrateContext, sym: @~str) {
474472
if ccx.all_llvm_symbols.contains(&sym) {
475-
ccx.sess.bug(~"duplicate LLVM symbol: " + sym);
473+
ccx.sess.bug(~"duplicate LLVM symbol: " + *sym);
476474
}
477475
ccx.all_llvm_symbols.insert(sym);
478476
}
@@ -2576,11 +2574,10 @@ pub fn trans_constant(ccx: @CrateContext, it: @ast::item) {
25762574
path_name(variant.node.name),
25772575
path_name(special_idents::descrim)
25782576
]);
2579-
let s = mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
2577+
let s = @mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
25802578
let disr_val = vi[i].disr_val;
2581-
// XXX: Bad copy.
2582-
note_unique_llvm_symbol(ccx, copy s);
2583-
let discrim_gvar = str::as_c_str(s, |buf| {
2579+
note_unique_llvm_symbol(ccx, s);
2580+
let discrim_gvar = str::as_c_str(*s, |buf| {
25842581
unsafe {
25852582
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
25862583
}

src/librustc/middle/trans/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub struct CrateContext {
173173
link_meta: LinkMeta,
174174
enum_sizes: @mut HashMap<ty::t, uint>,
175175
discrims: @mut HashMap<ast::def_id, ValueRef>,
176-
discrim_symbols: @mut HashMap<ast::node_id, ~str>,
176+
discrim_symbols: @mut HashMap<ast::node_id, @~str>,
177177
tydescs: @mut HashMap<ty::t, @mut tydesc_info>,
178178
// Set when running emit_tydescs to enforce that no more tydescs are
179179
// created.
@@ -215,7 +215,7 @@ pub struct CrateContext {
215215
symbol_hasher: @hash::State,
216216
type_hashcodes: @mut HashMap<ty::t, @str>,
217217
type_short_names: @mut HashMap<ty::t, ~str>,
218-
all_llvm_symbols: @mut HashSet<~str>,
218+
all_llvm_symbols: @mut HashSet<@~str>,
219219
tcx: ty::ctxt,
220220
maps: astencode::Maps,
221221
stats: @mut Stats,

src/librustc/middle/trans/glue.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -684,15 +684,14 @@ pub fn declare_tydesc(ccx: @CrateContext, t: ty::t) -> @mut tydesc_info {
684684
let llalign = llalign_of(ccx, llty);
685685
let addrspace = declare_tydesc_addrspace(ccx, t);
686686
//XXX this triggers duplicate LLVM symbols
687-
let name = if false /*ccx.sess.opts.debuginfo*/ {
687+
let name = @(if false /*ccx.sess.opts.debuginfo*/ {
688688
mangle_internal_name_by_type_only(ccx, t, ~"tydesc")
689689
} else {
690690
mangle_internal_name_by_seq(ccx, ~"tydesc")
691-
};
692-
// XXX: Bad copy.
693-
note_unique_llvm_symbol(ccx, copy name);
694-
debug!("+++ declare_tydesc %s %s", ppaux::ty_to_str(ccx.tcx, t), name);
695-
let gvar = str::as_c_str(name, |buf| {
691+
});
692+
note_unique_llvm_symbol(ccx, name);
693+
debug!("+++ declare_tydesc %s %s", ppaux::ty_to_str(ccx.tcx, t), *name);
694+
let gvar = str::as_c_str(*name, |buf| {
696695
unsafe {
697696
llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type, buf)
698697
}
@@ -718,17 +717,16 @@ pub fn declare_generic_glue(ccx: @CrateContext, t: ty::t, llfnty: TypeRef,
718717
+name: ~str) -> ValueRef {
719718
let _icx = ccx.insn_ctxt("declare_generic_glue");
720719
let name = name;
721-
let mut fn_nm;
722720
//XXX this triggers duplicate LLVM symbols
723-
if false /*ccx.sess.opts.debuginfo*/ {
724-
fn_nm = mangle_internal_name_by_type_only(ccx, t, (~"glue_" + name));
721+
let fn_nm = @(if false /*ccx.sess.opts.debuginfo*/ {
722+
mangle_internal_name_by_type_only(ccx, t, (~"glue_" + name))
725723
} else {
726-
fn_nm = mangle_internal_name_by_seq(ccx, (~"glue_" + name));
727-
}
728-
debug!("%s is for type %s", fn_nm, ppaux::ty_to_str(ccx.tcx, t));
724+
mangle_internal_name_by_seq(ccx, (~"glue_" + name))
725+
});
726+
debug!("%s is for type %s", *fn_nm, ppaux::ty_to_str(ccx.tcx, t));
729727
// XXX: Bad copy.
730-
note_unique_llvm_symbol(ccx, copy fn_nm);
731-
let llfn = decl_cdecl_fn(ccx.llmod, fn_nm, llfnty);
728+
note_unique_llvm_symbol(ccx, fn_nm);
729+
let llfn = decl_cdecl_fn(ccx.llmod, *fn_nm, llfnty);
732730
set_glue_inlining(llfn, t);
733731
return llfn;
734732
}

0 commit comments

Comments
 (0)