Skip to content

Commit 13d3306

Browse files
committed
Remove even more usage of clownshoes in symbols
This removes another large chunk of this odd 'clownshoes' identifier showing up in symbol names. These all originated from external crates because the encoded items were encoded independently of the paths calculated in ast_map. The encoding of these paths now uses the helper function in ast_map to calculate the "pretty name" for an impl block. Unfortunately there is still no information about generics in the symbol name, but it's certainly vastly better than before hash::__extensions__::write::_version::v0.8 becomes hash::Writer$SipState::write::hversion::v0.8 This also fixes bugs in which lots of methods would show up as `meth_XXX`, they now only show up as `meth` and throw some extra characters onto the version string.
1 parent 12bca20 commit 13d3306

File tree

8 files changed

+46
-45
lines changed

8 files changed

+46
-45
lines changed

src/librustc/back/link.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use syntax::ast_map::{path, path_mod, path_name, path_pretty_name};
3939
use syntax::attr;
4040
use syntax::attr::{AttrMetaMethods};
4141
use syntax::print::pprust;
42-
use syntax::parse::token;
4342

4443
#[deriving(Clone, Eq)]
4544
pub enum output_type {
@@ -678,8 +677,8 @@ pub fn symbol_hash(tcx: ty::ctxt,
678677
write_string(symbol_hasher, "-");
679678
write_string(symbol_hasher, encoder::encoded_ty(tcx, t));
680679
let mut hash = truncated_hash_result(symbol_hasher);
681-
// Prefix with _ so that it never blends into adjacent digits
682-
hash.unshift_char('_');
680+
// Prefix with 'h' so that it never blends into adjacent digits
681+
hash.unshift_char('h');
683682
// tjc: allocation is unfortunate; need to change std::hash
684683
hash.to_managed()
685684
}
@@ -722,7 +721,7 @@ pub fn sanitize(s: &str) -> ~str {
722721
'a' .. 'z'
723722
| 'A' .. 'Z'
724723
| '0' .. '9'
725-
| '_' | '.' => result.push_char(c),
724+
| '_' | '.' | '$' => result.push_char(c),
726725

727726
_ => {
728727
let mut tstr = ~"";
@@ -847,28 +846,25 @@ pub fn mangle_internal_name_by_type_and_seq(ccx: &mut CrateContext,
847846
name: &str) -> ~str {
848847
let s = ppaux::ty_to_str(ccx.tcx, t);
849848
let hash = get_symbol_hash(ccx, t);
849+
let (_, name) = gensym_name(name);
850850
return mangle(ccx.sess,
851-
~[path_name(ccx.sess.ident_of(s)),
852-
path_name(gensym_name(name))],
851+
~[path_name(ccx.sess.ident_of(s)), name],
853852
Some(hash.as_slice()),
854853
None);
855854
}
856855

857856
pub fn mangle_internal_name_by_path_and_seq(ccx: &mut CrateContext,
858857
mut path: path,
859858
flav: &str) -> ~str {
860-
path.push(path_name(gensym_name(flav)));
859+
let (_, name) = gensym_name(flav);
860+
path.push(name);
861861
mangle(ccx.sess, path, None, None)
862862
}
863863

864864
pub fn mangle_internal_name_by_path(ccx: &mut CrateContext, path: path) -> ~str {
865865
mangle(ccx.sess, path, None, None)
866866
}
867867

868-
pub fn mangle_internal_name_by_seq(_ccx: &mut CrateContext, flav: &str) -> ~str {
869-
return fmt!("%s_%u", flav, token::gensym(flav));
870-
}
871-
872868

873869
pub fn output_dll_filename(os: session::Os, lm: LinkMeta) -> ~str {
874870
let (dll_prefix, dll_suffix) = match os {

src/librustc/metadata/encoder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,12 +1063,13 @@ fn encode_info_for_item(ecx: &EncodeContext,
10631063
let impl_vtables = ty::lookup_impl_vtables(tcx, def_id);
10641064
encode_impl_vtables(ebml_w, ecx, &impl_vtables);
10651065
}
1066-
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
1066+
let elt = ast_map::impl_pretty_name(opt_trait, ty, item.ident);
1067+
encode_path(ecx, ebml_w, path, elt);
10671068
ebml_w.end_tag();
10681069

10691070
// >:-<
10701071
let mut impl_path = vec::append(~[], path);
1071-
impl_path.push(ast_map::path_name(item.ident));
1072+
impl_path.push(elt);
10721073

10731074
// Iterate down the methods, emitting them. We rely on the
10741075
// assumption that all of the actually implemented methods

src/librustc/middle/trans/common.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ use std::hashmap::{HashMap};
3939
use std::libc::{c_uint, c_longlong, c_ulonglong, c_char};
4040
use std::vec;
4141
use syntax::ast::Ident;
42-
use syntax::ast_map::{path, path_elt};
42+
use syntax::ast_map::{path, path_elt, path_pretty_name};
4343
use syntax::codemap::Span;
4444
use syntax::parse::token;
4545
use syntax::{ast, ast_map};
4646

4747
pub use middle::trans::context::CrateContext;
4848

49-
pub fn gensym_name(name: &str) -> Ident {
50-
token::str_to_ident(fmt!("%s_%u", name, token::gensym(name)))
49+
pub fn gensym_name(name: &str) -> (Ident, path_elt) {
50+
let name = token::gensym(name);
51+
let ident = Ident::new(name);
52+
(ident, path_pretty_name(ident, name as u64))
5153
}
5254

5355
pub struct tydesc_info {

src/librustc/middle/trans/debuginfo.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ use std::ptr;
6969
use std::vec;
7070
use syntax::codemap::Span;
7171
use syntax::{ast, codemap, ast_util, ast_map, opt_vec};
72+
use syntax::parse::token;
7273
use syntax::parse::token::special_idents;
7374

7475
static DW_LANG_RUST: c_uint = 0x9000;
@@ -513,7 +514,8 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
513514
ast_map::node_expr(ref expr) => {
514515
match expr.node {
515516
ast::ExprFnBlock(ref fn_decl, ref top_level_block) => {
516-
let name = gensym_name("fn");
517+
let name = fmt!("fn%u", token::gensym("fn"));
518+
let name = token::str_to_ident(name);
517519
(name, fn_decl,
518520
// This is not quite right. It should actually inherit the generics of the
519521
// enclosing function.

src/librustc/middle/trans/meth.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use std::vec;
3737
use syntax::ast_map::{path, path_mod, path_name, path_pretty_name};
3838
use syntax::ast_util;
3939
use syntax::{ast, ast_map};
40+
use syntax::parse::token;
4041
use syntax::visit;
4142

4243
/**
@@ -568,8 +569,8 @@ pub fn make_vtable(ccx: &mut CrateContext,
568569
}
569570

570571
let tbl = C_struct(components);
571-
let vtable = ccx.sess.str_of(gensym_name("vtable"));
572-
let vt_gvar = do vtable.with_c_str |buf| {
572+
let sym = token::gensym("vtable");
573+
let vt_gvar = do fmt!("vtable%u", sym).with_c_str |buf| {
573574
llvm::LLVMAddGlobal(ccx.llmod, val_ty(tbl).to_ref(), buf)
574575
};
575576
llvm::LLVMSetInitializer(vt_gvar, tbl);

src/librustc/middle/trans/monomorphize.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use util::ppaux::{Repr,ty_to_str};
3131

3232
use syntax::ast;
3333
use syntax::ast_map;
34-
use syntax::ast_map::path_name;
3534
use syntax::ast_util::local_def;
3635

3736
pub fn monomorphic_fn(ccx: @mut CrateContext,
@@ -194,7 +193,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
194193
}
195194
ccx.monomorphizing.insert(fn_id, depth + 1);
196195

197-
let elt = path_name(gensym_name(ccx.sess.str_of(name)));
196+
let (_, elt) = gensym_name(ccx.sess.str_of(name));
198197
let mut pt = (*pt).clone();
199198
pt.push(elt);
200199
let s = mangle_exported_name(ccx, pt.clone(), mono_ty);

src/libsyntax/ast_map.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,28 @@ pub fn path_elt_to_str(pe: path_elt, itr: @ident_interner) -> ~str {
7272
}
7373
}
7474

75+
pub fn impl_pretty_name(trait_ref: &Option<trait_ref>,
76+
ty: &Ty, default: Ident) -> path_elt {
77+
let itr = get_ident_interner();
78+
let ty_ident = match ty.node {
79+
ty_path(ref path, _, _) => path.segments.last().identifier,
80+
_ => default
81+
};
82+
let hash = (trait_ref, ty).hash();
83+
match *trait_ref {
84+
None => path_pretty_name(ty_ident, hash),
85+
Some(ref trait_ref) => {
86+
// XXX: this dollar sign is actually a relic of being one of the
87+
// very few valid symbol names on unix. These kinds of
88+
// details shouldn't be exposed way up here in the ast.
89+
let s = fmt!("%s$%s",
90+
itr.get(trait_ref.path.segments.last().identifier.name),
91+
itr.get(ty_ident.name));
92+
path_pretty_name(Ident::new(itr.gensym(s)), hash)
93+
}
94+
}
95+
}
96+
7597
#[deriving(Clone)]
7698
pub enum ast_node {
7799
node_item(@item, @path),
@@ -216,28 +238,6 @@ impl Ctx {
216238

217239
visit::walk_pat(self, pat, ());
218240
}
219-
220-
fn impl_pretty_name(&self, trait_ref: &Option<trait_ref>,
221-
ty: &Ty, default: Ident) -> path_elt {
222-
let itr = get_ident_interner();
223-
let ty_ident = match ty.node {
224-
ty_path(ref path, _, _) => path.segments.last().identifier,
225-
_ => default
226-
};
227-
let hash = (trait_ref, ty).hash();
228-
match *trait_ref {
229-
None => path_pretty_name(ty_ident, hash),
230-
Some(ref trait_ref) => {
231-
// XXX: this dollar sign is actually a relic of being one of the
232-
// very few valid symbol names on unix. These kinds of
233-
// details shouldn't be exposed way up here in the ast.
234-
let s = fmt!("%s$%s",
235-
itr.get(trait_ref.path.segments.last().identifier.name),
236-
itr.get(ty_ident.name));
237-
path_pretty_name(Ident::new(itr.gensym(s)), hash)
238-
}
239-
}
240-
}
241241
}
242242

243243
impl Visitor<()> for Ctx {
@@ -250,7 +250,7 @@ impl Visitor<()> for Ctx {
250250
// Right now the ident on impls is __extensions__ which isn't
251251
// very pretty when debugging, so attempt to select a better
252252
// name to use.
253-
let elt = self.impl_pretty_name(maybe_trait, ty, i.ident);
253+
let elt = impl_pretty_name(maybe_trait, ty, i.ident);
254254

255255
let impl_did = ast_util::local_def(i.id);
256256
for m in ms.iter() {

src/test/compile-fail/ambig_impl_2_exe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ trait me {
1717
}
1818
impl me for uint { fn me(&self) -> uint { *self } } //~ NOTE is `me$uint::me`
1919
fn main() { 1u.me(); } //~ ERROR multiple applicable methods in scope
20-
//~^ NOTE is `ambig_impl_2_lib::__extensions__::me`
20+
//~^ NOTE is `ambig_impl_2_lib::me$uint::me`

0 commit comments

Comments
 (0)