Skip to content

Remove useless namegen thunk #7272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use lib;
use metadata::common::LinkMeta;
use metadata::{encoder, csearch, cstore};
use middle::trans::context::CrateContext;
use middle::trans::common::gensym_name;
use middle::ty;
use util::ppaux;

Expand All @@ -37,6 +38,7 @@ use syntax::ast;
use syntax::ast_map::{path, path_mod, path_name};
use syntax::attr;
use syntax::print::pprust;
use syntax::parse::token;

#[deriving(Eq)]
pub enum output_type {
Expand Down Expand Up @@ -731,22 +733,22 @@ pub fn mangle_internal_name_by_type_and_seq(ccx: &mut CrateContext,
return mangle(ccx.sess,
~[path_name(ccx.sess.ident_of(s)),
path_name(ccx.sess.ident_of(hash)),
path_name((ccx.names)(name))]);
path_name(gensym_name(name))]);
}

pub fn mangle_internal_name_by_path_and_seq(ccx: &mut CrateContext,
path: path,
mut path: path,
flav: &str) -> ~str {
mangle(ccx.sess,
vec::append_one(path, path_name((ccx.names)(flav))))
path.push(path_name(gensym_name(flav)));
mangle(ccx.sess, path)
}

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

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


Expand Down
27 changes: 14 additions & 13 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,24 +1129,22 @@ pub fn new_block(cx: fn_ctxt, parent: Option<block>, kind: block_kind,
is_lpad: bool, name: &str, opt_node_info: Option<NodeInfo>)
-> block {

let s = if cx.ccx.sess.opts.save_temps || cx.ccx.sess.opts.debuginfo {
(cx.ccx.names)(name)
} else {
special_idents::invalid
};
unsafe {
let llbb = str::as_c_str(cx.ccx.sess.str_of(s), |buf| {
let llbb = do name.as_c_str |buf| {
llvm::LLVMAppendBasicBlockInContext(cx.ccx.llcx, cx.llfn, buf)
});
};
let bcx = mk_block(llbb,
parent,
kind,
is_lpad,
opt_node_info,
cx);
for parent.iter().advance |cx| {
if cx.unreachable { Unreachable(bcx); }
};
if cx.unreachable {
Unreachable(bcx);
break;
}
}
bcx
}
}
Expand Down Expand Up @@ -2532,12 +2530,15 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::node_id) -> ValueRef {

pub fn register_method(ccx: @mut CrateContext,
id: ast::node_id,
pth: @ast_map::path,
path: @ast_map::path,
m: @ast::method) -> ValueRef {
let mty = ty::node_id_to_type(ccx.tcx, id);
let pth = vec::append(/*bad*/copy *pth, [path_name((ccx.names)("meth")),
path_name(m.ident)]);
let llfn = register_fn_full(ccx, m.span, pth, id, m.attrs, mty);

let mut path = /*bad*/ copy *path;
path.push(path_name(gensym_name("meth")));
path.push(path_name(m.ident));

let llfn = register_fn_full(ccx, m.span, path, id, m.attrs, mty);
set_inline_hint_if_appr(m.attrs, llfn);
llfn
}
Expand Down
15 changes: 5 additions & 10 deletions src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,8 @@ use syntax::{ast, ast_map};

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

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

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

pub fn C_bytes_plus_null(bytes: &[u8]) -> ValueRef {
unsafe {
let ptr = cast::transmute(vec::raw::to_ptr(bytes));
return llvm::LLVMConstStringInContext(base::task_llcx(), ptr, bytes.len() as c_uint,False);
return llvm::LLVMConstStringInContext(base::task_llcx(),
cast::transmute(vec::raw::to_ptr(bytes)),
bytes.len() as c_uint, False);
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/librustc/middle/trans/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ use core::local_data;
use extra::time;
use syntax::ast;

use middle::trans::common::{ExternMap,tydesc_info,BuilderRef_res,Stats,namegen};
use middle::trans::common::{mono_id,new_namegen};
use middle::trans::common::{mono_id,ExternMap,tydesc_info,BuilderRef_res,Stats};

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

Expand Down Expand Up @@ -93,7 +92,6 @@ pub struct CrateContext {
lltypes: HashMap<ty::t, Type>,
llsizingtypes: HashMap<ty::t, Type>,
adt_reprs: HashMap<ty::t, @adt::Repr>,
names: namegen,
symbol_hasher: hash::State,
type_hashcodes: HashMap<ty::t, @str>,
type_short_names: HashMap<ty::t, ~str>,
Expand Down Expand Up @@ -194,7 +192,6 @@ impl CrateContext {
lltypes: HashMap::new(),
llsizingtypes: HashMap::new(),
adt_reprs: HashMap::new(),
names: new_namegen(),
symbol_hasher: symbol_hasher,
type_hashcodes: HashMap::new(),
type_short_names: HashMap::new(),
Expand Down
10 changes: 4 additions & 6 deletions src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ use core::sys;
use core::vec;
use syntax::codemap::span;
use syntax::{ast, codemap, ast_util, ast_map};
use syntax::parse::token;

static DW_LANG_RUST: int = 0x9000;

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

/// A context object for maintaining all state needed by the debuginfo module.
pub struct DebugContext {
names: namegen,
crate_file: ~str,
llcontext: ContextRef,
builder: DIBuilderRef,
Expand All @@ -104,7 +104,6 @@ impl DebugContext {
// DIBuilder inherits context from the module, so we'd better use the same one
let llcontext = unsafe { llvm::LLVMGetModuleContext(llmod) };
return DebugContext {
names: new_namegen(),
crate_file: crate,
llcontext: llcontext,
builder: builder,
Expand Down Expand Up @@ -276,7 +275,8 @@ pub fn create_function(fcx: fn_ctxt) -> DISubprogram {
ast_map::node_expr(expr) => {
match expr.node {
ast::expr_fn_block(ref decl, _) => {
((dbg_cx(cx).names)("fn"), decl.output, expr.id)
let name = gensym_name("fn");
(name, decl.output, expr.id)
}
_ => fcx.ccx.sess.span_bug(expr.span,
"create_function: expected an expr_fn_block here")
Expand Down Expand Up @@ -628,7 +628,7 @@ fn create_tuple(cx: &mut CrateContext, tuple_type: ty::t, elements: &[ty::t], sp
let loc = span_start(cx, span);
let file_md = create_file(cx, loc.file.name);

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




//=-------------------------------------------------------------------------------------------------
// Utility Functions
//=-------------------------------------------------------------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions src/librustc/middle/trans/meth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ use middle::trans::type_of::*;
use middle::ty;
use middle::typeck;
use util::common::indenter;
use util::ppaux::Repr;
use util::ppaux::{Repr, ty_to_str};

use middle::trans::type_::Type;

use core::str;
use core::vec;
use syntax::ast_map::{path, path_mod, path_name};
use syntax::ast_util;
use syntax::{ast, ast_map};
use syntax::parse::token;

/**
The main "translation" pass for methods. Generates code
Expand Down Expand Up @@ -753,9 +753,10 @@ pub fn make_vtable(ccx: &mut CrateContext,
components.push(ptr)
}

let name = fmt!("%s_vtable_%u", ty_to_str(ccx.tcx, tydesc.ty), token::gensym("vtable"));

let tbl = C_struct(components);
let vtable = ccx.sess.str_of((ccx.names)("vtable"));
let vt_gvar = do str::as_c_str(vtable) |buf| {
let vt_gvar = do name.as_c_str |buf| {
llvm::LLVMAddGlobal(ccx.llmod, val_ty(tbl).to_ref(), buf)
};
llvm::LLVMSetInitializer(vt_gvar, tbl);
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/middle/trans/monomorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
}
ccx.monomorphizing.insert(fn_id, depth + 1);

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

let mk_lldecl = || {
Expand Down