Skip to content

Commit 8600c18

Browse files
committed
auto merge of #7272 : Aatch/rust/namegen_thunk, r=thestinger
This removes the `namegen` thunk that was in `common.rs`. I also take the opportunity to refactor a few uses where we had a `str -> ident -> str` chain that seemed somewhat redundant to me. Also cleans up some warnings that made their way in already.
2 parents 61dc776 + a897a9a commit 8600c18

File tree

7 files changed

+40
-45
lines changed

7 files changed

+40
-45
lines changed

src/librustc/back/link.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use lib;
1919
use metadata::common::LinkMeta;
2020
use metadata::{encoder, csearch, cstore};
2121
use middle::trans::context::CrateContext;
22+
use middle::trans::common::gensym_name;
2223
use middle::ty;
2324
use util::ppaux;
2425

@@ -37,6 +38,7 @@ use syntax::ast;
3738
use syntax::ast_map::{path, path_mod, path_name};
3839
use syntax::attr;
3940
use syntax::print::pprust;
41+
use syntax::parse::token;
4042

4143
#[deriving(Eq)]
4244
pub enum output_type {
@@ -731,22 +733,22 @@ pub fn mangle_internal_name_by_type_and_seq(ccx: &mut CrateContext,
731733
return mangle(ccx.sess,
732734
~[path_name(ccx.sess.ident_of(s)),
733735
path_name(ccx.sess.ident_of(hash)),
734-
path_name((ccx.names)(name))]);
736+
path_name(gensym_name(name))]);
735737
}
736738

737739
pub fn mangle_internal_name_by_path_and_seq(ccx: &mut CrateContext,
738-
path: path,
740+
mut path: path,
739741
flav: &str) -> ~str {
740-
mangle(ccx.sess,
741-
vec::append_one(path, path_name((ccx.names)(flav))))
742+
path.push(path_name(gensym_name(flav)));
743+
mangle(ccx.sess, path)
742744
}
743745

744746
pub fn mangle_internal_name_by_path(ccx: &mut CrateContext, path: path) -> ~str {
745747
mangle(ccx.sess, path)
746748
}
747749

