Skip to content

Commit eb57a49

Browse files
committed
---
yaml --- r: 2302 b: refs/heads/master c: 1dd63ff h: refs/heads/master v: v3
1 parent c5064fb commit eb57a49

File tree

2 files changed

+32
-37
lines changed

2 files changed

+32
-37
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: f25e6783657cde34e25aa8ba105cd43fe9bda787
2+
refs/heads/master: 1dd63ff42d41df9392210127a9eb5a0744d9d5b9

trunk/src/comp/middle/resolve.rs

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,22 @@ tag scope {
2727
scope_arm(ast.arm);
2828
}
2929

30-
// This indicates whether we're searching up the scope chain
31-
// or whether we've found a path component and started following
32-
// it back down, which has an effect on export visibility
33-
tag search_direction {
34-
up;
35-
down;
36-
}
37-
3830
type env = rec(list[scope] scopes,
39-
session.session sess,
40-
search_direction direction);
31+
session.session sess);
4132

4233
tag namespace {
4334
ns_value;
4435
ns_type;
4536
}
4637

38+
// This indicates whether we're searching up the scope chain or whether we've
39+
// found a path component and started following it back down, which has an
40+
// effect on export visibility
41+
tag direction {
42+
up;
43+
down;
44+
}
45+
4746
type import_map = std.map.hashmap[ast.def_id,def_wrap];
4847

