Skip to content

Commit 652332f

Browse files
committed
Convert std::map::new_str_hash to istrs. Issue #855
1 parent faef949 commit 652332f

File tree

17 files changed

+181
-144
lines changed

17 files changed

+181
-144
lines changed

src/comp/lib/llvm.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -901,22 +901,26 @@ native "cdecl" mod llvm = "rustllvm" {
901901
/* Memory-managed object interface to type handles. */
902902

903903
obj type_names(type_names: std::map::hashmap<TypeRef, str>,
904-
named_types: std::map::hashmap<str, TypeRef>) {
904+
named_types: std::map::hashmap<istr, TypeRef>) {
905905

906906
fn associate(s: str, t: TypeRef) {
907-
assert (!named_types.contains_key(s));
907+
assert (!named_types.contains_key(istr::from_estr(s)));
908908
assert (!type_names.contains_key(t));
909909
type_names.insert(t, s);
910-
named_types.insert(s, t);
910+
named_types.insert(istr::from_estr(s), t);
911911
}
912912

913913
fn type_has_name(t: TypeRef) -> bool { ret type_names.contains_key(t); }
914914

915915
fn get_name(t: TypeRef) -> str { ret type_names.get(t); }
916916

917-
fn name_has_type(s: str) -> bool { ret named_types.contains_key(s); }
917+
fn name_has_type(s: str) -> bool {
918+
ret named_types.contains_key(istr::from_estr(s));
919+
}
918920

919-
fn get_type(s: str) -> TypeRef { ret named_types.get(s); }
921+
fn get_type(s: str) -> TypeRef {
922+
ret named_types.get(istr::from_estr(s));
923+
}
920924
}
921925

922926
fn mk_type_names() -> type_names {

src/comp/metadata/creader.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn read_crates(sess: session::session, crate: &ast::crate) {
4747

4848
type env =
4949
@{sess: session::session,
50-
crate_cache: @hashmap<str, int>,
50+
crate_cache: @hashmap<istr, int>,
5151
library_search_paths: [str],
5252
mutable next_crate_num: ast::crate_num};
5353

@@ -226,7 +226,7 @@ fn load_library_crate(sess: &session::session, span: span, ident: &ast::ident,
226226

227227
fn resolve_crate(e: env, ident: ast::ident, metas: [@ast::meta_item],
228228
span: span) -> ast::crate_num {
229-
if !e.crate_cache.contains_key(ident) {
229+
if !e.crate_cache.contains_key(istr::from_estr(ident)) {
230230
let cinfo =
231231
load_library_crate(e.sess, span, ident, metas,
232232
e.library_search_paths);
@@ -236,7 +236,7 @@ fn resolve_crate(e: env, ident: ast::ident, metas: [@ast::meta_item],
236236

237237
// Claim this crate number and cache it
238238
let cnum = e.next_crate_num;
239-
e.crate_cache.insert(ident, cnum);
239+
e.crate_cache.insert(istr::from_estr(ident), cnum);
240240
e.next_crate_num += 1;
241241

242242
// Now resolve the crates referenced by this crate
@@ -248,7 +248,7 @@ fn resolve_crate(e: env, ident: ast::ident, metas: [@ast::meta_item],
248248
cstore::set_crate_data(cstore, cnum, cmeta);
249249
cstore::add_used_crate_file(cstore, cfilename);
250250
ret cnum;
251-
} else { ret e.crate_cache.get(ident); }
251+
} else { ret e.crate_cache.get(istr::from_estr(ident)); }
252252
}
253253

254254
// Go through the crate metadata and load any crates that it references
@@ -261,10 +261,10 @@ fn resolve_crate_deps(e: env, cdata: &@[u8]) -> cstore::cnum_map {
261261
let extrn_cnum = dep.cnum;
262262
let cname = dep.ident;
263263
log #fmt["resolving dep %s", cname];
264-
if e.crate_cache.contains_key(cname) {
264+
if e.crate_cache.contains_key(istr::from_estr(cname)) {
265265
log "already have it";
266266
// We've already seen this crate
267-
let local_cnum = e.crate_cache.get(cname);
267+
let local_cnum = e.crate_cache.get(istr::from_estr(cname));
268268
cnum_map.insert(extrn_cnum, local_cnum);
269269
} else {
270270
log "need to load it";

src/comp/middle/gc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn add_gc_root(cx: &@block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
4747
bcx = td_r.result.bcx;
4848
let lltydesc = td_r.result.val;
4949

50-
let gcroot = bcx_ccx(bcx).intrinsics.get("llvm.gcroot");
50+
let gcroot = bcx_ccx(bcx).intrinsics.get(~"llvm.gcroot");
5151
let llvalptr = bld::PointerCast(bcx, llval, T_ptr(T_ptr(T_i8())));
5252

5353
alt td_r.kind {

src/comp/middle/resolve.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import std::option::is_none;
3333
import std::option::some;
3434
import std::option::none;
3535
import std::str;
36+
import std::istr;
3637
import syntax::print::pprust::*;
3738

3839
export resolve_crate;
@@ -101,7 +102,7 @@ tag mod_index_entry {
101102
mie_tag_variant(/* tag item */@ast::item, /* variant index */uint);
102103
}
103104

104-
type mod_index = hashmap<ident, list<mod_index_entry>>;
105+
type mod_index = hashmap<identistr, list<mod_index_entry>>;
105106

106107
// A tuple of an imported def and the import stmt that brung it
107108
type glob_imp_def = {def: def, item: @ast::view_item};
@@ -110,7 +111,7 @@ type indexed_mod =
110111
{m: option::t<ast::_mod>,
111112
index: mod_index,
112113
mutable glob_imports: [glob_imp_def],
113-
glob_imported_names: hashmap<str, import_state>};
114+
glob_imported_names: hashmap<istr, import_state>};
114115

115116

116117
/* native modules can't contain tags, and we don't store their ASTs because we
@@ -954,7 +955,7 @@ fn lookup_in_local_mod(e: &env, node_id: node_id, sp: &span, id: &ident,
954955
ret none::<def>; // name is not visible
955956

956957
}
957-
alt info.index.find(id) {
958+
alt info.index.find(istr::from_estr(id)) {
958959
none. { }
959960
some(lst_) {
960961
let lst = lst_;
@@ -1009,14 +1010,15 @@ fn lookup_glob_in_mod(e: &env, info: @indexed_mod, sp: &span, id: &ident,
10091010
// since we don't know what names we have in advance,
10101011
// absence takes the place of todo()
10111012

1012-
if !info.glob_imported_names.contains_key(id) {
1013-
info.glob_imported_names.insert(id, resolving(sp));
1013+
if !info.glob_imported_names.contains_key(istr::from_estr(id)) {
1014+
info.glob_imported_names.insert(istr::from_estr(id), resolving(sp));
10141015
let val = per_ns(e, info, sp, id, ns_value, dr);
10151016
let typ = per_ns(e, info, sp, id, ns_type, dr);
10161017
let md = per_ns(e, info, sp, id, ns_module, dr);
1017-
info.glob_imported_names.insert(id, resolved(val, typ, md));
1018+
info.glob_imported_names.insert(istr::from_estr(id),
1019+
resolved(val, typ, md));
10181020
}
1019-
alt info.glob_imported_names.get(id) {
1021+
alt info.glob_imported_names.get(istr::from_estr(id)) {
10201022
todo(_, _, _, _, _) { e.sess.bug("Shouldn't've put a todo in."); }
10211023
resolving(sp) {
10221024
ret none::<def>; //circularity is okay in import globs
@@ -1071,10 +1073,12 @@ fn lookup_in_mie(e: &env, mie: &mod_index_entry, ns: namespace) ->
10711073

10721074

10731075
// Module indexing
1074-
fn add_to_index(index: &hashmap<ident, list<mod_index_entry>>, id: &ident,
1075-
ent: &mod_index_entry) {
1076+
fn add_to_index(index: &hashmap<identistr, list<mod_index_entry>>,
1077+
id: &ident, ent: &mod_index_entry) {
1078+
let id = istr::from_estr(id);
10761079
alt index.find(id) {
1077-
none. { index.insert(id, cons(ent, @nil::<mod_index_entry>)); }
1080+
none. { index.insert(id,
1081+
cons(ent, @nil::<mod_index_entry>)); }
10781082
some(prev) { index.insert(id, cons(ent, @prev)); }
10791083
}
10801084
}
@@ -1187,9 +1191,9 @@ fn check_for_collisions(e: &@env, c: &ast::crate) {
11871191
// Module indices make checking those relatively simple -- just check each
11881192
// name for multiple entities in the same namespace.
11891193
for each m: @{key: ast::node_id, val: @indexed_mod} in e.mod_map.items() {
1190-
for each name: @{key: ident, val: list<mod_index_entry>} in
1194+
for each name: @{key: identistr, val: list<mod_index_entry>} in
11911195
m.val.index.items() {
1192-
check_mod_name(*e, name.key, name.val);
1196+
check_mod_name(*e, istr::to_estr(name.key), name.val);
11931197
}
11941198
}
11951199
// Other scopes have to be checked the hard way.

src/comp/middle/trans.rs

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -355,31 +355,35 @@ fn decl_glue(llmod: ModuleRef, cx: &crate_ctxt, s: &str) -> ValueRef {
355355
ret decl_cdecl_fn(llmod, s, T_fn([T_taskptr(cx)], T_void()));
356356
}
357357

358-
fn get_extern_fn(externs: &hashmap<str, ValueRef>, llmod: ModuleRef,
358+
fn get_extern_fn(externs: &hashmap<istr, ValueRef>, llmod: ModuleRef,
359359
name: &str, cc: uint, ty: TypeRef) -> ValueRef {
360-
if externs.contains_key(name) { ret externs.get(name); }
360+
if externs.contains_key(istr::from_estr(name)) {
361+
ret externs.get(istr::from_estr(name));
362+
}
361363
let f = decl_fn(llmod, name, cc, ty);
362-
externs.insert(name, f);
364+
externs.insert(istr::from_estr(name), f);
363365
ret f;
364366
}
365367

366-
fn get_extern_const(externs: &hashmap<str, ValueRef>, llmod: ModuleRef,
368+
fn get_extern_const(externs: &hashmap<istr, ValueRef>, llmod: ModuleRef,
367369
name: &str, ty: TypeRef) -> ValueRef {
368-
if externs.contains_key(name) { ret externs.get(name); }
370+
if externs.contains_key(istr::from_estr(name)) {
371+
ret externs.get(istr::from_estr(name));
372+
}
369373
let c = llvm::LLVMAddGlobal(llmod, ty, str::buf(name));
370-
externs.insert(name, c);
374+
externs.insert(istr::from_estr(name), c);
371375
ret c;
372376
}
373377

374-
fn get_simple_extern_fn(externs: &hashmap<str, ValueRef>, llmod: ModuleRef,
378+
fn get_simple_extern_fn(externs: &hashmap<istr, ValueRef>, llmod: ModuleRef,
375379
name: &str, n_args: int) -> ValueRef {
376380
let inputs = std::vec::init_elt::<TypeRef>(T_int(), n_args as uint);
377381
let output = T_int();
378382
let t = T_fn(inputs, output);
379383
ret get_extern_fn(externs, llmod, name, lib::llvm::LLVMCCallConv, t);
380384
}
381385

382-
fn trans_native_call(cx: &@block_ctxt, externs: &hashmap<str, ValueRef>,
386+
fn trans_native_call(cx: &@block_ctxt, externs: &hashmap<istr, ValueRef>,
383387
llmod: ModuleRef, name: &str, args: &[ValueRef]) ->
384388
ValueRef {
385389
let n: int = std::vec::len::<ValueRef>(args) as int;
@@ -2287,8 +2291,8 @@ fn call_memmove(cx: &@block_ctxt, dst: ValueRef, src: ValueRef,
22872291
// LLVM complains -- not even a constant element of a tydesc works).
22882292

22892293
let i = bcx_ccx(cx).intrinsics;
2290-
assert (i.contains_key("llvm.memmove.p0i8.p0i8.i32"));
2291-
let memmove = i.get("llvm.memmove.p0i8.p0i8.i32");
2294+
assert (i.contains_key(~"llvm.memmove.p0i8.p0i8.i32"));
2295+
let memmove = i.get(~"llvm.memmove.p0i8.p0i8.i32");
22922296
let src_ptr = bld::PointerCast(cx, src, T_ptr(T_i8()));
22932297
let dst_ptr = bld::PointerCast(cx, dst, T_ptr(T_i8()));
22942298
let size = bld::IntCast(cx, n_bytes, T_i32());
@@ -2304,8 +2308,8 @@ fn call_bzero(cx: &@block_ctxt, dst: ValueRef, n_bytes: ValueRef,
23042308
// FIXME: switch to the 64-bit variant when on such a platform.
23052309

23062310
let i = bcx_ccx(cx).intrinsics;
2307-
assert (i.contains_key("llvm.memset.p0i8.i32"));
2308-
let memset = i.get("llvm.memset.p0i8.i32");
2311+
assert (i.contains_key(~"llvm.memset.p0i8.i32"));
2312+
let memset = i.get(~"llvm.memset.p0i8.i32");
23092313
let dst_ptr = bld::PointerCast(cx, dst, T_ptr(T_i8()));
23102314
let size = bld::IntCast(cx, n_bytes, T_i32());
23112315
let align =
@@ -4524,8 +4528,8 @@ fn trans_log(lvl: int, cx: &@block_ctxt, e: &@ast::expr) -> result {
45244528
let lcx = cx.fcx.lcx;
45254529
let modname = str::connect(lcx.module_path, "::");
45264530
let global;
4527-
if lcx.ccx.module_data.contains_key(modname) {
4528-
global = lcx.ccx.module_data.get(modname);
4531+
if lcx.ccx.module_data.contains_key(istr::from_estr(modname)) {
4532+
global = lcx.ccx.module_data.get(istr::from_estr(modname));
45294533
} else {
45304534
let s =
45314535
link::mangle_internal_name_by_path_and_seq(lcx.ccx,
@@ -4536,7 +4540,7 @@ fn trans_log(lvl: int, cx: &@block_ctxt, e: &@ast::expr) -> result {
45364540
llvm::LLVMSetInitializer(global, C_null(T_int()));
45374541
llvm::LLVMSetLinkage(global,
45384542
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
4539-
lcx.ccx.module_data.insert(modname, global);
4543+
lcx.ccx.module_data.insert(istr::from_estr(modname), global);
45404544
}
45414545
let log_cx = new_scope_block_ctxt(cx, "log");
45424546
let after_cx = new_sub_block_ctxt(cx, "after");
@@ -6168,7 +6172,7 @@ fn vi2p(cx: &@block_ctxt, v: ValueRef, t: TypeRef) -> ValueRef {
61686172

61696173
fn p2i(v: ValueRef) -> ValueRef { ret llvm::LLVMConstPtrToInt(v, T_int()); }
61706174

6171-
fn declare_intrinsics(llmod: ModuleRef) -> hashmap<str, ValueRef> {
6175+
fn declare_intrinsics(llmod: ModuleRef) -> hashmap<istr, ValueRef> {
61726176
let T_memmove32_args: [TypeRef] =
61736177
[T_ptr(T_i8()), T_ptr(T_i8()), T_i32(), T_i32(), T_i1()];
61746178
let T_memmove64_args: [TypeRef] =
@@ -6198,19 +6202,19 @@ fn declare_intrinsics(llmod: ModuleRef) -> hashmap<str, ValueRef> {
61986202
T_fn(T_memset64_args, T_void()));
61996203
let trap = decl_cdecl_fn(llmod, "llvm.trap", T_fn(T_trap_args, T_void()));
62006204
let intrinsics = new_str_hash::<ValueRef>();
6201-
intrinsics.insert("llvm.gcroot", gcroot);
6202-
intrinsics.insert("llvm.gcread", gcread);
6203-
intrinsics.insert("llvm.memmove.p0i8.p0i8.i32", memmove32);
6204-
intrinsics.insert("llvm.memmove.p0i8.p0i8.i64", memmove64);
6205-
intrinsics.insert("llvm.memset.p0i8.i32", memset32);
6206-
intrinsics.insert("llvm.memset.p0i8.i64", memset64);
6207-
intrinsics.insert("llvm.trap", trap);
6205+
intrinsics.insert(~"llvm.gcroot", gcroot);
6206+
intrinsics.insert(~"llvm.gcread", gcread);
6207+
intrinsics.insert(~"llvm.memmove.p0i8.p0i8.i32", memmove32);
6208+
intrinsics.insert(~"llvm.memmove.p0i8.p0i8.i64", memmove64);
6209+
intrinsics.insert(~"llvm.memset.p0i8.i32", memset32);
6210+
intrinsics.insert(~"llvm.memset.p0i8.i64", memset64);
6211+
intrinsics.insert(~"llvm.trap", trap);
62086212
ret intrinsics;
62096213
}
62106214

62116215
fn trap(bcx: &@block_ctxt) {
62126216
let v: [ValueRef] = [];
6213-
alt bcx_ccx(bcx).intrinsics.find("llvm.trap") {
6217+
alt bcx_ccx(bcx).intrinsics.find(~"llvm.trap") {
62146218
some(x) { bld::Call(bcx, x, v); }
62156219
_ { bcx_ccx(bcx).sess.bug("unbound llvm.trap in trap"); }
62166220
}
@@ -6264,8 +6268,9 @@ fn create_module_map(ccx: &@crate_ctxt) -> ValueRef {
62646268
llvm::LLVMSetLinkage(map,
62656269
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
62666270
let elts: [ValueRef] = [];
6267-
for each item: @{key: str, val: ValueRef} in ccx.module_data.items() {
6268-
let elt = C_struct([p2i(C_cstr(ccx, item.key)), p2i(item.val)]);
6271+
for each item: @{key: istr, val: ValueRef} in ccx.module_data.items() {
6272+
let elt = C_struct([p2i(C_cstr(ccx, istr::to_estr(item.key))),
6273+
p2i(item.val)]);
62696274
elts += [elt];
62706275
}
62716276
let term = C_struct([C_int(0), C_int(0)]);

src/comp/middle/trans_alt.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import std::str;
2+
import std::istr;
23
import std::vec;
34
import std::option;
45
import option::some;
@@ -303,7 +304,8 @@ fn compile_submatch(bcx: @block_ctxt, m: &match, vals: [ValueRef],
303304
// the actual arm block.
304305
for each @{key, val} in data.id_map.items() {
305306
bcx.fcx.lllocals.insert
306-
(val, option::get(assoc(key, m[0].bound)));
307+
(val, option::get(assoc(istr::to_estr(key),
308+
m[0].bound)));
307309
}
308310
let {bcx: guard_bcx, val: guard_val} =
309311
trans::trans_expr(guard_cx, e);
@@ -467,12 +469,12 @@ fn make_phi_bindings(bcx: &@block_ctxt, map: &[exit_node],
467469
ids: &ast_util::pat_id_map) -> bool {
468470
let our_block = bcx.llbb as uint;
469471
let success = true;
470-
for each item: @{key: ast::ident, val: ast::node_id} in ids.items() {
472+
for each item: @{key: ast::identistr, val: ast::node_id} in ids.items() {
471473
let llbbs = [];
472474
let vals = [];
473475
for ex: exit_node in map {
474476
if ex.to as uint == our_block {
475-
alt assoc(item.key, ex.bound) {
477+
alt assoc(istr::to_estr(item.key), ex.bound) {
476478
some(val) { llbbs += [ex.from]; vals += [val]; }
477479
none. { }
478480
}

src/comp/middle/trans_common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ type crate_ctxt =
127127
llmod: ModuleRef,
128128
td: target_data,
129129
tn: type_names,
130-
externs: hashmap<str, ValueRef>,
131-
intrinsics: hashmap<str, ValueRef>,
130+
externs: hashmap<istr, ValueRef>,
131+
intrinsics: hashmap<istr, ValueRef>,
132132
item_ids: hashmap<ast::node_id, ValueRef>,
133133
ast_map: ast_map::map,
134134
item_symbols: hashmap<ast::node_id, str>,
@@ -141,7 +141,7 @@ type crate_ctxt =
141141
consts: hashmap<ast::node_id, ValueRef>,
142142
obj_methods: hashmap<ast::node_id, ()>,
143143
tydescs: hashmap<ty::t, @tydesc_info>,
144-
module_data: hashmap<str, ValueRef>,
144+
module_data: hashmap<istr, ValueRef>,
145145
lltypes: hashmap<ty::t, TypeRef>,
146146
glues: @glue_fns,
147147
names: namegen,

src/comp/middle/typeck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat,
13221322
let vid = lookup_local(fcx, pat.span, pat.id);
13231323
let typ = ty::mk_var(fcx.ccx.tcx, vid);
13241324
typ = demand::simple(fcx, pat.span, expected, typ);
1325-
let canon_id = map.get(name);
1325+
let canon_id = map.get(istr::from_estr(name));
13261326
if canon_id != pat.id {
13271327
let ct =
13281328
ty::mk_var(fcx.ccx.tcx,

src/comp/syntax/ast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import codemap::filename;
88
type spanned<T> = {node: T, span: span};
99

1010
type ident = str;
11+
type identistr = istr;
12+
1113
// Functions may or may not have names.
1214
type fn_ident = option::t<ident>;
1315

0 commit comments

Comments
 (0)