Convert std::map::new_str_hash to istrs. Issue #855

This commit is contained in:
Brian Anderson 2011-08-25 15:12:54 -07:00
parent faef9490ae
commit 652332f9d4
17 changed files with 181 additions and 144 deletions

View file

@ -901,22 +901,26 @@ native "cdecl" mod llvm = "rustllvm" {
/* Memory-managed object interface to type handles. */ /* Memory-managed object interface to type handles. */
obj type_names(type_names: std::map::hashmap<TypeRef, str>, obj type_names(type_names: std::map::hashmap<TypeRef, str>,
named_types: std::map::hashmap<str, TypeRef>) { named_types: std::map::hashmap<istr, TypeRef>) {
fn associate(s: str, t: TypeRef) { fn associate(s: str, t: TypeRef) {
assert (!named_types.contains_key(s)); assert (!named_types.contains_key(istr::from_estr(s)));
assert (!type_names.contains_key(t)); assert (!type_names.contains_key(t));
type_names.insert(t, s); type_names.insert(t, s);
named_types.insert(s, t); named_types.insert(istr::from_estr(s), t);
} }
fn type_has_name(t: TypeRef) -> bool { ret type_names.contains_key(t); } fn type_has_name(t: TypeRef) -> bool { ret type_names.contains_key(t); }
fn get_name(t: TypeRef) -> str { ret type_names.get(t); } fn get_name(t: TypeRef) -> str { ret type_names.get(t); }
fn name_has_type(s: str) -> bool { ret named_types.contains_key(s); } fn name_has_type(s: str) -> bool {
ret named_types.contains_key(istr::from_estr(s));
}
fn get_type(s: str) -> TypeRef { ret named_types.get(s); } fn get_type(s: str) -> TypeRef {
ret named_types.get(istr::from_estr(s));
}
} }
fn mk_type_names() -> type_names { fn mk_type_names() -> type_names {

View file

@ -47,7 +47,7 @@ fn read_crates(sess: session::session, crate: &ast::crate) {
type env = type env =
@{sess: session::session, @{sess: session::session,
crate_cache: @hashmap<str, int>, crate_cache: @hashmap<istr, int>,
library_search_paths: [str], library_search_paths: [str],
mutable next_crate_num: ast::crate_num}; mutable next_crate_num: ast::crate_num};
@ -226,7 +226,7 @@ fn load_library_crate(sess: &session::session, span: span, ident: &ast::ident,
fn resolve_crate(e: env, ident: ast::ident, metas: [@ast::meta_item], fn resolve_crate(e: env, ident: ast::ident, metas: [@ast::meta_item],
span: span) -> ast::crate_num { span: span) -> ast::crate_num {
if !e.crate_cache.contains_key(ident) { if !e.crate_cache.contains_key(istr::from_estr(ident)) {
let cinfo = let cinfo =
load_library_crate(e.sess, span, ident, metas, load_library_crate(e.sess, span, ident, metas,
e.library_search_paths); e.library_search_paths);
@ -236,7 +236,7 @@ fn resolve_crate(e: env, ident: ast::ident, metas: [@ast::meta_item],
// Claim this crate number and cache it // Claim this crate number and cache it
let cnum = e.next_crate_num; let cnum = e.next_crate_num;
e.crate_cache.insert(ident, cnum); e.crate_cache.insert(istr::from_estr(ident), cnum);
e.next_crate_num += 1; e.next_crate_num += 1;
// Now resolve the crates referenced by this crate // Now resolve the crates referenced by this crate
@ -248,7 +248,7 @@ fn resolve_crate(e: env, ident: ast::ident, metas: [@ast::meta_item],
cstore::set_crate_data(cstore, cnum, cmeta); cstore::set_crate_data(cstore, cnum, cmeta);
cstore::add_used_crate_file(cstore, cfilename); cstore::add_used_crate_file(cstore, cfilename);
ret cnum; ret cnum;
} else { ret e.crate_cache.get(ident); } } else { ret e.crate_cache.get(istr::from_estr(ident)); }
} }
// Go through the crate metadata and load any crates that it references // 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 {
let extrn_cnum = dep.cnum; let extrn_cnum = dep.cnum;
let cname = dep.ident; let cname = dep.ident;
log #fmt["resolving dep %s", cname]; log #fmt["resolving dep %s", cname];
if e.crate_cache.contains_key(cname) { if e.crate_cache.contains_key(istr::from_estr(cname)) {
log "already have it"; log "already have it";
// We've already seen this crate // We've already seen this crate
let local_cnum = e.crate_cache.get(cname); let local_cnum = e.crate_cache.get(istr::from_estr(cname));
cnum_map.insert(extrn_cnum, local_cnum); cnum_map.insert(extrn_cnum, local_cnum);
} else { } else {
log "need to load it"; log "need to load it";

View file

@ -47,7 +47,7 @@ fn add_gc_root(cx: &@block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
bcx = td_r.result.bcx; bcx = td_r.result.bcx;
let lltydesc = td_r.result.val; let lltydesc = td_r.result.val;
let gcroot = bcx_ccx(bcx).intrinsics.get("llvm.gcroot"); let gcroot = bcx_ccx(bcx).intrinsics.get(~"llvm.gcroot");
let llvalptr = bld::PointerCast(bcx, llval, T_ptr(T_ptr(T_i8()))); let llvalptr = bld::PointerCast(bcx, llval, T_ptr(T_ptr(T_i8())));
alt td_r.kind { alt td_r.kind {

View file

@ -33,6 +33,7 @@ import std::option::is_none;
import std::option::some; import std::option::some;
import std::option::none; import std::option::none;
import std::str; import std::str;
import std::istr;
import syntax::print::pprust::*; import syntax::print::pprust::*;
export resolve_crate; export resolve_crate;
@ -101,7 +102,7 @@ tag mod_index_entry {
mie_tag_variant(/* tag item */@ast::item, /* variant index */uint); mie_tag_variant(/* tag item */@ast::item, /* variant index */uint);
} }
type mod_index = hashmap<ident, list<mod_index_entry>>; type mod_index = hashmap<identistr, list<mod_index_entry>>;
// A tuple of an imported def and the import stmt that brung it // A tuple of an imported def and the import stmt that brung it
type glob_imp_def = {def: def, item: @ast::view_item}; type glob_imp_def = {def: def, item: @ast::view_item};
@ -110,7 +111,7 @@ type indexed_mod =
{m: option::t<ast::_mod>, {m: option::t<ast::_mod>,
index: mod_index, index: mod_index,
mutable glob_imports: [glob_imp_def], mutable glob_imports: [glob_imp_def],
glob_imported_names: hashmap<str, import_state>}; glob_imported_names: hashmap<istr, import_state>};
/* native modules can't contain tags, and we don't store their ASTs because we /* 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,
ret none::<def>; // name is not visible ret none::<def>; // name is not visible
} }
alt info.index.find(id) { alt info.index.find(istr::from_estr(id)) {
none. { } none. { }
some(lst_) { some(lst_) {
let lst = lst_; let lst = lst_;
@ -1009,14 +1010,15 @@ fn lookup_glob_in_mod(e: &env, info: @indexed_mod, sp: &span, id: &ident,
// since we don't know what names we have in advance, // since we don't know what names we have in advance,
// absence takes the place of todo() // absence takes the place of todo()
if !info.glob_imported_names.contains_key(id) { if !info.glob_imported_names.contains_key(istr::from_estr(id)) {
info.glob_imported_names.insert(id, resolving(sp)); info.glob_imported_names.insert(istr::from_estr(id), resolving(sp));
let val = per_ns(e, info, sp, id, ns_value, dr); let val = per_ns(e, info, sp, id, ns_value, dr);
let typ = per_ns(e, info, sp, id, ns_type, dr); let typ = per_ns(e, info, sp, id, ns_type, dr);
let md = per_ns(e, info, sp, id, ns_module, dr); let md = per_ns(e, info, sp, id, ns_module, dr);
info.glob_imported_names.insert(id, resolved(val, typ, md)); info.glob_imported_names.insert(istr::from_estr(id),
resolved(val, typ, md));
} }
alt info.glob_imported_names.get(id) { alt info.glob_imported_names.get(istr::from_estr(id)) {
todo(_, _, _, _, _) { e.sess.bug("Shouldn't've put a todo in."); } todo(_, _, _, _, _) { e.sess.bug("Shouldn't've put a todo in."); }
resolving(sp) { resolving(sp) {
ret none::<def>; //circularity is okay in import globs 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) ->
// Module indexing // Module indexing
fn add_to_index(index: &hashmap<ident, list<mod_index_entry>>, id: &ident, fn add_to_index(index: &hashmap<identistr, list<mod_index_entry>>,
ent: &mod_index_entry) { id: &ident, ent: &mod_index_entry) {
let id = istr::from_estr(id);
alt index.find(id) { alt index.find(id) {
none. { index.insert(id, cons(ent, @nil::<mod_index_entry>)); } none. { index.insert(id,
cons(ent, @nil::<mod_index_entry>)); }
some(prev) { index.insert(id, cons(ent, @prev)); } some(prev) { index.insert(id, cons(ent, @prev)); }
} }
} }
@ -1187,9 +1191,9 @@ fn check_for_collisions(e: &@env, c: &ast::crate) {
// Module indices make checking those relatively simple -- just check each // Module indices make checking those relatively simple -- just check each
// name for multiple entities in the same namespace. // name for multiple entities in the same namespace.
for each m: @{key: ast::node_id, val: @indexed_mod} in e.mod_map.items() { for each m: @{key: ast::node_id, val: @indexed_mod} in e.mod_map.items() {
for each name: @{key: ident, val: list<mod_index_entry>} in for each name: @{key: identistr, val: list<mod_index_entry>} in
m.val.index.items() { m.val.index.items() {
check_mod_name(*e, name.key, name.val); check_mod_name(*e, istr::to_estr(name.key), name.val);
} }
} }
// Other scopes have to be checked the hard way. // Other scopes have to be checked the hard way.

View file

@ -355,23 +355,27 @@ fn decl_glue(llmod: ModuleRef, cx: &crate_ctxt, s: &str) -> ValueRef {
ret decl_cdecl_fn(llmod, s, T_fn([T_taskptr(cx)], T_void())); ret decl_cdecl_fn(llmod, s, T_fn([T_taskptr(cx)], T_void()));
} }
fn get_extern_fn(externs: &hashmap<str, ValueRef>, llmod: ModuleRef, fn get_extern_fn(externs: &hashmap<istr, ValueRef>, llmod: ModuleRef,
name: &str, cc: uint, ty: TypeRef) -> ValueRef { name: &str, cc: uint, ty: TypeRef) -> ValueRef {
if externs.contains_key(name) { ret externs.get(name); } if externs.contains_key(istr::from_estr(name)) {
ret externs.get(istr::from_estr(name));
}
let f = decl_fn(llmod, name, cc, ty); let f = decl_fn(llmod, name, cc, ty);
externs.insert(name, f); externs.insert(istr::from_estr(name), f);
ret f; ret f;
} }
fn get_extern_const(externs: &hashmap<str, ValueRef>, llmod: ModuleRef, fn get_extern_const(externs: &hashmap<istr, ValueRef>, llmod: ModuleRef,
name: &str, ty: TypeRef) -> ValueRef { name: &str, ty: TypeRef) -> ValueRef {
if externs.contains_key(name) { ret externs.get(name); } if externs.contains_key(istr::from_estr(name)) {
ret externs.get(istr::from_estr(name));
}
let c = llvm::LLVMAddGlobal(llmod, ty, str::buf(name)); let c = llvm::LLVMAddGlobal(llmod, ty, str::buf(name));
externs.insert(name, c); externs.insert(istr::from_estr(name), c);
ret c; ret c;
} }
fn get_simple_extern_fn(externs: &hashmap<str, ValueRef>, llmod: ModuleRef, fn get_simple_extern_fn(externs: &hashmap<istr, ValueRef>, llmod: ModuleRef,
name: &str, n_args: int) -> ValueRef { name: &str, n_args: int) -> ValueRef {
let inputs = std::vec::init_elt::<TypeRef>(T_int(), n_args as uint); let inputs = std::vec::init_elt::<TypeRef>(T_int(), n_args as uint);
let output = T_int(); let output = T_int();
@ -379,7 +383,7 @@ fn get_simple_extern_fn(externs: &hashmap<str, ValueRef>, llmod: ModuleRef,
ret get_extern_fn(externs, llmod, name, lib::llvm::LLVMCCallConv, t); ret get_extern_fn(externs, llmod, name, lib::llvm::LLVMCCallConv, t);
} }
fn trans_native_call(cx: &@block_ctxt, externs: &hashmap<str, ValueRef>, fn trans_native_call(cx: &@block_ctxt, externs: &hashmap<istr, ValueRef>,
llmod: ModuleRef, name: &str, args: &[ValueRef]) -> llmod: ModuleRef, name: &str, args: &[ValueRef]) ->
ValueRef { ValueRef {
let n: int = std::vec::len::<ValueRef>(args) as int; let n: int = std::vec::len::<ValueRef>(args) as int;
@ -2287,8 +2291,8 @@ fn call_memmove(cx: &@block_ctxt, dst: ValueRef, src: ValueRef,
// LLVM complains -- not even a constant element of a tydesc works). // LLVM complains -- not even a constant element of a tydesc works).
let i = bcx_ccx(cx).intrinsics; let i = bcx_ccx(cx).intrinsics;
assert (i.contains_key("llvm.memmove.p0i8.p0i8.i32")); assert (i.contains_key(~"llvm.memmove.p0i8.p0i8.i32"));
let memmove = i.get("llvm.memmove.p0i8.p0i8.i32"); let memmove = i.get(~"llvm.memmove.p0i8.p0i8.i32");
let src_ptr = bld::PointerCast(cx, src, T_ptr(T_i8())); let src_ptr = bld::PointerCast(cx, src, T_ptr(T_i8()));
let dst_ptr = bld::PointerCast(cx, dst, T_ptr(T_i8())); let dst_ptr = bld::PointerCast(cx, dst, T_ptr(T_i8()));
let size = bld::IntCast(cx, n_bytes, T_i32()); let size = bld::IntCast(cx, n_bytes, T_i32());
@ -2304,8 +2308,8 @@ fn call_bzero(cx: &@block_ctxt, dst: ValueRef, n_bytes: ValueRef,
// FIXME: switch to the 64-bit variant when on such a platform. // FIXME: switch to the 64-bit variant when on such a platform.
let i = bcx_ccx(cx).intrinsics; let i = bcx_ccx(cx).intrinsics;
assert (i.contains_key("llvm.memset.p0i8.i32")); assert (i.contains_key(~"llvm.memset.p0i8.i32"));
let memset = i.get("llvm.memset.p0i8.i32"); let memset = i.get(~"llvm.memset.p0i8.i32");
let dst_ptr = bld::PointerCast(cx, dst, T_ptr(T_i8())); let dst_ptr = bld::PointerCast(cx, dst, T_ptr(T_i8()));
let size = bld::IntCast(cx, n_bytes, T_i32()); let size = bld::IntCast(cx, n_bytes, T_i32());
let align = let align =
@ -4524,8 +4528,8 @@ fn trans_log(lvl: int, cx: &@block_ctxt, e: &@ast::expr) -> result {
let lcx = cx.fcx.lcx; let lcx = cx.fcx.lcx;
let modname = str::connect(lcx.module_path, "::"); let modname = str::connect(lcx.module_path, "::");
let global; let global;
if lcx.ccx.module_data.contains_key(modname) { if lcx.ccx.module_data.contains_key(istr::from_estr(modname)) {
global = lcx.ccx.module_data.get(modname); global = lcx.ccx.module_data.get(istr::from_estr(modname));
} else { } else {
let s = let s =
link::mangle_internal_name_by_path_and_seq(lcx.ccx, 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 {
llvm::LLVMSetInitializer(global, C_null(T_int())); llvm::LLVMSetInitializer(global, C_null(T_int()));
llvm::LLVMSetLinkage(global, llvm::LLVMSetLinkage(global,
lib::llvm::LLVMInternalLinkage as llvm::Linkage); lib::llvm::LLVMInternalLinkage as llvm::Linkage);
lcx.ccx.module_data.insert(modname, global); lcx.ccx.module_data.insert(istr::from_estr(modname), global);
} }
let log_cx = new_scope_block_ctxt(cx, "log"); let log_cx = new_scope_block_ctxt(cx, "log");
let after_cx = new_sub_block_ctxt(cx, "after"); let after_cx = new_sub_block_ctxt(cx, "after");
@ -6168,7 +6172,7 @@ fn vi2p(cx: &@block_ctxt, v: ValueRef, t: TypeRef) -> ValueRef {
fn p2i(v: ValueRef) -> ValueRef { ret llvm::LLVMConstPtrToInt(v, T_int()); } fn p2i(v: ValueRef) -> ValueRef { ret llvm::LLVMConstPtrToInt(v, T_int()); }
fn declare_intrinsics(llmod: ModuleRef) -> hashmap<str, ValueRef> { fn declare_intrinsics(llmod: ModuleRef) -> hashmap<istr, ValueRef> {
let T_memmove32_args: [TypeRef] = let T_memmove32_args: [TypeRef] =
[T_ptr(T_i8()), T_ptr(T_i8()), T_i32(), T_i32(), T_i1()]; [T_ptr(T_i8()), T_ptr(T_i8()), T_i32(), T_i32(), T_i1()];
let T_memmove64_args: [TypeRef] = let T_memmove64_args: [TypeRef] =
@ -6198,19 +6202,19 @@ fn declare_intrinsics(llmod: ModuleRef) -> hashmap<str, ValueRef> {
T_fn(T_memset64_args, T_void())); T_fn(T_memset64_args, T_void()));
let trap = decl_cdecl_fn(llmod, "llvm.trap", T_fn(T_trap_args, T_void())); let trap = decl_cdecl_fn(llmod, "llvm.trap", T_fn(T_trap_args, T_void()));
let intrinsics = new_str_hash::<ValueRef>(); let intrinsics = new_str_hash::<ValueRef>();
intrinsics.insert("llvm.gcroot", gcroot); intrinsics.insert(~"llvm.gcroot", gcroot);
intrinsics.insert("llvm.gcread", gcread); intrinsics.insert(~"llvm.gcread", gcread);
intrinsics.insert("llvm.memmove.p0i8.p0i8.i32", memmove32); intrinsics.insert(~"llvm.memmove.p0i8.p0i8.i32", memmove32);
intrinsics.insert("llvm.memmove.p0i8.p0i8.i64", memmove64); intrinsics.insert(~"llvm.memmove.p0i8.p0i8.i64", memmove64);
intrinsics.insert("llvm.memset.p0i8.i32", memset32); intrinsics.insert(~"llvm.memset.p0i8.i32", memset32);
intrinsics.insert("llvm.memset.p0i8.i64", memset64); intrinsics.insert(~"llvm.memset.p0i8.i64", memset64);
intrinsics.insert("llvm.trap", trap); intrinsics.insert(~"llvm.trap", trap);
ret intrinsics; ret intrinsics;
} }
fn trap(bcx: &@block_ctxt) { fn trap(bcx: &@block_ctxt) {
let v: [ValueRef] = []; let v: [ValueRef] = [];
alt bcx_ccx(bcx).intrinsics.find("llvm.trap") { alt bcx_ccx(bcx).intrinsics.find(~"llvm.trap") {
some(x) { bld::Call(bcx, x, v); } some(x) { bld::Call(bcx, x, v); }
_ { bcx_ccx(bcx).sess.bug("unbound llvm.trap in trap"); } _ { bcx_ccx(bcx).sess.bug("unbound llvm.trap in trap"); }
} }
@ -6264,8 +6268,9 @@ fn create_module_map(ccx: &@crate_ctxt) -> ValueRef {
llvm::LLVMSetLinkage(map, llvm::LLVMSetLinkage(map,
lib::llvm::LLVMInternalLinkage as llvm::Linkage); lib::llvm::LLVMInternalLinkage as llvm::Linkage);
let elts: [ValueRef] = []; let elts: [ValueRef] = [];
for each item: @{key: str, val: ValueRef} in ccx.module_data.items() { for each item: @{key: istr, val: ValueRef} in ccx.module_data.items() {
let elt = C_struct([p2i(C_cstr(ccx, item.key)), p2i(item.val)]); let elt = C_struct([p2i(C_cstr(ccx, istr::to_estr(item.key))),
p2i(item.val)]);
elts += [elt]; elts += [elt];
} }
let term = C_struct([C_int(0), C_int(0)]); let term = C_struct([C_int(0), C_int(0)]);

View file

@ -1,4 +1,5 @@
import std::str; import std::str;
import std::istr;
import std::vec; import std::vec;
import std::option; import std::option;
import option::some; import option::some;
@ -303,7 +304,8 @@ fn compile_submatch(bcx: @block_ctxt, m: &match, vals: [ValueRef],
// the actual arm block. // the actual arm block.
for each @{key, val} in data.id_map.items() { for each @{key, val} in data.id_map.items() {
bcx.fcx.lllocals.insert bcx.fcx.lllocals.insert
(val, option::get(assoc(key, m[0].bound))); (val, option::get(assoc(istr::to_estr(key),
m[0].bound)));
} }
let {bcx: guard_bcx, val: guard_val} = let {bcx: guard_bcx, val: guard_val} =
trans::trans_expr(guard_cx, e); trans::trans_expr(guard_cx, e);
@ -467,12 +469,12 @@ fn make_phi_bindings(bcx: &@block_ctxt, map: &[exit_node],
ids: &ast_util::pat_id_map) -> bool { ids: &ast_util::pat_id_map) -> bool {
let our_block = bcx.llbb as uint; let our_block = bcx.llbb as uint;
let success = true; let success = true;
for each item: @{key: ast::ident, val: ast::node_id} in ids.items() { for each item: @{key: ast::identistr, val: ast::node_id} in ids.items() {
let llbbs = []; let llbbs = [];
let vals = []; let vals = [];
for ex: exit_node in map { for ex: exit_node in map {
if ex.to as uint == our_block { if ex.to as uint == our_block {
alt assoc(item.key, ex.bound) { alt assoc(istr::to_estr(item.key), ex.bound) {
some(val) { llbbs += [ex.from]; vals += [val]; } some(val) { llbbs += [ex.from]; vals += [val]; }
none. { } none. { }
} }

View file

@ -127,8 +127,8 @@ type crate_ctxt =
llmod: ModuleRef, llmod: ModuleRef,
td: target_data, td: target_data,
tn: type_names, tn: type_names,
externs: hashmap<str, ValueRef>, externs: hashmap<istr, ValueRef>,
intrinsics: hashmap<str, ValueRef>, intrinsics: hashmap<istr, ValueRef>,
item_ids: hashmap<ast::node_id, ValueRef>, item_ids: hashmap<ast::node_id, ValueRef>,
ast_map: ast_map::map, ast_map: ast_map::map,
item_symbols: hashmap<ast::node_id, str>, item_symbols: hashmap<ast::node_id, str>,
@ -141,7 +141,7 @@ type crate_ctxt =
consts: hashmap<ast::node_id, ValueRef>, consts: hashmap<ast::node_id, ValueRef>,
obj_methods: hashmap<ast::node_id, ()>, obj_methods: hashmap<ast::node_id, ()>,
tydescs: hashmap<ty::t, @tydesc_info>, tydescs: hashmap<ty::t, @tydesc_info>,
module_data: hashmap<str, ValueRef>, module_data: hashmap<istr, ValueRef>,
lltypes: hashmap<ty::t, TypeRef>, lltypes: hashmap<ty::t, TypeRef>,
glues: @glue_fns, glues: @glue_fns,
names: namegen, names: namegen,

View file

@ -1322,7 +1322,7 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat,
let vid = lookup_local(fcx, pat.span, pat.id); let vid = lookup_local(fcx, pat.span, pat.id);
let typ = ty::mk_var(fcx.ccx.tcx, vid); let typ = ty::mk_var(fcx.ccx.tcx, vid);
typ = demand::simple(fcx, pat.span, expected, typ); typ = demand::simple(fcx, pat.span, expected, typ);
let canon_id = map.get(name); let canon_id = map.get(istr::from_estr(name));
if canon_id != pat.id { if canon_id != pat.id {
let ct = let ct =
ty::mk_var(fcx.ccx.tcx, ty::mk_var(fcx.ccx.tcx,

View file

@ -8,6 +8,8 @@ import codemap::filename;
type spanned<T> = {node: T, span: span}; type spanned<T> = {node: T, span: span};
type ident = str; type ident = str;
type identistr = istr;
// Functions may or may not have names. // Functions may or may not have names.
type fn_ident = option::t<ident>; type fn_ident = option::t<ident>;

View file

@ -1,4 +1,5 @@
import std::str; import std::str;
import std::istr;
import std::option; import std::option;
import codemap::span; import codemap::span;
import ast::*; import ast::*;
@ -43,7 +44,7 @@ fn def_id_of_def(d: def) -> def_id {
} }
} }
type pat_id_map = std::map::hashmap<str, ast::node_id>; type pat_id_map = std::map::hashmap<istr, ast::node_id>;
// This is used because same-named variables in alternative patterns need to // This is used because same-named variables in alternative patterns need to
// use the node_id of their namesake in the first pattern. // use the node_id of their namesake in the first pattern.
@ -51,7 +52,7 @@ fn pat_id_map(pat: &@pat) -> pat_id_map {
let map = std::map::new_str_hash::<node_id>(); let map = std::map::new_str_hash::<node_id>();
for each bound in pat_bindings(pat) { for each bound in pat_bindings(pat) {
let name = alt bound.node { pat_bind(n) { n } }; let name = alt bound.node { pat_bind(n) { n } };
map.insert(name, bound.id); map.insert(istr::from_estr(name), bound.id);
} }
ret map; ret map;
} }

View file

@ -1,3 +1,4 @@
import std::istr;
import std::vec; import std::vec;
import std::option; import std::option;
import std::map::hashmap; import std::map::hashmap;
@ -19,17 +20,17 @@ tag syntax_extension {
// A temporary hard-coded map of methods for expanding syntax extension // A temporary hard-coded map of methods for expanding syntax extension
// AST nodes into full ASTs // AST nodes into full ASTs
fn syntax_expander_table() -> hashmap<str, syntax_extension> { fn syntax_expander_table() -> hashmap<istr, syntax_extension> {
let syntax_expanders = new_str_hash::<syntax_extension>(); let syntax_expanders = new_str_hash::<syntax_extension>();
syntax_expanders.insert("fmt", normal(ext::fmt::expand_syntax_ext)); syntax_expanders.insert(~"fmt", normal(ext::fmt::expand_syntax_ext));
syntax_expanders.insert("env", normal(ext::env::expand_syntax_ext)); syntax_expanders.insert(~"env", normal(ext::env::expand_syntax_ext));
syntax_expanders.insert("macro", syntax_expanders.insert(~"macro",
macro_defining(ext::simplext::add_new_extension)); macro_defining(ext::simplext::add_new_extension));
syntax_expanders.insert("concat_idents", syntax_expanders.insert(~"concat_idents",
normal(ext::concat_idents::expand_syntax_ext)); normal(ext::concat_idents::expand_syntax_ext));
syntax_expanders.insert("ident_to_str", syntax_expanders.insert(~"ident_to_str",
normal(ext::ident_to_str::expand_syntax_ext)); normal(ext::ident_to_str::expand_syntax_ext));
syntax_expanders.insert("log_syntax", syntax_expanders.insert(~"log_syntax",
normal(ext::log_syntax::expand_syntax_ext)); normal(ext::log_syntax::expand_syntax_ext));
ret syntax_expanders; ret syntax_expanders;
} }

View file

@ -5,6 +5,7 @@ import std::option::some;
import std::map::hashmap; import std::map::hashmap;
import std::vec; import std::vec;
import std::istr;
import syntax::ast::crate; import syntax::ast::crate;
import syntax::ast::expr_; import syntax::ast::expr_;
@ -14,7 +15,7 @@ import syntax::fold::*;
import syntax::ext::base::*; import syntax::ext::base::*;
fn expand_expr(exts: &hashmap<str, syntax_extension>, cx: &ext_ctxt, fn expand_expr(exts: &hashmap<istr, syntax_extension>, cx: &ext_ctxt,
e: &expr_, fld: ast_fold, orig: &fn(&expr_, ast_fold) -> expr_) e: &expr_, fld: ast_fold, orig: &fn(&expr_, ast_fold) -> expr_)
-> expr_ { -> expr_ {
ret alt e { ret alt e {
@ -23,7 +24,7 @@ fn expand_expr(exts: &hashmap<str, syntax_extension>, cx: &ext_ctxt,
mac_invoc(pth, args, body) { mac_invoc(pth, args, body) {
assert (vec::len(pth.node.idents) > 0u); assert (vec::len(pth.node.idents) > 0u);
let extname = pth.node.idents[0]; let extname = pth.node.idents[0];
alt exts.find(extname) { alt exts.find(istr::from_estr(extname)) {
none. { none. {
cx.span_fatal(pth.span, cx.span_fatal(pth.span,
#fmt["macro undefined: '%s'", extname]) #fmt["macro undefined: '%s'", extname])
@ -40,7 +41,9 @@ fn expand_expr(exts: &hashmap<str, syntax_extension>, cx: &ext_ctxt,
} }
some(macro_defining(ext)) { some(macro_defining(ext)) {
let named_extension = ext(cx, pth.span, args, body); let named_extension = ext(cx, pth.span, args, body);
exts.insert(named_extension.ident, named_extension.ext); exts.insert(
istr::from_estr(named_extension.ident),
named_extension.ext);
ast::expr_rec([], none) ast::expr_rec([], none)
} }
} }

View file

@ -2,6 +2,7 @@ use std;
import codemap::span; import codemap::span;
import std::vec; import std::vec;
import std::istr;
import std::option; import std::option;
import std::map::hashmap; import std::map::hashmap;
import std::map::new_str_hash; import std::map::new_str_hash;
@ -18,6 +19,7 @@ import fold::*;
import ast::node_id; import ast::node_id;
import ast_util::respan; import ast_util::respan;
import ast::ident; import ast::ident;
import ast::identistr;
import ast::path; import ast::path;
import ast::ty; import ast::ty;
import ast::blk; import ast::blk;
@ -155,9 +157,9 @@ fn compose_sels(s1: selector, s2: selector) -> selector {
type binders = type binders =
{real_binders: hashmap<ident, selector>, {real_binders: hashmap<identistr, selector>,
mutable literal_ast_matchers: [selector]}; mutable literal_ast_matchers: [selector]};
type bindings = hashmap<ident, arb_depth<matchable>>; type bindings = hashmap<identistr, arb_depth<matchable>>;
fn acumm_bindings(_cx: &ext_ctxt, _b_dest: &bindings, _b_src: &bindings) { } fn acumm_bindings(_cx: &ext_ctxt, _b_dest: &bindings, _b_src: &bindings) { }
@ -189,7 +191,8 @@ fn use_selectors_to_bind(b: &binders, e: @expr) -> option::t<bindings> {
alt sel(match_expr(e)) { none. { ret none; } _ { } } alt sel(match_expr(e)) { none. { ret none; } _ { } }
} }
let never_mind: bool = false; let never_mind: bool = false;
for each pair: @{key: ident, val: selector} in b.real_binders.items() { for each pair: @{key: identistr,
val: selector} in b.real_binders.items() {
alt pair.val(match_expr(e)) { alt pair.val(match_expr(e)) {
none. { never_mind = true; } none. { never_mind = true; }
some(mtc) { res.insert(pair.key, mtc); } some(mtc) { res.insert(pair.key, mtc); }
@ -262,10 +265,12 @@ fn follow_for_trans(cx: &ext_ctxt, mmaybe: &option::t<arb_depth<matchable>>,
/* helper for transcribe_exprs: what vars from `b` occur in `e`? */ /* helper for transcribe_exprs: what vars from `b` occur in `e`? */
iter free_vars(b: &bindings, e: @expr) -> ident { iter free_vars(b: &bindings, e: @expr) -> ident {
let idents: hashmap<ident, ()> = new_str_hash::<()>(); let idents: hashmap<identistr, ()> = new_str_hash::<()>();
fn mark_ident(i: &ident, _fld: ast_fold, b: &bindings, fn mark_ident(i: &ident, _fld: ast_fold, b: &bindings,
idents: &hashmap<ident, ()>) -> ident { idents: &hashmap<identistr, ()>) -> ident {
if b.contains_key(i) { idents.insert(i, ()); } if b.contains_key(istr::from_estr(i)) {
idents.insert(istr::from_estr(i), ());
}
ret i; ret i;
} }
// using fold is a hack: we want visit, but it doesn't hit idents ) : // using fold is a hack: we want visit, but it doesn't hit idents ) :
@ -276,7 +281,7 @@ iter free_vars(b: &bindings, e: @expr) -> ident {
let f = make_fold(f_pre); let f = make_fold(f_pre);
f.fold_expr(e); // ignore result f.fold_expr(e); // ignore result
dummy_out(f); dummy_out(f);
for each id: ident in idents.keys() { put id; } for each id: identistr in idents.keys() { put istr::to_estr(id); }
} }
@ -293,7 +298,7 @@ fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
/* we need to walk over all the free vars in lockstep, except for /* we need to walk over all the free vars in lockstep, except for
the leaves, which are just duplicated */ the leaves, which are just duplicated */
for each fv: ident in free_vars(b, repeat_me) { for each fv: ident in free_vars(b, repeat_me) {
let cur_pos = follow(b.get(fv), idx_path); let cur_pos = follow(b.get(istr::from_estr(fv)), idx_path);
alt cur_pos { alt cur_pos {
leaf(_) { } leaf(_) { }
seq(ms, _) { seq(ms, _) {
@ -345,7 +350,7 @@ fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
// substitute, in a position that's required to be an ident // substitute, in a position that's required to be an ident
fn transcribe_ident(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], fn transcribe_ident(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
i: &ident, _fld: ast_fold) -> ident { i: &ident, _fld: ast_fold) -> ident {
ret alt follow_for_trans(cx, b.find(i), idx_path) { ret alt follow_for_trans(cx, b.find(istr::from_estr(i)), idx_path) {
some(match_ident(a_id)) { a_id.node } some(match_ident(a_id)) { a_id.node }
some(m) { match_error(cx, m, "an identifier") } some(m) { match_error(cx, m, "an identifier") }
none. { i } none. { i }
@ -357,7 +362,8 @@ fn transcribe_path(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
p: &path_, _fld: ast_fold) -> path_ { p: &path_, _fld: ast_fold) -> path_ {
// Don't substitute into qualified names. // Don't substitute into qualified names.
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { ret p; } if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { ret p; }
ret alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) { ret alt follow_for_trans(cx, b.find(
istr::from_estr(p.idents[0])), idx_path) {
some(match_ident(id)) { some(match_ident(id)) {
{global: false, idents: [id.node], types: []} {global: false, idents: [id.node], types: []}
} }
@ -378,7 +384,8 @@ fn transcribe_expr(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
if vec::len(p.node.types) > 0u || vec::len(p.node.idents) != 1u { if vec::len(p.node.types) > 0u || vec::len(p.node.idents) != 1u {
e e
} }
alt follow_for_trans(cx, b.find(p.node.idents[0]), idx_path) { alt follow_for_trans(cx, b.find(
istr::from_estr(p.node.idents[0])), idx_path) {
some(match_ident(id)) { some(match_ident(id)) {
expr_path(respan(id.span, expr_path(respan(id.span,
{global: false, {global: false,
@ -402,7 +409,8 @@ fn transcribe_type(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
ast::ty_path(pth, _) { ast::ty_path(pth, _) {
alt path_to_ident(pth) { alt path_to_ident(pth) {
some(id) { some(id) {
alt follow_for_trans(cx, b.find(id), idx_path) { alt follow_for_trans(cx, b.find(
istr::from_estr(id)), idx_path) {
some(match_ty(ty)) { ty.node } some(match_ty(ty)) { ty.node }
some(m) { match_error(cx, m, "a type") } some(m) { match_error(cx, m, "a type") }
none. { orig(t, fld) } none. { orig(t, fld) }
@ -424,7 +432,8 @@ fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint],
orig: fn(&blk_, ast_fold) -> blk_) -> blk_ { orig: fn(&blk_, ast_fold) -> blk_) -> blk_ {
ret alt block_to_ident(blk) { ret alt block_to_ident(blk) {
some(id) { some(id) {
alt follow_for_trans(cx, b.find(id), idx_path) { alt follow_for_trans(cx, b.find(
istr::from_estr(id)), idx_path) {
some(match_block(new_blk)) { new_blk.node } some(match_block(new_blk)) { new_blk.node }
@ -525,10 +534,11 @@ fn p_t_s_r_path(cx: &ext_ctxt, p: &path, s: &selector, b: &binders) {
_ { cx.bug("broken traversal in p_t_s_r") } _ { cx.bug("broken traversal in p_t_s_r") }
} }
} }
if b.real_binders.contains_key(p_id) { if b.real_binders.contains_key(istr::from_estr(p_id)) {
cx.span_fatal(p.span, "duplicate binding identifier"); cx.span_fatal(p.span, "duplicate binding identifier");
} }
b.real_binders.insert(p_id, compose_sels(s, bind select(cx, _))); b.real_binders.insert(istr::from_estr(p_id),
compose_sels(s, bind select(cx, _)));
} }
none. { } none. { }
} }
@ -573,7 +583,8 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) {
} }
} }
let final_step = bind select_pt_1(cx, _, select_pt_2); let final_step = bind select_pt_1(cx, _, select_pt_2);
b.real_binders.insert(id, compose_sels(s, final_step)); b.real_binders.insert(
istr::from_estr(id), compose_sels(s, final_step));
} }
none. { no_des(cx, pth.span, "under `#<>`"); } none. { no_des(cx, pth.span, "under `#<>`"); }
} }
@ -593,7 +604,8 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) {
} }
} }
let final_step = bind select_pt_1(cx, _, select_pt_2); let final_step = bind select_pt_1(cx, _, select_pt_2);
b.real_binders.insert(id, compose_sels(s, final_step)); b.real_binders.insert(istr::from_estr(id),
compose_sels(s, final_step));
} }
none. { no_des(cx, blk.span, "under `#{}`"); } none. { no_des(cx, blk.span, "under `#{}`"); }
} }

View file

@ -53,7 +53,7 @@ type parser =
fn get_str(token::str_num) -> str; fn get_str(token::str_num) -> str;
fn get_reader() -> lexer::reader; fn get_reader() -> lexer::reader;
fn get_filemap() -> codemap::filemap; fn get_filemap() -> codemap::filemap;
fn get_bad_expr_words() -> hashmap<str, ()>; fn get_bad_expr_words() -> hashmap<istr, ()>;
fn get_chpos() -> uint; fn get_chpos() -> uint;
fn get_byte_pos() -> uint; fn get_byte_pos() -> uint;
fn get_id() -> node_id; fn get_id() -> node_id;
@ -84,7 +84,7 @@ fn new_parser(sess: parse_sess, cfg: ast::crate_cfg, rdr: lexer::reader,
mutable restr: restriction, mutable restr: restriction,
rdr: lexer::reader, rdr: lexer::reader,
precs: @[op_spec], precs: @[op_spec],
bad_words: hashmap<str, ()>) { bad_words: hashmap<istr, ()>) {
fn peek() -> token::token { ret tok; } fn peek() -> token::token { ret tok; }
fn bump() { fn bump() {
last_tok_span = tok_span; last_tok_span = tok_span;
@ -132,7 +132,7 @@ fn new_parser(sess: parse_sess, cfg: ast::crate_cfg, rdr: lexer::reader,
} }
fn get_reader() -> lexer::reader { ret rdr; } fn get_reader() -> lexer::reader { ret rdr; }
fn get_filemap() -> codemap::filemap { ret rdr.get_filemap(); } fn get_filemap() -> codemap::filemap { ret rdr.get_filemap(); }
fn get_bad_expr_words() -> hashmap<str, ()> { ret bad_words; } fn get_bad_expr_words() -> hashmap<istr, ()> { ret bad_words; }
fn get_chpos() -> uint { ret rdr.get_chpos(); } fn get_chpos() -> uint { ret rdr.get_chpos(); }
fn get_byte_pos() -> uint { ret rdr.get_byte_pos(); } fn get_byte_pos() -> uint { ret rdr.get_byte_pos(); }
fn get_id() -> node_id { ret next_node_id(sess); } fn get_id() -> node_id { ret next_node_id(sess); }
@ -148,44 +148,44 @@ fn new_parser(sess: parse_sess, cfg: ast::crate_cfg, rdr: lexer::reader,
// These are the words that shouldn't be allowed as value identifiers, // These are the words that shouldn't be allowed as value identifiers,
// because, if used at the start of a line, they will cause the line to be // because, if used at the start of a line, they will cause the line to be
// interpreted as a specific kind of statement, which would be confusing. // interpreted as a specific kind of statement, which would be confusing.
fn bad_expr_word_table() -> hashmap<str, ()> { fn bad_expr_word_table() -> hashmap<istr, ()> {
let words = new_str_hash(); let words = new_str_hash();
words.insert("mod", ()); words.insert(~"mod", ());
words.insert("if", ()); words.insert(~"if", ());
words.insert("else", ()); words.insert(~"else", ());
words.insert("while", ()); words.insert(~"while", ());
words.insert("do", ()); words.insert(~"do", ());
words.insert("alt", ()); words.insert(~"alt", ());
words.insert("for", ()); words.insert(~"for", ());
words.insert("each", ()); words.insert(~"each", ());
words.insert("break", ()); words.insert(~"break", ());
words.insert("cont", ()); words.insert(~"cont", ());
words.insert("put", ()); words.insert(~"put", ());
words.insert("ret", ()); words.insert(~"ret", ());
words.insert("be", ()); words.insert(~"be", ());
words.insert("fail", ()); words.insert(~"fail", ());
words.insert("type", ()); words.insert(~"type", ());
words.insert("resource", ()); words.insert(~"resource", ());
words.insert("check", ()); words.insert(~"check", ());
words.insert("assert", ()); words.insert(~"assert", ());
words.insert("claim", ()); words.insert(~"claim", ());
words.insert("prove", ()); words.insert(~"prove", ());
words.insert("native", ()); words.insert(~"native", ());
words.insert("fn", ()); words.insert(~"fn", ());
words.insert("block", ()); words.insert(~"block", ());
words.insert("lambda", ()); words.insert(~"lambda", ());
words.insert("pure", ()); words.insert(~"pure", ());
words.insert("iter", ()); words.insert(~"iter", ());
words.insert("block", ()); words.insert(~"block", ());
words.insert("import", ()); words.insert(~"import", ());
words.insert("export", ()); words.insert(~"export", ());
words.insert("let", ()); words.insert(~"let", ());
words.insert("const", ()); words.insert(~"const", ());
words.insert("log", ()); words.insert(~"log", ());
words.insert("log_err", ()); words.insert(~"log_err", ());
words.insert("tag", ()); words.insert(~"tag", ());
words.insert("obj", ()); words.insert(~"obj", ());
words.insert("copy", ()); words.insert(~"copy", ());
ret words; ret words;
} }
@ -273,7 +273,7 @@ fn check_bad_word(p: &parser) {
alt p.peek() { alt p.peek() {
token::IDENT(sid, false) { token::IDENT(sid, false) {
let w = p.get_str(sid); let w = p.get_str(sid);
if p.get_bad_expr_words().contains_key(w) { if p.get_bad_expr_words().contains_key(istr::from_estr(w)) {
p.fatal("found " + w + " in expression position"); p.fatal("found " + w + " in expression position");
} }
} }
@ -1455,7 +1455,8 @@ fn parse_pat(p: &parser) -> @ast::pat {
p.bump(); p.bump();
subpat = parse_pat(p); subpat = parse_pat(p);
} else { } else {
if p.get_bad_expr_words().contains_key(fieldname) { if p.get_bad_expr_words()
.contains_key(istr::from_estr(fieldname)) {
p.fatal("found " + fieldname + " in binding position"); p.fatal("found " + fieldname + " in binding position");
} }
subpat = subpat =
@ -2061,7 +2062,7 @@ fn parse_item_tag(p: &parser, attrs: &[ast::attribute]) -> @ast::item {
let variants: [ast::variant] = []; let variants: [ast::variant] = [];
// Newtype syntax // Newtype syntax
if p.peek() == token::EQ { if p.peek() == token::EQ {
if p.get_bad_expr_words().contains_key(id) { if p.get_bad_expr_words().contains_key(istr::from_estr(id)) {
p.fatal("found " + id + " in tag constructor position"); p.fatal("found " + id + " in tag constructor position");
} }
p.bump(); p.bump();

View file

@ -194,8 +194,8 @@ fn mk_hashmap<@K, @V>(hasher: &hashfn<K>, eqer: &eqfn<K>) -> hashmap<K, V> {
// Hash map constructors for basic types // Hash map constructors for basic types
fn new_str_hash<@V>() -> hashmap<str, V> { fn new_str_hash<@V>() -> hashmap<istr, V> {
ret mk_hashmap(str::hash, str::eq); ret mk_hashmap(istr::hash, istr::eq);
} }
fn new_int_hash<@V>() -> hashmap<int, V> { fn new_int_hash<@V>() -> hashmap<int, V> {

View file

@ -81,10 +81,10 @@ mod map_reduce {
// log_err "map_task " + input; // log_err "map_task " + input;
let intermediates = map::new_str_hash(); let intermediates = map::new_str_hash();
fn emit(im: &map::hashmap<str, chan<reduce_proto>>, fn emit(im: &map::hashmap<istr, chan<reduce_proto>>,
ctrl: chan<ctrl_proto>, key: str, val: int) { ctrl: chan<ctrl_proto>, key: str, val: int) {
let c; let c;
alt im.find(key) { alt im.find(istr::from_estr(key)) {
some(_c) { some(_c) {
c = _c c = _c
@ -94,7 +94,7 @@ mod map_reduce {
let keyi = str::bytes(key); let keyi = str::bytes(key);
send(ctrl, find_reducer(keyi, chan(p))); send(ctrl, find_reducer(keyi, chan(p)));
c = recv(p); c = recv(p);
im.insert(key, c); im.insert(istr::from_estr(key), c);
send(c, ref); send(c, ref);
} }
} }
@ -103,7 +103,7 @@ mod map_reduce {
map(input, bind emit(intermediates, ctrl, _, _)); map(input, bind emit(intermediates, ctrl, _, _));
for each kv: @{key: str, val: chan<reduce_proto>} in for each kv: @{key: istr, val: chan<reduce_proto>} in
intermediates.items() { intermediates.items() {
send(kv.val, release); send(kv.val, release);
} }
@ -147,7 +147,7 @@ mod map_reduce {
// This task becomes the master control task. It task::_spawns // This task becomes the master control task. It task::_spawns
// to do the rest. // to do the rest.
let reducers: map::hashmap<str, chan<reduce_proto>>; let reducers: map::hashmap<istr, chan<reduce_proto>>;
reducers = map::new_str_hash(); reducers = map::new_str_hash();
@ -163,7 +163,7 @@ mod map_reduce {
} }
find_reducer(ki, cc) { find_reducer(ki, cc) {
let c; let c;
let k = str::unsafe_from_bytes(ki); let k = istr::unsafe_from_bytes(ki);
// log_err "finding reducer for " + k; // log_err "finding reducer for " + k;
alt reducers.find(k) { alt reducers.find(k) {
some(_c) { some(_c) {
@ -174,7 +174,8 @@ mod map_reduce {
// log_err "creating new reducer for " + k; // log_err "creating new reducer for " + k;
let p = port(); let p = port();
tasks += tasks +=
[task::spawn_joinable(bind reduce_task(k, chan(p)))]; [task::spawn_joinable(
bind reduce_task(istr::to_estr(k), chan(p)))];
c = recv(p); c = recv(p);
reducers.insert(k, c); reducers.insert(k, c);
} }
@ -184,7 +185,7 @@ mod map_reduce {
} }
} }
for each kv: @{key: str, val: chan<reduce_proto>} in reducers.items() for each kv: @{key: istr, val: chan<reduce_proto>} in reducers.items()
{ {
send(kv.val, done); send(kv.val, done);
} }

View file

@ -10,6 +10,7 @@ import option = std::option::t;
import std::option::some; import std::option::some;
import std::option::none; import std::option::none;
import std::str; import std::str;
import std::istr;
import std::vec; import std::vec;
import std::map; import std::map;
import std::task; import std::task;
@ -40,10 +41,10 @@ mod map_reduce {
let intermediates = map::new_str_hash(); let intermediates = map::new_str_hash();
fn emit(im: &map::hashmap<str, int>, ctrl: chan<ctrl_proto>, fn emit(im: &map::hashmap<istr, int>, ctrl: chan<ctrl_proto>,
key: str, val: str) { key: str, val: str) {
let c; let c;
alt im.find(key) { alt im.find(istr::from_estr(key)) {
some(_c) { c = _c } some(_c) { c = _c }
none. { none. {
let p = port(); let p = port();
@ -52,7 +53,7 @@ mod map_reduce {
log_err "receiving"; log_err "receiving";
c = recv(p); c = recv(p);
log_err c; log_err c;
im.insert(key, c); im.insert(istr::from_estr(key), c);
} }
} }
} }
@ -67,7 +68,7 @@ mod map_reduce {
// This task becomes the master control task. It spawns others // This task becomes the master control task. It spawns others
// to do the rest. // to do the rest.
let reducers: map::hashmap<str, int>; let reducers: map::hashmap<istr, int>;
reducers = map::new_str_hash(); reducers = map::new_str_hash();
@ -80,7 +81,7 @@ mod map_reduce {
mapper_done. { num_mappers -= 1; } mapper_done. { num_mappers -= 1; }
find_reducer(k, cc) { find_reducer(k, cc) {
let c; let c;
alt reducers.find(str::unsafe_from_bytes(k)) { alt reducers.find(istr::unsafe_from_bytes(k)) {
some(_c) { c = _c; } some(_c) { c = _c; }
none. { c = 0; } none. { c = 0; }
} }