Skip to content

Commit 3436979

Browse files
committed
Split trans' collection in two passes. This allows us to handle tags
that are defined after use in a block. This is really inefficient, but for now it lets us compile the included test.
1 parent fdc22ef commit 3436979

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

src/comp/middle/trans.rs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5484,6 +5484,25 @@ fn collect_native_item(&@crate_ctxt cx, @ast.native_item i) -> @crate_ctxt {
54845484

54855485
fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
54865486

5487+
alt (i.node) {
5488+
case (ast.item_const(?name, _, _, ?cid, _)) {
5489+
cx.items.insert(cid, i);
5490+
}
5491+
5492+
case (ast.item_mod(?name, ?m, ?mid)) {
5493+
cx.items.insert(mid, i);
5494+
}
5495+
5496+
case (ast.item_tag(_, ?variants, ?tps, ?tag_id)) {
5497+
cx.items.insert(tag_id, i);
5498+
}
5499+
5500+
case (_) { /* fall through */ }
5501+
}
5502+
ret cx;
5503+
}
5504+
5505+
fn collect_item_pass2(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
54875506
alt (i.node) {
54885507
case (ast.item_fn(?name, ?f, ?tps, ?fid, ?ann)) {
54895508
cx.items.insert(fid, i);
@@ -5500,18 +5519,6 @@ fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
55005519
}
55015520
}
55025521

5503-
case (ast.item_const(?name, _, _, ?cid, _)) {
5504-
cx.items.insert(cid, i);
5505-
}
5506-
5507-
case (ast.item_mod(?name, ?m, ?mid)) {
5508-
cx.items.insert(mid, i);
5509-
}
5510-
5511-
case (ast.item_tag(_, ?variants, ?tps, ?tag_id)) {
5512-
cx.items.insert(tag_id, i);
5513-
}
5514-
55155522
case (_) { /* fall through */ }
55165523
}
55175524
ret cx;
@@ -5523,11 +5530,20 @@ fn collect_items(@crate_ctxt cx, @ast.crate crate) {
55235530
let fold.ast_fold[@crate_ctxt] fld =
55245531
fold.new_identity_fold[@crate_ctxt]();
55255532

5526-
fld = @rec( update_env_for_item = bind collect_item(_,_),
5527-
update_env_for_native_item = bind collect_native_item(_,_)
5528-
with *fld );
5533+
// FIXME: if ty_tag had a pointer directly to the definition instead
5534+
// of a def_id, we wouldn't need the second pass.
55295535

5530-
fold.fold_crate[@crate_ctxt](cx, fld, crate);
5536+
auto fld1 =
5537+
@rec( update_env_for_item = bind collect_item(_,_),
5538+
update_env_for_native_item = bind collect_native_item(_,_)
5539+
with *fld );
5540+
5541+
fold.fold_crate[@crate_ctxt](cx, fld1, crate);
5542+
5543+
auto fld2 = @rec( update_env_for_item = bind collect_item_pass2(_,_)
5544+
with *fld );
5545+
5546+
fold.fold_crate[@crate_ctxt](cx, fld2, crate);
55315547
}
55325548

55335549
fn collect_tag_ctor(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {

src/test/run-pass/tag-in-block.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn foo() {
2+
fn zed(bar z) {
3+
}
4+
tag bar {
5+
nil;
6+
}
7+
fn baz() {
8+
zed(nil);
9+
}
10+
}
11+
12+
fn main(vec[str] args) {
13+
}

0 commit comments

Comments
 (0)