Skip to content

Commit 854b3a9

Browse files
committed
Use ast_map in typeck, instead of building another index
1 parent 40db3aa commit 854b3a9

File tree

3 files changed

+12
-49
lines changed

3 files changed

+12
-49
lines changed

src/comp/driver/rustc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn compile_input(session::session sess, eval::env env, str input,
8585
auto d =
8686
time(time_passes, "resolution",
8787
bind resolve::resolve_crate(sess, ast_map, crate));
88-
auto ty_cx = ty::mk_ctxt(sess, d._0, d._1);
88+
auto ty_cx = ty::mk_ctxt(sess, d._0, d._1, ast_map);
8989
time[()](time_passes, "typechecking",
9090
bind typeck::check_crate(ty_cx, crate));
9191
if (sess.get_opts().run_typestate) {
@@ -111,7 +111,7 @@ fn pretty_print_input(session::session sess, eval::env env, str input,
111111
case (ppm_typed) {
112112
auto amap = middle::ast_map::map_crate(*crate);
113113
auto d = resolve::resolve_crate(sess, amap, crate);
114-
auto ty_cx = ty::mk_ctxt(sess, d._0, d._1);
114+
auto ty_cx = ty::mk_ctxt(sess, d._0, d._1, amap);
115115
typeck::check_crate(ty_cx, crate);
116116
mode = ppaux::mo_typed(ty_cx);
117117
}

src/comp/middle/ty.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,6 @@ type method =
190190
controlflow cf,
191191
vec[@constr_def] constrs);
192192

193-
tag any_item {
194-
any_item_rust(@ast::item);
195-
any_item_native(@ast::native_item, ast::native_abi);
196-
}
197-
198-
type item_table = hashmap[ast::node_id, any_item];
199193
type constr_table = hashmap[ast::node_id, vec[constr_def]];
200194

201195
type mt = rec(t ty, ast::mutability mut);
@@ -210,7 +204,7 @@ type ctxt =
210204
session::session sess,
211205
resolve::def_map def_map,
212206
node_type_table node_types,
213-
item_table items, // Only contains type items
207+
ast_map::map items,
214208

215209
constr_table fn_constrs,
216210
type_cache tcache,
@@ -395,18 +389,18 @@ fn mk_rcache() -> creader_cache {
395389
ret map::mk_hashmap[tup(int, uint, uint), t](h, e);
396390
}
397391

398-
fn mk_ctxt(session::session s, resolve::def_map dm, constr_table cs) -> ctxt {
392+
fn mk_ctxt(session::session s, resolve::def_map dm, constr_table cs,
393+
ast_map::map amap) -> ctxt {
399394
let node_type_table ntt =
400395
@smallintmap::mk[ty::ty_param_substs_opt_and_ty]();
401396
auto tcache = new_def_hash[ty::ty_param_count_and_ty]();
402-
auto items = new_int_hash[any_item]();
403397
auto ts = @interner::mk[raw_t](hash_raw_ty, eq_raw_ty);
404398
auto cx =
405399
rec(ts=ts,
406400
sess=s,
407401
def_map=dm,
408402
node_types=ntt,
409-
items=items,
403+
items=amap,
410404
fn_constrs=cs,
411405
tcache=tcache,
412406
rcache=mk_rcache(),
@@ -2691,7 +2685,7 @@ fn tag_variants(&ctxt cx, &ast::def_id id) -> vec[variant_info] {
26912685
}
26922686
assert (cx.items.contains_key(id._1));
26932687
alt (cx.items.get(id._1)) {
2694-
case (any_item_rust(?item)) {
2688+
case (ast_map::node_item(?item)) {
26952689
alt (item.node) {
26962690
case (ast::item_tag(?variants, _)) {
26972691
let vec[variant_info] result = [];

src/comp/middle/typeck.rs

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,10 @@ mod collect {
492492
auto it = cx.tcx.items.get(id._1);
493493
auto tpt;
494494
alt (it) {
495-
case (ty::any_item_rust(?item)) { tpt = ty_of_item(cx, item); }
496-
case (ty::any_item_native(?native_item, ?abi)) {
497-
tpt = ty_of_native_item(cx, native_item, abi);
495+
case (ast_map::node_item(?item)) { tpt = ty_of_item(cx, item); }
496+
case (ast_map::node_native_item(?native_item)) {
497+
tpt = ty_of_native_item(cx, native_item,
498+
ast::native_abi_cdecl);
498499
}
499500
}
500501
ret tpt;
@@ -671,30 +672,6 @@ mod collect {
671672
ret vec::map[@ast::method,
672673
method](bind ty_of_method(cx, _), object.methods);
673674
}
674-
fn collect(ty::item_table id_to_ty_item, &@ast::item i) {
675-
alt (i.node) {
676-
case (ast::item_ty(_, _)) {
677-
id_to_ty_item.insert(i.id, ty::any_item_rust(i));
678-
}
679-
case (ast::item_tag(_, _)) {
680-
id_to_ty_item.insert(i.id, ty::any_item_rust(i));
681-
}
682-
case (ast::item_obj(_, _, _)) {
683-
id_to_ty_item.insert(i.id, ty::any_item_rust(i));
684-
}
685-
case (_) {/* empty */ }
686-
}
687-
}
688-
fn collect_native(ty::item_table id_to_ty_item, &@ast::native_item i) {
689-
alt (i.node) {
690-
case (ast::native_item_ty(_, ?id)) {
691-
// The abi of types is not used.
692-
auto abi = ast::native_abi_cdecl;
693-
id_to_ty_item.insert(id, ty::any_item_native(i, abi));
694-
}
695-
case (_) {/* no-op */ }
696-
}
697-
}
698675
fn convert(@ctxt cx, @mutable option::t[ast::native_abi] abi,
699676
&@ast::item it) {
700677
alt (it.node) {
@@ -790,20 +767,12 @@ mod collect {
790767
}
791768
}
792769
fn collect_item_types(&ty::ctxt tcx, &@ast::crate crate) {
793-
// First pass: collect all type item IDs.
794-
795-
auto module = crate.node.module;
796-
auto visit =
797-
rec(visit_item_pre=bind collect(tcx.items, _),
798-
visit_native_item_pre=bind collect_native(tcx.items, _)
799-
with walk::default_visitor());
800-
walk::walk_crate(visit, *crate);
801770
// We have to propagate the surrounding ABI to the native items
802771
// contained within the native module.
803772

804773
auto abi = @mutable none[ast::native_abi];
805774
auto cx = @rec(tcx=tcx);
806-
visit =
775+
auto visit =
807776
rec(visit_item_pre=bind convert(cx, abi, _),
808777
visit_native_item_pre=bind convert_native(cx, abi, _)
809778
with walk::default_visitor());

0 commit comments

Comments
 (0)