Skip to content

Commit 8de8721

Browse files
committed
---
yaml --- r: 2506 b: refs/heads/master c: eb419fd h: refs/heads/master v: v3
1 parent c7e9b19 commit 8de8721

File tree

5 files changed

+86
-114
lines changed

5 files changed

+86
-114
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 1a12a7b04b5c279b897dda998e946085883d9cf9
2+
refs/heads/master: eb419fd8c78f907f1a5cd20f5e71009ba37ef7e9

trunk/src/comp/front/creader.rs

Lines changed: 51 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ type env = @rec(
3434
mutable int next_crate_num
3535
);
3636

37-
tag resolve_result {
38-
rr_ok(ast::def_id);
39-
rr_not_found(ast::ident);
40-
}
41-
4237
// Type decoding
4338

4439
// Compact string representation for ty::t values. API ty_str & parse_from_str
@@ -282,64 +277,58 @@ fn parse_def_id(vec[u8] buf) -> ast::def_id {
282277
}
283278

284279
fn lookup_hash(&ebml::doc d, fn(vec[u8]) -> bool eq_fn, uint hash)
285-
-> option::t[ebml::doc] {
280+
-> vec[ebml::doc] {
286281
auto index = ebml::get_doc(d, metadata::tag_index);
287282
auto table = ebml::get_doc(index, metadata::tag_index_table);
288283

289284
auto hash_pos = table.start + (hash % 256u) * 4u;
290285
auto pos = ebml::be_uint_from_bytes(d.data, hash_pos, 4u);
291286
auto bucket = ebml::doc_at(d.data, pos);
292287
// Awkward logic because we can't ret from foreach yet
293-
auto result = option::none[ebml::doc];
288+
let vec[ebml::doc] result = vec();
294289
auto belt = metadata::tag_index_buckets_bucket_elt;
295290
for each (ebml::doc elt in ebml::tagged_docs(bucket, belt)) {
296-
alt (result) {
297-
case (option::none[ebml::doc]) {
298-
auto pos = ebml::be_uint_from_bytes(elt.data, elt.start, 4u);
299-
if (eq_fn(_vec::slice[u8](elt.data, elt.start+4u, elt.end))) {
300-
result = option::some[ebml::doc]
301-
(ebml::doc_at(d.data, pos));
302-
}
303-
}
304-
case (_) {}
291+
auto pos = ebml::be_uint_from_bytes(elt.data, elt.start, 4u);
292+
if (eq_fn(_vec::slice[u8](elt.data, elt.start+4u, elt.end))) {
293+
_vec::push(result, ebml::doc_at(d.data, pos));
305294
}
306295
}
307296
ret result;
308297
}
309298

310299
// Given a path and serialized crate metadata, returns the ID of the
311300
// definition the path refers to.
312-
fn resolve_path(vec[ast::ident] path, vec[u8] data) -> resolve_result {
301+
fn resolve_path(vec[ast::ident] path, vec[u8] data) -> vec[ast::def_id] {
313302
fn eq_item(vec[u8] data, str s) -> bool {
314303
ret _str::eq(_str::unsafe_from_bytes(data), s);
315304
}
316305
auto s = _str::connect(path, "::");
317306
auto md = ebml::new_doc(data);
318307
auto paths = ebml::get_doc(md, metadata::tag_paths);
319308
auto eqer = bind eq_item(_, s);
320-
alt (lookup_hash(paths, eqer, metadata::hash_path(s))) {
321-
case (option::some[ebml::doc](?d)) {
322-
auto did_doc = ebml::get_doc(d, metadata::tag_def_id);
323-
ret rr_ok(parse_def_id(ebml::doc_data(did_doc)));
324-
}
325-
case (option::none[ebml::doc]) {
326-
ret rr_not_found(s);
327-
}
309+
let vec[ast::def_id] result = vec();
310+
for (ebml::doc doc in lookup_hash(paths, eqer, metadata::hash_path(s))) {
311+
auto did_doc = ebml::get_doc(doc, metadata::tag_def_id);
312+
_vec::push(result, parse_def_id(ebml::doc_data(did_doc)));
328313
}
314+
ret result;
329315
}
330316

331317
fn maybe_find_item(int item_id, &ebml::doc items) -> option::t[ebml::doc] {
332318
fn eq_item(vec[u8] bytes, int item_id) -> bool {
333319
ret ebml::be_uint_from_bytes(bytes, 0u, 4u) as int == item_id;
334320
}
335321
auto eqer = bind eq_item(_, item_id);
336-
ret lookup_hash(items, eqer, metadata::hash_def_num(item_id));
322+
auto found = lookup_hash(items, eqer, metadata::hash_def_num(item_id));
323+
if (_vec::len(found) == 0u) {
324+
ret option::none[ebml::doc];
325+
} else {
326+
ret option::some[ebml::doc](found.(0));
327+
}
337328
}
338329

339330
fn find_item(int item_id, &ebml::doc items) -> ebml::doc {
340-
alt (maybe_find_item(item_id, items)) {
341-
case (option::some[ebml::doc](?d)) {ret d;}
342-
}
331+
ret option::get(maybe_find_item(item_id, items));
343332
}
344333

345334
// Looks up an item in the given metadata and returns an ebml doc pointing
@@ -478,67 +467,49 @@ fn read_crates(session::session sess,
478467

479468

480469
fn kind_has_type_params(u8 kind_ch) -> bool {
481-
// FIXME: It'd be great if we had u8 char literals.
482-
if (kind_ch == ('c' as u8)) { ret false; }
483-
else if (kind_ch == ('f' as u8)) { ret true; }
484-
else if (kind_ch == ('F' as u8)) { ret true; }
485-
else if (kind_ch == ('y' as u8)) { ret true; }
486-
else if (kind_ch == ('o' as u8)) { ret true; }
487-
else if (kind_ch == ('t' as u8)) { ret true; }
488-
else if (kind_ch == ('T' as u8)) { ret false; }
489-
else if (kind_ch == ('m' as u8)) { ret false; }
490-
else if (kind_ch == ('n' as u8)) { ret false; }
491-
else if (kind_ch == ('v' as u8)) { ret true; }
492-
else {
493-
log_err #fmt("kind_has_type_params(): unknown kind char: %d",
494-
kind_ch as int);
495-
fail;
496-
}
470+
ret alt (kind_ch as char) {
471+
case ('c') { false } case ('f') { true } case ('F') { true }
472+
case ('y') { true } case ('o') { true } case ('t') { true }
473+
case ('T') { false } case ('m') { false } case ('n') { false }
474+
case ('v') { true }
475+
};
497476
}
498477

499-
500478
// Crate metadata queries
501479

502-
fn lookup_def(session::session sess, int cnum, vec[ast::ident] path)
503-
-> option::t[ast::def] {
480+
fn lookup_defs(session::session sess, int cnum, vec[ast::ident] path)
481+
-> vec[ast::def] {
504482
auto data = sess.get_external_crate(cnum).data;
505483

506-
auto did;
507-
alt (resolve_path(path, data)) {
508-
case (rr_ok(?di)) { did = di; }
509-
case (rr_not_found(?name)) {
510-
ret none[ast::def];
511-
}
512-
}
484+
ret _vec::map(bind lookup_def(cnum, data, _),
485+
resolve_path(path, data));
486+
}
513487

488+
// FIXME doesn't yet handle re-exported externals
489+
fn lookup_def(int cnum, vec[u8] data, &ast::def_id did) -> ast::def {
514490
auto item = lookup_item(did._1, data);
515491
auto kind_ch = item_kind(item);
516492

517493
did = tup(cnum, did._1);
518494

519-
// FIXME: It'd be great if we had u8 char literals.
520-
auto def;
521-
if (kind_ch == ('c' as u8)) { def = ast::def_const(did); }
522-
else if (kind_ch == ('f' as u8)) { def = ast::def_fn(did); }
523-
else if (kind_ch == ('F' as u8)) { def = ast::def_native_fn(did); }
524-
else if (kind_ch == ('y' as u8)) { def = ast::def_ty(did); }
525-
else if (kind_ch == ('o' as u8)) { def = ast::def_obj(did); }
526-
else if (kind_ch == ('T' as u8)) { def = ast::def_native_ty(did); }
527-
else if (kind_ch == ('t' as u8)) {
495+
auto def = alt (kind_ch as char) {
496+
case ('c') { ast::def_const(did) }
497+
case ('f') { ast::def_fn(did) }
498+
case ('F') { ast::def_native_fn(did) }
499+
case ('y') { ast::def_ty(did) }
500+
case ('o') { ast::def_obj(did) }
501+
case ('T') { ast::def_native_ty(did) }
528502
// We treat references to tags as references to types.
529-
def = ast::def_ty(did);
530-
} else if (kind_ch == ('m' as u8)) { def = ast::def_mod(did); }
531-
else if (kind_ch == ('n' as u8)) { def = ast::def_native_mod(did); }
532-
else if (kind_ch == ('v' as u8)) {
533-
auto tid = variant_tag_id(item);
534-
tid = tup(cnum, tid._1);
535-
def = ast::def_variant(tid, did);
536-
} else {
537-
log_err #fmt("lookup_def(): unknown kind char: %d", kind_ch as int);
538-
fail;
539-
}
540-
541-
ret some[ast::def](def);
503+
case ('t') { ast::def_ty(did) }
504+
case ('m') { ast::def_mod(did) }
505+
case ('n') { ast::def_native_mod(did) }
506+
case ('v') {
507+
auto tid = variant_tag_id(item);
508+
tid = tup(cnum, tid._1);
509+
ast::def_variant(tid, did)
510+
}
511+
};
512+
ret def;
542513
}
543514

544515
fn get_type(session::session sess, ty::ctxt tcx, ast::def_id def)
@@ -563,8 +534,7 @@ fn get_type(session::session sess, ty::ctxt tcx, ast::def_id def)
563534
fn get_symbol(session::session sess, ast::def_id def) -> str {
564535
auto external_crate_id = def._0;
565536
auto data = sess.get_external_crate(external_crate_id).data;
566-
auto item = lookup_item(def._1, data);
567-
ret item_symbol(item);
537+
ret item_symbol(lookup_item(def._1, data));
568538
}
569539

570540
fn get_tag_variants(session::session sess, ty::ctxt tcx, ast::def_id def)
@@ -636,9 +606,8 @@ fn list_crate_metadata(vec[u8] bytes, io::writer out) {
636606
}
637607

638608
fn describe_def(&ebml::doc items, ast::def_id id) -> str {
639-
if (id._0 != 0) {ret "external";}
640-
auto item = find_item(id._1, items);
641-
ret item_kind_to_str(item_kind(item));
609+
if (id._0 != 0) { ret "external"; }
610+
ret item_kind_to_str(item_kind(find_item(id._1, items)));
642611
}
643612

644613
fn item_kind_to_str(u8 kind) -> str {

trunk/src/comp/middle/metadata.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const uint tag_items_data_item_type = 0x0cu;
3737
const uint tag_items_data_item_symbol = 0x0du;
3838
const uint tag_items_data_item_variant = 0x0eu;
3939
const uint tag_items_data_item_tag_id = 0x0fu;
40-
const uint tag_items_data_item_obj_type_id = 0x10u;
4140

4241
const uint tag_index = 0x11u;
4342
const uint tag_index_buckets = 0x12u;
@@ -165,7 +164,7 @@ mod Encode {
165164
}
166165
case (ty::ty_char) {w.write_char('c');}
167166
case (ty::ty_str) {w.write_char('s');}
168-
case (ty::ty_tag(?def,?tys)) { // TODO restore def_id
167+
case (ty::ty_tag(?def,?tys)) {
169168
w.write_str("t[");
170169
w.write_str(cx.ds(def));
171170
w.write_char('|');
@@ -387,7 +386,12 @@ fn encode_module_item_paths(&ebml::writer ebml_w,
387386
ebml::start_tag(ebml_w, tag_paths_data_item);
388387
encode_name(ebml_w, id);
389388
encode_def_id(ebml_w, odid.ctor);
390-
encode_obj_type_id(ebml_w, odid.ty);
389+
ebml::end_tag(ebml_w);
390+
391+
add_to_index(ebml_w, path, index, id);
392+
ebml::start_tag(ebml_w, tag_paths_data_item);
393+
encode_name(ebml_w, id);
394+
encode_def_id(ebml_w, odid.ty);
391395
ebml::end_tag(ebml_w);
392396
}
393397
}
@@ -459,11 +463,6 @@ fn encode_tag_id(&ebml::writer ebml_w, &ast::def_id id) {
459463
ebml::end_tag(ebml_w);
460464
}
461465

462-
fn encode_obj_type_id(&ebml::writer ebml_w, &ast::def_id id) {
463-
ebml::start_tag(ebml_w, tag_items_data_item_obj_type_id);
464-
ebml_w.writer.write(_str::bytes(def_to_str(id)));
465-
ebml::end_tag(ebml_w);
466-
}
467466

468467

469468
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,
550549
encode_symbol(cx, ebml_w, odid.ctor);
551550
ebml::end_tag(ebml_w);
552551

552+
index += vec(tup(odid.ty._1, ebml_w.writer.tell()));
553553
ebml::start_tag(ebml_w, tag_items_data_item);
554554
encode_def_id(ebml_w, odid.ty);
555555
encode_kind(ebml_w, 'y' as u8);

trunk/src/comp/middle/resolve.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,22 @@ tag import_state {
4747
resolved(option::t[def] /* value */, option::t[def] /* type */);
4848
}
4949

50-
type ext_hash = hashmap[tup(def_id,str),def];
50+
type ext_hash = hashmap[tup(def_id,str,namespace),def];
5151
fn new_ext_hash() -> ext_hash {
52-
fn hash(&tup(def_id,str) v) -> uint {
53-
ret _str::hash(v._1) + util::common::hash_def(v._0);
54-
}
55-
fn eq(&tup(def_id,str) v1, &tup(def_id,str) v2) -> bool {
52+
fn hash(&tup(def_id,str,namespace) v) -> uint {
53+
ret _str::hash(v._1) + util::common::hash_def(v._0) + (alt (v._2) {
54+
case (ns_value) { 1u }
55+
case (ns_type) { 2u }
56+
case (ns_module) { 3u }
57+
});
58+
}
59+
fn eq(&tup(def_id,str,namespace) v1,
60+
&tup(def_id,str,namespace) v2) -> bool {
5661
ret util::common::def_eq(v1._0, v2._0) &&
57-
_str::eq(v1._1, v2._1);
62+
_str::eq(v1._1, v2._1) &&
63+
v1._2 == v2._2;
5864
}
59-
ret std::map::mk_hashmap[tup(def_id,str),def](hash, eq);
65+
ret std::map::mk_hashmap[tup(def_id,str,namespace),def](hash, eq);
6066
}
6167

6268
tag mod_index_entry {
@@ -509,7 +515,7 @@ fn lookup_in_scope(&env e, list[scope] sc, &span sp, &ident id, namespace ns)
509515
}
510516
case (cons[scope](?hd, ?tl)) {
511517
auto fnd = in_scope(e, id, hd, ns);
512-
if (fnd != none[def]) {
518+
if (!option::is_none(fnd)) {
513519
auto df = option::get(fnd);
514520
if ((left_fn && def_is_local(df)) ||
515521
(left_fn_level2 && def_is_obj_field(df))) {
@@ -550,7 +556,7 @@ fn lookup_in_pat(&ident id, &ast::pat pat) -> option::t[def] {
550556
case (ast::pat_tag(_, ?pats, _)) {
551557
for (@ast::pat p in pats) {
552558
auto found = lookup_in_pat(id, *p);
553-
if (found != none[def]) { ret found; }
559+
if (!option::is_none(found)) { ret found; }
554560
}
555561
}
556562
}
@@ -617,7 +623,7 @@ fn lookup_in_block(&ident id, &ast::block_ b, namespace ns)
617623
case (_) {
618624
if (_str::eq(ast::item_ident(it), id)) {
619625
auto found = found_def_item(it, ns);
620-
if (found != none[def]) { ret found; }
626+
if (!option::is_none(found)) { ret found; }
621627
}
622628
}
623629
}
@@ -676,17 +682,15 @@ fn lookup_in_mod(&env e, def m, &ident id, namespace ns, dir dr)
676682
-> option::t[def] {
677683
auto defid = ast::def_id_of_def(m);
678684
if (defid._0 != ast::local_crate) { // Not in this crate
679-
auto cached = e.ext_cache.find(tup(defid,id));
680-
if (cached != none[def] && check_def_by_ns(option::get(cached), ns)) {
681-
ret cached;
682-
}
685+
auto cached = e.ext_cache.find(tup(defid,id,ns));
686+
if (!option::is_none(cached)) { ret cached; }
683687
auto path = vec(id);
684688
if (defid._1 != -1) {
685689
path = e.ext_map.get(defid) + path;
686690
}
687691
auto fnd = lookup_external(e, defid._0, path, ns);
688-
if (fnd != none[def]) {
689-
e.ext_cache.insert(tup(defid,id), option::get(fnd));
692+
if (!option::is_none(fnd)) {
693+
e.ext_cache.insert(tup(defid,id,ns), option::get(fnd));
690694
}
691695
ret fnd;
692696
}
@@ -728,8 +732,8 @@ fn lookup_import(&env e, def_id defid, namespace ns) -> option::t[def] {
728732
}
729733
}
730734

731-
fn lookup_in_regular_mod(&env e, def_id defid, &ident id, namespace ns, dir dr)
732-
-> option::t[def] {
735+
fn lookup_in_regular_mod(&env e, def_id defid, &ident id, namespace ns,
736+
dir dr) -> option::t[def] {
733737
auto info = e.mod_map.get(defid._1);
734738
auto found = info.index.find(id);
735739
if (option::is_none(found) ||
@@ -935,13 +939,11 @@ fn check_def_by_ns(def d, namespace ns) -> bool {
935939

936940
fn lookup_external(&env e, int cnum, vec[ident] ids, namespace ns)
937941
-> option::t[def] {
938-
auto found = creader::lookup_def(e.sess, cnum, ids);
939-
if (found != none[def]) {
940-
auto d = option::get(found);
941-
if (!check_def_by_ns(d, ns)) { ret none[def]; }
942+
for (def d in creader::lookup_defs(e.sess, cnum, ids)) {
942943
e.ext_map.insert(ast::def_id_of_def(d), ids);
944+
if (check_def_by_ns(d, ns)) { ret some(d); }
943945
}
944-
ret found;
946+
ret none[def];
945947
}
946948

947949
// Local Variables:

trunk/src/comp/middle/ty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,6 +1929,7 @@ mod Unify {
19291929
} else if (actual_input.mode == mo_either) {
19301930
result_mode = expected_input.mode;
19311931
} else if (expected_input.mode != actual_input.mode) {
1932+
// FIXME this is the wrong error
19321933
ret fn_common_res_err(ures_err(terr_arg_count,
19331934
expected, actual));
19341935
} else {

0 commit comments

Comments
 (0)