aboutsummaryrefslogtreecommitdiff
path: root/src/comp/middle
diff options
context:
space:
mode:
authorMarijn Haverbeke <[email protected]>2011-05-13 15:17:24 +0200
committerMarijn Haverbeke <[email protected]>2011-05-13 17:20:39 +0200
commiteb419fd8c78f907f1a5cd20f5e71009ba37ef7e9 (patch)
tree924709adb23c244bb06f23bde47dff88b48eb20e /src/comp/middle
parentMake module indices hold a list of items (diff)
downloadrust-eb419fd8c78f907f1a5cd20f5e71009ba37ef7e9.tar.xz
rust-eb419fd8c78f907f1a5cd20f5e71009ba37ef7e9.zip
Extend crate format to allow multiple definitions for a single name
The type/value namespace distinction pretty much works now. Module namespace is up next.
Diffstat (limited to 'src/comp/middle')
-rw-r--r--src/comp/middle/metadata.rs16
-rw-r--r--src/comp/middle/resolve.rs48
-rw-r--r--src/comp/middle/ty.rs1
3 files changed, 34 insertions, 31 deletions
diff --git a/src/comp/middle/metadata.rs b/src/comp/middle/metadata.rs
index e10f2e73..b3078424 100644
--- a/src/comp/middle/metadata.rs
+++ b/src/comp/middle/metadata.rs
@@ -37,7 +37,6 @@ const uint tag_items_data_item_type = 0x0cu;
const uint tag_items_data_item_symbol = 0x0du;
const uint tag_items_data_item_variant = 0x0eu;
const uint tag_items_data_item_tag_id = 0x0fu;
-const uint tag_items_data_item_obj_type_id = 0x10u;
const uint tag_index = 0x11u;
const uint tag_index_buckets = 0x12u;
@@ -165,7 +164,7 @@ mod Encode {
}
case (ty::ty_char) {w.write_char('c');}
case (ty::ty_str) {w.write_char('s');}
- case (ty::ty_tag(?def,?tys)) { // TODO restore def_id
+ case (ty::ty_tag(?def,?tys)) {
w.write_str("t[");
w.write_str(cx.ds(def));
w.write_char('|');
@@ -387,7 +386,12 @@ fn encode_module_item_paths(&ebml::writer ebml_w,
ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, id);
encode_def_id(ebml_w, odid.ctor);
- encode_obj_type_id(ebml_w, odid.ty);
+ ebml::end_tag(ebml_w);
+
+ add_to_index(ebml_w, path, index, id);
+ ebml::start_tag(ebml_w, tag_paths_data_item);
+ encode_name(ebml_w, id);
+ encode_def_id(ebml_w, odid.ty);
ebml::end_tag(ebml_w);
}
}
@@ -459,11 +463,6 @@ fn encode_tag_id(&ebml::writer ebml_w, &ast::def_id id) {
ebml::end_tag(ebml_w);
}
-fn encode_obj_type_id(&ebml::writer ebml_w, &ast::def_id id) {
- ebml::start_tag(ebml_w, tag_items_data_item_obj_type_id);
- ebml_w.writer.write(_str::bytes(def_to_str(id)));
- ebml::end_tag(ebml_w);
-}
fn encode_tag_variant_info(&@trans::crate_ctxt cx, &ebml::writer ebml_w,
@@ -550,6 +549,7 @@ fn encode_info_for_item(@trans::crate_ctxt cx, &ebml::writer ebml_w,
encode_symbol(cx, ebml_w, odid.ctor);
ebml::end_tag(ebml_w);
+ index += vec(tup(odid.ty._1, ebml_w.writer.tell()));
ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, odid.ty);
encode_kind(ebml_w, 'y' as u8);
diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs
index 93ce248b..ad1a5fe9 100644
--- a/src/comp/middle/resolve.rs
+++ b/src/comp/middle/resolve.rs
@@ -47,16 +47,22 @@ tag import_state {
resolved(option::t[def] /* value */, option::t[def] /* type */);
}
-type ext_hash = hashmap[tup(def_id,str),def];
+type ext_hash = hashmap[tup(def_id,str,namespace),def];
fn new_ext_hash() -> ext_hash {
- fn hash(&tup(def_id,str) v) -> uint {
- ret _str::hash(v._1) + util::common::hash_def(v._0);
- }
- fn eq(&tup(def_id,str) v1, &tup(def_id,str) v2) -> bool {
+ fn hash(&tup(def_id,str,namespace) v) -> uint {
+ ret _str::hash(v._1) + util::common::hash_def(v._0) + (alt (v._2) {
+ case (ns_value) { 1u }
+ case (ns_type) { 2u }
+ case (ns_module) { 3u }
+ });
+ }
+ fn eq(&tup(def_id,str,namespace) v1,
+ &tup(def_id,str,namespace) v2) -> bool {
ret util::common::def_eq(v1._0, v2._0) &&
- _str::eq(v1._1, v2._1);
+ _str::eq(v1._1, v2._1) &&
+ v1._2 == v2._2;
}
- ret std::map::mk_hashmap[tup(def_id,str),def](hash, eq);
+ ret std::map::mk_hashmap[tup(def_id,str,namespace),def](hash, eq);
}
tag mod_index_entry {
@@ -509,7 +515,7 @@ fn lookup_in_scope(&env e, list[scope] sc, &span sp, &ident id, namespace ns)
}
case (cons[scope](?hd, ?tl)) {
auto fnd = in_scope(e, id, hd, ns);
- if (fnd != none[def]) {
+ if (!option::is_none(fnd)) {
auto df = option::get(fnd);
if ((left_fn && def_is_local(df)) ||
(left_fn_level2 && def_is_obj_field(df))) {
@@ -550,7 +556,7 @@ fn lookup_in_pat(&ident id, &ast::pat pat) -> option::t[def] {
case (ast::pat_tag(_, ?pats, _)) {
for (@ast::pat p in pats) {
auto found = lookup_in_pat(id, *p);
- if (found != none[def]) { ret found; }
+ if (!option::is_none(found)) { ret found; }
}
}
}
@@ -617,7 +623,7 @@ fn lookup_in_block(&ident id, &ast::block_ b, namespace ns)
case (_) {
if (_str::eq(ast::item_ident(it), id)) {
auto found = found_def_item(it, ns);
- if (found != none[def]) { ret found; }
+ if (!option::is_none(found)) { ret found; }
}
}
}
@@ -676,17 +682,15 @@ fn lookup_in_mod(&env e, def m, &ident id, namespace ns, dir dr)
-> option::t[def] {
auto defid = ast::def_id_of_def(m);
if (defid._0 != ast::local_crate) { // Not in this crate
- auto cached = e.ext_cache.find(tup(defid,id));
- if (cached != none[def] && check_def_by_ns(option::get(cached), ns)) {
- ret cached;
- }
+ auto cached = e.ext_cache.find(tup(defid,id,ns));
+ if (!option::is_none(cached)) { ret cached; }
auto path = vec(id);
if (defid._1 != -1) {
path = e.ext_map.get(defid) + path;
}
auto fnd = lookup_external(e, defid._0, path, ns);
- if (fnd != none[def]) {
- e.ext_cache.insert(tup(defid,id), option::get(fnd));
+ if (!option::is_none(fnd)) {
+ e.ext_cache.insert(tup(defid,id,ns), option::get(fnd));
}
ret fnd;
}
@@ -728,8 +732,8 @@ fn lookup_import(&env e, def_id defid, namespace ns) -> option::t[def] {
}
}
-fn lookup_in_regular_mod(&env e, def_id defid, &ident id, namespace ns, dir dr)
- -> option::t[def] {
+fn lookup_in_regular_mod(&env e, def_id defid, &ident id, namespace ns,
+ dir dr) -> option::t[def] {
auto info = e.mod_map.get(defid._1);
auto found = info.index.find(id);
if (option::is_none(found) ||
@@ -935,13 +939,11 @@ fn check_def_by_ns(def d, namespace ns) -> bool {
fn lookup_external(&env e, int cnum, vec[ident] ids, namespace ns)
-> option::t[def] {
- auto found = creader::lookup_def(e.sess, cnum, ids);
- if (found != none[def]) {
- auto d = option::get(found);
- if (!check_def_by_ns(d, ns)) { ret none[def]; }
+ for (def d in creader::lookup_defs(e.sess, cnum, ids)) {
e.ext_map.insert(ast::def_id_of_def(d), ids);
+ if (check_def_by_ns(d, ns)) { ret some(d); }
}
- ret found;
+ ret none[def];
}
// Local Variables:
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index 42bd68af..ccbbeed0 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -1929,6 +1929,7 @@ mod Unify {
} else if (actual_input.mode == mo_either) {
result_mode = expected_input.mode;
} else if (expected_input.mode != actual_input.mode) {
+ // FIXME this is the wrong error
ret fn_common_res_err(ures_err(terr_arg_count,
expected, actual));
} else {