From 854b3a9b73ca78551a8ca8a933e07a12a0e77aeb Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 20 Jun 2011 10:20:16 +0200 Subject: [PATCH] Use ast_map in typeck, instead of building another index --- src/comp/driver/rustc.rs | 4 ++-- src/comp/middle/ty.rs | 16 +++++---------- src/comp/middle/typeck.rs | 41 +++++---------------------------------- 3 files changed, 12 insertions(+), 49 deletions(-) diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 040b551a529..d265ac2aeee 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -85,7 +85,7 @@ fn compile_input(session::session sess, eval::env env, str input, auto d = time(time_passes, "resolution", bind resolve::resolve_crate(sess, ast_map, crate)); - auto ty_cx = ty::mk_ctxt(sess, d._0, d._1); + auto ty_cx = ty::mk_ctxt(sess, d._0, d._1, ast_map); time[()](time_passes, "typechecking", bind typeck::check_crate(ty_cx, crate)); if (sess.get_opts().run_typestate) { @@ -111,7 +111,7 @@ fn pretty_print_input(session::session sess, eval::env env, str input, case (ppm_typed) { auto amap = middle::ast_map::map_crate(*crate); auto d = resolve::resolve_crate(sess, amap, crate); - auto ty_cx = ty::mk_ctxt(sess, d._0, d._1); + auto ty_cx = ty::mk_ctxt(sess, d._0, d._1, amap); typeck::check_crate(ty_cx, crate); mode = ppaux::mo_typed(ty_cx); } diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index 4dbe8444ef8..77b8639f260 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -190,12 +190,6 @@ type method = controlflow cf, vec[@constr_def] constrs); -tag any_item { - any_item_rust(@ast::item); - any_item_native(@ast::native_item, ast::native_abi); -} - -type item_table = hashmap[ast::node_id, any_item]; type constr_table = hashmap[ast::node_id, vec[constr_def]]; type mt = rec(t ty, ast::mutability mut); @@ -210,7 +204,7 @@ type ctxt = session::session sess, resolve::def_map def_map, node_type_table node_types, - item_table items, // Only contains type items + ast_map::map items, constr_table fn_constrs, type_cache tcache, @@ -395,18 +389,18 @@ fn mk_rcache() -> creader_cache { ret map::mk_hashmap[tup(int, uint, uint), t](h, e); } -fn mk_ctxt(session::session s, resolve::def_map dm, constr_table cs) -> ctxt { +fn mk_ctxt(session::session s, resolve::def_map dm, constr_table cs, + ast_map::map amap) -> ctxt { let node_type_table ntt = @smallintmap::mk[ty::ty_param_substs_opt_and_ty](); auto tcache = new_def_hash[ty::ty_param_count_and_ty](); - auto items = new_int_hash[any_item](); auto ts = @interner::mk[raw_t](hash_raw_ty, eq_raw_ty); auto cx = rec(ts=ts, sess=s, def_map=dm, node_types=ntt, - items=items, + items=amap, fn_constrs=cs, tcache=tcache, rcache=mk_rcache(), @@ -2691,7 +2685,7 @@ fn tag_variants(&ctxt cx, &ast::def_id id) -> vec[variant_info] { } assert (cx.items.contains_key(id._1)); alt (cx.items.get(id._1)) { - case (any_item_rust(?item)) { + case (ast_map::node_item(?item)) { alt (item.node) { case (ast::item_tag(?variants, _)) { let vec[variant_info] result = []; diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index ca07350f2e8..381cc442fdc 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -492,9 +492,10 @@ mod collect { auto it = cx.tcx.items.get(id._1); auto tpt; alt (it) { - case (ty::any_item_rust(?item)) { tpt = ty_of_item(cx, item); } - case (ty::any_item_native(?native_item, ?abi)) { - tpt = ty_of_native_item(cx, native_item, abi); + case (ast_map::node_item(?item)) { tpt = ty_of_item(cx, item); } + case (ast_map::node_native_item(?native_item)) { + tpt = ty_of_native_item(cx, native_item, + ast::native_abi_cdecl); } } ret tpt; @@ -671,30 +672,6 @@ mod collect { ret vec::map[@ast::method, method](bind ty_of_method(cx, _), object.methods); } - fn collect(ty::item_table id_to_ty_item, &@ast::item i) { - alt (i.node) { - case (ast::item_ty(_, _)) { - id_to_ty_item.insert(i.id, ty::any_item_rust(i)); - } - case (ast::item_tag(_, _)) { - id_to_ty_item.insert(i.id, ty::any_item_rust(i)); - } - case (ast::item_obj(_, _, _)) { - id_to_ty_item.insert(i.id, ty::any_item_rust(i)); - } - case (_) {/* empty */ } - } - } - fn collect_native(ty::item_table id_to_ty_item, &@ast::native_item i) { - alt (i.node) { - case (ast::native_item_ty(_, ?id)) { - // The abi of types is not used. - auto abi = ast::native_abi_cdecl; - id_to_ty_item.insert(id, ty::any_item_native(i, abi)); - } - case (_) {/* no-op */ } - } - } fn convert(@ctxt cx, @mutable option::t[ast::native_abi] abi, &@ast::item it) { alt (it.node) { @@ -790,20 +767,12 @@ mod collect { } } fn collect_item_types(&ty::ctxt tcx, &@ast::crate crate) { - // First pass: collect all type item IDs. - - auto module = crate.node.module; - auto visit = - rec(visit_item_pre=bind collect(tcx.items, _), - visit_native_item_pre=bind collect_native(tcx.items, _) - with walk::default_visitor()); - walk::walk_crate(visit, *crate); // We have to propagate the surrounding ABI to the native items // contained within the native module. auto abi = @mutable none[ast::native_abi]; auto cx = @rec(tcx=tcx); - visit = + auto visit = rec(visit_item_pre=bind convert(cx, abi, _), visit_native_item_pre=bind convert_native(cx, abi, _) with walk::default_visitor());