Skip to content

Commit 5e3ffb6

Browse files
committed
rustc: Re-export the same name in different namespaces
Issue #1115.
1 parent bd30063 commit 5e3ffb6

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

src/comp/metadata/encoder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ fn encode_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt, crate: @crate)
155155

156156
fn encode_reexport_paths(ebml_w: ebml::writer,
157157
ecx: @encode_ctxt, &index: [entry<str>]) {
158-
ecx.ccx.exp_map.items {|path, def|
158+
ecx.ccx.exp_map.items {|key, def|
159+
let path = key.path;
159160
index += [{val: path, pos: ebml_w.writer.tell()}];
160161
ebml::start_tag(ebml_w, tag_paths_data_item);
161162
encode_name(ebml_w, path);

src/comp/middle/resolve.rs

+30-10
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ fn new_ext_hash() -> ext_hash {
7979
ret std::map::mk_hashmap::<key, def>(hash, eq);
8080
}
8181

82+
fn new_exp_hash() -> exp_map {
83+
type key = {path: str, ns: namespace};
84+
fn hash(v: key) -> uint {
85+
ret str::hash(v.path) +
86+
alt v.ns {
87+
ns_value. { 1u }
88+
ns_type. { 2u }
89+
ns_module. { 3u }
90+
};
91+
}
92+
fn eq(v1: key, v2: key) -> bool {
93+
ret str::eq(v1.path, v2.path) && v1.ns == v2.ns;
94+
}
95+
ret std::map::mk_hashmap::<key, def>(hash, eq);
96+
}
97+
8298
tag mod_index_entry {
8399
mie_view_item(@ast::view_item);
84100
mie_import_ident(node_id, codemap::span);
@@ -105,7 +121,7 @@ type indexed_mod = {
105121

106122
type def_map = hashmap<node_id, def>;
107123
type ext_map = hashmap<def_id, [ident]>;
108-
type exp_map = hashmap<str, def>;
124+
type exp_map = hashmap<{path: str, ns: namespace}, def>;
109125
type impl_map = hashmap<node_id, iscopes>;
110126
type impl_cache = hashmap<def_id, @[@_impl]>;
111127

@@ -142,7 +158,7 @@ fn resolve_crate(sess: session, amap: ast_map::map, crate: @ast::crate) ->
142158
def_map: new_int_hash(),
143159
ast_map: amap,
144160
imports: new_int_hash(),
145-
exp_map: new_str_hash(),
161+
exp_map: new_exp_hash(),
146162
mod_map: new_int_hash(),
147163
block_map: new_int_hash(),
148164
ext_map: new_def_hash(),
@@ -1363,6 +1379,9 @@ fn lookup_external(e: env, cnum: int, ids: [ident], ns: namespace) ->
13631379
let cname = cstore::get_crate_data(e.cstore, did.crate).name;
13641380
let name =
13651381
csearch::get_item_name(e.cstore, did.crate, did.node);
1382+
log #fmt("lookup_external: %s %d, %d, %s, %s", cname,
1383+
did.crate, did.node,
1384+
str::connect(ids, "::"), name);
13661385
e.ext_map.insert(did, vec::init(ids) + [name]);
13671386
} else {
13681387
e.ext_map.insert(did, ids);
@@ -1615,15 +1634,16 @@ fn check_exports(e: @env) {
16151634
let (m, v, t) = (lookup(ns_module),
16161635
lookup(ns_value),
16171636
lookup(ns_type));
1618-
maybe_add_reexport(e, path + ident, m);
1619-
maybe_add_reexport(e, path + ident, v);
1620-
maybe_add_reexport(e, path + ident, t);
1637+
maybe_add_reexport(e, path + ident, ns_module, m);
1638+
maybe_add_reexport(e, path + ident, ns_value, v);
1639+
maybe_add_reexport(e, path + ident, ns_type, t);
16211640
ret is_some(m) || is_some(v) || is_some(t);
16221641
}
16231642

1624-
fn maybe_add_reexport(e: @env, path: str, def: option::t<def>) {
1643+
fn maybe_add_reexport(e: @env, path: str, ns: namespace,
1644+
def: option::t<def>) {
16251645
if option::is_some(def) {
1626-
e.exp_map.insert(path, option::get(def));
1646+
e.exp_map.insert({path: path, ns: ns}, option::get(def));
16271647
}
16281648
}
16291649

@@ -1635,9 +1655,9 @@ fn check_exports(e: @env) {
16351655
mie_import_ident(id, _) {
16361656
alt e.imports.get(id) {
16371657
resolved(v, t, m, _, rid, _) {
1638-
maybe_add_reexport(e, val.path + rid, v);
1639-
maybe_add_reexport(e, val.path + rid, t);
1640-
maybe_add_reexport(e, val.path + rid, m);
1658+
maybe_add_reexport(e, val.path + rid, ns_value, v);
1659+
maybe_add_reexport(e, val.path + rid, ns_type, t);
1660+
maybe_add_reexport(e, val.path + rid, ns_module, m);
16411661
}
16421662
_ { }
16431663
}

src/comp/middle/trans_common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import std::map::hashmap;
99
import option::some;
1010
import syntax::ast;
1111
import driver::session;
12-
import middle::ty;
12+
import middle::{resolve, ty};
1313
import back::{link, abi, upcall};
1414
import util::common::*;
1515
import syntax::codemap::span;
@@ -84,7 +84,7 @@ type crate_ctxt =
8484
intrinsics: hashmap<str, ValueRef>,
8585
item_ids: hashmap<ast::node_id, ValueRef>,
8686
ast_map: ast_map::map,
87-
exp_map: hashmap<str, ast::def>,
87+
exp_map: resolve::exp_map,
8888
item_symbols: hashmap<ast::node_id, str>,
8989
mutable main_fn: option::t<ValueRef>,
9090
link_meta: link::link_meta,

0 commit comments

Comments
 (0)