748-
pub fn mangle_internal_name_by_seq(ccx: &mut CrateContext, flav: &str) -> ~str {
749-
fmt!("%s_%u", flav, (ccx.names)(flav).name)
750+
pub fn mangle_internal_name_by_seq(_ccx: &mut CrateContext, flav: &str) -> ~str {
751+
return fmt!("%s_%u", flav, token::gensym(flav));
750752
}
751753

752754

src/librustc/middle/trans/base.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,24 +1129,22 @@ pub fn new_block(cx: fn_ctxt, parent: Option<block>, kind: block_kind,
11291129
is_lpad: bool, name: &str, opt_node_info: Option<NodeInfo>)
11301130
-> block {
11311131

1132-
let s = if cx.ccx.sess.opts.save_temps || cx.ccx.sess.opts.debuginfo {
1133-
(cx.ccx.names)(name)
1134-
} else {
1135-
special_idents::invalid
1136-
};
11371132
unsafe {
1138-
let llbb = str::as_c_str(cx.ccx.sess.str_of(s), |buf| {
1133+
let llbb = do name.as_c_str |buf| {
11391134
llvm::LLVMAppendBasicBlockInContext(cx.ccx.llcx, cx.llfn, buf)
1140-
});
1135+
};
11411136
let bcx = mk_block(llbb,
11421137
parent,
11431138
kind,
11441139
is_lpad,
11451140
opt_node_info,
11461141
cx);
11471142
for parent.iter().advance |cx| {
1148-
if cx.unreachable { Unreachable(bcx); }
1149-
};
1143+
if cx.unreachable {
1144+
Unreachable(bcx);
1145+
break;
1146+
}
1147+
}
11501148
bcx
11511149
}
11521150
}
@@ -2524,12 +2522,15 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::node_id) -> ValueRef {
25242522
25252523
pub fn register_method(ccx: @mut CrateContext,
25262524
id: ast::node_id,
2527-
pth: @ast_map::path,
2525+
path: @ast_map::path,
25282526
m: @ast::method) -> ValueRef {
25292527
let mty = ty::node_id_to_type(ccx.tcx, id);
2530-
let pth = vec::append(/*bad*/copy *pth, [path_name((ccx.names)("meth")),
2531-
path_name(m.ident)]);
2532-
let llfn = register_fn_full(ccx, m.span, pth, id, m.attrs, mty);
2528+
2529+
let mut path = /*bad*/ copy *path;
2530+
path.push(path_name(gensym_name("meth")));
2531+
path.push(path_name(m.ident));
2532+
2533+
let llfn = register_fn_full(ccx, m.span, path, id, m.attrs, mty);
25332534
set_inline_hint_if_appr(m.attrs, llfn);
25342535
llfn
25352536
}

src/librustc/middle/trans/common.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,8 @@ use syntax::{ast, ast_map};
4545

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

48-
// NOTE: this thunk is totally pointless now that we're not passing
49-
// interners around...
50-
pub type namegen = @fn(s: &str) -> ident;
51-
pub fn new_namegen() -> namegen {
52-
let f: @fn(s: &str) -> ident = |prefix| {
53-
token::str_to_ident(fmt!("%s_%u", prefix, token::gensym(prefix)))
54-
};
55-
f
48+
pub fn gensym_name(name: &str) -> ident {
49+
token::str_to_ident(fmt!("%s_%u", name, token::gensym(name)))
5650
}
5751

5852
pub struct tydesc_info {
@@ -819,8 +813,9 @@ pub fn C_bytes(bytes: &[u8]) -> ValueRef {
819813

820814
pub fn C_bytes_plus_null(bytes: &[u8]) -> ValueRef {
821815
unsafe {
822-
let ptr = cast::transmute(vec::raw::to_ptr(bytes));
823-
return llvm::LLVMConstStringInContext(base::task_llcx(), ptr, bytes.len() as c_uint,False);
816+
return llvm::LLVMConstStringInContext(base::task_llcx(),
817+
cast::transmute(vec::raw::to_ptr(bytes)),
818+
bytes.len() as c_uint, False);
824819
}
825820
}
826821

src/librustc/middle/trans/context.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ use core::local_data;
3434
use extra::time;
3535
use syntax::ast;
3636

37-
use middle::trans::common::{ExternMap,tydesc_info,BuilderRef_res,Stats,namegen};
38-
use middle::trans::common::{mono_id,new_namegen};
37+
use middle::trans::common::{mono_id,ExternMap,tydesc_info,BuilderRef_res,Stats};
3938

4039
use middle::trans::base::{decl_crate_map};
4140

@@ -93,7 +92,6 @@ pub struct CrateContext {
9392
lltypes: HashMap<ty::t, Type>,
9493
llsizingtypes: HashMap<ty::t, Type>,
9594
adt_reprs: HashMap<ty::t, @adt::Repr>,
96-
names: namegen,
9795
symbol_hasher: hash::State,
9896
type_hashcodes: HashMap<ty::t, @str>,
9997
type_short_names: HashMap<ty::t, ~str>,
@@ -194,7 +192,6 @@ impl CrateContext {
194192
lltypes: HashMap::new(),
195193
llsizingtypes: HashMap::new(),
196194
adt_reprs: HashMap::new(),
197-
names: new_namegen(),
198195
symbol_hasher: symbol_hasher,
199196
type_hashcodes: HashMap::new(),
200197
type_short_names: HashMap::new(),

src/librustc/middle/trans/debuginfo.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ use core::sys;
6464
use core::vec;
6565
use syntax::codemap::span;
6666
use syntax::{ast, codemap, ast_util, ast_map};
67+
use syntax::parse::token;
6768

6869
static DW_LANG_RUST: int = 0x9000;
6970

@@ -86,7 +87,6 @@ static DW_ATE_unsigned_char: int = 0x08;
8687

8788
/// A context object for maintaining all state needed by the debuginfo module.
8889
pub struct DebugContext {
89-
names: namegen,
9090
crate_file: ~str,
9191
llcontext: ContextRef,
9292
builder: DIBuilderRef,
@@ -104,7 +104,6 @@ impl DebugContext {
104104
// DIBuilder inherits context from the module, so we'd better use the same one
105105
let llcontext = unsafe { llvm::LLVMGetModuleContext(llmod) };
106106
return DebugContext {
107-
names: new_namegen(),
108107
crate_file: crate,
109108
llcontext: llcontext,
110109
builder: builder,
@@ -276,7 +275,8 @@ pub fn create_function(fcx: fn_ctxt) -> DISubprogram {
276275
ast_map::node_expr(expr) => {
277276
match expr.node {
278277
ast::expr_fn_block(ref decl, _) => {
279-
((dbg_cx(cx).names)("fn"), decl.output, expr.id)
278+
let name = gensym_name("fn");
279+
(name, decl.output, expr.id)
280280
}
281281
_ => fcx.ccx.sess.span_bug(expr.span,
282282
"create_function: expected an expr_fn_block here")
@@ -628,7 +628,7 @@ fn create_tuple(cx: &mut CrateContext, tuple_type: ty::t, elements: &[ty::t], sp
628628
let loc = span_start(cx, span);
629629
let file_md = create_file(cx, loc.file.name);
630630

631-
let name = (cx.sess.str_of((dbg_cx(cx).names)("tuple"))).to_owned();
631+
let name = fmt!("tuple_%u", token::gensym("tuple"));
632632
let mut scx = StructContext::new(cx, name, file_md, loc.line);
633633
for elements.iter().advance |element| {
634634
let ty_md = create_ty(cx, *element, span);
@@ -911,8 +911,6 @@ fn set_debug_location(cx: @mut CrateContext, scope: DIScope, line: uint, col: ui
911911
}
912912

913913

914-
915-
916914
//=-------------------------------------------------------------------------------------------------
917915
// Utility Functions
918916
//=-------------------------------------------------------------------------------------------------

src/librustc/middle/trans/meth.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ use middle::trans::type_of::*;
2828
use middle::ty;
2929
use middle::typeck;
3030
use util::common::indenter;
31-
use util::ppaux::Repr;
31+
use util::ppaux::{Repr, ty_to_str};
3232

3333
use middle::trans::type_::Type;
3434

35-
use core::str;
3635
use core::vec;
3736
use syntax::ast_map::{path, path_mod, path_name};
3837
use syntax::ast_util;
3938
use syntax::{ast, ast_map};
39+
use syntax::parse::token;
4040

4141
/**
4242
The main "translation" pass for methods. Generates code
@@ -755,9 +755,10 @@ pub fn make_vtable(ccx: &mut CrateContext,
755755
components.push(ptr)
756756
}
757757

758+
let name = fmt!("%s_vtable_%u", ty_to_str(ccx.tcx, tydesc.ty), token::gensym("vtable"));
759+
758760
let tbl = C_struct(components);
759-
let vtable = ccx.sess.str_of((ccx.names)("vtable"));
760-
let vt_gvar = do str::as_c_str(vtable) |buf| {
761+
let vt_gvar = do name.as_c_str |buf| {
761762
llvm::LLVMAddGlobal(ccx.llmod, val_ty(tbl).to_ref(), buf)
762763
};
763764
llvm::LLVMSetInitializer(vt_gvar, tbl);

src/librustc/middle/trans/monomorphize.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
161161
}
162162
ccx.monomorphizing.insert(fn_id, depth + 1);
163163

164-
let pt = vec::append(/*bad*/copy *pt,
165-
[path_name((ccx.names)(ccx.sess.str_of(name)))]);
164+
let elt = path_name(gensym_name(ccx.sess.str_of(name)));
165+
let mut pt = /* bad */copy (*pt);
166+
pt.push(elt);
166167
let s = mangle_exported_name(ccx, /*bad*/copy pt, mono_ty);
167168

168169
let mk_lldecl = || {

0 commit comments

Comments
 (0)