Skip to content

Commit de421af

Browse files
committed
rustc: Use walk instead of fold for the first item collection pass
1 parent 8b3f359 commit de421af

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/comp/middle/typeck.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,7 @@ mod collect {
658658
ret result;
659659
}
660660

661-
fn collect(&@ty_item_table id_to_ty_item, &@ast::item i)
662-
-> @ty_item_table {
661+
fn collect(&@ty_item_table id_to_ty_item, &@ast::item i) {
663662
alt (i.node) {
664663
case (ast::item_ty(_, _, _, ?def_id, _)) {
665664
id_to_ty_item.insert(def_id, any_item_rust(i));
@@ -672,22 +671,17 @@ mod collect {
672671
}
673672
case (_) { /* empty */ }
674673
}
675-
ret id_to_ty_item;
676674
}
677675

678-
fn collect_native(&@ty_item_table id_to_ty_item, &@ast::native_item i)
679-
-> @ty_item_table {
676+
fn collect_native(&@ty_item_table id_to_ty_item, &@ast::native_item i) {
680677
alt (i.node) {
681678
case (ast::native_item_ty(_, ?def_id)) {
682679
// The abi of types is not used.
683680
id_to_ty_item.insert(def_id,
684-
any_item_native(i,
685-
ast::native_abi_cdecl));
686-
}
687-
case (_) {
681+
any_item_native(i, ast::native_abi_cdecl));
688682
}
683+
case (_) { /* no-op */ }
689684
}
690-
ret id_to_ty_item;
691685
}
692686

693687
fn convert(&@env e, &@ast::item i) -> @env {
@@ -884,11 +878,12 @@ mod collect {
884878
vec(mutable);
885879
let node_type_table ntt = @mutable ntt_sub;
886880

887-
auto fld_1 = fold::new_identity_fold[@ty_item_table]();
888-
fld_1 = @rec(update_env_for_item = bind collect(_, _),
889-
update_env_for_native_item = bind collect_native(_, _)
890-
with *fld_1);
891-
fold::fold_crate[@ty_item_table](id_to_ty_item, fld_1, crate);
881+
auto visit = rec(
882+
visit_item_pre = bind collect(id_to_ty_item, _),
883+
visit_native_item_pre = bind collect_native(id_to_ty_item, _)
884+
with walk::default_visitor()
885+
);
886+
walk::walk_crate(visit, *crate);
892887

893888
// Second pass: translate the types of all items.
894889
auto type_cache = common::new_def_hash[ty::ty_param_count_and_ty]();

0 commit comments

Comments
 (0)