4948
// A simple wrapper over defs that stores a bit more information about modules
@@ -157,11 +156,10 @@ fn find_final_def(&env e, import_map index,
157156
auto len = _vec.len[ident](idents);
158157
auto rest_idents = _vec.slice[ident](idents, 1u, len);
159158
auto empty_e = rec(scopes = nil[scope],
160-
sess = e.sess,
161-
direction = down);
159+
sess = e.sess);
162160
auto tmp_e = update_env_for_item(empty_e, i);
163161
auto next_i = rest_idents.(0);
164-
auto next_ = lookup_name_wrapped(tmp_e, next_i, ns);
162+
auto next_ = lookup_name_wrapped(tmp_e, next_i, ns, down);
165163
alt (next_) {
166164
case (none[tup(@env, def_wrap)]) {
167165
e.sess.span_err(sp, "unresolved name: " + next_i);
@@ -183,11 +181,10 @@ fn find_final_def(&env e, import_map index,
183181
auto len = _vec.len[ident](idents);
184182
auto rest_idents = _vec.slice[ident](idents, 1u, len);
185183
auto empty_e = rec(scopes = nil[scope],
186-
sess = e.sess,
187-
direction = down);
184+
sess = e.sess);
188185
auto tmp_e = update_env_for_external_mod(empty_e, mod_id, idents);
189186
auto next_i = rest_idents.(0);
190-
auto next_ = lookup_name_wrapped(tmp_e, next_i, ns);
187+
auto next_ = lookup_name_wrapped(tmp_e, next_i, ns, down);
191188
alt (next_) {
192189
case (none[tup(@env, def_wrap)]) {
193190
e.sess.span_err(sp, "unresolved name: " + next_i);
@@ -282,7 +279,7 @@ fn find_final_def(&env e, import_map index,
282279
index.insert(option.get[ast.def_id](import_id), def_wrap_resolving);
283280
}
284281
auto first = idents.(0);
285-
auto d_ = lookup_name_wrapped(e, first, ns);
282+
auto d_ = lookup_name_wrapped(e, first, ns, up);
286283
alt (d_) {
287284
case (none[tup(@env, def_wrap)]) {
288285
e.sess.span_err(sp, "unresolved name: " + first);
@@ -298,8 +295,8 @@ fn find_final_def(&env e, import_map index,
298295
}
299296
}
300297

301-
fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
302-
-> option.t[tup(@env, def_wrap)] {
298+
fn lookup_name_wrapped(&env e, ast.ident i, namespace ns, direction dir)
299+
-> option.t[tup(@env, def_wrap)] {
303300

304301
// log "resolving name " + i;
305302

@@ -359,12 +356,12 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
359356
fail;
360357
}
361358

362-
fn check_mod(&env e, ast.ident i, ast._mod m, namespace ns)
363-
-> option.t[def_wrap] {
359+
fn check_mod(ast.ident i, ast._mod m, namespace ns,
360+
direction dir) -> option.t[def_wrap] {
364361

365-
fn visible(&env e, ast.ident i, ast._mod m) -> bool {
362+
fn visible(ast.ident i, ast._mod m, direction dir) -> bool {
366363

367-
alt (e.direction) {
364+
alt (dir) {
368365
case (up) {
369366
ret true;
370367
}
@@ -400,14 +397,14 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
400397
ret some(found_def_view(view_item));
401398
}
402399
case (ast.mie_item(?item)) {
403-
if (visible(e, i, m)) {
400+
if (visible(i, m, dir)) {
404401
ret some(found_def_item(item, ns));
405402
}
406403
}
407404
case (ast.mie_tag_variant(?item, ?variant_idx)) {
408405
alt (item.node) {
409406
case (ast.item_tag(_, ?variants, _, ?tid, _)) {
410-
if (visible(e, i, m)) {
407+
if (visible(i, m, dir)) {
411408
auto vid = variants.(variant_idx).node.id;
412409
auto t = ast.def_variant(tid, vid);
413410
ret some[def_wrap](def_wrap_other(t));
@@ -501,12 +498,12 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
501498
}
502499
}
503500

504-
fn in_scope(&env e, ast.ident identifier, &scope s,
505-
namespace ns) -> option.t[def_wrap] {
501+
fn in_scope(&session.session sess, ast.ident identifier, &scope s,
502+
namespace ns, direction dir) -> option.t[def_wrap] {
506503
alt (s) {
507504

508505
case (scope_crate(?c)) {
509-
ret check_mod(e, identifier, c.node.module, ns);
506+
ret check_mod(identifier, c.node.module, ns, dir);
510507
}
511508

512509
case (scope_item(?it)) {
@@ -542,7 +539,7 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
542539
}
543540
}
544541
case (ast.item_mod(_, ?m, _)) {
545-
ret check_mod(e, identifier, m, ns);
542+
ret check_mod(identifier, m, ns, dir);
546543
}
547544
case (ast.item_native_mod(_, ?m, _)) {
548545
ret check_native_mod(identifier, m);
@@ -570,7 +567,7 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
570567
}
571568

572569
case (scope_external_mod(?mod_id, ?path)) {
573-
ret lookup_external_def(e.sess, mod_id._0, path);
570+
ret lookup_external_def(sess, mod_id._0, path);
574571
}
575572

576573
case (scope_loop(?d)) {
@@ -606,14 +603,14 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
606603
ret none[tup(@env, def_wrap)];
607604
}
608605
case (cons[scope](?hd, ?tl)) {
609-
auto x = in_scope(e, i, hd, ns);
606+
auto x = in_scope(e.sess, i, hd, ns, dir);
610607
alt (x) {
611608
case (some[def_wrap](?x)) {
612609
ret some(tup(@e, x));
613610
}
614611
case (none[def_wrap]) {
615612
auto outer_env = rec(scopes = *tl with e);
616-
ret lookup_name_wrapped(outer_env, i, ns);
613+
ret lookup_name_wrapped(outer_env, i, ns, up);
617614
}
618615
}
619616
}
@@ -785,8 +782,7 @@ fn resolve_imports(session.session sess, @ast.crate crate) -> @ast.crate {
785782
with *fld );
786783

787784
auto e = rec(scopes = nil[scope],
788-
sess = sess,
789-
direction = up);
785+
sess = sess);
790786

791787
ret fold.fold_crate[env](e, fld, crate);
792788
}
@@ -810,8 +806,7 @@ fn resolve_crate(session.session sess, @ast.crate crate) -> @ast.crate {
810806
with *fld );
811807

812808
auto e = rec(scopes = nil[scope],
813-
sess = sess,
814-
direction = up);
809+
sess = sess);
815810

816811
ret fold.fold_crate[env](e, fld, new_crate);
817812
}

0 commit comments

Comments
 (0)