From 75681f9ad7a6b79c5a34fd80c95c22258e30ddb5 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Sun, 19 Jun 2011 22:41:21 +0200 Subject: [PATCH 1/6] Get rid of def_ids and anns in AST nodes, use single node_id This reduces some redundancy in the AST data structures and cruft in the code that works with them. To get a def_id from a node_id, apply ast::local_def, which adds the local crate_num to the given node_id. Most code only deals with crate-local node_ids, and won't have to create def_ids at all. --- src/comp/driver/rustc.rs | 6 +- src/comp/front/ast.rs | 162 +++--- src/comp/front/creader.rs | 10 +- src/comp/front/eval.rs | 30 +- src/comp/front/ext.rs | 10 +- src/comp/front/extenv.rs | 2 +- src/comp/front/extfmt.rs | 12 +- src/comp/front/parser.rs | 208 ++++---- src/comp/middle/alias.rs | 76 +-- src/comp/middle/ast_map.rs | 56 ++ src/comp/middle/metadata.rs | 215 ++++---- src/comp/middle/resolve.rs | 205 ++++---- src/comp/middle/trans.rs | 481 +++++++++--------- src/comp/middle/tstate/annotate.rs | 56 +- src/comp/middle/tstate/auxiliary.rs | 143 +++--- src/comp/middle/tstate/bitvectors.rs | 30 +- src/comp/middle/tstate/ck.rs | 25 +- src/comp/middle/tstate/collect_locals.rs | 25 +- src/comp/middle/tstate/pre_post_conditions.rs | 260 +++++----- src/comp/middle/tstate/states.rs | 294 +++++------ src/comp/middle/ty.rs | 182 +++---- src/comp/middle/typeck.rs | 453 +++++++++-------- src/comp/middle/visit.rs | 18 +- src/comp/middle/walk.rs | 29 +- src/comp/pretty/pprust.rs | 21 +- 25 files changed, 1537 insertions(+), 1472 deletions(-) create mode 100644 src/comp/middle/ast_map.rs diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 0acf1dfac873..f5f79fb0a2a6 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -76,8 +76,7 @@ fn time[T](bool do_it, str what, fn() -> T thunk) -> T { fn compile_input(session::session sess, eval::env env, str input, str output) { auto time_passes = sess.get_opts().time_passes; - auto def = tup(ast::local_crate, 0); - auto p = parser::new_parser(sess, env, def, input, 0u, 0u); + auto p = parser::new_parser(sess, env, input, 0u, 0); auto crate = time(time_passes, "parsing", bind parse_input(sess, p, input)); if (sess.get_opts().output_type == link::output_type_none) { ret; } @@ -103,8 +102,7 @@ fn compile_input(session::session sess, eval::env env, str input, fn pretty_print_input(session::session sess, eval::env env, str input, pp_mode ppm) { - auto def = tup(ast::local_crate, 0); - auto p = front::parser::new_parser(sess, env, def, input, 0u, 0u); + auto p = front::parser::new_parser(sess, env, input, 0u, 0); auto crate = parse_input(sess, p, input); auto mode; alt (ppm) { diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index e5638474dc4b..c873f798f471 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -16,17 +16,16 @@ type path = spanned[path_]; fn path_name(&path p) -> str { ret str::connect(p.node.idents, "::"); } type crate_num = int; +type node_id = int; +type def_id = tup(crate_num, node_id); const crate_num local_crate = 0; - -type def_num = int; - -type def_id = tup(crate_num, def_num); +fn local_def(node_id id) -> def_id { + ret tup(local_crate, id); +} type ty_param = ident; -type ann = rec(uint id); - tag def { def_fn(def_id); def_obj(def_id); @@ -102,15 +101,15 @@ type meta_item_ = rec(ident key, str value); type block = spanned[block_]; -type block_ = rec(vec[@stmt] stmts, option::t[@expr] expr, ann a); +type block_ = rec(vec[@stmt] stmts, option::t[@expr] expr, node_id id); type pat = spanned[pat_]; tag pat_ { - pat_wild(ann); - pat_bind(ident, def_id, ann); - pat_lit(@lit, ann); - pat_tag(path, vec[@pat], ann); + pat_wild(node_id); + pat_bind(ident, node_id); + pat_lit(@lit, node_id); + pat_tag(path, vec[@pat], node_id); } tag mutability { mut; imm; maybe_mut; } @@ -183,8 +182,8 @@ tag mode { val; alias(bool); } type stmt = spanned[stmt_]; tag stmt_ { - stmt_decl(@decl, ann); - stmt_expr(@expr, ann); + stmt_decl(@decl, node_id); + stmt_expr(@expr, node_id); // These only exist in crate-level blocks. stmt_crate_directive(@crate_directive); @@ -199,8 +198,7 @@ type local_ = bool infer, ident ident, option::t[initializer] init, - def_id id, - ann ann); + node_id id); type local = spanned[local_]; @@ -225,58 +223,58 @@ tag seq_kind { sk_unique; sk_rc; } type expr = spanned[expr_]; tag expr_ { - expr_vec(vec[@expr], mutability, seq_kind, ann); - expr_tup(vec[elt], ann); - expr_rec(vec[field], option::t[@expr], ann); - expr_call(@expr, vec[@expr], ann); - expr_self_method(ident, ann); - expr_bind(@expr, vec[option::t[@expr]], ann); - expr_spawn(spawn_dom, option::t[str], @expr, vec[@expr], ann); - expr_binary(binop, @expr, @expr, ann); - expr_unary(unop, @expr, ann); - expr_lit(@lit, ann); - expr_cast(@expr, @ty, ann); - expr_if(@expr, block, option::t[@expr], ann); - expr_while(@expr, block, ann); - expr_for(@local, @expr, block, ann); - expr_for_each(@local, @expr, block, ann); - expr_do_while(block, @expr, ann); - expr_alt(@expr, vec[arm], ann); - expr_fn(_fn, ann); - expr_block(block, ann); + expr_vec(vec[@expr], mutability, seq_kind, node_id); + expr_tup(vec[elt], node_id); + expr_rec(vec[field], option::t[@expr], node_id); + expr_call(@expr, vec[@expr], node_id); + expr_self_method(ident, node_id); + expr_bind(@expr, vec[option::t[@expr]], node_id); + expr_spawn(spawn_dom, option::t[str], @expr, vec[@expr], node_id); + expr_binary(binop, @expr, @expr, node_id); + expr_unary(unop, @expr, node_id); + expr_lit(@lit, node_id); + expr_cast(@expr, @ty, node_id); + expr_if(@expr, block, option::t[@expr], node_id); + expr_while(@expr, block, node_id); + expr_for(@local, @expr, block, node_id); + expr_for_each(@local, @expr, block, node_id); + expr_do_while(block, @expr, node_id); + expr_alt(@expr, vec[arm], node_id); + expr_fn(_fn, node_id); + expr_block(block, node_id); /* * FIXME: many of these @exprs should be constrained with * is_lval once we have constrained types working. */ - expr_move(@expr, @expr, ann); - expr_assign(@expr,@expr, ann); - expr_swap(@expr, @expr, ann); - expr_assign_op(binop, @expr, @expr, ann); - expr_send(@expr, @expr, ann); - expr_recv(@expr, @expr, ann); - expr_field(@expr, ident, ann); - expr_index(@expr, @expr, ann); - expr_path(path, ann); - expr_ext(path, vec[@expr], option::t[str], @expr, ann); - expr_fail(ann, option::t[str]); - expr_break(ann); - expr_cont(ann); - expr_ret(option::t[@expr], ann); - expr_put(option::t[@expr], ann); - expr_be(@expr, ann); - expr_log(int, @expr, ann); + expr_move(@expr, @expr, node_id); + expr_assign(@expr,@expr, node_id); + expr_swap(@expr, @expr, node_id); + expr_assign_op(binop, @expr, @expr, node_id); + expr_send(@expr, @expr, node_id); + expr_recv(@expr, @expr, node_id); + expr_field(@expr, ident, node_id); + expr_index(@expr, @expr, node_id); + expr_path(path, node_id); + expr_ext(path, vec[@expr], option::t[str], @expr, node_id); + expr_fail(node_id, option::t[str]); + expr_break(node_id); + expr_cont(node_id); + expr_ret(option::t[@expr], node_id); + expr_put(option::t[@expr], node_id); + expr_be(@expr, node_id); + expr_log(int, @expr, node_id); /* just an assert, no significance to typestate */ - expr_assert(@expr, ann); + expr_assert(@expr, node_id); /* preds that typestate is aware of */ - expr_check(@expr, ann); + expr_check(@expr, node_id); /* FIXME Would be nice if expr_check desugared to expr_if_check. */ - expr_if_check(@expr, block, option::t[@expr], ann); - expr_port(ann); - expr_chan(@expr, ann); - expr_anon_obj(anon_obj, vec[ty_param], obj_def_ids, ann); + expr_if_check(@expr, block, option::t[@expr], node_id); + expr_port(node_id); + expr_chan(@expr, node_id); + expr_anon_obj(anon_obj, vec[ty_param], obj_def_ids, node_id); } type lit = spanned[lit_]; @@ -348,7 +346,7 @@ tag ty_ { ty_rec(vec[ty_field]); ty_fn(proto, vec[ty_arg], @ty, controlflow, vec[@constr]); ty_obj(vec[ty_method]); - ty_path(path, ann); + ty_path(path, node_id); ty_type; ty_constr(@ty, vec[@constr]); } @@ -368,7 +366,9 @@ type constr_arg = constr_arg_general[uint]; type constr_arg_general[T] = spanned[constr_arg_general_[T]]; -type constr_ = rec(path path, vec[@constr_arg_general[uint]] args, ann ann); +type constr_ = rec(path path, + vec[@constr_arg_general[uint]] args, + node_id id); type constr = spanned[constr_]; @@ -376,7 +376,7 @@ type constr = spanned[constr_]; /* The parser generates ast::constrs; resolve generates a mapping from each function to a list of ty::constr_defs, corresponding to these. */ -type arg = rec(mode mode, @ty ty, ident ident, def_id id); +type arg = rec(mode mode, @ty ty, ident ident, node_id id); type fn_decl = rec(vec[arg] inputs, @@ -402,11 +402,11 @@ tag controlflow { type _fn = rec(fn_decl decl, proto proto, block body); -type method_ = rec(ident ident, _fn meth, def_id id, ann ann); +type method_ = rec(ident ident, _fn meth, node_id id); type method = spanned[method_]; -type obj_field = rec(mutability mut, @ty ty, ident ident, def_id id, ann ann); +type obj_field = rec(mutability mut, @ty ty, ident ident, node_id id); type _obj = rec(vec[obj_field] fields, vec[@method] methods, option::t[@method] dtor); @@ -435,22 +435,22 @@ type native_mod = vec[@view_item] view_items, vec[@native_item] items); -type variant_arg = rec(@ty ty, def_id id); +type variant_arg = rec(@ty ty, node_id id); -type variant_ = rec(str name, vec[variant_arg] args, def_id id, ann ann); +type variant_ = rec(str name, vec[variant_arg] args, node_id id); type variant = spanned[variant_]; type view_item = spanned[view_item_]; tag view_item_ { - view_item_use(ident, vec[@meta_item], def_id, ann); - view_item_import(ident, vec[ident], def_id); - view_item_import_glob(vec[ident], def_id); - view_item_export(ident); + view_item_use(ident, vec[@meta_item], node_id); + view_item_import(ident, vec[ident], node_id); + view_item_import_glob(vec[ident], node_id); + view_item_export(ident, node_id); } -type obj_def_ids = rec(def_id ty, def_id ctor); +type obj_def_ids = rec(node_id ty, node_id ctor); // Meta-data associated with an item @@ -464,14 +464,11 @@ tag attr_style { attr_outer; attr_inner; } type attribute_ = rec(attr_style style, meta_item value); -type item = - rec(ident ident, - vec[attribute] attrs, - def_id id, // For objs, this is the type def_id - - ann ann, - item_ node, - span span); +type item = rec(ident ident, + vec[attribute] attrs, + node_id id, // For objs, this is the type's def_id + item_ node, + span span); tag item_ { item_const(@ty, @expr); @@ -480,21 +477,18 @@ tag item_ { item_native_mod(native_mod); item_ty(@ty, vec[ty_param]); item_tag(vec[variant], vec[ty_param]); - item_obj(_obj, vec[ty_param], def_id); - /* constructor id */ - + item_obj(_obj, vec[ty_param], node_id /* constructor id */); } type native_item = spanned[native_item_]; tag native_item_ { - native_item_ty(ident, def_id); + native_item_ty(ident, node_id); native_item_fn(ident, option::t[str], fn_decl, vec[ty_param], - def_id, - ann); + node_id); } fn is_exported(ident i, _mod m) -> bool { @@ -514,7 +508,7 @@ fn is_exported(ident i, _mod m) -> bool { auto count = 0u; for (@ast::view_item vi in m.view_items) { alt (vi.node) { - case (ast::view_item_export(?id)) { + case (ast::view_item_export(?id, _)) { if (str::eq(i, id)) { // even if it's nonlocal (since it's explicit) diff --git a/src/comp/front/creader.rs b/src/comp/front/creader.rs index c57e7b732fac..f118775d3f8b 100644 --- a/src/comp/front/creader.rs +++ b/src/comp/front/creader.rs @@ -359,8 +359,8 @@ fn parse_def_id(vec[u8] buf) -> ast::def_id { auto crate_part = vec::slice[u8](buf, 0u, colon_idx); auto def_part = vec::slice[u8](buf, colon_idx + 1u, len); auto crate_num = uint::parse_buf(crate_part, 10u) as int; - auto def_num = uint::parse_buf(def_part, 10u) as int; - ret tup(crate_num, def_num); + auto def_id = uint::parse_buf(def_part, 10u) as int; + ret tup(crate_num, def_id); } fn lookup_hash(&ebml::doc d, fn(vec[u8]) -> bool eq_fn, uint hash) -> @@ -407,7 +407,7 @@ fn maybe_find_item(int item_id, &ebml::doc items) -> option::t[ebml::doc] { ret ebml::be_uint_from_bytes(bytes, 0u, 4u) as int == item_id; } auto eqer = bind eq_item(_, item_id); - auto found = lookup_hash(items, eqer, metadata::hash_def_num(item_id)); + auto found = lookup_hash(items, eqer, metadata::hash_def_id(item_id)); if (vec::len(found) == 0u) { ret option::none[ebml::doc]; } else { ret option::some[ebml::doc](found.(0)); } @@ -606,7 +606,7 @@ type env = fn visit_view_item(env e, &@ast::view_item i) { alt (i.node) { - case (ast::view_item_use(?ident, ?meta_items, ?id, ?ann)) { + case (ast::view_item_use(?ident, ?meta_items, ?id)) { auto cnum; if (!e.crate_cache.contains_key(ident)) { cnum = e.next_crate_num; @@ -615,7 +615,7 @@ fn visit_view_item(env e, &@ast::view_item i) { e.crate_cache.insert(ident, e.next_crate_num); e.next_crate_num += 1; } else { cnum = e.crate_cache.get(ident); } - e.crate_map.insert(ann.id, cnum); + e.crate_map.insert(id, cnum); } case (_) { } } diff --git a/src/comp/front/eval.rs b/src/comp/front/eval.rs index 4553ff2fc0a1..1de0688d488d 100644 --- a/src/comp/front/eval.rs +++ b/src/comp/front/eval.rs @@ -31,7 +31,7 @@ type ctx = mutable vec[str] deps, session::session sess, mutable uint chpos, - mutable uint next_ann); + mutable int next_id); fn mk_env() -> env { ret []; } @@ -287,23 +287,18 @@ fn eval_crate_directive(ctx cx, env e, @ast::crate_directive cdir, str prefix, } auto full_path = prefix + std::fs::path_sep() + file_path; if (cx.mode == mode_depend) { cx.deps += [full_path]; ret; } - auto start_id = cx.p.next_def_id(); auto p0 = - new_parser(cx.sess, e, start_id, full_path, cx.chpos, - cx.next_ann); + new_parser(cx.sess, e, full_path, cx.chpos, + cx.next_id); auto inner_attrs = parse_inner_attrs_and_next(p0); auto first_item_outer_attrs = inner_attrs._1; - auto m0 = parse_mod_items(p0, token::EOF, - first_item_outer_attrs); - auto next_id = p0.next_def_id(); - // Thread defids and chpos through the parsers + auto m0 = parse_mod_items(p0, token::EOF, first_item_outer_attrs); - cx.p.set_def(next_id._1); + auto i = front::parser::mk_item(p0, cdir.span.lo, cdir.span.hi, + id, ast::item_mod(m0), []); + // Thread defids and chpos through the parsers cx.chpos = p0.get_chpos(); - cx.next_ann = p0.next_ann_num(); - auto i = front::parser::mk_item(cx.p, cdir.span.lo, cdir.span.hi, - id, ast::item_mod(m0), - inner_attrs._0); + cx.next_id = p0.next_id(); vec::push[@ast::item](items, i); } case (ast::cdir_dir_mod(?id, ?dir_opt, ?cdirs)) { @@ -311,9 +306,12 @@ fn eval_crate_directive(ctx cx, env e, @ast::crate_directive cdir, str prefix, alt (dir_opt) { case (some(?d)) { path = d; } case (none) { } } auto full_path = prefix + std::fs::path_sep() + path; auto m0 = eval_crate_directives_to_mod(cx, e, cdirs, full_path); - auto i = - front::parser::mk_item(cx.p, cdir.span.lo, cdir.span.hi, id, - ast::item_mod(m0), []); + auto i = @rec(ident=id, + attrs=[], + id=cx.next_id, + node=ast::item_mod(m0), + span=cdir.span); + cx.next_id += 1; vec::push[@ast::item](items, i); } case (ast::cdir_view_item(?vi)) { diff --git a/src/comp/front/ext.rs b/src/comp/front/ext.rs index 782c135482a0..d300febbc45b 100644 --- a/src/comp/front/ext.rs +++ b/src/comp/front/ext.rs @@ -25,7 +25,7 @@ fn syntax_expander_table() -> hashmap[str, syntax_extension] { type span_msg_fn = fn(span, str) -> ! ; -type next_ann_fn = fn() -> ast::ann ; +type next_id_fn = fn() -> ast::node_id ; // Provides a limited set of services necessary for syntax extensions @@ -33,7 +33,7 @@ type next_ann_fn = fn() -> ast::ann ; type ext_ctxt = rec(span_msg_fn span_fatal, span_msg_fn span_unimpl, - next_ann_fn next_ann); + next_id_fn next_id); fn mk_ctxt(parser parser) -> ext_ctxt { auto sess = parser.get_session(); @@ -45,11 +45,11 @@ fn mk_ctxt(parser parser) -> ext_ctxt { sess.span_unimpl(sp, msg); } auto ext_span_unimpl = bind ext_span_unimpl_(sess, _, _); - fn ext_next_ann_(parser parser) -> ast::ann { parser.get_ann() } - auto ext_next_ann = bind ext_next_ann_(parser); + fn ext_next_id_(parser parser) -> ast::node_id { parser.get_id() } + auto ext_next_id = bind ext_next_id_(parser); ret rec(span_fatal=ext_span_fatal, span_unimpl=ext_span_unimpl, - next_ann=ext_next_ann); + next_id=ext_next_id); } // // Local Variables: diff --git a/src/comp/front/extenv.rs b/src/comp/front/extenv.rs index 373685a4240e..b85a54a8d9b0 100644 --- a/src/comp/front/extenv.rs +++ b/src/comp/front/extenv.rs @@ -44,7 +44,7 @@ fn expr_to_str(&ext_ctxt cx, @ast::expr expr) -> str { fn make_new_lit(&ext_ctxt cx, common::span sp, ast::lit_ lit) -> @ast::expr { auto sp_lit = @rec(node=lit, span=sp); - auto expr = ast::expr_lit(sp_lit, cx.next_ann()); + auto expr = ast::expr_lit(sp_lit, cx.next_id()); ret @rec(node=expr, span=sp); } diff --git a/src/comp/front/extfmt.rs b/src/comp/front/extfmt.rs index 831b846d5f17..42f712feefc6 100644 --- a/src/comp/front/extfmt.rs +++ b/src/comp/front/extfmt.rs @@ -56,7 +56,7 @@ fn pieces_to_expr(&ext_ctxt cx, common::span sp, vec[piece] pieces, fn make_new_lit(&ext_ctxt cx, common::span sp, ast::lit_ lit) -> @ast::expr { auto sp_lit = @rec(node=lit, span=sp); - auto expr = ast::expr_lit(sp_lit, cx.next_ann()); + auto expr = ast::expr_lit(sp_lit, cx.next_id()); ret @rec(node=expr, span=sp); } fn make_new_str(&ext_ctxt cx, common::span sp, str s) -> @ast::expr { @@ -73,7 +73,7 @@ fn pieces_to_expr(&ext_ctxt cx, common::span sp, vec[piece] pieces, } fn make_add_expr(&ext_ctxt cx, common::span sp, @ast::expr lhs, @ast::expr rhs) -> @ast::expr { - auto binexpr = ast::expr_binary(ast::add, lhs, rhs, cx.next_ann()); + auto binexpr = ast::expr_binary(ast::add, lhs, rhs, cx.next_id()); ret @rec(node=binexpr, span=sp); } fn make_path_expr(&ext_ctxt cx, common::span sp, vec[ast::ident] idents) @@ -81,21 +81,21 @@ fn pieces_to_expr(&ext_ctxt cx, common::span sp, vec[piece] pieces, let vec[@ast::ty] types = []; auto path = rec(idents=idents, types=types); auto sp_path = rec(node=path, span=sp); - auto pathexpr = ast::expr_path(sp_path, cx.next_ann()); + auto pathexpr = ast::expr_path(sp_path, cx.next_id()); auto sp_pathexpr = @rec(node=pathexpr, span=sp); ret sp_pathexpr; } fn make_vec_expr(&ext_ctxt cx, common::span sp, vec[@ast::expr] exprs) -> @ast::expr { auto vecexpr = - ast::expr_vec(exprs, ast::imm, ast::sk_rc, cx.next_ann()); + ast::expr_vec(exprs, ast::imm, ast::sk_rc, cx.next_id()); auto sp_vecexpr = @rec(node=vecexpr, span=sp); ret sp_vecexpr; } fn make_call(&ext_ctxt cx, common::span sp, vec[ast::ident] fn_path, vec[@ast::expr] args) -> @ast::expr { auto pathexpr = make_path_expr(cx, sp, fn_path); - auto callexpr = ast::expr_call(pathexpr, args, cx.next_ann()); + auto callexpr = ast::expr_call(pathexpr, args, cx.next_id()); auto sp_callexpr = @rec(node=callexpr, span=sp); ret sp_callexpr; } @@ -110,7 +110,7 @@ fn pieces_to_expr(&ext_ctxt cx, common::span sp, vec[piece] pieces, astfields += [astfield]; } auto recexpr = - ast::expr_rec(astfields, option::none[@ast::expr], cx.next_ann()); + ast::expr_rec(astfields, option::none[@ast::expr], cx.next_id()); auto sp_recexpr = @rec(node=recexpr, span=sp); ret sp_recexpr; } diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 9b4a230c0a65..b3366298e987 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -38,8 +38,6 @@ type parser = fn get_lo_pos() -> uint ; fn get_hi_pos() -> uint ; fn get_last_lo_pos() -> uint ; - fn next_def_id() -> ast::def_id ; - fn set_def(ast::def_num) ; fn get_prec_table() -> vec[op_spec] ; fn get_str(token::str_num) -> str ; fn get_reader() -> lexer::reader ; @@ -47,12 +45,12 @@ type parser = fn get_bad_expr_words() -> hashmap[str, ()] ; fn get_syntax_expanders() -> hashmap[str, ext::syntax_extension] ; fn get_chpos() -> uint ; - fn get_ann() -> ast::ann ; - fn next_ann_num() -> uint ; + fn get_id() -> ast::node_id ; + fn next_id() -> ast::node_id ; }; -fn new_parser(session::session sess, eval::env env, ast::def_id initial_def, - str path, uint pos, uint next_ann) -> parser { +fn new_parser(session::session sess, eval::env env, + str path, uint pos, ast::node_id next_id) -> parser { obj stdio_parser(session::session sess, eval::env env, file_type ftype, @@ -60,12 +58,10 @@ fn new_parser(session::session sess, eval::env env, ast::def_id initial_def, mutable uint lo, mutable uint hi, mutable uint last_lo, - mutable ast::def_num def, mutable restriction res, - ast::crate_num crate, lexer::reader rdr, vec[op_spec] precs, - mutable uint next_ann_var, + mutable ast::node_id next_id_var, hashmap[str, ()] bad_words, hashmap[str, ext::syntax_extension] syntax_expanders) { fn peek() -> token::token { ret tok; } @@ -86,8 +82,6 @@ fn new_parser(session::session sess, eval::env env, ast::def_id initial_def, fn get_lo_pos() -> uint { ret lo; } fn get_hi_pos() -> uint { ret hi; } fn get_last_lo_pos() -> uint { ret last_lo; } - fn next_def_id() -> ast::def_id { def += 1; ret tup(crate, def); } - fn set_def(ast::def_num d) { def = d; } fn get_file_type() -> file_type { ret ftype; } fn get_env() -> eval::env { ret env; } fn get_prec_table() -> vec[op_spec] { ret precs; } @@ -101,12 +95,12 @@ fn new_parser(session::session sess, eval::env env, ast::def_id initial_def, ret syntax_expanders; } fn get_chpos() -> uint { ret rdr.get_chpos(); } - fn get_ann() -> ast::ann { - auto rv = rec(id=next_ann_var); - next_ann_var += 1u; + fn get_id() -> ast::node_id { + auto rv = next_id_var; + next_id_var += 1; ret rv; } - fn next_ann_num() -> uint { ret next_ann_var; } + fn next_id() -> ast::node_id { ret next_id_var; } } auto ftype = SOURCE_FILE; if (str::ends_with(path, ".rc")) { ftype = CRATE_FILE; } @@ -120,8 +114,8 @@ fn new_parser(session::session sess, eval::env env, ast::def_id initial_def, lexer::consume_whitespace_and_comments(rdr); auto npos = rdr.get_chpos(); ret stdio_parser(sess, env, ftype, lexer::next_token(rdr), npos, npos, - npos, initial_def._1, UNRESTRICTED, initial_def._0, rdr, - prec_table(), next_ann, bad_expr_word_table(), + npos, UNRESTRICTED, rdr, + prec_table(), next_id, bad_expr_word_table(), ext::syntax_expander_table()); } @@ -378,7 +372,7 @@ fn parse_ty_constr(&vec[ast::arg] fn_args, &parser p) -> @ast::constr { // FIXME fix the def_id ret @spanned(lo, args.span.hi, - rec(path=path, args=args.node, ann=p.get_ann())); + rec(path=path, args=args.node, id=p.get_id())); } @@ -576,7 +570,7 @@ fn parse_ty(&parser p) -> @ast::ty { hi = typ.span.hi; } else if (is_ident(p.peek())) { auto path = parse_path(p); - t = ast::ty_path(path, p.get_ann()); + t = ast::ty_path(path, p.get_id()); hi = path.span.hi; } else { p.err("expecting type"); t = ast::ty_nil; fail; } ret parse_ty_postfix(@spanned(lo, hi, t), p); @@ -590,7 +584,7 @@ fn parse_arg(&parser p) -> ast::arg { } let @ast::ty t = parse_ty(p); let ast::ident i = parse_value_ident(p); - ret rec(mode=m, ty=t, ident=i, id=p.next_def_id()); + ret rec(mode=m, ty=t, ident=i, id=p.get_id()); } fn parse_seq_to_end[T](token::token ket, option::t[token::token] sep, @@ -714,7 +708,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr { // alt-exhaustive-match checking are co-operating. auto lit = @spanned(lo, hi, ast::lit_nil); - let ast::expr_ ex = ast::expr_lit(lit, p.get_ann()); + let ast::expr_ ex = ast::expr_lit(lit, p.get_id()); if (p.peek() == token::LPAREN) { p.bump(); alt (p.peek()) { @@ -722,7 +716,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr { hi = p.get_hi_pos(); p.bump(); auto lit = @spanned(lo, hi, ast::lit_nil); - ret @spanned(lo, hi, ast::expr_lit(lit, p.get_ann())); + ret @spanned(lo, hi, ast::expr_lit(lit, p.get_id())); } case (_) {/* fall through */ } } @@ -733,7 +727,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr { } else if (p.peek() == token::LBRACE) { auto blk = parse_block(p); ret @spanned(blk.span.lo, blk.span.hi, - ast::expr_block(blk, p.get_ann())); + ast::expr_block(blk, p.get_id())); } else if (eat_word(p, "if")) { ret parse_if_expr(p); } else if (eat_word(p, "for")) { @@ -758,14 +752,14 @@ fn parse_bottom_expr(&parser p) -> @ast::expr { parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_elt, p); hi = es.span.hi; - ex = ast::expr_tup(es.node, p.get_ann()); + ex = ast::expr_tup(es.node, p.get_id()); } else if (p.peek() == token::LBRACKET) { p.bump(); auto mut = parse_mutability(p); auto es = parse_seq_to_end(token::RBRACKET, some(token::COMMA), parse_expr, p); - ex = ast::expr_vec(es, mut, ast::sk_rc, p.get_ann()); + ex = ast::expr_vec(es, mut, ast::sk_rc, p.get_id()); } else if (p.peek() == token::TILDE) { p.bump(); alt (p.peek()) { @@ -776,14 +770,14 @@ fn parse_bottom_expr(&parser p) -> @ast::expr { auto es = parse_seq_to_end(token::RBRACKET, some(token::COMMA), parse_expr, p); - ex = ast::expr_vec(es, mut, ast::sk_unique, p.get_ann()); + ex = ast::expr_vec(es, mut, ast::sk_unique, p.get_id()); } case (token::LIT_STR(?s)) { p.bump(); auto lit = @rec(node=ast::lit_str(p.get_str(s), ast::sk_unique), span=p.get_span()); - ex = ast::expr_lit(lit, p.get_ann()); + ex = ast::expr_lit(lit, p.get_id()); } case (_) { p.get_session().span_unimpl(p.get_span(), @@ -824,8 +818,8 @@ fn parse_bottom_expr(&parser p) -> @ast::expr { let ast::anon_obj ob = rec(fields=fields, methods=meths, with_obj=with_obj); - auto odid = rec(ty=p.next_def_id(), ctor=p.next_def_id()); - ex = ast::expr_anon_obj(ob, ty_params, odid, p.get_ann()); + auto odid = rec(ty=p.get_id(), ctor=p.get_id()); + ex = ast::expr_anon_obj(ob, ty_params, odid, p.get_id()); } else if (eat_word(p, "rec")) { expect(p, token::LPAREN); auto fields = [parse_field(p)]; @@ -846,7 +840,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr { fields += [parse_field(p)]; } else { unexpected(p, p.peek()); } } - ex = ast::expr_rec(fields, base, p.get_ann()); + ex = ast::expr_rec(fields, base, p.get_id()); } else if (eat_word(p, "bind")) { auto e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS); fn parse_expr_opt(&parser p) -> option::t[@ast::expr] { @@ -859,7 +853,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr { parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_expr_opt, p); hi = es.span.hi; - ex = ast::expr_bind(e, es.node, p.get_ann()); + ex = ast::expr_bind(e, es.node, p.get_id()); } else if (p.peek() == token::POUND) { auto ex_ext = parse_syntax_ext(p); lo = ex_ext.span.lo; @@ -870,19 +864,19 @@ fn parse_bottom_expr(&parser p) -> @ast::expr { case (token::LIT_STR(?s)) { msg = some(p.get_str(s)); p.bump(); } case (_) { msg = none; } } - ex = ast::expr_fail(p.get_ann(), msg); + ex = ast::expr_fail(p.get_id(), msg); } else if (eat_word(p, "log")) { auto e = parse_expr(p); auto hi = e.span.hi; - ex = ast::expr_log(1, e, p.get_ann()); + ex = ast::expr_log(1, e, p.get_id()); } else if (eat_word(p, "log_err")) { auto e = parse_expr(p); auto hi = e.span.hi; - ex = ast::expr_log(0, e, p.get_ann()); + ex = ast::expr_log(0, e, p.get_id()); } else if (eat_word(p, "assert")) { auto e = parse_expr(p); auto hi = e.span.hi; - ex = ast::expr_assert(e, p.get_ann()); + ex = ast::expr_assert(e, p.get_id()); } else if (eat_word(p, "check")) { /* Should be a predicate (pure boolean function) applied to arguments that are all either slot variables or literals. @@ -890,27 +884,27 @@ fn parse_bottom_expr(&parser p) -> @ast::expr { auto e = parse_expr(p); auto hi = e.span.hi; - ex = ast::expr_check(e, p.get_ann()); + ex = ast::expr_check(e, p.get_id()); } else if (eat_word(p, "ret")) { alt (p.peek()) { - case (token::SEMI) { ex = ast::expr_ret(none, p.get_ann()); } + case (token::SEMI) { ex = ast::expr_ret(none, p.get_id()); } case (_) { auto e = parse_expr(p); hi = e.span.hi; - ex = ast::expr_ret(some(e), p.get_ann()); + ex = ast::expr_ret(some(e), p.get_id()); } } } else if (eat_word(p, "break")) { - ex = ast::expr_break(p.get_ann()); + ex = ast::expr_break(p.get_id()); } else if (eat_word(p, "cont")) { - ex = ast::expr_cont(p.get_ann()); + ex = ast::expr_cont(p.get_id()); } else if (eat_word(p, "put")) { alt (p.peek()) { - case (token::SEMI) { ex = ast::expr_put(none, p.get_ann()); } + case (token::SEMI) { ex = ast::expr_put(none, p.get_id()); } case (_) { auto e = parse_expr(p); hi = e.span.hi; - ex = ast::expr_put(some(e), p.get_ann()); + ex = ast::expr_put(some(e), p.get_id()); } } } else if (eat_word(p, "be")) { @@ -919,19 +913,19 @@ fn parse_bottom_expr(&parser p) -> @ast::expr { // FIXME: Is this the right place for this check? if (/*check*/ast::is_call_expr(e)) { hi = e.span.hi; - ex = ast::expr_be(e, p.get_ann()); + ex = ast::expr_be(e, p.get_id()); } else { p.err("Non-call expression in tail call"); } } else if (eat_word(p, "port")) { expect(p, token::LPAREN); expect(p, token::RPAREN); hi = p.get_hi_pos(); - ex = ast::expr_port(p.get_ann()); + ex = ast::expr_port(p.get_id()); } else if (eat_word(p, "chan")) { expect(p, token::LPAREN); auto e = parse_expr(p); hi = e.span.hi; expect(p, token::RPAREN); - ex = ast::expr_chan(e, p.get_ann()); + ex = ast::expr_chan(e, p.get_id()); } else if (eat_word(p, "self")) { log "parsing a self-call..."; expect(p, token::DOT); @@ -942,17 +936,17 @@ fn parse_bottom_expr(&parser p) -> @ast::expr { parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_expr, p); hi = es.span.hi; - ex = ast::expr_call(f, es.node, p.get_ann()); + ex = ast::expr_call(f, es.node, p.get_id()); } else if (is_ident(p.peek()) && !is_word(p, "true") && !is_word(p, "false")) { check_bad_word(p); auto pth = parse_path_and_ty_param_substs(p); hi = pth.span.hi; - ex = ast::expr_path(pth, p.get_ann()); + ex = ast::expr_path(pth, p.get_id()); } else { auto lit = parse_lit(p); hi = lit.span.hi; - ex = ast::expr_lit(@lit, p.get_ann()); + ex = ast::expr_lit(@lit, p.get_id()); } ret @spanned(lo, hi, ex); } @@ -989,7 +983,7 @@ fn expand_syntax_ext(&parser p, common::span sp, &ast::path path, case (some(ext::x(?ext))) { auto ext_cx = ext::mk_ctxt(p); ret ast::expr_ext(path, args, body, ext(ext_cx, sp, args, body), - p.get_ann()); + p.get_id()); } } } @@ -998,7 +992,7 @@ fn parse_self_method(&parser p) -> @ast::expr { auto sp = p.get_span(); let ast::ident f_name = parse_ident(p); auto hi = p.get_span(); - ret @rec(node=ast::expr_self_method(f_name, p.get_ann()), span=sp); + ret @rec(node=ast::expr_self_method(f_name, p.get_id()), span=sp); } fn parse_dot_or_call_expr(&parser p) -> @ast::expr { @@ -1020,7 +1014,7 @@ fn parse_dot_or_call_expr_with(&parser p, @ast::expr e) -> @ast::expr { parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_expr, p); hi = es.span.hi; - auto e_ = ast::expr_call(e, es.node, p.get_ann()); + auto e_ = ast::expr_call(e, es.node, p.get_id()); e = @spanned(lo, hi, e_); } } @@ -1031,7 +1025,7 @@ fn parse_dot_or_call_expr_with(&parser p, @ast::expr e) -> @ast::expr { hi = p.get_hi_pos(); p.bump(); auto e_ = - ast::expr_field(e, p.get_str(i), p.get_ann()); + ast::expr_field(e, p.get_str(i), p.get_id()); e = @spanned(lo, hi, e_); } case (token::LPAREN) { @@ -1039,7 +1033,7 @@ fn parse_dot_or_call_expr_with(&parser p, @ast::expr e) -> @ast::expr { auto ix = parse_expr(p); hi = ix.span.hi; expect(p, token::RPAREN); - auto e_ = ast::expr_index(e, ix, p.get_ann()); + auto e_ = ast::expr_index(e, ix, p.get_id()); e = @spanned(lo, hi, e_); } case (?t) { unexpected(p, t); } @@ -1063,13 +1057,13 @@ fn parse_prefix_expr(&parser p) -> @ast::expr { // alt-exhaustive-match checking are co-operating. auto lit = @spanned(lo, lo, ast::lit_nil); - let ast::expr_ ex = ast::expr_lit(lit, p.get_ann()); + let ast::expr_ ex = ast::expr_lit(lit, p.get_id()); alt (p.peek()) { case (token::NOT) { p.bump(); auto e = parse_prefix_expr(p); hi = e.span.hi; - ex = ast::expr_unary(ast::not, e, p.get_ann()); + ex = ast::expr_unary(ast::not, e, p.get_id()); } case (token::BINOP(?b)) { alt (b) { @@ -1077,13 +1071,13 @@ fn parse_prefix_expr(&parser p) -> @ast::expr { p.bump(); auto e = parse_prefix_expr(p); hi = e.span.hi; - ex = ast::expr_unary(ast::neg, e, p.get_ann()); + ex = ast::expr_unary(ast::neg, e, p.get_id()); } case (token::STAR) { p.bump(); auto e = parse_prefix_expr(p); hi = e.span.hi; - ex = ast::expr_unary(ast::deref, e, p.get_ann()); + ex = ast::expr_unary(ast::deref, e, p.get_id()); } case (_) { ret parse_dot_or_call_expr(p); } } @@ -1093,7 +1087,7 @@ fn parse_prefix_expr(&parser p) -> @ast::expr { auto m = parse_mutability(p); auto e = parse_prefix_expr(p); hi = e.span.hi; - ex = ast::expr_unary(ast::box(m), e, p.get_ann()); + ex = ast::expr_unary(ast::box(m), e, p.get_id()); } case (_) { ret parse_dot_or_call_expr(p); } } @@ -1141,14 +1135,14 @@ fn parse_more_binops(&parser p, @ast::expr lhs, int min_prec) -> @ast::expr { if (cur.prec > min_prec && cur.tok == peeked) { p.bump(); auto rhs = parse_more_binops(p, parse_prefix_expr(p), cur.prec); - auto bin = ast::expr_binary(cur.op, lhs, rhs, p.get_ann()); + auto bin = ast::expr_binary(cur.op, lhs, rhs, p.get_id()); auto span = @spanned(lhs.span.lo, rhs.span.hi, bin); ret parse_more_binops(p, span, min_prec); } } if (as_prec > min_prec && eat_word(p, "as")) { auto rhs = parse_ty(p); - auto _as = ast::expr_cast(lhs, rhs, p.get_ann()); + auto _as = ast::expr_cast(lhs, rhs, p.get_id()); auto span = @spanned(lhs.span.lo, rhs.span.hi, _as); ret parse_more_binops(p, span, min_prec); } @@ -1163,7 +1157,7 @@ fn parse_assign_expr(&parser p) -> @ast::expr { p.bump(); auto rhs = parse_expr(p); ret @spanned(lo, rhs.span.hi, - ast::expr_assign(lhs, rhs, p.get_ann())); + ast::expr_assign(lhs, rhs, p.get_id())); } case (token::BINOPEQ(?op)) { p.bump(); @@ -1183,31 +1177,31 @@ fn parse_assign_expr(&parser p) -> @ast::expr { case (token::ASR) { aop = ast::asr; } } ret @spanned(lo, rhs.span.hi, - ast::expr_assign_op(aop, lhs, rhs, p.get_ann())); + ast::expr_assign_op(aop, lhs, rhs, p.get_id())); } case (token::LARROW) { p.bump(); auto rhs = parse_expr(p); ret @spanned(lo, rhs.span.hi, - ast::expr_move(lhs, rhs, p.get_ann())); + ast::expr_move(lhs, rhs, p.get_id())); } case (token::SEND) { p.bump(); auto rhs = parse_expr(p); ret @spanned(lo, rhs.span.hi, - ast::expr_send(lhs, rhs, p.get_ann())); + ast::expr_send(lhs, rhs, p.get_id())); } case (token::RECV) { p.bump(); auto rhs = parse_expr(p); ret @spanned(lo, rhs.span.hi, - ast::expr_recv(lhs, rhs, p.get_ann())); + ast::expr_recv(lhs, rhs, p.get_id())); } case (token::DARROW) { p.bump(); auto rhs = parse_expr(p); ret @spanned(lo, rhs.span.hi, - ast::expr_swap(lhs, rhs, p.get_ann())); + ast::expr_swap(lhs, rhs, p.get_id())); } case (_) {/* fall through */ } } @@ -1216,7 +1210,7 @@ fn parse_assign_expr(&parser p) -> @ast::expr { fn parse_if_expr_1(&parser p) -> tup(@ast::expr, ast::block, option::t[@ast::expr], - ast::ann, uint, uint) { + ast::node_id, uint, uint) { auto lo = p.get_last_lo_pos(); expect(p, token::LPAREN); auto cond = parse_expr(p); @@ -1229,7 +1223,7 @@ fn parse_if_expr_1(&parser p) -> tup(@ast::expr, els = some(elexpr); hi = elexpr.span.hi; } - ret tup(cond, thn, els, p.get_ann(), lo, hi); + ret tup(cond, thn, els, p.get_id(), lo, hi); } fn parse_if_expr(&parser p) -> @ast::expr { @@ -1250,7 +1244,7 @@ fn parse_fn_expr(&parser p) -> @ast::expr { auto decl = parse_fn_decl(p, ast::impure_fn); auto body = parse_block(p); auto _fn = rec(decl=decl, proto=ast::proto_fn, body=body); - ret @spanned(lo, body.span.hi, ast::expr_fn(_fn, p.get_ann())); + ret @spanned(lo, body.span.hi, ast::expr_fn(_fn, p.get_id())); } fn parse_else_expr(&parser p) -> @ast::expr { @@ -1259,7 +1253,7 @@ fn parse_else_expr(&parser p) -> @ast::expr { } else { auto blk = parse_block(p); ret @spanned(blk.span.lo, blk.span.hi, - ast::expr_block(blk, p.get_ann())); + ast::expr_block(blk, p.get_id())); } } @@ -1284,9 +1278,9 @@ fn parse_for_expr(&parser p) -> @ast::expr { auto hi = body.span.hi; if (is_each) { ret @spanned(lo, hi, - ast::expr_for_each(decl, seq, body, p.get_ann())); + ast::expr_for_each(decl, seq, body, p.get_id())); } else { - ret @spanned(lo, hi, ast::expr_for(decl, seq, body, p.get_ann())); + ret @spanned(lo, hi, ast::expr_for(decl, seq, body, p.get_id())); } } @@ -1297,7 +1291,7 @@ fn parse_while_expr(&parser p) -> @ast::expr { expect(p, token::RPAREN); auto body = parse_block(p); auto hi = body.span.hi; - ret @spanned(lo, hi, ast::expr_while(cond, body, p.get_ann())); + ret @spanned(lo, hi, ast::expr_while(cond, body, p.get_id())); } fn parse_do_while_expr(&parser p) -> @ast::expr { @@ -1308,7 +1302,7 @@ fn parse_do_while_expr(&parser p) -> @ast::expr { auto cond = parse_expr(p); expect(p, token::RPAREN); auto hi = cond.span.hi; - ret @spanned(lo, hi, ast::expr_do_while(body, cond, p.get_ann())); + ret @spanned(lo, hi, ast::expr_do_while(body, cond, p.get_id())); } fn parse_alt_expr(&parser p) -> @ast::expr { @@ -1335,7 +1329,7 @@ fn parse_alt_expr(&parser p) -> @ast::expr { } auto hi = p.get_hi_pos(); p.bump(); - auto expr = ast::expr_alt(discriminant, arms, p.get_ann()); + auto expr = ast::expr_alt(discriminant, arms, p.get_id()); ret @spanned(lo, hi, expr); } @@ -1351,7 +1345,7 @@ fn parse_spawn_expr(&parser p) -> @ast::expr { auto hi = es.span.hi; auto spawn_expr = ast::expr_spawn(ast::dom_implicit, option::none, fn_expr, es.node, - p.get_ann()); + p.get_id()); ret @spanned(lo, hi, spawn_expr); } @@ -1398,7 +1392,7 @@ fn parse_pat(&parser p) -> @ast::pat { alt (p.peek()) { case (token::UNDERSCORE) { p.bump(); - pat = ast::pat_wild(p.get_ann()); + pat = ast::pat_wild(p.get_id()); } case (token::QUES) { p.bump(); @@ -1407,8 +1401,7 @@ fn parse_pat(&parser p) -> @ast::pat { hi = p.get_hi_pos(); p.bump(); pat = - ast::pat_bind(p.get_str(id), p.next_def_id(), - p.get_ann()); + ast::pat_bind(p.get_str(id), p.get_id()); } case (?tok) { p.err("expected identifier after '?' in pattern but " + @@ -1421,7 +1414,7 @@ fn parse_pat(&parser p) -> @ast::pat { if (!is_ident(tok) || is_word(p, "true") || is_word(p, "false")) { auto lit = parse_lit(p); hi = lit.span.hi; - pat = ast::pat_lit(@lit, p.get_ann()); + pat = ast::pat_lit(@lit, p.get_id()); } else { auto tag_path = parse_path_and_ty_param_substs(p); hi = tag_path.span.hi; @@ -1437,7 +1430,7 @@ fn parse_pat(&parser p) -> @ast::pat { } case (_) { args = []; } } - pat = ast::pat_tag(tag_path, args, p.get_ann()); + pat = ast::pat_tag(tag_path, args, p.get_id()); } } } @@ -1454,9 +1447,7 @@ fn parse_local_full(&option::t[@ast::ty] tyopt, &parser p) infer=false, ident=ident, init=init, - id=p.next_def_id(), - ann=p.get_ann())); - + id=p.get_id())); } fn parse_typed_local(&parser p) -> @ast::local { @@ -1497,11 +1488,11 @@ fn parse_source_stmt(&parser p) -> @ast::stmt { if (eat_word(p, "let")) { auto decl = parse_let(p); auto hi = p.get_span(); - ret @spanned(lo, decl.span.hi, ast::stmt_decl(decl, p.get_ann())); + ret @spanned(lo, decl.span.hi, ast::stmt_decl(decl, p.get_id())); } else if (eat_word(p, "auto")) { auto decl = parse_auto(p); auto hi = p.get_span(); - ret @spanned(lo, decl.span.hi, ast::stmt_decl(decl, p.get_ann())); + ret @spanned(lo, decl.span.hi, ast::stmt_decl(decl, p.get_id())); } else { auto item_attrs; @@ -1514,7 +1505,7 @@ fn parse_source_stmt(&parser p) -> @ast::stmt { } case (some(right(?ext))) { ret @spanned(lo, ext.span.hi, - ast::stmt_expr(ext, p.get_ann())); + ast::stmt_expr(ext, p.get_id())); } } @@ -1534,19 +1525,19 @@ fn parse_source_stmt(&parser p) -> @ast::stmt { case (got_item(?i)) { auto hi = i.span.hi; auto decl = @spanned(lo, hi, ast::decl_item(i)); - ret @spanned(lo, hi, ast::stmt_decl(decl, p.get_ann())); + ret @spanned(lo, hi, ast::stmt_decl(decl, p.get_id())); } case (fn_no_item) { // parse_item will have already skipped "fn" auto e = parse_fn_expr(p); e = parse_dot_or_call_expr_with(p, e); - ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_ann())); + ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_id())); } case (no_item) { // Remainder are line-expr stmts. auto e = parse_expr(p); - ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_ann())); + ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_id())); } } } @@ -1667,7 +1658,7 @@ fn parse_block(&parser p) -> ast::block { } auto hi = p.get_hi_pos(); p.bump(); - auto bloc = rec(stmts=stmts, expr=expr, a=p.get_ann()); + auto bloc = rec(stmts=stmts, expr=expr, id=p.get_id()); ret spanned(lo, hi, bloc); } @@ -1731,8 +1722,7 @@ fn mk_item(&parser p, uint lo, uint hi, &ast::ident ident, &ast::item_ node, &vec[ast::attribute] attrs) -> @ast::item { ret @rec(ident=ident, attrs=attrs, - id=p.next_def_id(), - ann=p.get_ann(), + id=p.get_id(), node=node, span=rec(lo=lo, hi=hi)); } @@ -1749,7 +1739,7 @@ fn parse_obj_field(&parser p) -> ast::obj_field { auto mut = parse_mutability(p); auto ty = parse_ty(p); auto ident = parse_value_ident(p); - ret rec(mut=mut, ty=ty, ident=ident, id=p.next_def_id(), ann=p.get_ann()); + ret rec(mut=mut, ty=ty, ident=ident, id=p.get_id()); } fn parse_method(&parser p) -> @ast::method { @@ -1757,7 +1747,7 @@ fn parse_method(&parser p) -> @ast::method { auto proto = parse_proto(p); auto ident = parse_value_ident(p); auto f = parse_fn(p, proto, ast::impure_fn); - auto meth = rec(ident=ident, meth=f, id=p.next_def_id(), ann=p.get_ann()); + auto meth = rec(ident=ident, meth=f, id=p.get_id()); ret @spanned(lo, f.body.span.hi, meth); } @@ -1776,7 +1766,7 @@ fn parse_dtor(&parser p) -> @ast::method { constraints=[]); let ast::_fn f = rec(decl=d, proto=ast::proto_fn, body=b); let ast::method_ m = - rec(ident="drop", meth=f, id=p.next_def_id(), ann=p.get_ann()); + rec(ident="drop", meth=f, id=p.get_id()); ret @spanned(lo, f.body.span.hi, m); } @@ -1801,7 +1791,7 @@ fn parse_item_obj(&parser p, ast::layer lyr, vec[ast::attribute] attrs) -> expect(p, token::RBRACE); let ast::_obj ob = rec(fields=fields.node, methods=meths, dtor=dtor); ret mk_item(p, lo, hi, ident, ast::item_obj(ob, ty_params, - p.next_def_id()), attrs); + p.get_id()), attrs); } fn parse_mod_items(&parser p, token::token term, @@ -1856,7 +1846,7 @@ fn parse_item_native_type(&parser p) -> @ast::native_item { auto t = parse_type_decl(p); auto hi = p.get_hi_pos(); expect(p, token::SEMI); - auto item = ast::native_item_ty(t._1, p.next_def_id()); + auto item = ast::native_item_ty(t._1, p.get_id()); ret @spanned(t._0, hi, item); } @@ -1872,8 +1862,7 @@ fn parse_item_native_fn(&parser p) -> @ast::native_item { auto hi = p.get_hi_pos(); expect(p, token::SEMI); auto item = - ast::native_item_fn(t._0, link_name, decl, t._1, p.next_def_id(), - p.get_ann()); + ast::native_item_fn(t._0, link_name, decl, t._1, p.get_id()); ret @spanned(lo, hi, item); } @@ -1975,19 +1964,18 @@ fn parse_item_tag(&parser p, vec[ast::attribute] attrs) -> @ast::item { parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_ty, p); for (@ast::ty ty in arg_tys.node) { - args += [rec(ty=ty, id=p.next_def_id())]; + args += [rec(ty=ty, id=p.get_id())]; } } case (_) {/* empty */ } } auto vhi = p.get_hi_pos(); expect(p, token::SEMI); - auto id = p.next_def_id(); + auto id = p.get_id(); auto vr = rec(name=p.get_str(name), args=args, - id=id, - ann=p.get_ann()); + id=p.get_id()); variants += [spanned(vlo, vhi, vr)]; } case (token::RBRACE) {/* empty */ } @@ -2165,7 +2153,7 @@ fn parse_use(&parser p) -> @ast::view_item { auto hi = p.get_hi_pos(); expect(p, token::SEMI); auto use_decl = - ast::view_item_use(ident, metadata, p.next_def_id(), p.get_ann()); + ast::view_item_use(ident, metadata, p.get_id()); ret @spanned(lo, hi, use_decl); } @@ -2201,17 +2189,17 @@ fn parse_rest_import_name(&parser p, ast::ident first, case (some(?i)) { if (glob) { p.err("globbed imports can't be renamed"); } import_decl = - ast::view_item_import(i, identifiers, p.next_def_id()); + ast::view_item_import(i, identifiers, p.get_id()); } case (_) { if (glob) { import_decl = - ast::view_item_import_glob(identifiers, p.next_def_id()); + ast::view_item_import_glob(identifiers, p.get_id()); } else { auto len = vec::len(identifiers); import_decl = ast::view_item_import(identifiers.(len - 1u), identifiers, - p.next_def_id()); + p.get_id()); } } } @@ -2254,7 +2242,7 @@ fn parse_export(&parser p) -> @ast::view_item { auto id = parse_ident(p); auto hi = p.get_hi_pos(); expect(p, token::SEMI); - ret @spanned(lo, hi, ast::view_item_export(id)); + ret @spanned(lo, hi, ast::view_item_export(id, p.get_id())); } fn parse_view_item(&parser p) -> @ast::view_item { @@ -2390,7 +2378,7 @@ fn parse_crate_from_crate_file(&parser p) -> @ast::crate { mutable deps=deps, sess=p.get_session(), mutable chpos=p.get_chpos(), - mutable next_ann=p.next_ann_num()); + mutable next_id=p.next_id()); auto m = eval::eval_crate_directives_to_mod(cx, p.get_env(), cdirs, prefix); auto hi = p.get_hi_pos(); diff --git a/src/comp/middle/alias.rs b/src/comp/middle/alias.rs index 8705b342502f..da41d0652296 100644 --- a/src/comp/middle/alias.rs +++ b/src/comp/middle/alias.rs @@ -1,7 +1,8 @@ import front::ast; import front::ast::ident; -import front::ast::def_num; +import front::ast::node_id; +import front::ast::def_id; import util::common::span; import visit::vt; import std::vec; @@ -22,9 +23,9 @@ import std::option::is_none; tag valid { valid; overwritten(span, ast::path); val_taken(span, ast::path); } type restrict = - @rec(vec[def_num] root_vars, - def_num block_defnum, - vec[def_num] bindings, + @rec(vec[node_id] root_vars, + node_id block_defnum, + vec[node_id] bindings, vec[ty::t] tys, vec[uint] depends_on, mutable valid ok); @@ -33,8 +34,8 @@ type scope = vec[restrict]; tag local_info { arg(ast::mode); objfield(ast::mutability); } -type ctx = - rec(@ty::ctxt tcx, std::map::hashmap[def_num, local_info] local_map); +type ctx = rec(@ty::ctxt tcx, + std::map::hashmap[node_id, local_info] local_map); fn check_crate(@ty::ctxt tcx, &@ast::crate crate) { auto cx = @@ -44,7 +45,7 @@ fn check_crate(@ty::ctxt tcx, &@ast::crate crate) { // arguments that's otherwise not easily available. local_map=util::common::new_int_hash()); auto v = - @rec(visit_fn=bind visit_fn(cx, _, _, _, _, _, _, _, _), + @rec(visit_fn=bind visit_fn(cx, _, _, _, _, _, _, _), visit_item=bind visit_item(cx, _, _, _), visit_expr=bind visit_expr(cx, _, _, _) with *visit::default_visitor[scope]()); @@ -52,11 +53,10 @@ fn check_crate(@ty::ctxt tcx, &@ast::crate crate) { } fn visit_fn(@ctx cx, &ast::_fn f, &vec[ast::ty_param] tp, &span sp, - &ident name, &ast::def_id d_id, &ast::ann a, &scope sc, - &vt[scope] v) { + &ident name, ast::node_id id, &scope sc, &vt[scope] v) { visit::visit_fn_decl(f.decl, sc, v); for (ast::arg arg_ in f.decl.inputs) { - cx.local_map.insert(arg_.id._1, arg(arg_.mode)); + cx.local_map.insert(arg_.id, arg(arg_.mode)); } vt(v).visit_block(f.body, [], v); } @@ -65,7 +65,7 @@ fn visit_item(@ctx cx, &@ast::item i, &scope sc, &vt[scope] v) { alt (i.node) { case (ast::item_obj(?o, _, _)) { for (ast::obj_field f in o.fields) { - cx.local_map.insert(f.id._1, objfield(f.mut)); + cx.local_map.insert(f.id, objfield(f.mut)); } } case (_) { } @@ -107,8 +107,8 @@ fn visit_expr(@ctx cx, &@ast::expr ex, &scope sc, &vt[scope] v) { case (ast::expr_for(?decl, ?seq, ?block, _)) { check_for(*cx, decl, seq, block, sc, v); } - case (ast::expr_path(?pt, ?ann)) { - check_var(*cx, ex, pt, ann, false, sc); + case (ast::expr_path(?pt, ?id)) { + check_var(*cx, ex, pt, id, false, sc); handled = false; } case (ast::expr_move(?dest, ?src, _)) { @@ -126,11 +126,11 @@ fn visit_expr(@ctx cx, &@ast::expr ex, &scope sc, &vt[scope] v) { } fn check_call(&ctx cx, &@ast::expr f, &vec[@ast::expr] args, &scope sc) -> - rec(vec[def_num] root_vars, vec[ty::t] unsafe_ts) { + rec(vec[node_id] root_vars, vec[ty::t] unsafe_ts) { auto fty = ty::expr_ty(*cx.tcx, f); auto arg_ts = fty_args(cx, fty); - let vec[def_num] roots = []; - let vec[tup(uint, def_num)] mut_roots = []; + let vec[node_id] roots = []; + let vec[tup(uint, node_id)] mut_roots = []; let vec[ty::t] unsafe_ts = []; let vec[uint] unsafe_t_offsets = []; auto i = 0u; @@ -169,8 +169,8 @@ fn check_call(&ctx cx, &@ast::expr f, &vec[@ast::expr] args, &scope sc) -> } if (vec::len(unsafe_ts) > 0u) { alt (f.node) { - case (ast::expr_path(_, ?ann)) { - if (def_is_local(cx.tcx.def_map.get(ann.id), true)) { + case (ast::expr_path(_, ?id)) { + if (def_is_local(cx.tcx.def_map.get(id), true)) { cx.tcx.sess.span_fatal(f.span, #fmt("function may alias with \ argument %u, which is not immutably rooted", @@ -200,7 +200,7 @@ fn check_call(&ctx cx, &@ast::expr f, &vec[@ast::expr] args, &scope sc) -> } // Ensure we're not passing a root by mutable alias. - for (tup(uint, def_num) root in mut_roots) { + for (tup(uint, node_id) root in mut_roots) { auto mut_alias_to_root = vec::count(root._1, roots) > 1u; for (restrict r in sc) { if (vec::member(root._1, r.root_vars)) { @@ -228,8 +228,8 @@ fn check_tail_call(&ctx cx, &@ast::expr call) { auto mut_a = arg_t.mode == ty::mo_alias(true); auto ok = true; alt (args.(i).node) { - case (ast::expr_path(_, ?ann)) { - auto def = cx.tcx.def_map.get(ann.id); + case (ast::expr_path(_, ?id)) { + auto def = cx.tcx.def_map.get(id); auto dnum = ast::def_id_of_def(def)._1; alt (cx.local_map.find(dnum)) { case (some(arg(ast::alias(?mut)))) { @@ -282,11 +282,11 @@ fn check_alt(&ctx cx, &@ast::expr input, &vec[ast::arm] arms, &scope sc, } } -fn arm_defnums(&ast::arm arm) -> vec[def_num] { +fn arm_defnums(&ast::arm arm) -> vec[node_id] { auto dnums = []; - fn walk_pat(&mutable vec[def_num] found, &@ast::pat p) { + fn walk_pat(&mutable vec[node_id] found, &@ast::pat p) { alt (p.node) { - case (ast::pat_bind(_, ?did, _)) { vec::push(found, did._1); } + case (ast::pat_bind(_, ?id)) { vec::push(found, id); } case (ast::pat_tag(_, ?children, _)) { for (@ast::pat child in children) { walk_pat(found, child); } } @@ -303,7 +303,7 @@ fn check_for_each(&ctx cx, &@ast::local local, &@ast::expr call, alt (call.node) { case (ast::expr_call(?f, ?args, _)) { auto data = check_call(cx, f, args, sc); - auto defnum = local.node.id._1; + auto defnum = local.node.id; auto new_sc = @rec(root_vars=data.root_vars, block_defnum=defnum, @@ -319,7 +319,7 @@ fn check_for_each(&ctx cx, &@ast::local local, &@ast::expr call, fn check_for(&ctx cx, &@ast::local local, &@ast::expr seq, &ast::block block, &scope sc, &vt[scope] v) { visit::visit_expr(seq, sc, v); - auto defnum = local.node.id._1; + auto defnum = local.node.id; auto root = expr_root(cx, seq, false); auto root_def = alt (path_def_id(cx, root.ex)) { @@ -347,9 +347,9 @@ fn check_for(&ctx cx, &@ast::local local, &@ast::expr seq, &ast::block block, visit::visit_block(block, sc + [new_sc], v); } -fn check_var(&ctx cx, &@ast::expr ex, &ast::path p, ast::ann ann, bool assign, - &scope sc) { - auto def = cx.tcx.def_map.get(ann.id); +fn check_var(&ctx cx, &@ast::expr ex, &ast::path p, ast::node_id id, + bool assign, &scope sc) { + auto def = cx.tcx.def_map.get(id); if (!def_is_local(def, true)) { ret; } auto my_defnum = ast::def_id_of_def(def)._1; auto var_t = ty::expr_ty(*cx.tcx, ex); @@ -374,8 +374,8 @@ fn check_assign(&@ctx cx, &@ast::expr dest, &@ast::expr src, &scope sc, &vt[scope] v) { visit_expr(cx, src, sc, v); alt (dest.node) { - case (ast::expr_path(?p, ?ann)) { - auto dnum = ast::def_id_of_def(cx.tcx.def_map.get(ann.id))._1; + case (ast::expr_path(?p, ?id)) { + auto dnum = ast::def_id_of_def(cx.tcx.def_map.get(id))._1; if (is_immutable_alias(cx, sc, dnum)) { cx.tcx.sess.span_fatal(dest.span, "assigning to immutable alias"); @@ -389,7 +389,7 @@ fn check_assign(&@ctx cx, &@ast::expr dest, &@ast::expr src, &scope sc, r.ok = overwritten(dest.span, p); } } - check_var(*cx, dest, p, ann, true, sc); + check_var(*cx, dest, p, id, true, sc); } case (_) { auto root = expr_root(*cx, dest, false); @@ -410,7 +410,7 @@ fn check_assign(&@ctx cx, &@ast::expr dest, &@ast::expr src, &scope sc, } } -fn is_immutable_alias(&@ctx cx, &scope sc, def_num dnum) -> bool { +fn is_immutable_alias(&@ctx cx, &scope sc, node_id dnum) -> bool { alt (cx.local_map.find(dnum)) { case (some(arg(ast::alias(false)))) { ret true; } case (_) { } @@ -421,7 +421,7 @@ fn is_immutable_alias(&@ctx cx, &scope sc, def_num dnum) -> bool { ret false; } -fn is_immutable_objfield(&@ctx cx, def_num dnum) -> bool { +fn is_immutable_objfield(&@ctx cx, node_id dnum) -> bool { ret cx.local_map.find(dnum) == some(objfield(ast::imm)); } @@ -447,11 +447,11 @@ fn test_scope(&ctx cx, &scope sc, &restrict r, &ast::path p) { } } -fn deps(&scope sc, vec[def_num] roots) -> vec[uint] { +fn deps(&scope sc, vec[node_id] roots) -> vec[uint] { auto i = 0u; auto result = []; for (restrict r in sc) { - for (def_num dn in roots) { + for (node_id dn in roots) { if (vec::member(dn, r.bindings)) { vec::push(result, i); } } i += 1u; @@ -567,8 +567,8 @@ fn inner_mut(&vec[deref] ds) -> option::t[ty::t] { fn path_def_id(&ctx cx, &@ast::expr ex) -> option::t[ast::def_id] { alt (ex.node) { - case (ast::expr_path(_, ?ann)) { - ret some(ast::def_id_of_def(cx.tcx.def_map.get(ann.id))); + case (ast::expr_path(_, ?id)) { + ret some(ast::def_id_of_def(cx.tcx.def_map.get(id))); } case (_) { ret none; } } diff --git a/src/comp/middle/ast_map.rs b/src/comp/middle/ast_map.rs new file mode 100644 index 000000000000..ca486a6e5f3e --- /dev/null +++ b/src/comp/middle/ast_map.rs @@ -0,0 +1,56 @@ +import front::ast::*; +import visit::vt; + +tag ast_node { + node_item(@item); + node_obj_ctor(@item); + node_native_item(@native_item); + node_expr(@expr); +} + +type map = std::map::hashmap[node_id, ast_node]; + +fn map_crate(&crate c) -> map { + auto map = util::common::new_int_hash[ast_node](); + + auto v_map = @rec(visit_item=bind map_item(map, _, _, _), + visit_native_item=bind map_native_item(map, _, _, _), + visit_expr=bind map_expr(map, _, _, _) + with *visit::default_visitor[()]()); + visit::visit_crate(c, (), visit::vtor(v_map)); + ret map; +} + +fn map_item(&map map, &@item i, &() e, &vt[()] v) { + map.insert(i.id, node_item(i)); + alt (i.node) { + case (item_obj(_, _, ?ctor_id)) { + map.insert(ctor_id, node_obj_ctor(i)); + } + case (_) {} + } + visit::visit_item(i, e, v); +} + +fn map_native_item(&map map, &@native_item i, &() e, &vt[()] v) { + auto id = alt (i.node) { + case (native_item_ty(_, ?id)) { id } + case (native_item_fn(_, _, _, _, ?id)) { id } + }; + map.insert(id, node_native_item(i)); + visit::visit_native_item(i, e, v); +} + +fn map_expr(&map map, &@expr ex, &() e, &vt[()] v) { + map.insert(ty::expr_node_id(ex), node_expr(ex)); + visit::visit_expr(ex, e, v); +} + +// Local Variables: +// mode: rust +// fill-column: 78; +// indent-tabs-mode: nil +// c-basic-offset: 4 +// buffer-file-coding-system: utf-8-unix +// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; +// End: diff --git a/src/comp/middle/metadata.rs b/src/comp/middle/metadata.rs index 25973458e5c1..29ef13f59e07 100644 --- a/src/comp/middle/metadata.rs +++ b/src/comp/middle/metadata.rs @@ -8,7 +8,6 @@ import std::io; import std::option; import std::option::some; import std::option::none; -import front::ast; import front::ast::*; import middle::trans; import middle::ty; @@ -83,7 +82,7 @@ tag abbrev_ctxt { ac_no_abbrevs; ac_use_abbrevs(hashmap[ty::t, ty_abbrev]); } mod Encode { type ctxt = - rec(fn(&ast::def_id) -> str ds, // Def -> str Callback: + rec(fn(&def_id) -> str ds, // Def -> str Callback: ty::ctxt tcx, // The type context. @@ -149,9 +148,9 @@ mod Encode { } fn enc_mt(&io::writer w, &@ctxt cx, &ty::mt mt) { alt (mt.mut) { - case (ast::imm) { } - case (ast::mut) { w.write_char('m'); } - case (ast::maybe_mut) { w.write_char('?'); } + case (imm) { } + case (mut) { w.write_char('m'); } + case (maybe_mut) { w.write_char('?'); } } enc_ty(w, cx, mt.ty); } @@ -214,14 +213,14 @@ mod Encode { case (ty::ty_native_fn(?abi, ?args, ?out)) { w.write_char('N'); alt (abi) { - case (ast::native_abi_rust) { w.write_char('r'); } - case (ast::native_abi_rust_intrinsic) { + case (native_abi_rust) { w.write_char('r'); } + case (native_abi_rust_intrinsic) { w.write_char('i'); } - case (ast::native_abi_cdecl) { w.write_char('c'); } - case (ast::native_abi_llvm) { w.write_char('l'); } + case (native_abi_cdecl) { w.write_char('c'); } + case (native_abi_llvm) { w.write_char('l'); } } - enc_ty_fn(w, cx, args, out, ast::return, []); + enc_ty_fn(w, cx, args, out, return, []); } case (ty::ty_obj(?methods)) { w.write_str("O["); @@ -245,14 +244,14 @@ mod Encode { case (ty::ty_task) { w.write_char('a'); } } } - fn enc_proto(&io::writer w, ast::proto proto) { + fn enc_proto(&io::writer w, proto proto) { alt (proto) { - case (ast::proto_iter) { w.write_char('W'); } - case (ast::proto_fn) { w.write_char('F'); } + case (proto_iter) { w.write_char('W'); } + case (proto_fn) { w.write_char('F'); } } } fn enc_ty_fn(&io::writer w, &@ctxt cx, &vec[ty::arg] args, &ty::t out, - &ast::controlflow cf, &vec[@ty::constr_def] constrs) { + &controlflow cf, &vec[@ty::constr_def] constrs) { w.write_char('['); for (ty::arg arg in args) { alt (arg.mode) { @@ -266,7 +265,7 @@ mod Encode { } w.write_char(']'); alt (cf) { - case (ast::noreturn) { w.write_char('!'); } + case (noreturn) { w.write_char('!'); } case (_) { enc_ty(w, cx, out); } } auto colon = true; @@ -310,20 +309,20 @@ fn encode_name(&ebml::writer ebml_w, &str name) { ebml::end_tag(ebml_w); } -fn encode_def_id(&ebml::writer ebml_w, &ast::def_id id) { +fn encode_def_id(&ebml::writer ebml_w, &def_id id) { ebml::start_tag(ebml_w, tag_def_id); ebml_w.writer.write(str::bytes(def_to_str(id))); ebml::end_tag(ebml_w); } -fn encode_tag_variant_paths(&ebml::writer ebml_w, &vec[ast::variant] variants, +fn encode_tag_variant_paths(&ebml::writer ebml_w, &vec[variant] variants, &vec[str] path, &mutable vec[tup(str, uint)] index) { - for (ast::variant variant in variants) { + for (variant variant in variants) { add_to_index(ebml_w, path, index, variant.node.name); ebml::start_tag(ebml_w, tag_paths_data_item); encode_name(ebml_w, variant.node.name); - encode_def_id(ebml_w, variant.node.id); + encode_def_id(ebml_w, local_def(variant.node.id)); ebml::end_tag(ebml_w); } } @@ -335,98 +334,98 @@ fn add_to_index(&ebml::writer ebml_w, &vec[str] path, } fn encode_native_module_item_paths(&ebml::writer ebml_w, - &ast::native_mod nmod, &vec[str] path, + &native_mod nmod, &vec[str] path, &mutable vec[tup(str, uint)] index) { - for (@ast::native_item nitem in nmod.items) { + for (@native_item nitem in nmod.items) { alt (nitem.node) { - case (ast::native_item_ty(?id, ?did)) { - add_to_index(ebml_w, path, index, id); + case (native_item_ty(?ident, ?id)) { + add_to_index(ebml_w, path, index, ident); ebml::start_tag(ebml_w, tag_paths_data_item); - encode_name(ebml_w, id); - encode_def_id(ebml_w, did); + encode_name(ebml_w, ident); + encode_def_id(ebml_w, local_def(id)); ebml::end_tag(ebml_w); } - case (ast::native_item_fn(?id, _, _, _, ?did, _)) { - add_to_index(ebml_w, path, index, id); + case (native_item_fn(?ident, _, _, _, ?id)) { + add_to_index(ebml_w, path, index, ident); ebml::start_tag(ebml_w, tag_paths_data_item); - encode_name(ebml_w, id); - encode_def_id(ebml_w, did); + encode_name(ebml_w, ident); + encode_def_id(ebml_w, local_def(id)); ebml::end_tag(ebml_w); } } } } -fn encode_module_item_paths(&ebml::writer ebml_w, &ast::_mod module, +fn encode_module_item_paths(&ebml::writer ebml_w, &_mod module, &vec[str] path, &mutable vec[tup(str, uint)] index) { - for (@ast::item it in module.items) { - if (!ast::is_exported(it.ident, module)) { cont; } + for (@item it in module.items) { + if (!is_exported(it.ident, module)) { cont; } alt (it.node) { - case (ast::item_const(_, _)) { + case (item_const(_, _)) { add_to_index(ebml_w, path, index, it.ident); ebml::start_tag(ebml_w, tag_paths_data_item); encode_name(ebml_w, it.ident); - encode_def_id(ebml_w, it.id); + encode_def_id(ebml_w, local_def(it.id)); ebml::end_tag(ebml_w); } - case (ast::item_fn(_, ?tps)) { + case (item_fn(_, ?tps)) { add_to_index(ebml_w, path, index, it.ident); ebml::start_tag(ebml_w, tag_paths_data_item); encode_name(ebml_w, it.ident); - encode_def_id(ebml_w, it.id); + encode_def_id(ebml_w, local_def(it.id)); ebml::end_tag(ebml_w); } - case (ast::item_mod(?_mod)) { + case (item_mod(?_mod)) { add_to_index(ebml_w, path, index, it.ident); ebml::start_tag(ebml_w, tag_paths_data_mod); encode_name(ebml_w, it.ident); - encode_def_id(ebml_w, it.id); + encode_def_id(ebml_w, local_def(it.id)); encode_module_item_paths(ebml_w, _mod, path + [it.ident], index); ebml::end_tag(ebml_w); } - case (ast::item_native_mod(?nmod)) { + case (item_native_mod(?nmod)) { add_to_index(ebml_w, path, index, it.ident); ebml::start_tag(ebml_w, tag_paths_data_mod); encode_name(ebml_w, it.ident); - encode_def_id(ebml_w, it.id); + encode_def_id(ebml_w, local_def(it.id)); encode_native_module_item_paths(ebml_w, nmod, path + [it.ident], index); ebml::end_tag(ebml_w); } - case (ast::item_ty(_, ?tps)) { + case (item_ty(_, ?tps)) { add_to_index(ebml_w, path, index, it.ident); ebml::start_tag(ebml_w, tag_paths_data_item); encode_name(ebml_w, it.ident); - encode_def_id(ebml_w, it.id); + encode_def_id(ebml_w, local_def(it.id)); ebml::end_tag(ebml_w); } - case (ast::item_tag(?variants, ?tps)) { + case (item_tag(?variants, ?tps)) { add_to_index(ebml_w, path, index, it.ident); ebml::start_tag(ebml_w, tag_paths_data_item); encode_name(ebml_w, it.ident); - encode_def_id(ebml_w, it.id); + encode_def_id(ebml_w, local_def(it.id)); ebml::end_tag(ebml_w); encode_tag_variant_paths(ebml_w, variants, path, index); } - case (ast::item_obj(_, ?tps, ?ctor_id)) { + case (item_obj(_, ?tps, ?ctor_id)) { add_to_index(ebml_w, path, index, it.ident); ebml::start_tag(ebml_w, tag_paths_data_item); encode_name(ebml_w, it.ident); - encode_def_id(ebml_w, ctor_id); + encode_def_id(ebml_w, local_def(ctor_id)); ebml::end_tag(ebml_w); add_to_index(ebml_w, path, index, it.ident); ebml::start_tag(ebml_w, tag_paths_data_item); encode_name(ebml_w, it.ident); - encode_def_id(ebml_w, it.id); + encode_def_id(ebml_w, local_def(it.id)); ebml::end_tag(ebml_w); } } } } -fn encode_item_paths(&ebml::writer ebml_w, &@ast::crate crate) -> +fn encode_item_paths(&ebml::writer ebml_w, &@crate crate) -> vec[tup(str, uint)] { let vec[tup(str, uint)] index = []; let vec[str] path = []; @@ -444,15 +443,15 @@ fn encode_kind(&ebml::writer ebml_w, u8 c) { ebml::end_tag(ebml_w); } -fn def_to_str(&ast::def_id did) -> str { ret #fmt("%d:%d", did._0, did._1); } +fn def_to_str(&def_id did) -> str { ret #fmt("%d:%d", did._0, did._1); } -fn encode_type_param_count(&ebml::writer ebml_w, &vec[ast::ty_param] tps) { +fn encode_type_param_count(&ebml::writer ebml_w, &vec[ty_param] tps) { ebml::start_tag(ebml_w, tag_items_data_item_ty_param_count); - ebml::write_vint(ebml_w.writer, vec::len[ast::ty_param](tps)); + ebml::write_vint(ebml_w.writer, vec::len[ty_param](tps)); ebml::end_tag(ebml_w); } -fn encode_variant_id(&ebml::writer ebml_w, &ast::def_id vid) { +fn encode_variant_id(&ebml::writer ebml_w, &def_id vid) { ebml::start_tag(ebml_w, tag_items_data_item_variant); ebml_w.writer.write(str::bytes(def_to_str(vid))); ebml::end_tag(ebml_w); @@ -468,37 +467,37 @@ fn encode_type(&@trans::crate_ctxt cx, &ebml::writer ebml_w, &ty::t typ) { } fn encode_symbol(&@trans::crate_ctxt cx, &ebml::writer ebml_w, - &ast::def_id did) { + node_id id) { ebml::start_tag(ebml_w, tag_items_data_item_symbol); - ebml_w.writer.write(str::bytes(cx.item_symbols.get(did))); + ebml_w.writer.write(str::bytes(cx.item_symbols.get(id))); ebml::end_tag(ebml_w); } fn encode_discriminant(&@trans::crate_ctxt cx, &ebml::writer ebml_w, - &ast::def_id did) { + node_id id) { ebml::start_tag(ebml_w, tag_items_data_item_symbol); - ebml_w.writer.write(str::bytes(cx.discrim_symbols.get(did))); + ebml_w.writer.write(str::bytes(cx.discrim_symbols.get(id))); ebml::end_tag(ebml_w); } -fn encode_tag_id(&ebml::writer ebml_w, &ast::def_id id) { +fn encode_tag_id(&ebml::writer ebml_w, &def_id id) { ebml::start_tag(ebml_w, tag_items_data_item_tag_id); ebml_w.writer.write(str::bytes(def_to_str(id))); ebml::end_tag(ebml_w); } fn encode_tag_variant_info(&@trans::crate_ctxt cx, &ebml::writer ebml_w, - &ast::def_id did, &vec[ast::variant] variants, + node_id id, &vec[variant] variants, &mutable vec[tup(int, uint)] index, - &vec[ast::ty_param] ty_params) { - for (ast::variant variant in variants) { - index += [tup(variant.node.id._1, ebml_w.writer.tell())]; + &vec[ty_param] ty_params) { + for (variant variant in variants) { + index += [tup(variant.node.id, ebml_w.writer.tell())]; ebml::start_tag(ebml_w, tag_items_data_item); - encode_def_id(ebml_w, variant.node.id); + encode_def_id(ebml_w, local_def(variant.node.id)); encode_kind(ebml_w, 'v' as u8); - encode_tag_id(ebml_w, did); - encode_type(cx, ebml_w, trans::node_ann_type(cx, variant.node.ann)); - if (vec::len[ast::variant_arg](variant.node.args) > 0u) { + encode_tag_id(ebml_w, local_def(id)); + encode_type(cx, ebml_w, trans::node_id_type(cx, variant.node.id)); + if (vec::len[variant_arg](variant.node.args) > 0u) { encode_symbol(cx, ebml_w, variant.node.id); } encode_discriminant(cx, ebml_w, variant.node.id); @@ -508,70 +507,70 @@ fn encode_tag_variant_info(&@trans::crate_ctxt cx, &ebml::writer ebml_w, } fn encode_info_for_item(@trans::crate_ctxt cx, &ebml::writer ebml_w, - @ast::item item, &mutable vec[tup(int, uint)] index) { + @item item, &mutable vec[tup(int, uint)] index) { alt (item.node) { - case (ast::item_const(_, _)) { + case (item_const(_, _)) { ebml::start_tag(ebml_w, tag_items_data_item); - encode_def_id(ebml_w, item.id); + encode_def_id(ebml_w, local_def(item.id)); encode_kind(ebml_w, 'c' as u8); - encode_type(cx, ebml_w, trans::node_ann_type(cx, item.ann)); + encode_type(cx, ebml_w, trans::node_id_type(cx, item.id)); encode_symbol(cx, ebml_w, item.id); ebml::end_tag(ebml_w); } - case (ast::item_fn(_, ?tps)) { + case (item_fn(_, ?tps)) { ebml::start_tag(ebml_w, tag_items_data_item); - encode_def_id(ebml_w, item.id); + encode_def_id(ebml_w, local_def(item.id)); encode_kind(ebml_w, 'f' as u8); encode_type_param_count(ebml_w, tps); - encode_type(cx, ebml_w, trans::node_ann_type(cx, item.ann)); + encode_type(cx, ebml_w, trans::node_id_type(cx, item.id)); encode_symbol(cx, ebml_w, item.id); ebml::end_tag(ebml_w); } - case (ast::item_mod(_)) { + case (item_mod(_)) { ebml::start_tag(ebml_w, tag_items_data_item); - encode_def_id(ebml_w, item.id); + encode_def_id(ebml_w, local_def(item.id)); encode_kind(ebml_w, 'm' as u8); ebml::end_tag(ebml_w); } - case (ast::item_native_mod(_)) { + case (item_native_mod(_)) { ebml::start_tag(ebml_w, tag_items_data_item); - encode_def_id(ebml_w, item.id); + encode_def_id(ebml_w, local_def(item.id)); encode_kind(ebml_w, 'n' as u8); ebml::end_tag(ebml_w); } - case (ast::item_ty(_, ?tps)) { + case (item_ty(_, ?tps)) { ebml::start_tag(ebml_w, tag_items_data_item); - encode_def_id(ebml_w, item.id); + encode_def_id(ebml_w, local_def(item.id)); encode_kind(ebml_w, 'y' as u8); encode_type_param_count(ebml_w, tps); - encode_type(cx, ebml_w, trans::node_ann_type(cx, item.ann)); + encode_type(cx, ebml_w, trans::node_id_type(cx, item.id)); ebml::end_tag(ebml_w); } - case (ast::item_tag(?variants, ?tps)) { + case (item_tag(?variants, ?tps)) { ebml::start_tag(ebml_w, tag_items_data_item); - encode_def_id(ebml_w, item.id); + encode_def_id(ebml_w, local_def(item.id)); encode_kind(ebml_w, 't' as u8); encode_type_param_count(ebml_w, tps); - encode_type(cx, ebml_w, trans::node_ann_type(cx, item.ann)); - for (ast::variant v in variants) { - encode_variant_id(ebml_w, v.node.id); + encode_type(cx, ebml_w, trans::node_id_type(cx, item.id)); + for (variant v in variants) { + encode_variant_id(ebml_w, local_def(v.node.id)); } ebml::end_tag(ebml_w); encode_tag_variant_info(cx, ebml_w, item.id, variants, index, tps); } - case (ast::item_obj(_, ?tps, ?ctor_id)) { + case (item_obj(_, ?tps, ?ctor_id)) { ebml::start_tag(ebml_w, tag_items_data_item); - encode_def_id(ebml_w, ctor_id); + encode_def_id(ebml_w, local_def(ctor_id)); encode_kind(ebml_w, 'o' as u8); encode_type_param_count(ebml_w, tps); - auto fn_ty = trans::node_ann_type(cx, item.ann); + auto fn_ty = trans::node_id_type(cx, item.id); encode_type(cx, ebml_w, fn_ty); encode_symbol(cx, ebml_w, ctor_id); ebml::end_tag(ebml_w); - index += [tup(item.id._1, ebml_w.writer.tell())]; + index += [tup(item.id, ebml_w.writer.tell())]; ebml::start_tag(ebml_w, tag_items_data_item); - encode_def_id(ebml_w, item.id); + encode_def_id(ebml_w, local_def(item.id)); encode_kind(ebml_w, 'y' as u8); encode_type_param_count(ebml_w, tps); encode_type(cx, ebml_w, ty::ty_fn_ret(cx.tcx, fn_ty)); @@ -581,20 +580,20 @@ fn encode_info_for_item(@trans::crate_ctxt cx, &ebml::writer ebml_w, } fn encode_info_for_native_item(&@trans::crate_ctxt cx, &ebml::writer ebml_w, - &@ast::native_item nitem) { + &@native_item nitem) { ebml::start_tag(ebml_w, tag_items_data_item); alt (nitem.node) { - case (ast::native_item_ty(_, ?did)) { - encode_def_id(ebml_w, did); + case (native_item_ty(_, ?id)) { + encode_def_id(ebml_w, local_def(id)); encode_kind(ebml_w, 'T' as u8); encode_type(cx, ebml_w, ty::mk_native(cx.tcx)); } - case (ast::native_item_fn(_, _, _, ?tps, ?did, ?ann)) { - encode_def_id(ebml_w, did); + case (native_item_fn(_, _, _, ?tps, ?id)) { + encode_def_id(ebml_w, local_def(id)); encode_kind(ebml_w, 'F' as u8); encode_type_param_count(ebml_w, tps); - encode_type(cx, ebml_w, trans::node_ann_type(cx, ann)); - encode_symbol(cx, ebml_w, did); + encode_type(cx, ebml_w, trans::node_id_type(cx, id)); + encode_symbol(cx, ebml_w, id); } } ebml::end_tag(ebml_w); @@ -604,13 +603,13 @@ fn encode_info_for_items(&@trans::crate_ctxt cx, &ebml::writer ebml_w) -> vec[tup(int, uint)] { let vec[tup(int, uint)] index = []; ebml::start_tag(ebml_w, tag_items_data); - for each (@tup(ast::def_id, @ast::item) kvp in cx.items.items()) { - index += [tup(kvp._0._1, ebml_w.writer.tell())]; + for each (@tup(node_id, @item) kvp in cx.items.items()) { + index += [tup(kvp._0, ebml_w.writer.tell())]; encode_info_for_item(cx, ebml_w, kvp._1, index); } - for each (@tup(ast::def_id, @ast::native_item) kvp in + for each (@tup(node_id, @native_item) kvp in cx.native_items.items()) { - index += [tup(kvp._0._1, ebml_w.writer.tell())]; + index += [tup(kvp._0, ebml_w.writer.tell())]; encode_info_for_native_item(cx, ebml_w, kvp._1); } ebml::end_tag(ebml_w); @@ -621,7 +620,7 @@ fn encode_info_for_items(&@trans::crate_ctxt cx, &ebml::writer ebml_w) -> // Path and definition ID indexing // djb's cdb hashes. -fn hash_def_num(&int def_num) -> uint { ret 177573u ^ (def_num as uint); } +fn hash_def_id(&int def_id) -> uint { ret 177573u ^ (def_id as uint); } fn hash_path(&str s) -> uint { auto h = 5381u; @@ -670,8 +669,8 @@ fn write_int(&io::writer writer, &int n) { writer.write_be_uint(n as uint, 4u); } -fn encode_meta_items(&ebml::writer ebml_w, &ast::crate crate) { - fn encode_meta_item(&ebml::writer ebml_w, &ast::meta_item mi) { +fn encode_meta_items(&ebml::writer ebml_w, &crate crate) { + fn encode_meta_item(&ebml::writer ebml_w, &meta_item mi) { ebml::start_tag(ebml_w, tag_meta_item); ebml::start_tag(ebml_w, tag_meta_item_key); ebml_w.writer.write(str::bytes(mi.node.key)); @@ -682,18 +681,18 @@ fn encode_meta_items(&ebml::writer ebml_w, &ast::crate crate) { ebml::end_tag(ebml_w); } ebml::start_tag(ebml_w, tag_meta_export); - for each (@ast::meta_item mi in link::crate_export_metas(crate)) { + for each (@meta_item mi in link::crate_export_metas(crate)) { encode_meta_item(ebml_w, *mi); } ebml::end_tag(ebml_w); ebml::start_tag(ebml_w, tag_meta_local); - for each (@ast::meta_item mi in link::crate_local_metas(crate)) { + for each (@meta_item mi in link::crate_local_metas(crate)) { encode_meta_item(ebml_w, *mi); } ebml::end_tag(ebml_w); } -fn encode_metadata(&@trans::crate_ctxt cx, &@ast::crate crate) -> ValueRef { +fn encode_metadata(&@trans::crate_ctxt cx, &@crate crate) -> ValueRef { auto string_w = io::string_writer(); auto buf_w = string_w.get_writer().get_buf_writer(); auto ebml_w = ebml::create_writer(buf_w); @@ -714,7 +713,7 @@ fn encode_metadata(&@trans::crate_ctxt cx, &@ast::crate crate) -> ValueRef { ebml::start_tag(ebml_w, tag_items); auto items_index = encode_info_for_items(cx, ebml_w); auto int_writer = write_int; - auto item_hasher = hash_def_num; + auto item_hasher = hash_def_id; auto items_buckets = create_index[int](items_index, item_hasher); encode_index[int](ebml_w, items_buckets, int_writer); ebml::end_tag(ebml_w); @@ -725,7 +724,7 @@ fn encode_metadata(&@trans::crate_ctxt cx, &@ast::crate crate) -> ValueRef { ret C_postr(string_w.get_str()); } -fn write_metadata(&@trans::crate_ctxt cx, &@ast::crate crate) { +fn write_metadata(&@trans::crate_ctxt cx, &@crate crate) { if (!cx.sess.get_opts().shared) { ret; } auto llmeta = encode_metadata(cx, crate); auto llconst = trans::C_struct([llmeta]); diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs index e8333d09fb08..356dab840396 100644 --- a/src/comp/middle/resolve.rs +++ b/src/comp/middle/resolve.rs @@ -3,12 +3,13 @@ import front::ast; import front::ast::ident; import front::ast::def; import front::ast::def_id; -import front::ast::ann; +import front::ast::node_id; +import front::ast::local_def; + import front::creader; import driver::session::session; import util::common::new_def_hash; import util::common::new_int_hash; -import util::common::new_uint_hash; import util::common::new_str_hash; import util::common::span; import util::common::respan; @@ -107,17 +108,17 @@ type indexed_mod = only need to look at them to determine exports, which they can't control.*/ // It should be safe to use index to memoize lookups of globbed names. -type crate_map = hashmap[uint, ast::crate_num]; +type crate_map = hashmap[node_id, ast::crate_num]; -type def_map = hashmap[uint, def]; +type def_map = hashmap[node_id, def]; type env = rec(crate_map crate_map, def_map def_map, constr_table fn_constrs, - hashmap[def_id, @ast::item] ast_map, - hashmap[ast::def_num, import_state] imports, - hashmap[ast::def_num, @indexed_mod] mod_map, + hashmap[ast::node_id, @ast::item] ast_map, + hashmap[ast::node_id, import_state] imports, + hashmap[ast::node_id, @indexed_mod] mod_map, hashmap[def_id, vec[ident]] ext_map, ext_hash ext_cache, session sess); @@ -132,10 +133,10 @@ tag namespace { ns_value; ns_type; ns_module; } fn resolve_crate(session sess, @ast::crate crate) -> tup(def_map, constr_table) { auto e = - @rec(crate_map=new_uint_hash[ast::crate_num](), - def_map=new_uint_hash[def](), - fn_constrs=new_def_hash[vec[ty::constr_def]](), - ast_map=new_def_hash[@ast::item](), + @rec(crate_map=new_int_hash[ast::crate_num](), + def_map=new_int_hash[def](), + fn_constrs = new_int_hash[vec[ty::constr_def]](), + ast_map=new_int_hash[@ast::item](), imports=new_int_hash[import_state](), mod_map=new_int_hash[@indexed_mod](), ext_map=new_def_hash[vec[ident]](), @@ -170,8 +171,8 @@ fn map_crate(&@env e, &@ast::crate c) { glob_imported_names=new_str_hash[import_state]())); fn index_vi(@env e, &@ast::view_item i, &scopes sc, &vt[scopes] v) { alt (i.node) { - case (ast::view_item_import(_, ?ids, ?defid)) { - e.imports.insert(defid._1, todo(i, sc)); + case (ast::view_item_import(_, ?ids, ?id)) { + e.imports.insert(id, todo(i, sc)); } case (_) { } } @@ -181,7 +182,7 @@ fn map_crate(&@env e, &@ast::crate c) { alt (i.node) { case (ast::item_mod(?md)) { auto s = new_str_hash[import_state](); - e.mod_map.insert(i.id._1, + e.mod_map.insert(i.id, @rec(m=some(md), index=index_mod(md), mutable glob_imports=vec::empty[def](), @@ -190,7 +191,7 @@ fn map_crate(&@env e, &@ast::crate c) { } case (ast::item_native_mod(?nmd)) { auto s = new_str_hash[import_state](); - e.mod_map.insert(i.id._1, + e.mod_map.insert(i.id, @rec(m=none[ast::_mod], index=index_nmod(nmd), mutable glob_imports=vec::empty[def](), @@ -218,10 +219,10 @@ fn map_crate(&@env e, &@ast::crate c) { case (cons(scope_item(?i), ?tl)) { alt (i.node) { case (ast::item_mod(_)) { - ret e.mod_map.get(i.id._1); + ret e.mod_map.get(i.id); } case (ast::item_native_mod(_)) { - ret e.mod_map.get(i.id._1); + ret e.mod_map.get(i.id); } case (_) { be find_mod(e, *tl); } } @@ -248,7 +249,7 @@ fn map_crate(&@env e, &@ast::crate c) { } fn resolve_imports(&env e) { - for each (@tup(ast::def_num, import_state) it in e.imports.items()) { + for each (@tup(ast::node_id, import_state) it in e.imports.items()) { alt (it._1) { case (todo(?item, ?sc)) { resolve_import(e, item, sc); } case (resolved(_, _, _)) { } @@ -266,7 +267,7 @@ fn resolve_names(&@env e, &@ast::crate c) { visit_expr=bind walk_expr(e, _, _, _), visit_ty=bind walk_ty(e, _, _, _), visit_constr=bind walk_constr(e, _, _, _), - visit_fn=bind visit_fn_with_scope(e, _, _, _, _, _, _, _, _) + visit_fn=bind visit_fn_with_scope(e, _, _, _, _, _, _, _) with *visit::default_visitor()); visit::visit_crate(*c, cons(scope_crate(c), @nil), visit::vtor(v)); e.sess.abort_if_errors(); @@ -274,8 +275,8 @@ fn resolve_names(&@env e, &@ast::crate c) { fn walk_expr(@env e, &@ast::expr exp, &scopes sc, &vt[scopes] v) { visit_expr_with_scope(exp, sc, v); alt (exp.node) { - case (ast::expr_path(?p, ?a)) { - maybe_insert(e, a.id, + case (ast::expr_path(?p, ?id)) { + maybe_insert(e, id, lookup_path_strict(*e, sc, exp.span, p.node.idents, ns_value)); } @@ -285,8 +286,8 @@ fn resolve_names(&@env e, &@ast::crate c) { fn walk_ty(@env e, &@ast::ty t, &scopes sc, &vt[scopes] v) { visit::visit_ty(t, sc, v); alt (t.node) { - case (ast::ty_path(?p, ?a)) { - maybe_insert(e, a.id, + case (ast::ty_path(?p, ?id)) { + maybe_insert(e, id, lookup_path_strict(*e, sc, t.span, p.node.idents, ns_type)); } @@ -294,7 +295,7 @@ fn resolve_names(&@env e, &@ast::crate c) { } } fn walk_constr(@env e, &@ast::constr c, &scopes sc, &vt[scopes] v) { - maybe_insert(e, c.node.ann.id, + maybe_insert(e, c.node.id, lookup_path_strict(*e, sc, c.span, c.node.path.node.idents, ns_value)); } @@ -304,14 +305,14 @@ fn resolve_names(&@env e, &@ast::crate c) { } fn walk_pat(&env e, &scopes sc, &@ast::pat pat) { alt (pat.node) { - case (ast::pat_tag(?p, ?children, ?a)) { + case (ast::pat_tag(?p, ?children, ?id)) { auto fnd = lookup_path_strict(e, sc, p.span, p.node.idents, ns_value); if (option::is_some(fnd)) { alt (option::get(fnd)) { case (ast::def_variant(?did, ?vid)) { - e.def_map.insert(a.id, option::get(fnd)); + e.def_map.insert(id, option::get(fnd)); for (@ast::pat child in children) { walk_pat(e, sc, child); } @@ -328,7 +329,7 @@ fn resolve_names(&@env e, &@ast::crate c) { } } - fn maybe_insert(@env e, uint id, + fn maybe_insert(@env e, node_id id, option::t[def] def) { if (option::is_some(def)) { e.def_map.insert(id, option::get(def)); @@ -348,16 +349,16 @@ fn visit_native_item_with_scope(&@ast::native_item ni, &scopes sc, } fn visit_fn_with_scope(&@env e, &ast::_fn f, &vec[ast::ty_param] tp, &span sp, - &ident name, &def_id d_id, &ann a, &scopes sc, + &ident name, node_id id, &scopes sc, &vt[scopes] v) { // here's where we need to set up the mapping // for f's constrs in the table. for (@ast::constr c in f.decl.constraints) { - resolve_constr(e, d_id, c, sc, v); + resolve_constr(e, id, c, sc, v); } - visit::visit_fn(f, tp, sp, name, d_id, a, cons(scope_fn(f.decl, tp), @sc), - v); + visit::visit_fn(f, tp, sp, name, id, + cons(scope_fn(f.decl, tp), @sc), v); } fn visit_block_with_scope(&ast::block b, &scopes sc, &vt[scopes] v) { @@ -411,7 +412,7 @@ fn follow_import(&env e, &scopes sc, } } -fn resolve_constr(@env e, &def_id d_id, &@ast::constr c, &scopes sc, +fn resolve_constr(@env e, node_id id, &@ast::constr c, &scopes sc, &vt[scopes] v) { auto new_def = lookup_path_strict(*e, sc, c.span, c.node.path.node.idents, ns_value); @@ -421,7 +422,7 @@ fn resolve_constr(@env e, &def_id d_id, &@ast::constr c, &scopes sc, let ty::constr_general[uint] c_ = rec(path=c.node.path, args=c.node.args, id=pred_id); let ty::constr_def new_constr = respan(c.span, c_); - add_constr(e, d_id, new_constr); + add_constr(e, id, new_constr); } case (_) { e.sess.span_err(c.span, @@ -432,9 +433,9 @@ fn resolve_constr(@env e, &def_id d_id, &@ast::constr c, &scopes sc, } } -fn add_constr(&@env e, &def_id d_id, &ty::constr_def c) { - e.fn_constrs.insert(d_id, - alt (e.fn_constrs.find(d_id)) { +fn add_constr(&@env e, node_id id, &ty::constr_def c) { + e.fn_constrs.insert(id, + alt (e.fn_constrs.find(id)) { case (none) { [c] } case (some(?cs)) { cs + [c] } }); @@ -446,8 +447,8 @@ fn resolve_import(&env e, &@ast::view_item it, &scopes sc) { auto defid; auto ids; alt (it.node) { - case (ast::view_item_import(_, ?_ids, ?_defid)) { - defid = _defid; + case (ast::view_item_import(_, ?_ids, ?_id)) { + defid = local_def(_id); ids = _ids; } } @@ -511,15 +512,15 @@ fn resolve_import(&env e, &@ast::view_item it, &scopes sc) { e.imports.insert(defid._1, resolved(val, typ, md)); } } - fn remove_if_unresolved(hashmap[ast::def_num, import_state] imports, - ast::def_num def_num) { + fn remove_if_unresolved(hashmap[ast::node_id, import_state] imports, + ast::node_id node_id) { // If we couldn't resolve the import, don't leave it in a partially // resolved state, to avoid having it reported later as a cyclic // import - if (imports.contains_key(def_num)) { - alt (imports.get(def_num)) { + if (imports.contains_key(node_id)) { + alt (imports.get(node_id)) { case (resolving(_)) { - imports.remove(def_num); + imports.remove(node_id); } case (_) { } } @@ -605,8 +606,7 @@ fn lookup_in_scope(&env e, scopes sc, &span sp, &ident id, namespace ns) -> alt (s) { case (scope_crate(?c)) { - auto defid = tup(ast::local_crate, -1); - ret lookup_in_local_mod(e, defid, sp, id, ns, inside); + ret lookup_in_local_mod(e, -1, sp, id, ns, inside); } case (scope_item(?it)) { alt (it.node) { @@ -634,7 +634,7 @@ fn lookup_in_scope(&env e, scopes sc, &span sp, &ident id, namespace ns) -> } case (scope_native_item(?it)) { alt (it.node) { - case (ast::native_item_fn(_, _, ?decl, ?ty_params, _, _)) + case (ast::native_item_fn(_, _, ?decl, ?ty_params, _)) { ret lookup_in_fn(id, decl, ty_params, ns); } @@ -646,7 +646,7 @@ fn lookup_in_scope(&env e, scopes sc, &span sp, &ident id, namespace ns) -> case (scope_loop(?local)) { if (ns == ns_value) { if (str::eq(local.node.ident, id)) { - ret some(ast::def_local(local.node.id)); + ret some(ast::def_local(local_def(local.node.id))); } } } @@ -696,16 +696,18 @@ fn lookup_in_ty_params(&ident id, &vec[ast::ty_param] ty_params) -> ret none[def]; } -fn lookup_in_pat(&ident id, &ast::pat pat) -> option::t[def] { +fn lookup_in_pat(&ident ident, &ast::pat pat) -> option::t[def] { alt (pat.node) { - case (ast::pat_bind(?name, ?defid, _)) { - if (str::eq(name, id)) { ret some(ast::def_binding(defid)); } + case (ast::pat_bind(?name, ?id)) { + if (str::eq(name, ident)) { + ret some(ast::def_binding(local_def(id))); + } } case (ast::pat_wild(_)) { } case (ast::pat_lit(_, _)) { } case (ast::pat_tag(_, ?pats, _)) { for (@ast::pat p in pats) { - auto found = lookup_in_pat(id, *p); + auto found = lookup_in_pat(ident, *p); if (!option::is_none(found)) { ret found; } } } @@ -718,7 +720,9 @@ fn lookup_in_fn(&ident id, &ast::fn_decl decl, &vec[ast::ty_param] ty_params, alt (ns) { case (ns_value) { for (ast::arg a in decl.inputs) { - if (str::eq(a.ident, id)) { ret some(ast::def_arg(a.id)); } + if (str::eq(a.ident, id)) { + ret some(ast::def_arg(local_def(a.id))); + } } ret none[def]; } @@ -733,7 +737,7 @@ fn lookup_in_obj(&ident id, &ast::_obj ob, &vec[ast::ty_param] ty_params, case (ns_value) { for (ast::obj_field f in ob.fields) { if (str::eq(f.ident, id)) { - ret some(ast::def_obj_field(f.id)); + ret some(ast::def_obj_field(local_def(f.id))); } } ret none[def]; @@ -751,7 +755,7 @@ fn lookup_in_block(&ident id, &ast::block_ b, namespace ns) -> alt (d.node) { case (ast::decl_local(?loc)) { if (ns == ns_value && str::eq(id, loc.node.ident)) { - ret some(ast::def_local(loc.node.id)); + ret some(ast::def_local(local_def(loc.node.id))); } } case (ast::decl_item(?it)) { @@ -759,14 +763,16 @@ fn lookup_in_block(&ident id, &ast::block_ b, namespace ns) -> case (ast::item_tag(?variants, _)) { if (ns == ns_type) { if (str::eq(it.ident, id)) { - ret some(ast::def_ty(it.id)); + ret some(ast::def_ty + (local_def(it.id))); } } else if (ns == ns_value) { for (ast::variant v in variants) { if (str::eq(v.node.name, id)) { auto i = v.node.id; - ret some(ast::def_variant(it.id, - i)); + ret some(ast::def_variant + (local_def(it.id), + local_def(i))); } } } @@ -792,27 +798,39 @@ fn lookup_in_block(&ident id, &ast::block_ b, namespace ns) -> fn found_def_item(&@ast::item i, namespace ns) -> option::t[def] { alt (i.node) { case (ast::item_const(_, _)) { - if (ns == ns_value) { ret some(ast::def_const(i.id)); } + if (ns == ns_value) { + ret some(ast::def_const(local_def(i.id))); + } } case (ast::item_fn(_, _)) { - if (ns == ns_value) { ret some(ast::def_fn(i.id)); } + if (ns == ns_value) { + ret some(ast::def_fn(local_def(i.id))); + } } case (ast::item_mod(_)) { - if (ns == ns_module) { ret some(ast::def_mod(i.id)); } + if (ns == ns_module) { + ret some(ast::def_mod(local_def(i.id))); + } } case (ast::item_native_mod(_)) { - if (ns == ns_module) { ret some(ast::def_native_mod(i.id)); } + if (ns == ns_module) { + ret some(ast::def_native_mod(local_def(i.id))); + } } case (ast::item_ty(_, _)) { - if (ns == ns_type) { ret some(ast::def_ty(i.id)); } + if (ns == ns_type) { + ret some(ast::def_ty(local_def(i.id))); + } } case (ast::item_tag(_, _)) { - if (ns == ns_type) { ret some(ast::def_ty(i.id)); } + if (ns == ns_type) { + ret some(ast::def_ty(local_def(i.id))); + } } case (ast::item_obj(_, _, ?ctor_id)) { alt (ns) { - case (ns_value) { ret some(ast::def_obj(ctor_id)); } - case (ns_type) { ret some(ast::def_obj(i.id)); } + case (ns_value) { ret some(ast::def_obj(local_def(ctor_id)));} + case (ns_type) { ret some(ast::def_obj(local_def(i.id))); } case (_) { } } } @@ -850,10 +868,10 @@ fn lookup_in_mod(&env e, def m, &span sp, &ident id, namespace ns, dir dr) -> } alt (m) { case (ast::def_mod(?defid)) { - ret lookup_in_local_mod(e, defid, sp, id, ns, dr); + ret lookup_in_local_mod(e, defid._1, sp, id, ns, dr); } case (ast::def_native_mod(?defid)) { - ret lookup_in_local_native_mod(e, defid, sp, id, ns); + ret lookup_in_local_native_mod(e, defid._1, sp, id, ns); } } } @@ -861,11 +879,11 @@ fn lookup_in_mod(&env e, def m, &span sp, &ident id, namespace ns, dir dr) -> fn found_view_item(&env e, @ast::view_item vi, namespace ns) -> option::t[def] { alt (vi.node) { - case (ast::view_item_use(_, _, _, ?ann)) { - ret some(ast::def_mod(tup(e.crate_map.get(ann.id), -1))); + case (ast::view_item_use(_, _, ?id)) { + ret some(ast::def_mod(tup(e.crate_map.get(id), -1))); } - case (ast::view_item_import(_, _, ?defid)) { - ret lookup_import(e, defid, ns); + case (ast::view_item_import(_, _, ?id)) { + ret lookup_import(e, local_def(id), ns); } case (ast::view_item_import_glob(_, ?defid)) { ret none[def]; //will be handled in the fallback glob pass @@ -894,14 +912,14 @@ fn lookup_import(&env e, def_id defid, namespace ns) -> option::t[def] { } } -fn lookup_in_local_native_mod(&env e, def_id defid, &span sp, &ident id, +fn lookup_in_local_native_mod(&env e, node_id node_id, &span sp, &ident id, namespace ns) -> option::t[def] { - ret lookup_in_local_mod(e, defid, sp, id, ns, inside); + ret lookup_in_local_mod(e, node_id, sp, id, ns, inside); } -fn lookup_in_local_mod(&env e, def_id defid, &span sp, &ident id, +fn lookup_in_local_mod(&env e, node_id node_id, &span sp, &ident id, namespace ns, dir dr) -> option::t[def] { - auto info = e.mod_map.get(defid._1); + auto info = e.mod_map.get(node_id); if (dr == outside && !ast::is_exported(id, option::get(info.m))) { // if we're in a native mod, then dr==inside, so info.m is some _mod @@ -947,14 +965,14 @@ fn lookup_glob_in_mod(&env e, @indexed_mod info, &span sp, &ident id, ret some[def](matches.(0)); } else { for (def match in matches) { - alt (e.ast_map.find(ast::def_id_of_def(match))) { + alt (e.ast_map.find(ast::def_id_of_def(match)._1)) { case (some(?it)) { e.sess.span_note(it.span, "'" + id + "' is defined here."); } case (_) { e.sess.bug("Internal error: imports and matches " + - "don't agree"); + "don't agree"); } } } @@ -1001,7 +1019,8 @@ fn lookup_in_mie(&env e, &mod_index_entry mie, namespace ns) -> case (ast::item_tag(?variants, _)) { if (ns == ns_value) { auto vid = variants.(variant_idx).node.id; - ret some(ast::def_variant(item.id, vid)); + ret some(ast::def_variant(local_def(item.id), + local_def(vid))); } else { ret none[def]; } } } @@ -1009,10 +1028,14 @@ fn lookup_in_mie(&env e, &mod_index_entry mie, namespace ns) -> case (mie_native_item(?native_item)) { alt (native_item.node) { case (ast::native_item_ty(_, ?id)) { - if (ns == ns_type) { ret some(ast::def_native_ty(id)); } + if (ns == ns_type) { + ret some(ast::def_native_ty(local_def(id))); + } } - case (ast::native_item_fn(_, _, _, _, ?id, _)) { - if (ns == ns_value) { ret some(ast::def_native_fn(id)); } + case (ast::native_item_fn(_, _, _, _, ?id)) { + if (ns == ns_value) { + ret some(ast::def_native_fn(local_def(id))); + } } } } @@ -1035,8 +1058,8 @@ fn index_mod(&ast::_mod md) -> mod_index { auto index = new_str_hash[list[mod_index_entry]](); for (@ast::view_item it in md.view_items) { alt (it.node) { - case (ast::view_item_use(?id, _, _, _)) { - add_to_index(index, id, mie_view_item(it)); + case (ast::view_item_use(?ident, _, _)) { + add_to_index(index, ident, mie_view_item(it)); } case (ast::view_item_import(?def_ident, _, _)) { add_to_index(index, def_ident, mie_view_item(it)); @@ -1045,7 +1068,7 @@ fn index_mod(&ast::_mod md) -> mod_index { //globbed imports have to be resolved lazily. ast::view_item_import_glob(_, _)) { } - case (ast::view_item_export(_)) { } + case (ast::view_item_export(_, _)) { } } } for (@ast::item it in md.items) { @@ -1090,16 +1113,16 @@ fn index_nmod(&ast::native_mod md) -> mod_index { add_to_index(index, def_ident, mie_view_item(it)); } case (ast::view_item_import_glob(_, _)) { } - case (ast::view_item_export(_)) { } + case (ast::view_item_export(_, _)) { } } } for (@ast::native_item it in md.items) { alt (it.node) { - case (ast::native_item_ty(?id, _)) { - add_to_index(index, id, mie_native_item(it)); + case (ast::native_item_ty(?ident, _)) { + add_to_index(index, ident, mie_native_item(it)); } - case (ast::native_item_fn(?id, _, _, _, _, _)) { - add_to_index(index, id, mie_native_item(it)); + case (ast::native_item_fn(?ident, _, _, _, _)) { + add_to_index(index, ident, mie_native_item(it)); } } } @@ -1142,7 +1165,7 @@ fn check_for_collisions(&@env e, &ast::crate c) { // Module indices make checking those relatively simple -- just check each // name for multiple entities in the same namespace. - for each (@tup(ast::def_num, @indexed_mod) m in e.mod_map.items()) { + for each (@tup(ast::node_id, @indexed_mod) m in e.mod_map.items()) { for each (@tup(ident, list[mod_index_entry]) name in m._1.index.items()) { check_mod_name(*e, name._0, name._1); @@ -1225,7 +1248,7 @@ fn check_arm(@env e, &ast::arm a, &() x, &vt[()] v) { visit::visit_arm(a, x, v); fn walk_pat(checker ch, &@ast::pat p) { alt (p.node) { - case (ast::pat_bind(?name, _, _)) { add_name(ch, p.span, name); } + case (ast::pat_bind(?name, _)) { add_name(ch, p.span, name); } case (ast::pat_tag(_, ?children, _)) { for (@ast::pat child in children) { walk_pat(ch, child); } } diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 408a9f3e7db4..726f7b491ef8 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -37,6 +37,7 @@ import visit::vt; import util::common; import util::common::istr; import util::common::new_def_hash; +import util::common::new_int_hash; import util::common::new_str_hash; import util::common::local_rhs_span; import util::common::span; @@ -124,10 +125,10 @@ type crate_ctxt = // A mapping from the def_id of each item in this crate to the address // of the first instruction of the item's definition in the executable // we're generating. - hashmap[ast::def_id, ValueRef] item_ids, - hashmap[ast::def_id, @ast::item] items, - hashmap[ast::def_id, @ast::native_item] native_items, - hashmap[ast::def_id, str] item_symbols, + hashmap[ast::node_id, ValueRef] item_ids, + hashmap[ast::node_id, @ast::item] items, + hashmap[ast::node_id, @ast::native_item] native_items, + hashmap[ast::node_id, str] item_symbols, mutable option::t[ValueRef] main_fn, str crate_meta_name, str crate_meta_vers, @@ -135,11 +136,11 @@ type crate_ctxt = // TODO: hashmap[tup(tag_id,subtys), @tag_info] hashmap[ty::t, uint] tag_sizes, - hashmap[ast::def_id, ValueRef] discrims, - hashmap[ast::def_id, str] discrim_symbols, - hashmap[ast::def_id, ValueRef] fn_pairs, - hashmap[ast::def_id, ValueRef] consts, - hashmap[ast::def_id, ()] obj_methods, + hashmap[ast::node_id, ValueRef] discrims, + hashmap[ast::node_id, str] discrim_symbols, + hashmap[ast::node_id, ValueRef] fn_pairs, + hashmap[ast::node_id, ValueRef] consts, + hashmap[ast::node_id, ()] obj_methods, hashmap[ty::t, @tydesc_info] tydescs, hashmap[str, ValueRef] module_data, hashmap[ty::t, TypeRef] lltypes, @@ -228,20 +229,20 @@ type fn_ctxt = // LLVM-stuff-in-the-frame. // Maps arguments to allocas created for them in llallocas. - hashmap[ast::def_id, ValueRef] llargs, + hashmap[ast::node_id, ValueRef] llargs, // Maps fields in objects to pointers into the interior of llself's // body. - hashmap[ast::def_id, ValueRef] llobjfields, + hashmap[ast::node_id, ValueRef] llobjfields, // Maps the def_ids for local variables to the allocas created for // them in llallocas. - hashmap[ast::def_id, ValueRef] lllocals, + hashmap[ast::node_id, ValueRef] lllocals, // The same as above, but for variables accessed via the frame pointer // we pass into an iter, for access to the static environment of the // iter-calling frame. - hashmap[ast::def_id, ValueRef] llupvars, + hashmap[ast::node_id, ValueRef] llupvars, // For convenience, a vector of the incoming tydescs for each of this // functions type parameters, fetched via llvm::LLVMGetParam. For @@ -3048,7 +3049,7 @@ fn move_val(@block_ctxt cx, copy_action action, ValueRef dst, ValueRef src, ty_to_str(cx.fcx.lcx.ccx.tcx, t)); } -fn trans_lit(&@crate_ctxt cx, &ast::lit lit, &ast::ann ann) -> ValueRef { +fn trans_lit(&@crate_ctxt cx, &ast::lit lit, ast::node_id id) -> ValueRef { alt (lit.node) { case (ast::lit_int(?i)) { ret C_int(i); } case (ast::lit_uint(?u)) { ret C_int(u as int); } @@ -3091,16 +3092,16 @@ fn trans_lit(&@crate_ctxt cx, &ast::lit lit, &ast::ann ann) -> ValueRef { // Converts an annotation to a type -fn node_ann_type(&@crate_ctxt cx, &ast::ann a) -> ty::t { - ret ty::ann_to_monotype(cx.tcx, a); +fn node_id_type(&@crate_ctxt cx, ast::node_id id) -> ty::t { + ret ty::node_id_to_monotype(cx.tcx, id); } -fn node_type(&@crate_ctxt cx, &span sp, &ast::ann a) -> TypeRef { - ret type_of(cx, sp, node_ann_type(cx, a)); +fn node_type(&@crate_ctxt cx, &span sp, ast::node_id id) -> TypeRef { + ret type_of(cx, sp, node_id_type(cx, id)); } -fn trans_unary(&@block_ctxt cx, ast::unop op, &@ast::expr e, &ast::ann a) -> - result { +fn trans_unary(&@block_ctxt cx, ast::unop op, &@ast::expr e, + ast::node_id id) -> result { auto sub = trans_expr(cx, e); auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e); alt (op) { @@ -3121,7 +3122,7 @@ fn trans_unary(&@block_ctxt cx, ast::unop op, &@ast::expr e, &ast::ann a) -> case (ast::box(_)) { auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e); auto e_val = sub.val; - auto box_ty = node_ann_type(sub.bcx.fcx.lcx.ccx, a); + auto box_ty = node_id_type(sub.bcx.fcx.lcx.ccx, id); sub = trans_malloc_boxed(sub.bcx, e_ty); find_scope_cx(cx).cleanups += [clean(bind drop_ty(_, sub.val, box_ty))]; @@ -4049,8 +4050,8 @@ fn join_branches(&@block_ctxt parent_cx, &vec[result] ins) -> @block_ctxt { tag out_method { return; save_in(ValueRef); } fn trans_if(&@block_ctxt cx, &@ast::expr cond, &ast::block thn, - &option::t[@ast::expr] els, &ast::ann ann, &out_method output) -> - result { + &option::t[@ast::expr] els, ast::node_id id, &out_method output) + -> result { auto cond_res = trans_expr(cx, cond); auto then_cx = new_scope_block_ctxt(cx, "then"); auto then_res = trans_block(then_cx, thn, output); @@ -4060,14 +4061,14 @@ fn trans_if(&@block_ctxt cx, &@ast::expr cond, &ast::block thn, alt (els) { case (some(?elexpr)) { alt (elexpr.node) { - case (ast::expr_if(_, _, _, ?ann)) { + case (ast::expr_if(_, _, _, ?id)) { // Synthesize a block here to act as the else block // containing an if expression. Needed in order for the // else scope to behave like a normal block scope. A tad // ugly. let ast::block_ elseif_blk_ = - rec(stmts=[], expr=some[@ast::expr](elexpr), a=ann); + rec(stmts=[], expr=some[@ast::expr](elexpr), id=id); auto elseif_blk = rec(node=elseif_blk_, span=elexpr.span); else_res = trans_block(else_cx, elseif_blk, output); } @@ -4082,7 +4083,7 @@ fn trans_if(&@block_ctxt cx, &@ast::expr cond, &ast::block thn, } // FIXME: This isn't quite right, particularly re: dynamic types - auto expr_ty = ty::ann_to_type(cx.fcx.lcx.ccx.tcx, ann); + auto expr_ty = ty::node_id_to_type(cx.fcx.lcx.ccx.tcx, id); if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, expr_ty)) { expr_llty = T_typaram_ptr(cx.fcx.lcx.ccx.tn); } else { @@ -4130,21 +4131,21 @@ fn trans_for(&@block_ctxt cx, &@ast::local local, &@ast::expr seq, // Searches through a block for all references to locals or upvars in this // frame and returns the list of definition IDs thus found. fn collect_upvars(&@block_ctxt cx, &ast::block bloc, - &ast::def_id initial_decl) -> vec[ast::def_id] { + ast::node_id initial_decl) -> vec[ast::node_id] { type env = - @rec(mutable vec[ast::def_id] refs, - hashmap[ast::def_id, ()] decls, + @rec(mutable vec[ast::node_id] refs, + hashmap[ast::node_id, ()] decls, resolve::def_map def_map); fn walk_expr(env e, &@ast::expr expr) { alt (expr.node) { - case (ast::expr_path(?path, ?ann)) { - alt (e.def_map.get(ann.id)) { + case (ast::expr_path(?path, ?id)) { + alt (e.def_map.get(id)) { case (ast::def_arg(?did)) { - vec::push[ast::def_id](e.refs, did); + vec::push(e.refs, did._1); } case (ast::def_local(?did)) { - vec::push[ast::def_id](e.refs, did); + vec::push(e.refs, did._1); } case (_) { } } @@ -4155,11 +4156,10 @@ fn collect_upvars(&@block_ctxt cx, &ast::block bloc, fn walk_local(env e, &@ast::local local) { e.decls.insert(local.node.id, ()); } - let vec[ast::def_id] refs = []; - let hashmap[ast::def_id, ()] decls = new_def_hash[()](); + let hashmap[ast::node_id, ()] decls = new_int_hash[()](); decls.insert(initial_decl, ()); let env e = - @rec(mutable refs=refs, + @rec(mutable refs=[], decls=decls, def_map=cx.fcx.lcx.ccx.tcx.def_map); auto visitor = @@ -4169,8 +4169,8 @@ fn collect_upvars(&@block_ctxt cx, &ast::block bloc, walk::walk_block(*visitor, bloc); // Calculate (refs - decls). This is the set of captured upvars. - let vec[ast::def_id] result = []; - for (ast::def_id ref_id_ in e.refs) { + let vec[ast::node_id] result = []; + for (ast::node_id ref_id_ in e.refs) { auto ref_id = ref_id_; if (!decls.contains_key(ref_id)) { result += [ref_id]; } } @@ -4208,23 +4208,23 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq, auto lcx = cx.fcx.lcx; // FIXME: possibly support alias-mode here? - auto decl_ty = node_ann_type(lcx.ccx, local.node.ann); + auto decl_ty = node_id_type(lcx.ccx, local.node.id); auto decl_id = local.node.id; auto upvars = collect_upvars(cx, body, decl_id); - auto upvar_count = vec::len[ast::def_id](upvars); + auto upvar_count = vec::len(upvars); auto llbindingsptr; if (upvar_count > 0u) { // Gather up the upvars. let vec[ValueRef] llbindings = []; let vec[TypeRef] llbindingtys = []; - for (ast::def_id did in upvars) { + for (ast::node_id nid in upvars) { auto llbinding; - alt (cx.fcx.lllocals.find(did)) { + alt (cx.fcx.lllocals.find(nid)) { case (none) { - alt (cx.fcx.llupvars.find(did)) { + alt (cx.fcx.llupvars.find(nid)) { case (none[ValueRef]) { - llbinding = cx.fcx.llargs.get(did); + llbinding = cx.fcx.llargs.get(nid); } case (some[ValueRef](?llval)) { llbinding = llval; } } @@ -4338,7 +4338,7 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq, // Step 3: Call iter passing [lliterbody, llenv], plus other args. alt (seq.node) { - case (ast::expr_call(?f, ?args, ?ann)) { + case (ast::expr_call(?f, ?args, ?id)) { auto pair = alloca(cx, T_fn_pair(lcx.ccx.tn, iter_body_llty)); auto code_cell = cx.build.GEP(pair, [C_int(0), C_int(abi::fn_field_code)]); @@ -4353,7 +4353,7 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq, r = trans_call(cx, f, some[ValueRef](cx.build.Load(pair)), args, - ann); + id); ret res(r.bcx, C_nil()); } } @@ -4394,23 +4394,23 @@ fn trans_pat_match(&@block_ctxt cx, &@ast::pat pat, ValueRef llval, &@block_ctxt next_cx) -> result { alt (pat.node) { case (ast::pat_wild(_)) { ret res(cx, llval); } - case (ast::pat_bind(_, _, _)) { ret res(cx, llval); } - case (ast::pat_lit(?lt, ?ann)) { - auto lllit = trans_lit(cx.fcx.lcx.ccx, *lt, ann); - auto lltype = ty::ann_to_type(cx.fcx.lcx.ccx.tcx, ann); + case (ast::pat_bind(_, _)) { ret res(cx, llval); } + case (ast::pat_lit(?lt, ?id)) { + auto lllit = trans_lit(cx.fcx.lcx.ccx, *lt, id); + auto lltype = ty::node_id_to_type(cx.fcx.lcx.ccx.tcx, id); auto lleq = trans_compare(cx, ast::eq, lltype, llval, lllit); auto matched_cx = new_sub_block_ctxt(lleq.bcx, "matched_cx"); lleq.bcx.build.CondBr(lleq.val, matched_cx.llbb, next_cx.llbb); ret res(matched_cx, llval); } - case (ast::pat_tag(?id, ?subpats, ?ann)) { + case (ast::pat_tag(?ident, ?subpats, ?id)) { auto lltagptr = cx.build.PointerCast(llval, T_opaque_tag_ptr(cx.fcx.lcx.ccx.tn)); auto lldiscrimptr = cx.build.GEP(lltagptr, [C_int(0), C_int(0)]); auto lldiscrim = cx.build.Load(lldiscrimptr); auto vdef = - ast::variant_def_ids(cx.fcx.lcx.ccx.tcx.def_map.get(ann.id)); + ast::variant_def_ids(cx.fcx.lcx.ccx.tcx.def_map.get(id)); auto variant_tag = 0; auto variants = ty::tag_variants(cx.fcx.lcx.ccx.tcx, vdef._0); auto i = 0; @@ -4427,7 +4427,8 @@ fn trans_pat_match(&@block_ctxt cx, &@ast::pat pat, ValueRef llval, cx.build.ICmp(lib::llvm::LLVMIntEQ, lldiscrim, C_int(variant_tag)); cx.build.CondBr(lleq, matched_cx.llbb, next_cx.llbb); - auto ty_params = ty::ann_to_type_params(cx.fcx.lcx.ccx.tcx, ann); + auto ty_params = ty::node_id_to_type_params + (cx.fcx.lcx.ccx.tcx, id); if (vec::len[@ast::pat](subpats) > 0u) { auto llblobptr = matched_cx.build.GEP(lltagptr, [C_int(0), C_int(1)]); @@ -4458,33 +4459,33 @@ fn trans_pat_binding(&@block_ctxt cx, &@ast::pat pat, ValueRef llval, alt (pat.node) { case (ast::pat_wild(_)) { ret res(cx, llval); } case (ast::pat_lit(_, _)) { ret res(cx, llval); } - case (ast::pat_bind(?id, ?def_id, ?ann)) { + case (ast::pat_bind(?name, ?id)) { if (bind_alias) { - cx.fcx.lllocals.insert(def_id, llval); + cx.fcx.lllocals.insert(id, llval); ret res(cx, llval); } else { - auto t = node_ann_type(cx.fcx.lcx.ccx, ann); + auto t = node_id_type(cx.fcx.lcx.ccx, id); auto rslt = alloc_ty(cx, t); auto dst = rslt.val; auto bcx = rslt.bcx; - maybe_name_value(cx.fcx.lcx.ccx, dst, id); - bcx.fcx.lllocals.insert(def_id, dst); + maybe_name_value(cx.fcx.lcx.ccx, dst, name); + bcx.fcx.lllocals.insert(id, dst); bcx.cleanups += [clean(bind drop_slot(_, dst, t))]; ret copy_val(bcx, INIT, dst, llval, t); } } - case (ast::pat_tag(_, ?subpats, ?ann)) { + case (ast::pat_tag(_, ?subpats, ?id)) { if (vec::len[@ast::pat](subpats) == 0u) { ret res(cx, llval); } // Get the appropriate variant for this tag. auto vdef = - ast::variant_def_ids(cx.fcx.lcx.ccx.tcx.def_map.get(ann.id)); + ast::variant_def_ids(cx.fcx.lcx.ccx.tcx.def_map.get(id)); auto lltagptr = cx.build.PointerCast(llval, T_opaque_tag_ptr(cx.fcx.lcx.ccx.tn)); auto llblobptr = cx.build.GEP(lltagptr, [C_int(0), C_int(1)]); auto ty_param_substs = - ty::ann_to_type_params(cx.fcx.lcx.ccx.tcx, ann); + ty::node_id_to_type_params(cx.fcx.lcx.ccx.tcx, id); auto this_cx = cx; auto i = 0; for (@ast::pat subpat in subpats) { @@ -4503,7 +4504,7 @@ fn trans_pat_binding(&@block_ctxt cx, &@ast::pat pat, ValueRef llval, } fn trans_alt(&@block_ctxt cx, &@ast::expr expr, &vec[ast::arm] arms, - &ast::ann ann, &out_method output) -> result { + ast::node_id id, &out_method output) -> result { auto expr_res = trans_expr(cx, expr); auto this_cx = expr_res.bcx; let vec[result] arm_results = []; @@ -4525,7 +4526,7 @@ fn trans_alt(&@block_ctxt cx, &@ast::expr expr, &vec[ast::arm] arms, "non-exhaustive match failure"); // FIXME: This isn't quite right, particularly re: dynamic types - auto expr_ty = ty::ann_to_type(cx.fcx.lcx.ccx.tcx, ann); + auto expr_ty = ty::node_id_to_type(cx.fcx.lcx.ccx.tcx, id); auto expr_llty; if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, expr_ty)) { expr_llty = T_typaram_ptr(cx.fcx.lcx.ccx.tn); @@ -4577,20 +4578,20 @@ fn trans_external_path(&@block_ctxt cx, &ast::def_id did, } fn lval_generic_fn(&@block_ctxt cx, &ty::ty_param_count_and_ty tpt, - &ast::def_id fn_id, &ast::ann ann) -> lval_result { + &ast::def_id fn_id, ast::node_id id) -> lval_result { auto lv; if (cx.fcx.lcx.ccx.sess.get_targ_crate_num() == fn_id._0) { // Internal reference. - assert (cx.fcx.lcx.ccx.fn_pairs.contains_key(fn_id)); - lv = lval_val(cx, cx.fcx.lcx.ccx.fn_pairs.get(fn_id)); + assert (cx.fcx.lcx.ccx.fn_pairs.contains_key(fn_id._1)); + lv = lval_val(cx, cx.fcx.lcx.ccx.fn_pairs.get(fn_id._1)); } else { // External reference. lv = trans_external_path(cx, fn_id, tpt); } - auto tys = ty::ann_to_type_params(cx.fcx.lcx.ccx.tcx, ann); - auto monoty = ty::ann_to_type(cx.fcx.lcx.ccx.tcx, ann); + auto tys = ty::node_id_to_type_params(cx.fcx.lcx.ccx.tcx, id); + auto monoty = ty::node_id_to_type(cx.fcx.lcx.ccx.tcx, id); if (vec::len[ty::t](tys) != 0u) { auto bcx = lv.res.bcx; let vec[ValueRef] tydescs = []; @@ -4614,7 +4615,7 @@ fn lval_generic_fn(&@block_ctxt cx, &ty::ty_param_count_and_ty tpt, fn lookup_discriminant(&@local_ctxt lcx, &ast::def_id tid, &ast::def_id vid) -> ValueRef { - alt (lcx.ccx.discrims.find(vid)) { + alt (lcx.ccx.discrims.find(vid._1)) { case (none) { // It's an external discriminant that we haven't seen yet. @@ -4626,48 +4627,48 @@ fn lookup_discriminant(&@local_ctxt lcx, &ast::def_id tid, &ast::def_id vid) lib::llvm::LLVMExternalLinkage as llvm::Linkage); llvm::LLVMSetGlobalConstant(gvar, True); - lcx.ccx.discrims.insert(vid, gvar); + lcx.ccx.discrims.insert(vid._1, gvar); ret gvar; } case (some(?llval)) { ret llval; } } } -fn trans_path(&@block_ctxt cx, &ast::path p, &ast::ann ann) -> lval_result { - alt (cx.fcx.lcx.ccx.tcx.def_map.get(ann.id)) { +fn trans_path(&@block_ctxt cx, &ast::path p, ast::node_id id) -> lval_result { + alt (cx.fcx.lcx.ccx.tcx.def_map.get(id)) { case (ast::def_arg(?did)) { - alt (cx.fcx.llargs.find(did)) { + alt (cx.fcx.llargs.find(did._1)) { case (none) { - assert (cx.fcx.llupvars.contains_key(did)); - ret lval_mem(cx, cx.fcx.llupvars.get(did)); + assert (cx.fcx.llupvars.contains_key(did._1)); + ret lval_mem(cx, cx.fcx.llupvars.get(did._1)); } case (some(?llval)) { ret lval_mem(cx, llval); } } } case (ast::def_local(?did)) { - alt (cx.fcx.lllocals.find(did)) { + alt (cx.fcx.lllocals.find(did._1)) { case (none) { - assert (cx.fcx.llupvars.contains_key(did)); - ret lval_mem(cx, cx.fcx.llupvars.get(did)); + assert (cx.fcx.llupvars.contains_key(did._1)); + ret lval_mem(cx, cx.fcx.llupvars.get(did._1)); } case (some(?llval)) { ret lval_mem(cx, llval); } } } case (ast::def_binding(?did)) { - assert (cx.fcx.lllocals.contains_key(did)); - ret lval_mem(cx, cx.fcx.lllocals.get(did)); + assert (cx.fcx.lllocals.contains_key(did._1)); + ret lval_mem(cx, cx.fcx.lllocals.get(did._1)); } case (ast::def_obj_field(?did)) { - assert (cx.fcx.llobjfields.contains_key(did)); - ret lval_mem(cx, cx.fcx.llobjfields.get(did)); + assert (cx.fcx.llobjfields.contains_key(did._1)); + ret lval_mem(cx, cx.fcx.llobjfields.get(did._1)); } case (ast::def_fn(?did)) { auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.tcx, did); - ret lval_generic_fn(cx, tyt, did, ann); + ret lval_generic_fn(cx, tyt, did, id); } case (ast::def_obj(?did)) { auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.tcx, did); - ret lval_generic_fn(cx, tyt, did, ann); + ret lval_generic_fn(cx, tyt, did, id); } case (ast::def_variant(?tid, ?vid)) { auto v_tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.tcx, vid); @@ -4675,12 +4676,12 @@ fn trans_path(&@block_ctxt cx, &ast::path p, &ast::ann ann) -> lval_result { case (ty::ty_fn(_, _, _, _, _)) { // N-ary variant. - ret lval_generic_fn(cx, v_tyt, vid, ann); + ret lval_generic_fn(cx, v_tyt, vid, id); } case (_) { // Nullary variant. - auto tag_ty = node_ann_type(cx.fcx.lcx.ccx, ann); + auto tag_ty = node_id_type(cx.fcx.lcx.ccx, id); auto lldiscrim_gv = lookup_discriminant(cx.fcx.lcx, tid, vid); auto lldiscrim = cx.build.Load(lldiscrim_gv); @@ -4707,12 +4708,12 @@ fn trans_path(&@block_ctxt cx, &ast::path p, &ast::ann ann) -> lval_result { case (ast::def_const(?did)) { // TODO: externals - assert (cx.fcx.lcx.ccx.consts.contains_key(did)); - ret lval_mem(cx, cx.fcx.lcx.ccx.consts.get(did)); + assert (cx.fcx.lcx.ccx.consts.contains_key(did._1)); + ret lval_mem(cx, cx.fcx.lcx.ccx.consts.get(did._1)); } case (ast::def_native_fn(?did)) { auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.tcx, did); - ret lval_generic_fn(cx, tyt, did, ann); + ret lval_generic_fn(cx, tyt, did, id); } case (_) { cx.fcx.lcx.ccx.sess.span_unimpl(cx.sp, "def variant in trans"); @@ -4721,7 +4722,7 @@ fn trans_path(&@block_ctxt cx, &ast::path p, &ast::ann ann) -> lval_result { } fn trans_field(&@block_ctxt cx, &span sp, ValueRef v, &ty::t t0, - &ast::ident field, &ast::ann ann) -> lval_result { + &ast::ident field, ast::node_id id) -> lval_result { auto r = autoderef(cx, v, t0); auto t = autoderefed_ty(cx.fcx.lcx.ccx, t0); alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) { @@ -4759,7 +4760,7 @@ fn trans_field(&@block_ctxt cx, &span sp, ValueRef v, &ty::t t0, } fn trans_index(&@block_ctxt cx, &span sp, &@ast::expr base, &@ast::expr idx, - &ast::ann ann) -> lval_result { + ast::node_id id) -> lval_result { // Is this an interior vector? auto base_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, base); @@ -4781,7 +4782,7 @@ fn trans_index(&@block_ctxt cx, &span sp, &@ast::expr base, &@ast::expr idx, } else if (ix_size > int_size) { ix_val = bcx.build.Trunc(ix.val, T_int()); } else { ix_val = ix.val; } - auto unit_ty = node_ann_type(cx.fcx.lcx.ccx, ann); + auto unit_ty = node_id_type(cx.fcx.lcx.ccx, id); auto unit_sz = size_of(bcx, unit_ty); bcx = unit_sz.bcx; maybe_name_value(cx.fcx.lcx.ccx, unit_sz.val, "unit_sz"); @@ -4839,16 +4840,16 @@ fn trans_index(&@block_ctxt cx, &span sp, &@ast::expr base, &@ast::expr idx, // immediate). fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result { alt (e.node) { - case (ast::expr_path(?p, ?ann)) { ret trans_path(cx, p, ann); } - case (ast::expr_field(?base, ?ident, ?ann)) { + case (ast::expr_path(?p, ?id)) { ret trans_path(cx, p, id); } + case (ast::expr_field(?base, ?ident, ?id)) { auto r = trans_expr(cx, base); auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, base); - ret trans_field(r.bcx, e.span, r.val, t, ident, ann); + ret trans_field(r.bcx, e.span, r.val, t, ident, id); } - case (ast::expr_index(?base, ?idx, ?ann)) { - ret trans_index(cx, e.span, base, idx, ann); + case (ast::expr_index(?base, ?idx, ?id)) { + ret trans_index(cx, e.span, base, idx, id); } - case (ast::expr_unary(?unop, ?base, ?ann)) { + case (ast::expr_unary(?unop, ?base, ?id)) { assert (unop == ast::deref); auto sub = trans_expr(cx, base); auto val = @@ -4856,12 +4857,12 @@ fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result { [C_int(0), C_int(abi::box_rc_field_body)]); ret lval_mem(sub.bcx, val); } - case (ast::expr_self_method(?ident, ?ann)) { + case (ast::expr_self_method(?ident, ?id)) { alt ({ cx.fcx.llself }) { case (some(?pair)) { auto r = pair.v; auto t = pair.t; - ret trans_field(cx, e.span, r, t, ident, ann); + ret trans_field(cx, e.span, r, t, ident, id); } case (_) { // Shouldn't happen. @@ -4898,10 +4899,10 @@ fn int_cast(&@block_ctxt bcx, TypeRef lldsttype, TypeRef llsrctype, ret bcx.build.TruncOrBitCast(llsrc, lldsttype); } -fn trans_cast(&@block_ctxt cx, &@ast::expr e, &ast::ann ann) -> result { +fn trans_cast(&@block_ctxt cx, &@ast::expr e, ast::node_id id) -> result { auto e_res = trans_expr(cx, e); auto llsrctype = val_ty(e_res.val); - auto t = node_ann_type(cx.fcx.lcx.ccx, ann); + auto t = node_id_type(cx.fcx.lcx.ccx, id); auto lldsttype = type_of(cx.fcx.lcx.ccx, e.span, t); if (!ty::type_is_fp(cx.fcx.lcx.ccx.tcx, t)) { @@ -5043,7 +5044,7 @@ fn trans_bind_thunk(&@local_ctxt cx, &span sp, &ty::t incoming_fty, } fn trans_bind(&@block_ctxt cx, &@ast::expr f, - &vec[option::t[@ast::expr]] args, &ast::ann ann) -> result { + &vec[option::t[@ast::expr]] args, ast::node_id id) -> result { auto f_res = trans_lval(cx, f); if (f_res.is_mem) { cx.fcx.lcx.ccx.sess.unimpl("re-binding existing function"); @@ -5077,7 +5078,7 @@ fn trans_bind(&@block_ctxt cx, &@ast::expr f, ret f_res.res; } else { auto bcx = f_res.res.bcx; - auto pair_t = node_type(cx.fcx.lcx.ccx, cx.sp, ann); + auto pair_t = node_type(cx.fcx.lcx.ccx, cx.sp, id); auto pair_v = alloca(bcx, pair_t); // Translate the bound expressions. @@ -5188,7 +5189,7 @@ fn trans_bind(&@block_ctxt cx, &@ast::expr f, auto pair_code = bcx.build.GEP(pair_v, [C_int(0), C_int(abi::fn_field_code)]); - let ty::t pair_ty = node_ann_type(cx.fcx.lcx.ccx, ann); + let ty::t pair_ty = node_id_type(cx.fcx.lcx.ccx, id); let ValueRef llthunk = trans_bind_thunk(cx.fcx.lcx, cx.sp, pair_ty, outgoing_fty, args, closure_ty, bound_tys, ty_param_count); @@ -5350,7 +5351,7 @@ fn trans_args(&@block_ctxt cx, ValueRef llenv, &option::t[ValueRef] llobj, } fn trans_call(&@block_ctxt cx, &@ast::expr f, &option::t[ValueRef] lliterbody, - &vec[@ast::expr] args, &ast::ann ann) -> result { + &vec[@ast::expr] args, ast::node_id id) -> result { // NB: 'f' isn't necessarily a function; it might be an entire self-call // expression because of the hack that allows us to process self-calls // with trans_call. @@ -5386,7 +5387,7 @@ fn trans_call(&@block_ctxt cx, &@ast::expr f, &option::t[ValueRef] lliterbody, } case (_) { fn_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, f); } } - auto ret_ty = ty::ann_to_type(cx.fcx.lcx.ccx.tcx, ann); + auto ret_ty = ty::node_id_to_type(cx.fcx.lcx.ccx.tcx, id); auto args_res = trans_args(f_res.res.bcx, llenv, f_res.llobj, f_res.generic, lliterbody, args, fn_ty); @@ -5425,9 +5426,10 @@ fn trans_call(&@block_ctxt cx, &@ast::expr f, &option::t[ValueRef] lliterbody, ret res(bcx, retval); } -fn trans_tup(&@block_ctxt cx, &vec[ast::elt] elts, &ast::ann ann) -> result { +fn trans_tup(&@block_ctxt cx, &vec[ast::elt] elts, ast::node_id id) + -> result { auto bcx = cx; - auto t = node_ann_type(bcx.fcx.lcx.ccx, ann); + auto t = node_id_type(bcx.fcx.lcx.ccx, id); auto tup_res = alloc_ty(bcx, t); auto tup_val = tup_res.val; bcx = tup_res.bcx; @@ -5445,9 +5447,9 @@ fn trans_tup(&@block_ctxt cx, &vec[ast::elt] elts, &ast::ann ann) -> result { ret res(bcx, tup_val); } -fn trans_vec(&@block_ctxt cx, &vec[@ast::expr] args, &ast::ann ann) -> +fn trans_vec(&@block_ctxt cx, &vec[@ast::expr] args, ast::node_id id) -> result { - auto t = node_ann_type(cx.fcx.lcx.ccx, ann); + auto t = node_id_type(cx.fcx.lcx.ccx, id); auto unit_ty = t; alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) { case (ty::ty_vec(?mt)) { unit_ty = mt.ty; } @@ -5505,9 +5507,9 @@ fn trans_vec(&@block_ctxt cx, &vec[@ast::expr] args, &ast::ann ann) -> // TODO: Move me to ivec:: -fn trans_ivec(@block_ctxt bcx, &vec[@ast::expr] args, &ast::ann ann) -> - result { - auto typ = node_ann_type(bcx.fcx.lcx.ccx, ann); +fn trans_ivec(@block_ctxt bcx, &vec[@ast::expr] args, ast::node_id id) -> + result { + auto typ = node_id_type(bcx.fcx.lcx.ccx, id); auto unit_ty; alt (ty::struct(bcx.fcx.lcx.ccx.tcx, typ)) { case (ty::ty_ivec(?mt)) { unit_ty = mt.ty; } @@ -5599,9 +5601,9 @@ fn trans_ivec(@block_ctxt bcx, &vec[@ast::expr] args, &ast::ann ann) -> } fn trans_rec(&@block_ctxt cx, &vec[ast::field] fields, - &option::t[@ast::expr] base, &ast::ann ann) -> result { + &option::t[@ast::expr] base, ast::node_id id) -> result { auto bcx = cx; - auto t = node_ann_type(bcx.fcx.lcx.ccx, ann); + auto t = node_id_type(bcx.fcx.lcx.ccx, id); auto rec_res = alloc_ty(bcx, t); auto rec_val = rec_res.val; bcx = rec_res.bcx; @@ -5653,18 +5655,18 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) -> // FIXME Fill in cx.sp alt (e.node) { - case (ast::expr_lit(?lit, ?ann)) { - ret res(cx, trans_lit(cx.fcx.lcx.ccx, *lit, ann)); + case (ast::expr_lit(?lit, ?id)) { + ret res(cx, trans_lit(cx.fcx.lcx.ccx, *lit, id)); } - case (ast::expr_unary(?op, ?x, ?ann)) { - if (op != ast::deref) { ret trans_unary(cx, op, x, ann); } + case (ast::expr_unary(?op, ?x, ?id)) { + if (op != ast::deref) { ret trans_unary(cx, op, x, id); } } case (ast::expr_binary(?op, ?x, ?y, _)) { ret trans_binary(cx, op, x, y); } - case (ast::expr_if(?cond, ?thn, ?els, ?ann)) { - ret with_out_method(bind trans_if(cx, cond, thn, els, ann, _), cx, - ann, output); + case (ast::expr_if(?cond, ?thn, ?els, ?id)) { + ret with_out_method(bind trans_if(cx, cond, thn, els, id, _), cx, + id, output); } case (ast::expr_if_check(?cond, ?thn, ?els, ?ann)) { ret with_out_method(bind trans_if(cx, cond, thn, els, ann, _), cx, @@ -5682,14 +5684,14 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) -> case (ast::expr_do_while(?body, ?cond, _)) { ret trans_do_while(cx, body, cond); } - case (ast::expr_alt(?expr, ?arms, ?ann)) { - ret with_out_method(bind trans_alt(cx, expr, arms, ann, _), cx, - ann, output); + case (ast::expr_alt(?expr, ?arms, ?id)) { + ret with_out_method(bind trans_alt(cx, expr, arms, id, _), cx, + id, output); } - case (ast::expr_fn(?f, ?ann)) { + case (ast::expr_fn(?f, ?id)) { auto ccx = cx.fcx.lcx.ccx; let TypeRef llfnty = - alt (ty::struct(ccx.tcx, node_ann_type(ccx, ann))) { + alt (ty::struct(ccx.tcx, node_id_type(ccx, id))) { case (ty::ty_fn(?proto, ?inputs, ?output, _, _)) { type_of_fn_full(ccx, e.span, proto, none, inputs, output, 0u) @@ -5698,14 +5700,14 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) -> auto sub_cx = extend_path(cx.fcx.lcx, ccx.names.next("anon")); auto s = mangle_internal_name_by_path(ccx, sub_cx.path); auto llfn = decl_internal_fastcall_fn(ccx.llmod, s, llfnty); - trans_fn(sub_cx, e.span, f, llfn, none, [], ann); + trans_fn(sub_cx, e.span, f, llfn, none, [], id); ret res(cx, create_fn_pair(ccx, s, llfnty, llfn, false)); } - case (ast::expr_block(?blk, ?ann)) { + case (ast::expr_block(?blk, ?id)) { auto sub_cx = new_scope_block_ctxt(cx, "block-expr body"); auto next_cx = new_sub_block_ctxt(cx, "next"); auto sub = - with_out_method(bind trans_block(sub_cx, blk, _), cx, ann, + with_out_method(bind trans_block(sub_cx, blk, _), cx, id, output); cx.build.Br(sub_cx.llbb); sub.bcx.build.Br(next_cx.llbb); @@ -5788,22 +5790,22 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) -> copy_val(v.bcx, DROP_EXISTING, lhs_res.res.val, v.val, t); ret res(copy_res.bcx, C_nil()); } - case (ast::expr_bind(?f, ?args, ?ann)) { - ret trans_bind(cx, f, args, ann); + case (ast::expr_bind(?f, ?args, ?id)) { + ret trans_bind(cx, f, args, id); } - case (ast::expr_call(?f, ?args, ?ann)) { - ret trans_call(cx, f, none[ValueRef], args, ann); + case (ast::expr_call(?f, ?args, ?id)) { + ret trans_call(cx, f, none[ValueRef], args, id); } - case (ast::expr_cast(?e, _, ?ann)) { ret trans_cast(cx, e, ann); } - case (ast::expr_vec(?args, _, ast::sk_rc, ?ann)) { - ret trans_vec(cx, args, ann); + case (ast::expr_cast(?e, _, ?id)) { ret trans_cast(cx, e, id); } + case (ast::expr_vec(?args, _, ast::sk_rc, ?id)) { + ret trans_vec(cx, args, id); } - case (ast::expr_vec(?args, _, ast::sk_unique, ?ann)) { - ret trans_ivec(cx, args, ann); + case (ast::expr_vec(?args, _, ast::sk_unique, ?id)) { + ret trans_ivec(cx, args, id); } - case (ast::expr_tup(?args, ?ann)) { ret trans_tup(cx, args, ann); } - case (ast::expr_rec(?args, ?base, ?ann)) { - ret trans_rec(cx, args, base, ann); + case (ast::expr_tup(?args, ?id)) { ret trans_tup(cx, args, id); } + case (ast::expr_rec(?args, ?base, ?id)) { + ret trans_rec(cx, args, base, id); } case (ast::expr_ext(_, _, _, ?expanded, _)) { ret trans_expr(cx, expanded); @@ -5828,19 +5830,19 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) -> case (ast::expr_ret(?e, _)) { ret trans_ret(cx, e); } case (ast::expr_put(?e, _)) { ret trans_put(cx, e); } case (ast::expr_be(?e, _)) { ret trans_be(cx, e); } - case (ast::expr_port(?ann)) { ret trans_port(cx, ann); } - case (ast::expr_chan(?e, ?ann)) { ret trans_chan(cx, e, ann); } - case (ast::expr_send(?lhs, ?rhs, ?ann)) { - ret trans_send(cx, lhs, rhs, ann); + case (ast::expr_port(?id)) { ret trans_port(cx, id); } + case (ast::expr_chan(?e, ?id)) { ret trans_chan(cx, e, id); } + case (ast::expr_send(?lhs, ?rhs, ?id)) { + ret trans_send(cx, lhs, rhs, id); } - case (ast::expr_recv(?lhs, ?rhs, ?ann)) { - ret trans_recv(cx, lhs, rhs, ann); + case (ast::expr_recv(?lhs, ?rhs, ?id)) { + ret trans_recv(cx, lhs, rhs, id); } - case (ast::expr_spawn(?dom, ?name, ?func, ?args, ?ann)) { - ret trans_spawn(cx, dom, name, func, args, ann); + case (ast::expr_spawn(?dom, ?name, ?func, ?args, ?id)) { + ret trans_spawn(cx, dom, name, func, args, id); } - case (ast::expr_anon_obj(?anon_obj, ?tps, ?odid, ?ann)) { - ret trans_anon_obj(cx, e.span, anon_obj, tps, odid.ctor, ann); + case (ast::expr_anon_obj(?anon_obj, ?tps, ?odid, ?id)) { + ret trans_anon_obj(cx, e.span, anon_obj, tps, odid.ctor, id); } case (_) { // The expression is an lvalue. Fall through. @@ -5857,12 +5859,12 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) -> } fn with_out_method(fn(&out_method) -> result work, @block_ctxt cx, - &ast::ann ann, &out_method outer_output) -> result { + ast::node_id id, &out_method outer_output) -> result { auto ccx = cx.fcx.lcx.ccx; if (outer_output != return) { ret work(outer_output); } else { - auto tp = node_ann_type(ccx, ann); + auto tp = node_id_type(ccx, id); if (ty::type_is_nil(ccx.tcx, tp)) { ret work(return); } auto res_alloca = alloc_ty(cx, tp); cx = zero_alloca(res_alloca.bcx, res_alloca.val, tp).bcx; @@ -6144,8 +6146,8 @@ fn trans_be(&@block_ctxt cx, &@ast::expr e) -> result { ret trans_ret(cx, some(e)); } -fn trans_port(&@block_ctxt cx, &ast::ann ann) -> result { - auto t = node_ann_type(cx.fcx.lcx.ccx, ann); +fn trans_port(&@block_ctxt cx, ast::node_id id) -> result { + auto t = node_id_type(cx.fcx.lcx.ccx, id); auto unit_ty; alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) { case (ty::ty_port(?t)) { unit_ty = t; } @@ -6165,7 +6167,7 @@ fn trans_port(&@block_ctxt cx, &ast::ann ann) -> result { ret res(bcx, port_val); } -fn trans_chan(&@block_ctxt cx, &@ast::expr e, &ast::ann ann) -> result { +fn trans_chan(&@block_ctxt cx, &@ast::expr e, ast::node_id id) -> result { auto bcx = cx; auto prt = trans_expr(bcx, e); bcx = prt.bcx; @@ -6173,7 +6175,7 @@ fn trans_chan(&@block_ctxt cx, &@ast::expr e, &ast::ann ann) -> result { auto chan_raw_val = bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.new_chan, [bcx.fcx.lltaskptr, prt_val]); - auto chan_ty = node_ann_type(bcx.fcx.lcx.ccx, ann); + auto chan_ty = node_id_type(bcx.fcx.lcx.ccx, id); auto chan_llty = type_of(bcx.fcx.lcx.ccx, e.span, chan_ty); auto chan_val = bcx.build.PointerCast(chan_raw_val, chan_llty); auto dropref = clean(bind drop_ty(_, chan_val, chan_ty)); @@ -6182,7 +6184,7 @@ fn trans_chan(&@block_ctxt cx, &@ast::expr e, &ast::ann ann) -> result { } fn trans_spawn(&@block_ctxt cx, &ast::spawn_dom dom, &option::t[str] name, - &@ast::expr func, &vec[@ast::expr] args, &ast::ann ann) -> + &@ast::expr func, &vec[@ast::expr] args, ast::node_id id) -> result { auto bcx = cx; // Make the task name @@ -6270,7 +6272,7 @@ fn trans_spawn(&@block_ctxt cx, &ast::spawn_dom dom, &option::t[str] name, bcx.build.Call(bcx.fcx.lcx.ccx.upcalls.start_task, [bcx.fcx.lltaskptr, new_task, llfnptr_i, llargs_i, args_size]); - auto task_ty = node_ann_type(bcx.fcx.lcx.ccx, ann); + auto task_ty = node_id_type(bcx.fcx.lcx.ccx, id); auto dropref = clean(bind drop_ty(_, new_task, task_ty)); find_scope_cx(bcx).cleanups += [dropref]; ret res(bcx, new_task); @@ -6377,13 +6379,13 @@ fn deep_copy(&@block_ctxt bcx, ValueRef v, ty::t t, ValueRef target_task) } fn trans_send(&@block_ctxt cx, &@ast::expr lhs, &@ast::expr rhs, - &ast::ann ann) -> result { + ast::node_id id) -> result { auto bcx = cx; auto chn = trans_expr(bcx, lhs); bcx = chn.bcx; auto data = trans_expr(bcx, rhs); bcx = data.bcx; - auto chan_ty = node_ann_type(cx.fcx.lcx.ccx, ann); + auto chan_ty = node_id_type(cx.fcx.lcx.ccx, id); auto unit_ty; alt (ty::struct(cx.fcx.lcx.ccx.tcx, chan_ty)) { case (ty::ty_chan(?t)) { unit_ty = t; } @@ -6403,12 +6405,12 @@ fn trans_send(&@block_ctxt cx, &@ast::expr lhs, &@ast::expr rhs, } fn trans_recv(&@block_ctxt cx, &@ast::expr lhs, &@ast::expr rhs, - &ast::ann ann) -> result { + ast::node_id id) -> result { auto bcx = cx; auto data = trans_lval(bcx, rhs); assert (data.is_mem); bcx = data.res.bcx; - auto unit_ty = node_ann_type(bcx.fcx.lcx.ccx, ann); + auto unit_ty = node_id_type(bcx.fcx.lcx.ccx, id); // FIXME: calculate copy init-ness in typestate. ret recv_val(bcx, data.res.val, lhs, unit_ty, DROP_EXISTING); @@ -6469,9 +6471,10 @@ fn recv_val(&@block_ctxt cx, ValueRef to, &@ast::expr from, &ty::t unit_ty, // function and putting it in the generated code as an object item, we are // instead "inlining" the construction of the object and returning the object // itself. -fn trans_anon_obj(@block_ctxt bcx, &span sp, &ast::anon_obj anon_obj, - &vec[ast::ty_param] ty_params, ast::def_id oid, - &ast::ann ann) -> result { +fn trans_anon_obj(@block_ctxt bcx, &span sp, &ast::anon_obj anon_obj, + &vec[ast::ty_param] ty_params, ast::node_id oid, + ast::node_id id) -> result { + // Right now, we're assuming that anon objs don't take ty params, even // though the AST supports it. It's nonsensical to write an expression // like "obj[T](){ ... with ... }", since T is never instantiated; @@ -6498,7 +6501,7 @@ fn trans_anon_obj(@block_ctxt bcx, &span sp, &ast::anon_obj anon_obj, // trans_obj for translating the anonymous wrapper object. Eventually we // should abstract this code out of trans_anon_obj and trans_obj. - auto self_ty = ty::ann_to_type(ccx.tcx, ann); + auto self_ty = ty::node_id_to_type(ccx.tcx, id); auto llself_ty = type_of(ccx, sp, self_ty); // Allocate the object that we're going to return. It's a two-word pair // containing a vtable pointer and a body pointer. @@ -6569,7 +6572,7 @@ fn init_local(&@block_ctxt cx, &@ast::local local) -> result { assert (cx.fcx.lllocals.contains_key(local.node.id)); auto llptr = cx.fcx.lllocals.get(local.node.id); - auto ty = node_ann_type(cx.fcx.lcx.ccx, local.node.ann); + auto ty = node_id_type(cx.fcx.lcx.ccx, local.node.id); auto bcx = cx; find_scope_cx(cx).cleanups += [clean(bind drop_slot(_, llptr, ty))]; alt (local.node.init) { @@ -6581,8 +6584,8 @@ fn init_local(&@block_ctxt cx, &@ast::local local) -> result { // the value. ty = - node_ann_type(cx.fcx.lcx.ccx, - ty::expr_ann(init.expr)); + node_id_type(cx.fcx.lcx.ccx, + ty::expr_node_id(init.expr)); auto sub = trans_expr(bcx, init.expr); bcx = copy_val(sub.bcx, INIT, llptr, sub.val, ty).bcx; } @@ -6794,7 +6797,7 @@ fn alloc_ty(&@block_ctxt cx, &ty::t t) -> result { } fn alloc_local(&@block_ctxt cx, &@ast::local local) -> result { - auto t = node_ann_type(cx.fcx.lcx.ccx, local.node.ann); + auto t = node_id_type(cx.fcx.lcx.ccx, local.node.id); auto r = alloc_ty(cx, t); r.bcx.fcx.lllocals.insert(local.node.id, r.val); ret r; @@ -6890,10 +6893,11 @@ fn new_fn_ctxt(@local_ctxt cx, &span sp, ValueRef llfndecl) -> @fn_ctxt { let ValueRef llretptr = llvm::LLVMGetParam(llfndecl, 0u); let ValueRef lltaskptr = llvm::LLVMGetParam(llfndecl, 1u); let ValueRef llenv = llvm::LLVMGetParam(llfndecl, 2u); - let hashmap[ast::def_id, ValueRef] llargs = new_def_hash[ValueRef](); - let hashmap[ast::def_id, ValueRef] llobjfields = new_def_hash[ValueRef](); - let hashmap[ast::def_id, ValueRef] lllocals = new_def_hash[ValueRef](); - let hashmap[ast::def_id, ValueRef] llupvars = new_def_hash[ValueRef](); + let hashmap[ast::node_id, ValueRef] llargs = new_int_hash[ValueRef](); + let hashmap[ast::node_id, ValueRef] llobjfields = + new_int_hash[ValueRef](); + let hashmap[ast::node_id, ValueRef] lllocals = new_int_hash[ValueRef](); + let hashmap[ast::node_id, ValueRef] llupvars = new_int_hash[ValueRef](); auto derived_tydescs = map::mk_hashmap[ty::t, derived_tydesc_info](ty::hash_ty, ty::eq_ty); auto llbbs = mk_standard_basic_blocks(llfndecl); @@ -7034,8 +7038,8 @@ fn is_terminated(&@block_ctxt cx) -> bool { ret llvm::LLVMIsATerminatorInst(inst) as int != 0; } -fn arg_tys_of_fn(&@crate_ctxt ccx, ast::ann ann) -> vec[ty::arg] { - alt (ty::struct(ccx.tcx, ty::ann_to_type(ccx.tcx, ann))) { +fn arg_tys_of_fn(&@crate_ctxt ccx,ast::node_id id) -> vec[ty::arg] { + alt (ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, id))) { case (ty::ty_fn(_, ?arg_tys, _, _, _)) { ret arg_tys; } } } @@ -7044,7 +7048,7 @@ fn populate_fn_ctxt_from_llself(@fn_ctxt fcx, val_self_pair llself) { auto bcx = llstaticallocas_block_ctxt(fcx); let vec[ty::t] field_tys = []; for (ast::obj_field f in bcx.fcx.lcx.obj_fields) { - field_tys += [node_ann_type(bcx.fcx.lcx.ccx, f.ann)]; + field_tys += [node_id_type(bcx.fcx.lcx.ccx, f.id)]; } // Synthesize a tuple type for the fields so that GEP_tup_like() can work // its magic. @@ -7107,20 +7111,20 @@ fn finish_fn(&@fn_ctxt fcx, BasicBlockRef lltop) { // function. fn trans_fn(@local_ctxt cx, &span sp, &ast::_fn f, ValueRef llfndecl, option::t[ty_self_pair] ty_self, &vec[ast::ty_param] ty_params, - &ast::ann ann) { + ast::node_id id) { set_uwtable(llfndecl); // Set up arguments to the function. auto fcx = new_fn_ctxt(cx, sp, llfndecl); create_llargs_for_fn_args(fcx, f.proto, ty_self, - ty::ret_ty_of_fn(cx.ccx.tcx, ann), + ty::ret_ty_of_fn(cx.ccx.tcx, id), f.decl.inputs, ty_params); copy_any_self_to_alloca(fcx, ty_self); alt ({ fcx.llself }) { case (some(?llself)) { populate_fn_ctxt_from_llself(fcx, llself); } case (_) { } } - auto arg_tys = arg_tys_of_fn(fcx.lcx.ccx, ann); + auto arg_tys = arg_tys_of_fn(fcx.lcx.ccx, id); copy_args_to_allocas(fcx, f.decl.inputs, arg_tys); // Create the first basic block in the function and keep a handle on it to // pass to finish_fn later. @@ -7128,7 +7132,7 @@ fn trans_fn(@local_ctxt cx, &span sp, &ast::_fn f, ValueRef llfndecl, auto bcx = new_top_block_ctxt(fcx); add_cleanups_for_args(bcx, f.decl.inputs, arg_tys); auto lltop = bcx.llbb; - auto block_ty = node_ann_type(cx.ccx, f.body.node.a); + auto block_ty = node_id_type(cx.ccx, f.body.node.id); // This call to trans_block is the place where we bridge between // translation calls that don't have a return value (trans_crate, // trans_mod, trans_item, trans_obj, et cetera) and those that do @@ -7171,7 +7175,7 @@ fn create_vtbl(@local_ctxt cx, TypeRef llself_ty, ty::t self_ty, std::sort::merge_sort[@ast::method](bind meth_lteq(_, _), ob.methods); for (@ast::method m in meths) { auto llfnty = T_nil(); - alt (ty::struct(cx.ccx.tcx, node_ann_type(cx.ccx, m.node.ann))) { + alt (ty::struct(cx.ccx.tcx, node_id_type(cx.ccx, m.node.id))) { case (ty::ty_fn(?proto, ?inputs, ?output, _, _)) { llfnty = type_of_fn_full(cx.ccx, m.span, proto, @@ -7192,7 +7196,7 @@ fn create_vtbl(@local_ctxt cx, TypeRef llself_ty, ty::t self_ty, cx.ccx.item_symbols.insert(m.node.id, s); trans_fn(mcx, m.span, m.node.meth, llfn, some[ty_self_pair](tup(llself_ty, self_ty)), ty_params, - m.node.ann); + m.node.id); methods += [llfn]; } auto vtbl = C_struct(methods); @@ -7215,20 +7219,20 @@ fn trans_dtor(@local_ctxt cx, TypeRef llself_ty, ty::t self_ty, cx.ccx.item_symbols.insert(dtor.node.id, s); trans_fn(cx, dtor.span, dtor.node.meth, llfn, some[ty_self_pair](tup(llself_ty, self_ty)), ty_params, - dtor.node.ann); + dtor.node.id); ret llfn; } // trans_obj: creates an LLVM function that is the object constructor for the // object being translated. -fn trans_obj(@local_ctxt cx, &span sp, &ast::_obj ob, ast::def_id oid, - &vec[ast::ty_param] ty_params, &ast::ann ann) { +fn trans_obj(@local_ctxt cx, &span sp, &ast::_obj ob, ast::node_id ctor_id, + &vec[ast::ty_param] ty_params, ast::node_id type_id) { // To make a function, we have to create a function context and, inside // that, a number of block contexts for which code is generated. auto ccx = cx.ccx; - auto llctor_decl = ccx.item_ids.get(oid); + auto llctor_decl = ccx.item_ids.get(ctor_id); // Much like trans_fn, we must create an LLVM function, but since we're // starting with an ast::_obj rather than an ast::_fn, we have some setup // work to do. @@ -7245,9 +7249,9 @@ fn trans_obj(@local_ctxt cx, &span sp, &ast::_obj ob, ast::def_id oid, // Both regular arguments and type parameters are handled here. create_llargs_for_fn_args(fcx, ast::proto_fn, none[ty_self_pair], - ty::ret_ty_of_fn(ccx.tcx, ann), + ty::ret_ty_of_fn(ccx.tcx, type_id), fn_args, ty_params); - let vec[ty::arg] arg_tys = arg_tys_of_fn(ccx, ann); + let vec[ty::arg] arg_tys = arg_tys_of_fn(ccx, type_id); copy_args_to_allocas(fcx, fn_args, arg_tys); // Create the first block context in the function and keep a handle on it // to pass to finish_fn later. @@ -7257,7 +7261,7 @@ fn trans_obj(@local_ctxt cx, &span sp, &ast::_obj ob, ast::def_id oid, // Pick up the type of this object by looking at our own output type, that // is, the output type of the object constructor we're building. - auto self_ty = ty::ret_ty_of_fn(ccx.tcx, ann); + auto self_ty = ty::ret_ty_of_fn(ccx.tcx, type_id); auto llself_ty = type_of(ccx, sp, self_ty); // Set up the two-word pair that we're going to return from the object // constructor we're building. The two elements of this pair will be a @@ -7410,7 +7414,7 @@ fn trans_obj(@local_ctxt cx, &span sp, &ast::_obj ob, ast::def_id oid, finish_fn(fcx, lltop); } -fn trans_tag_variant(@local_ctxt cx, ast::def_id tag_id, +fn trans_tag_variant(@local_ctxt cx, ast::node_id tag_id, &ast::variant variant, int index, &vec[ast::ty_param] ty_params) { if (vec::len[ast::variant_arg](variant.node.args) == 0u) { @@ -7432,16 +7436,15 @@ fn trans_tag_variant(@local_ctxt cx, ast::def_id tag_id, let ValueRef llfndecl = cx.ccx.item_ids.get(variant.node.id); auto fcx = new_fn_ctxt(cx, variant.span, llfndecl); create_llargs_for_fn_args(fcx, ast::proto_fn, none[ty_self_pair], - ty::ret_ty_of_fn(cx.ccx.tcx, variant.node.ann), - fn_args, - ty_params); + ty::ret_ty_of_fn(cx.ccx.tcx, variant.node.id), + fn_args, ty_params); let vec[ty::t] ty_param_substs = []; i = 0u; for (ast::ty_param tp in ty_params) { ty_param_substs += [ty::mk_param(cx.ccx.tcx, i)]; i += 1u; } - auto arg_tys = arg_tys_of_fn(cx.ccx, variant.node.ann); + auto arg_tys = arg_tys_of_fn(cx.ccx, variant.node.id); copy_args_to_allocas(fcx, fn_args, arg_tys); auto bcx = new_top_block_ctxt(fcx); auto lltop = bcx.llbb; @@ -7455,7 +7458,8 @@ fn trans_tag_variant(@local_ctxt cx, ast::def_id tag_id, i = 0u; for (ast::variant_arg va in variant.node.args) { auto rslt = - GEP_tag(bcx, llblobptr, tag_id, variant.node.id, ty_param_substs, + GEP_tag(bcx, llblobptr, ast::local_def(tag_id), + ast::local_def(variant.node.id), ty_param_substs, i as int); bcx = rslt.bcx; auto lldestptr = rslt.val; @@ -7486,21 +7490,20 @@ fn trans_tag_variant(@local_ctxt cx, ast::def_id tag_id, // that does so later on? fn trans_const_expr(&@crate_ctxt cx, @ast::expr e) -> ValueRef { alt (e.node) { - case (ast::expr_lit(?lit, ?ann)) { ret trans_lit(cx, *lit, ann); } + case (ast::expr_lit(?lit, ?id)) { ret trans_lit(cx, *lit, id); } case (_) { cx.sess.span_unimpl(e.span, "consts that's not a plain literal"); } } } -fn trans_const(&@crate_ctxt cx, @ast::expr e, &ast::def_id cid, - &ast::ann ann) { - auto t = node_ann_type(cx, ann); +fn trans_const(&@crate_ctxt cx, @ast::expr e, ast::node_id id) { + auto t = node_id_type(cx, id); auto v = trans_const_expr(cx, e); // The scalars come back as 1st class LLVM vals // which we have to stick into global constants. - auto g = cx.consts.get(cid); + auto g = cx.consts.get(id); llvm::LLVMSetInitializer(g, v); llvm::LLVMSetGlobalConstant(g, True); } @@ -7511,13 +7514,13 @@ fn trans_item(@local_ctxt cx, &ast::item item) { auto sub_cx = extend_path(cx, item.ident); auto llfndecl = cx.ccx.item_ids.get(item.id); trans_fn(sub_cx, item.span, f, llfndecl, none[ty_self_pair], tps, - item.ann); + item.id); } case (ast::item_obj(?ob, ?tps, ?ctor_id)) { auto sub_cx = @rec(obj_typarams=tps, obj_fields=ob.fields with *extend_path(cx, item.ident)); - trans_obj(sub_cx, item.span, ob, ctor_id, tps, item.ann); + trans_obj(sub_cx, item.span, ob, ctor_id, tps, item.id); } case (ast::item_mod(?m)) { auto sub_cx = @@ -7534,7 +7537,7 @@ fn trans_item(@local_ctxt cx, &ast::item item) { } } case (ast::item_const(_, ?expr)) { - trans_const(cx.ccx, expr, item.id, item.ann); + trans_const(cx.ccx, expr, item.id); } case (_) {/* fall through */ } } @@ -7557,10 +7560,10 @@ fn get_pair_fn_ty(TypeRef llpairty) -> TypeRef { } fn decl_fn_and_pair(&@crate_ctxt ccx, &span sp, vec[str] path, str flav, - vec[ast::ty_param] ty_params, &ast::ann ann, - ast::def_id id) { + vec[ast::ty_param] ty_params, ast::node_id node_id, + ast::node_id def_id) { auto llfty; - alt (ty::struct(ccx.tcx, node_ann_type(ccx, ann))) { + alt (ty::struct(ccx.tcx, node_id_type(ccx, node_id))) { case (ty::ty_fn(?proto, ?inputs, ?output, _, _)) { llfty = type_of_fn(ccx, sp, proto, inputs, output, @@ -7581,8 +7584,8 @@ fn decl_fn_and_pair(&@crate_ctxt ccx, &span sp, vec[str] path, str flav, let ValueRef llfn = decl_internal_fastcall_fn(ccx.llmod, s, llfty); // Declare the global constant pair that points to it. - let str ps = mangle_exported_name(ccx, path, node_ann_type(ccx, ann)); - register_fn_pair(ccx, ps, llfty, llfn, id); + let str ps = mangle_exported_name(ccx, path, node_id_type(ccx, node_id)); + register_fn_pair(ccx, ps, llfty, llfn, def_id); if (is_main) { if (ccx.main_fn != none[ValueRef]) { ccx.sess.span_fatal(sp, "multiple 'main' functions"); @@ -7608,7 +7611,7 @@ fn create_fn_pair(&@crate_ctxt cx, str ps, TypeRef llfnty, ValueRef llfn, } fn register_fn_pair(&@crate_ctxt cx, str ps, TypeRef llfnty, ValueRef llfn, - ast::def_id id) { + ast::node_id id) { // FIXME: We should also hide the unexported pairs in crates. auto gvar = @@ -7620,7 +7623,7 @@ fn register_fn_pair(&@crate_ctxt cx, str ps, TypeRef llfnty, ValueRef llfn, // Returns the number of type parameters that the given native function has. -fn native_fn_ty_param_count(&@crate_ctxt cx, &ast::def_id id) -> uint { +fn native_fn_ty_param_count(&@crate_ctxt cx, ast::node_id id) -> uint { auto count; auto native_item = cx.native_items.get(id); alt (native_item.node) { @@ -7628,7 +7631,7 @@ fn native_fn_ty_param_count(&@crate_ctxt cx, &ast::def_id id) -> uint { cx.sess.bug("decl_native_fn_and_pair(): native fn isn't " + "actually a fn"); } - case (ast::native_item_fn(_, _, _, ?tps, _, _)) { + case (ast::native_item_fn(_, _, _, ?tps, _)) { count = vec::len[ast::ty_param](tps); } } @@ -7645,18 +7648,18 @@ fn native_fn_wrapper_type(&@crate_ctxt cx, &span sp, uint ty_param_count, } fn decl_native_fn_and_pair(&@crate_ctxt ccx, &span sp, vec[str] path, - str name, &ast::ann ann, ast::def_id id) { + str name, ast::node_id id) { auto num_ty_param = native_fn_ty_param_count(ccx, id); // Declare the wrapper. - auto t = node_ann_type(ccx, ann); + auto t = node_id_type(ccx, id); auto wrapper_type = native_fn_wrapper_type(ccx, sp, num_ty_param, t); let str s = mangle_internal_name_by_path(ccx, path); let ValueRef wrapper_fn = decl_internal_fastcall_fn(ccx.llmod, s, wrapper_type); // Declare the global constant pair that points to it. - let str ps = mangle_exported_name(ccx, path, node_ann_type(ccx, ann)); + let str ps = mangle_exported_name(ccx, path, node_id_type(ccx, id)); register_fn_pair(ccx, ps, wrapper_type, wrapper_fn, id); // Build the wrapper. @@ -7666,7 +7669,7 @@ fn decl_native_fn_and_pair(&@crate_ctxt ccx, &span sp, vec[str] path, // Declare the function itself. auto item = ccx.native_items.get(id); - auto fn_type = node_ann_type(ccx, ann); // NB: has no type params + auto fn_type = node_id_type(ccx, id); // NB: has no type params auto abi = ty::ty_fn_abi(ccx.tcx, fn_type); auto llfnty = @@ -7803,14 +7806,14 @@ fn item_path(&@ast::item item) -> vec[str] { ret [item.ident]; } fn collect_native_item(@crate_ctxt ccx, &@ast::native_item i, &vec[str] pt, &vt[vec[str]] v) { alt (i.node) { - case (ast::native_item_fn(?name, _, _, _, ?fid, ?ann)) { - ccx.native_items.insert(fid, i); - if (!ccx.obj_methods.contains_key(fid)) { - decl_native_fn_and_pair(ccx, i.span, pt, name, ann, fid); + case (ast::native_item_fn(?name, _, _, _, ?id)) { + ccx.native_items.insert(id, i); + if (!ccx.obj_methods.contains_key(id)) { + decl_native_fn_and_pair(ccx, i.span, pt, name, id); } } - case (ast::native_item_ty(_, ?tid)) { - ccx.native_items.insert(tid, i); + case (ast::native_item_ty(_, ?id)) { + ccx.native_items.insert(id, i); } } } @@ -7820,7 +7823,7 @@ fn collect_item_1(@crate_ctxt ccx, &@ast::item i, &vec[str] pt, visit::visit_item(i, pt + item_path(i), v); alt (i.node) { case (ast::item_const(_, _)) { - auto typ = node_ann_type(ccx, i.ann); + auto typ = node_id_type(ccx, i.id); auto g = llvm::LLVMAddGlobal(ccx.llmod, type_of(ccx, i.span, typ), str::buf(ccx.names.next(i.ident))); @@ -7846,12 +7849,12 @@ fn collect_item_2(&@crate_ctxt ccx, &@ast::item i, &vec[str] pt, case (ast::item_fn(?f, ?tps)) { ccx.items.insert(i.id, i); if (!ccx.obj_methods.contains_key(i.id)) { - decl_fn_and_pair(ccx, i.span, new_pt, "fn", tps, i.ann, i.id); + decl_fn_and_pair(ccx, i.span, new_pt, "fn", tps, i.id, i.id); } } case (ast::item_obj(?ob, ?tps, ?ctor_id)) { ccx.items.insert(ctor_id, i); - decl_fn_and_pair(ccx, i.span, new_pt, "obj_ctor", tps, i.ann, + decl_fn_and_pair(ccx, i.span, new_pt, "obj_ctor", tps, i.id, ctor_id); for (@ast::method m in ob.methods) { ccx.obj_methods.insert(m.node.id, ()); @@ -7882,7 +7885,7 @@ fn collect_tag_ctor(@crate_ctxt ccx, &@ast::item i, &vec[str] pt, if (vec::len[ast::variant_arg](variant.node.args) != 0u) { decl_fn_and_pair(ccx, i.span, new_pt + [variant.node.name], "tag", tps, - variant.node.ann, variant.node.id); + variant.node.id, variant.node.id); } } } @@ -7929,7 +7932,7 @@ fn trans_constant(@crate_ctxt ccx, &@ast::item it, &vec[str] pt, ccx.item_ids.insert(it.id, v); auto s = mangle_exported_name(ccx, new_pt + [it.ident], - node_ann_type(ccx, it.ann)); + node_id_type(ccx, it.id)); ccx.item_symbols.insert(it.id, s); } case (_) { } @@ -8128,20 +8131,20 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx, tn=tn, externs=new_str_hash[ValueRef](), intrinsics=intrinsics, - item_ids=new_def_hash[ValueRef](), - items=new_def_hash[@ast::item](), - native_items=new_def_hash[@ast::native_item](), - item_symbols=new_def_hash[str](), + item_ids=new_int_hash[ValueRef](), + items=new_int_hash[@ast::item](), + native_items=new_int_hash[@ast::native_item](), + item_symbols=new_int_hash[str](), mutable main_fn=none[ValueRef], crate_meta_name=crate_meta_name(sess, *crate, output), crate_meta_vers=crate_meta_vers(sess, *crate), crate_meta_extras_hash=crate_meta_extras_hash(sha, *crate), tag_sizes=tag_sizes, - discrims=new_def_hash[ValueRef](), - discrim_symbols=new_def_hash[str](), - fn_pairs=new_def_hash[ValueRef](), - consts=new_def_hash[ValueRef](), - obj_methods=new_def_hash[()](), + discrims=new_int_hash[ValueRef](), + discrim_symbols=new_int_hash[str](), + fn_pairs=new_int_hash[ValueRef](), + consts=new_int_hash[ValueRef](), + obj_methods=new_int_hash[()](), tydescs=tydescs, module_data=new_str_hash[ValueRef](), lltypes=lltypes, diff --git a/src/comp/middle/tstate/annotate.rs b/src/comp/middle/tstate/annotate.rs index c29705f78fc1..59a0b5369479 100644 --- a/src/comp/middle/tstate/annotate.rs +++ b/src/comp/middle/tstate/annotate.rs @@ -4,7 +4,8 @@ import std::option; import std::option::some; import std::option::none; import front::ast::*; -import middle::ty::expr_ann; +import middle::ty::expr_node_id; +import util::common::istr; import util::common::uistr; import util::common::span; import util::common::new_str_hash; @@ -23,70 +24,69 @@ import aux::crate_ctxt; import aux::add_node; import middle::tstate::ann::empty_ann; -fn collect_ids_expr(&@expr e, @mutable vec[uint] res) { - vec::push(*res, expr_ann(e).id); +fn collect_ids_expr(&@expr e, @mutable vec[node_id] res) { + vec::push(*res, expr_node_id(e)); } -fn collect_ids_block(&block b, @mutable vec[uint] res) { - vec::push(*res, b.node.a.id); +fn collect_ids_block(&block b, @mutable vec[node_id] res) { + vec::push(*res, b.node.id); } -fn collect_ids_stmt(&@stmt s, @mutable vec[uint] res) { +fn collect_ids_stmt(&@stmt s, @mutable vec[node_id] res) { alt (s.node) { - case (stmt_decl(_, ?a)) { - log "node_id " + uistr(a.id); + case (stmt_decl(_, ?id)) { + log "node_id " + istr(id); log_stmt(*s); - vec::push(*res, a.id); + vec::push(*res, id); } - case (stmt_expr(_, ?a)) { - log "node_id " + uistr(a.id); + case (stmt_expr(_, ?id)) { + log "node_id " + istr(id); log_stmt(*s); - vec::push(*res, a.id); + vec::push(*res, id); } case (_) { } } } -fn collect_ids_local(&@local l, @mutable vec[uint] res) { - vec::push(*res, l.node.ann.id); +fn collect_ids_local(&@local l, @mutable vec[node_id] res) { + vec::push(*res, l.node.id); } -fn node_ids_in_fn(&_fn f, &span sp, &ident i, &def_id d, &ann a, - @mutable vec[uint] res) { +fn node_ids_in_fn(&_fn f, &span sp, &ident i, node_id id, + @mutable vec[node_id] res) { auto collect_ids = walk::default_visitor(); collect_ids = rec(visit_expr_pre=bind collect_ids_expr(_, res), visit_block_pre=bind collect_ids_block(_, res), visit_stmt_pre=bind collect_ids_stmt(_, res), visit_local_pre=bind collect_ids_local(_, res) with collect_ids); - walk::walk_fn(collect_ids, f, sp, i, d, a); + walk::walk_fn(collect_ids, f, sp, i, id); } -fn init_vecs(&crate_ctxt ccx, &vec[uint] node_ids, uint len) { - for (uint i in node_ids) { - log uistr(i) + " |-> " + uistr(len); +fn init_vecs(&crate_ctxt ccx, &vec[node_id] node_ids, uint len) { + for (node_id i in node_ids) { + log istr(i) + " |-> " + uistr(len); add_node(ccx, i, empty_ann(len)); } } fn visit_fn(&crate_ctxt ccx, uint num_constraints, &_fn f, &span sp, &ident i, - &def_id d, &ann a) { - let @mutable vec[uint] node_ids = @mutable []; - node_ids_in_fn(f, sp, i, d, a, node_ids); + node_id id) { + let @mutable vec[node_id] node_ids = @mutable []; + node_ids_in_fn(f, sp, i, id, node_ids); auto node_id_vec = *node_ids; init_vecs(ccx, node_id_vec, num_constraints); } -fn annotate_in_fn(&crate_ctxt ccx, &_fn f, &span sp, &ident i, &def_id f_id, - &ann a) { - auto f_info = get_fn_info(ccx, f_id); - visit_fn(ccx, num_constraints(f_info), f, sp, i, f_id, a); +fn annotate_in_fn(&crate_ctxt ccx, &_fn f, &span sp, &ident i, node_id id) { + auto f_info = get_fn_info(ccx, id); + visit_fn(ccx, num_constraints(f_info), f, sp, i, id); } fn annotate_crate(&crate_ctxt ccx, &crate crate) { auto do_ann = walk::default_visitor(); do_ann = - rec(visit_fn_pre=bind annotate_in_fn(ccx, _, _, _, _, _) with do_ann); + rec(visit_fn_pre=bind annotate_in_fn(ccx, _, _, _, _) with do_ann); walk::walk_crate(do_ann, crate); } // diff --git a/src/comp/middle/tstate/auxiliary.rs b/src/comp/middle/tstate/auxiliary.rs index efd69f137c6a..582a1971d545 100644 --- a/src/comp/middle/tstate/auxiliary.rs +++ b/src/comp/middle/tstate/auxiliary.rs @@ -10,14 +10,15 @@ import std::option::some; import std::option::maybe; import front::ast; import front::ast::*; -import middle::ty::expr_ann; +import middle::ty::expr_node_id; import util::common; import util::common::span; import util::common::respan; import util::common::log_block; -import util::common::new_def_hash; +import util::common::new_int_hash; import util::common::new_uint_hash; import util::common::log_expr_err; +import util::common::istr; import util::common::uistr; import util::common::lit_eq; import pretty::pprust::path_to_str; @@ -37,7 +38,6 @@ import tstate::ann::extend_poststate; import tstate::ann::set_precondition; import tstate::ann::set_postcondition; import tstate::ann::ts_ann; -import util::common::istr; import pretty::ppaux::constr_args_to_str; import pretty::ppaux::lit_to_str; @@ -210,13 +210,13 @@ tag constraint { tag constr__ { ninit(ident); npred(path, vec[@constr_arg_use]); } -type constr_ = rec(def_id id, constr__ c); +type constr_ = rec(node_id id, constr__ c); type constr = spanned[constr_]; type norm_constraint = rec(uint bit_num, constr c); -type constr_map = @std::map::hashmap[def_id, constraint]; +type constr_map = @std::map::hashmap[node_id, constraint]; type fn_info = rec(constr_map constrs, uint num_constraints, controlflow cf); @@ -226,51 +226,53 @@ type node_ann_table = @mutable vec[mutable ts_ann]; /* mapping from function name to fn_info map */ -type fn_info_map = @std::map::hashmap[def_id, fn_info]; +type fn_info_map = @std::map::hashmap[node_id, fn_info]; -type fn_ctxt = rec(fn_info enclosing, def_id id, ident name, crate_ctxt ccx); +type fn_ctxt = rec(fn_info enclosing, node_id id, ident name, crate_ctxt ccx); type crate_ctxt = rec(ty::ctxt tcx, node_ann_table node_anns, fn_info_map fm); -fn get_fn_info(&crate_ctxt ccx, def_id did) -> fn_info { - assert (ccx.fm.contains_key(did)); - ret ccx.fm.get(did); +fn get_fn_info(&crate_ctxt ccx, node_id id) -> fn_info { + assert (ccx.fm.contains_key(id)); + ret ccx.fm.get(id); } -fn add_node(&crate_ctxt ccx, uint i, &ts_ann a) { +fn add_node(&crate_ctxt ccx, node_id i, &ts_ann a) { auto sz = len(*ccx.node_anns); - if (sz <= i) { grow(*ccx.node_anns, i - sz + 1u, empty_ann(0u)); } + if (sz <= i as uint) { + grow(*ccx.node_anns, (i as uint) - sz + 1u, empty_ann(0u)); + } ccx.node_anns.(i) = a; } -fn get_ts_ann(&crate_ctxt ccx, uint i) -> option::t[ts_ann] { - if (i < len(*ccx.node_anns)) { +fn get_ts_ann(&crate_ctxt ccx, node_id i) -> option::t[ts_ann] { + if (i as uint < len(*ccx.node_anns)) { ret some[ts_ann](ccx.node_anns.(i)); } else { ret none[ts_ann]; } } /********* utils ********/ -fn ann_to_ts_ann(&crate_ctxt ccx, &ann a) -> ts_ann { - alt (get_ts_ann(ccx, a.id)) { +fn node_id_to_ts_ann(&crate_ctxt ccx, node_id id) -> ts_ann { + alt (get_ts_ann(ccx, id)) { case (none) { - log_err "ann_to_ts_ann: no ts_ann for node_id " + uistr(a.id); + log_err "node_id_to_ts_ann: no ts_ann for node_id " + istr(id); fail; } case (some(?t)) { ret t; } } } -fn ann_to_poststate(&crate_ctxt ccx, ann a) -> poststate { - log "ann_to_poststate"; - ret ann_to_ts_ann(ccx, a).states.poststate; +fn node_id_to_poststate(&crate_ctxt ccx, node_id id) -> poststate { + log "node_id_to_poststate"; + ret node_id_to_ts_ann(ccx, id).states.poststate; } fn stmt_to_ann(&crate_ctxt ccx, &stmt s) -> ts_ann { log "stmt_to_ann"; alt (s.node) { - case (stmt_decl(_, ?a)) { ret ann_to_ts_ann(ccx, a); } - case (stmt_expr(_, ?a)) { ret ann_to_ts_ann(ccx, a); } + case (stmt_decl(_, ?id)) { ret node_id_to_ts_ann(ccx, id); } + case (stmt_expr(_, ?id)) { ret node_id_to_ts_ann(ccx, id); } case (stmt_crate_directive(_)) { log_err "expecting an annotated statement here"; fail; @@ -282,14 +284,14 @@ fn stmt_to_ann(&crate_ctxt ccx, &stmt s) -> ts_ann { /* fails if e has no annotation */ fn expr_states(&crate_ctxt ccx, @expr e) -> pre_and_post_state { log "expr_states"; - ret ann_to_ts_ann(ccx, expr_ann(e)).states; + ret node_id_to_ts_ann(ccx, expr_node_id(e)).states; } /* fails if e has no annotation */ fn expr_pp(&crate_ctxt ccx, @expr e) -> pre_and_post { log "expr_pp"; - ret ann_to_ts_ann(ccx, expr_ann(e)).conditions; + ret node_id_to_ts_ann(ccx, expr_node_id(e)).conditions; } fn stmt_pp(&crate_ctxt ccx, &stmt s) -> pre_and_post { @@ -300,7 +302,7 @@ fn stmt_pp(&crate_ctxt ccx, &stmt s) -> pre_and_post { /* fails if b has no annotation */ fn block_pp(&crate_ctxt ccx, &block b) -> pre_and_post { log "block_pp"; - ret ann_to_ts_ann(ccx, b.node.a).conditions; + ret node_id_to_ts_ann(ccx, b.node.id).conditions; } fn clear_pp(pre_and_post pp) { @@ -308,14 +310,14 @@ fn clear_pp(pre_and_post pp) { ann::clear(pp.postcondition); } -fn clear_precond(&crate_ctxt ccx, &ann a) { - auto pp = ann_to_ts_ann(ccx, a); +fn clear_precond(&crate_ctxt ccx, node_id id) { + auto pp = node_id_to_ts_ann(ccx, id); ann::clear(pp.conditions.precondition); } fn block_states(&crate_ctxt ccx, &block b) -> pre_and_post_state { log "block_states"; - ret ann_to_ts_ann(ccx, b.node.a).states; + ret node_id_to_ts_ann(ccx, b.node.id).states; } fn stmt_states(&crate_ctxt ccx, &stmt s) -> pre_and_post_state { @@ -376,60 +378,63 @@ fn block_poststate(&crate_ctxt ccx, &block b) -> poststate { /* sets the pre_and_post for an ann */ -fn with_pp(&crate_ctxt ccx, &ann a, pre_and_post p) { - add_node(ccx, a.id, @rec(conditions=p, states=empty_states(pps_len(p)))); +fn with_pp(&crate_ctxt ccx, node_id id, pre_and_post p) { + add_node(ccx, id, @rec(conditions=p, states=empty_states(pps_len(p)))); } -fn set_prestate_ann(&crate_ctxt ccx, &ann a, &prestate pre) -> bool { +fn set_prestate_ann(&crate_ctxt ccx, node_id id, &prestate pre) -> bool { log "set_prestate_ann"; - ret set_prestate(ann_to_ts_ann(ccx, a), pre); + ret set_prestate(node_id_to_ts_ann(ccx, id), pre); } -fn extend_prestate_ann(&crate_ctxt ccx, &ann a, &prestate pre) -> bool { +fn extend_prestate_ann(&crate_ctxt ccx, node_id id, &prestate pre) -> bool { log "extend_prestate_ann"; - ret extend_prestate(ann_to_ts_ann(ccx, a).states.prestate, pre); + ret extend_prestate(node_id_to_ts_ann(ccx, id).states.prestate, pre); } -fn set_poststate_ann(&crate_ctxt ccx, &ann a, &poststate post) -> bool { +fn set_poststate_ann(&crate_ctxt ccx, node_id id, &poststate post) -> bool { log "set_poststate_ann"; - ret set_poststate(ann_to_ts_ann(ccx, a), post); + ret set_poststate(node_id_to_ts_ann(ccx, id), post); } -fn extend_poststate_ann(&crate_ctxt ccx, &ann a, &poststate post) -> bool { +fn extend_poststate_ann(&crate_ctxt ccx, node_id id, &poststate post) + -> bool { log "extend_poststate_ann"; - ret extend_poststate(ann_to_ts_ann(ccx, a).states.poststate, post); + ret extend_poststate(node_id_to_ts_ann(ccx, id).states.poststate, post); } -fn set_pre_and_post(&crate_ctxt ccx, &ann a, &precond pre, &postcond post) { +fn set_pre_and_post(&crate_ctxt ccx, node_id id, &precond pre, + &postcond post) { log "set_pre_and_post"; - auto t = ann_to_ts_ann(ccx, a); + auto t = node_id_to_ts_ann(ccx, id); set_precondition(t, pre); set_postcondition(t, post); } -fn copy_pre_post(&crate_ctxt ccx, &ann a, &@expr sub) { +fn copy_pre_post(&crate_ctxt ccx, node_id id, &@expr sub) { log "set_pre_and_post"; auto p = expr_pp(ccx, sub); - copy_pre_post_(ccx, a, p.precondition, p.postcondition); + copy_pre_post_(ccx, id, p.precondition, p.postcondition); } -fn copy_pre_post_(&crate_ctxt ccx, &ann a, &prestate pre, &poststate post) { +fn copy_pre_post_(&crate_ctxt ccx, node_id id, &prestate pre, + &poststate post) { log "set_pre_and_post"; - auto t = ann_to_ts_ann(ccx, a); + auto t = node_id_to_ts_ann(ccx, id); set_precondition(t, pre); set_postcondition(t, post); } /* sets all bits to *1* */ -fn set_postcond_false(&crate_ctxt ccx, &ann a) { - auto p = ann_to_ts_ann(ccx, a); +fn set_postcond_false(&crate_ctxt ccx, node_id id) { + auto p = node_id_to_ts_ann(ccx, id); ann::set(p.conditions.postcondition); } -fn pure_exp(&crate_ctxt ccx, &ann a, &prestate p) -> bool { +fn pure_exp(&crate_ctxt ccx, node_id id, &prestate p) -> bool { auto changed = false; - changed = extend_prestate_ann(ccx, a, p) || changed; - changed = extend_poststate_ann(ccx, a, p) || changed; + changed = extend_prestate_ann(ccx, id, p) || changed; + changed = extend_poststate_ann(ccx, id, p) || changed; ret changed; } @@ -449,49 +454,41 @@ fn num_constraints(fn_info m) -> uint { ret m.num_constraints; } fn new_crate_ctxt(ty::ctxt cx) -> crate_ctxt { let vec[mutable ts_ann] na = vec::empty_mut(); - ret rec(tcx=cx, node_anns=@mutable na, fm=@new_def_hash[fn_info]()); + ret rec(tcx=cx, node_anns=@mutable na, fm=@new_int_hash[fn_info]()); } -fn controlflow_def_id(&crate_ctxt ccx, &def_id d) -> controlflow { - alt (ccx.fm.find(d)) { - case (some(?fi)) { ret fi.cf; } - case (none) { ret return; } - } -} - - /* Use e's type to determine whether it returns. If it has a function type with a ! annotation, the answer is noreturn. */ fn controlflow_expr(&crate_ctxt ccx, @expr e) -> controlflow { - alt (ty::struct(ccx.tcx, ty::ann_to_type(ccx.tcx, expr_ann(e)))) { + alt (ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, expr_node_id(e)))) { case (ty::ty_fn(_, _, _, ?cf, _)) { ret cf; } case (_) { ret return; } } } fn constraints_expr(&ty::ctxt cx, @expr e) -> vec[@ty::constr_def] { - alt (ty::struct(cx, ty::ann_to_type(cx, expr_ann(e)))) { + alt (ty::struct(cx, ty::node_id_to_type(cx, expr_node_id(e)))) { case (ty::ty_fn(_, _, _, _, ?cs)) { ret cs; } case (_) { ret []; } } } -fn ann_to_def_strict(&ty::ctxt cx, &ann a) -> def { - alt (cx.def_map.find(a.id)) { +fn node_id_to_def_strict(&ty::ctxt cx, node_id id) -> def { + alt (cx.def_map.find(id)) { case (none) { - log_err "ann_to_def: node_id " + uistr(a.id) + " has no def"; + log_err "node_id_to_def: node_id " + istr(id) + " has no def"; fail; } case (some(?d)) { ret d; } } } -fn ann_to_def(&crate_ctxt ccx, &ann a) -> option::t[def] { - ret ccx.tcx.def_map.find(a.id); +fn node_id_to_def(&crate_ctxt ccx, node_id id) -> option::t[def] { + ret ccx.tcx.def_map.find(id); } -fn norm_a_constraint(&def_id id, &constraint c) -> vec[norm_constraint] { +fn norm_a_constraint(node_id id, &constraint c) -> vec[norm_constraint] { alt (c) { case (cinit(?n, ?sp, ?i)) { ret [rec(bit_num=n, c=respan(sp, rec(id=id, c=ninit(i))))]; @@ -515,7 +512,7 @@ fn norm_a_constraint(&def_id id, &constraint c) -> vec[norm_constraint] { // non-exhaustive match in trans. fn constraints(&fn_ctxt fcx) -> vec[norm_constraint] { let vec[norm_constraint] res = []; - for each (@tup(def_id, constraint) p in fcx.enclosing.constrs.items()) { + for each (@tup(node_id, constraint) p in fcx.enclosing.constrs.items()) { res += norm_a_constraint(p._0, p._1); } ret res; @@ -536,14 +533,14 @@ fn match_args(&fn_ctxt fcx, vec[pred_desc] occs, vec[@constr_arg_use] occ) -> fcx.ccx.tcx.sess.bug("match_args: no match for occurring args"); } -fn def_id_for_constr(ty::ctxt tcx, uint t) -> def_id { +fn node_id_for_constr(ty::ctxt tcx, node_id t) -> node_id { alt (tcx.def_map.find(t)) { case (none) { - tcx.sess.bug("def_id_for_constr: bad node_id " + uistr(t)); + tcx.sess.bug("node_id_for_constr: bad node_id " + istr(t)); } - case (some(def_fn(?i))) { ret i; } + case (some(def_fn(?i))) { ret i._1; } case (_) { - tcx.sess.bug("def_id_for_constr: pred is not a function"); + tcx.sess.bug("node_id_for_constr: pred is not a function"); } } } @@ -580,9 +577,9 @@ fn expr_to_constr(ty::ctxt tcx, &@expr e) -> constr { // typechecker bug expr_call(?operator, ?args, _)) { alt (operator.node) { - case (expr_path(?p, ?a)) { + case (expr_path(?p, ?id)) { ret respan(e.span, - rec(id=def_id_for_constr(tcx, a.id), + rec(id=node_id_for_constr(tcx, id), c=npred(p, exprs_to_constr_args(tcx, args)))); } diff --git a/src/comp/middle/tstate/bitvectors.rs b/src/comp/middle/tstate/bitvectors.rs index 850add38d5e1..3850986a4f8f 100644 --- a/src/comp/middle/tstate/bitvectors.rs +++ b/src/comp/middle/tstate/bitvectors.rs @@ -21,7 +21,7 @@ import aux::expr_precond; import aux::block_prestate; import aux::expr_prestate; import aux::stmt_prestate; -import tstate::aux::ann_to_ts_ann; +import tstate::aux::node_id_to_ts_ann; import tstate::ann::pre_and_post; import tstate::ann::precond; import tstate::ann::postcond; @@ -136,9 +136,9 @@ fn intersect_postconds(&vec[postcond] pcs) -> postcond { ret intersect_postconds_go(bitv::clone(pcs.(0)), pcs); } -fn gen(&fn_ctxt fcx, &ann a, &constr_ c) -> bool { +fn gen(&fn_ctxt fcx, node_id id, &constr_ c) -> bool { ret set_in_postcond(bit_num(fcx, c), - ann_to_ts_ann(fcx.ccx, a).conditions); + node_id_to_ts_ann(fcx.ccx, id).conditions); } fn declare_var(&fn_ctxt fcx, &constr_ c, prestate pre) -> prestate { @@ -149,19 +149,19 @@ fn declare_var(&fn_ctxt fcx, &constr_ c, prestate pre) -> prestate { ret res; } -fn relax_precond_block_non_recursive(&fn_ctxt fcx, uint i, &block b) { - relax_precond(i, block_precond(fcx.ccx, b)); +fn relax_precond_block_non_recursive(&fn_ctxt fcx, node_id i, &block b) { + relax_precond(i as uint, block_precond(fcx.ccx, b)); } -fn relax_precond_expr(&fn_ctxt fcx, uint i, &@expr e) { - relax_precond(i, expr_precond(fcx.ccx, e)); +fn relax_precond_expr(&fn_ctxt fcx, node_id i, &@expr e) { + relax_precond(i as uint, expr_precond(fcx.ccx, e)); } -fn relax_precond_stmt(&fn_ctxt fcx, uint i, &@stmt s) { - relax_precond(i, stmt_precond(fcx.ccx, *s)); +fn relax_precond_stmt(&fn_ctxt fcx, node_id i, &@stmt s) { + relax_precond(i as uint, stmt_precond(fcx.ccx, *s)); } -fn relax_precond_block(&fn_ctxt fcx, uint i, &block b) { +fn relax_precond_block(&fn_ctxt fcx, node_id i, &block b) { relax_precond_block_non_recursive(fcx, i, b); // FIXME: should use visit instead // could at least generalize this pattern @@ -184,14 +184,16 @@ fn relax_precond_block(&fn_ctxt fcx, uint i, &block b) { walk::walk_block(v, b); } -fn gen_poststate(&fn_ctxt fcx, &ann a, &constr_ c) -> bool { +fn gen_poststate(&fn_ctxt fcx, node_id id, &constr_ c) -> bool { log "gen_poststate"; - ret set_in_poststate(bit_num(fcx, c), ann_to_ts_ann(fcx.ccx, a).states); + ret set_in_poststate(bit_num(fcx, c), + node_id_to_ts_ann(fcx.ccx, id).states); } -fn kill_poststate(&fn_ctxt fcx, &ann a, &constr_ c) -> bool { +fn kill_poststate(&fn_ctxt fcx, node_id id, &constr_ c) -> bool { log "kill_poststate"; - ret clear_in_poststate(bit_num(fcx, c), ann_to_ts_ann(fcx.ccx, a).states); + ret clear_in_poststate(bit_num(fcx, c), + node_id_to_ts_ann(fcx.ccx, id).states); } // // Local Variables: diff --git a/src/comp/middle/tstate/ck.rs b/src/comp/middle/tstate/ck.rs index 7098d070660f..27933ee8eab1 100644 --- a/src/comp/middle/tstate/ck.rs +++ b/src/comp/middle/tstate/ck.rs @@ -1,7 +1,6 @@ import front::ast; import front::ast::method; -import front::ast::ann; import front::ast::item; import front::ast::item_fn; import front::ast::_fn; @@ -9,7 +8,9 @@ import front::ast::obj_field; import front::ast::_obj; import front::ast::stmt; import front::ast::ident; +import front::ast::node_id; import front::ast::def_id; +import front::ast::local_def; import front::ast::ty_param; import front::ast::crate; import front::ast::return; @@ -118,8 +119,8 @@ fn check_states_stmt(&fn_ctxt fcx, &@stmt s) { } } -fn check_states_against_conditions(&fn_ctxt fcx, &_fn f, &ann a, - &span sp, &ident i, &def_id d) { +fn check_states_against_conditions(&fn_ctxt fcx, &_fn f, node_id id, + &span sp, &ident i) { /* Postorder traversal instead of pre is important because we want the smallest possible erroneous statement or expression. */ @@ -141,13 +142,13 @@ fn check_states_against_conditions(&fn_ctxt fcx, &_fn f, &ann a, keep_going=bind kg(keepgoing) with walk::default_visitor()); - walk::walk_fn(v, f, sp, i, d, a); + walk::walk_fn(v, f, sp, i, id); /* Finally, check that the return value is initialized */ auto post = aux::block_poststate(fcx.ccx, f.body); let aux::constr_ ret_c = rec(id=fcx.id, c=aux::ninit(fcx.name)); if (f.proto == ast::proto_fn && !promises(fcx, post, ret_c) && - !type_is_nil(fcx.ccx.tcx, ret_ty_of_fn(fcx.ccx.tcx, a)) && + !type_is_nil(fcx.ccx.tcx, ret_ty_of_fn(fcx.ccx.tcx, id)) && f.decl.cf == return) { fcx.ccx.tcx.sess.span_note(f.body.span, "In function " + fcx.name + @@ -171,8 +172,7 @@ fn check_states_against_conditions(&fn_ctxt fcx, &_fn f, &ann a, } } -fn check_fn_states(&fn_ctxt fcx, &_fn f, &ann a, &span sp, &ident i, - &def_id d) { +fn check_fn_states(&fn_ctxt fcx, &_fn f, node_id id, &span sp, &ident i) { /* Compute the pre- and post-states for this function */ auto g = find_pre_post_state_fn; @@ -180,17 +180,16 @@ fn check_fn_states(&fn_ctxt fcx, &_fn f, &ann a, &span sp, &ident i, /* Now compare each expr's pre-state to its precondition and post-state to its postcondition */ - check_states_against_conditions(fcx, f, a, sp, i, d); + check_states_against_conditions(fcx, f, id, sp, i); } -fn fn_states(&crate_ctxt ccx, &_fn f, &span sp, &ident i, &def_id id, - &ann a) { +fn fn_states(&crate_ctxt ccx, &_fn f, &span sp, &ident i, node_id id) { /* Look up the var-to-bit-num map for this function */ assert (ccx.fm.contains_key(id)); auto f_info = ccx.fm.get(id); auto fcx = rec(enclosing=f_info, id=id, name=i, ccx=ccx); - check_fn_states(fcx, f, a, sp, i, id); + check_fn_states(fcx, f, id, sp, i); } fn check_crate(ty::ctxt cx, @crate crate) { @@ -205,7 +204,7 @@ fn check_crate(ty::ctxt cx, @crate crate) { auto do_pre_post = walk::default_visitor(); do_pre_post = - rec(visit_fn_post=bind fn_pre_post(ccx, _, _, _, _, _) + rec(visit_fn_post=bind fn_pre_post(ccx, _, _, _, _) with do_pre_post); walk::walk_crate(do_pre_post, *crate); /* Check the pre- and postcondition against the pre- and poststate @@ -213,7 +212,7 @@ fn check_crate(ty::ctxt cx, @crate crate) { auto do_states = walk::default_visitor(); do_states = - rec(visit_fn_post=bind fn_states(ccx, _, _, _, _, _) with do_states); + rec(visit_fn_post=bind fn_states(ccx, _, _, _, _) with do_states); walk::walk_crate(do_states, *crate); } // diff --git a/src/comp/middle/tstate/collect_locals.rs b/src/comp/middle/tstate/collect_locals.rs index 587caf244b34..203eff471d31 100644 --- a/src/comp/middle/tstate/collect_locals.rs +++ b/src/comp/middle/tstate/collect_locals.rs @@ -18,7 +18,8 @@ import aux::num_constraints; import aux::constr_map; import aux::expr_to_constr; import aux::constraints_expr; -import aux::ann_to_def_strict; +import aux::node_id_to_def_strict; +import util::common::new_int_hash; import util::common::new_def_hash; import util::common::uistr; import util::common::span; @@ -42,10 +43,10 @@ fn collect_pred(&ctxt cx, &@expr e) { } // If it's a call, generate appropriate instances of the // call's constraints. - case (expr_call(?operator, ?operands, ?a)) { + case (expr_call(?operator, ?operands, _)) { for (@ty::constr_def c in constraints_expr(cx.tcx, operator)) { let aux::constr ct = respan(c.span, - rec(id=c.node.id, + rec(id=c.node.id._1, c=aux::substitute_constr_args(cx.tcx, operands, c))); vec::push(*cx.cs, ct); @@ -55,14 +56,14 @@ fn collect_pred(&ctxt cx, &@expr e) { } } -fn find_locals(&ty::ctxt tcx, &_fn f, &span sp, &ident i, &def_id d, &ann a) - -> ctxt { +fn find_locals(&ty::ctxt tcx, &_fn f, &span sp, &ident i, node_id id) + -> ctxt { let ctxt cx = rec(cs=@mutable vec::alloc(0u), tcx=tcx); auto visitor = walk::default_visitor(); visitor = rec(visit_local_pre=bind collect_local(cx, _), visit_expr_pre=bind collect_pred(cx, _) with visitor); - walk_fn(visitor, f, sp, i, d, a); + walk_fn(visitor, f, sp, i, id); ret cx; } @@ -103,14 +104,14 @@ fn add_constraint(&ty::ctxt tcx, aux::constr c, uint next, constr_map tbl) -> /* builds a table mapping each local var defined in f to a bit number in the precondition/postcondition vectors */ fn mk_fn_info(&crate_ctxt ccx, &_fn f, &span f_sp, &ident f_name, - &def_id f_id, &ann a) { - auto res_map = @new_def_hash[constraint](); + node_id id) { + auto res_map = @new_int_hash[constraint](); let uint next = 0u; let vec[arg] f_args = f.decl.inputs; /* ignore args, which we know are initialized; just collect locally declared vars */ - let ctxt cx = find_locals(ccx.tcx, f, f_sp, f_name, f_id, a); + let ctxt cx = find_locals(ccx.tcx, f, f_sp, f_name, id); /* now we have to add bit nums for both the constraints and the variables... */ @@ -120,13 +121,13 @@ fn mk_fn_info(&crate_ctxt ccx, &_fn f, &span f_sp, &ident f_name, /* add a pseudo-entry for the function's return value we can safely use the function's name itself for this purpose */ - add_constraint(cx.tcx, respan(f_sp, rec(id=f_id, c=ninit(f_name))), next, + add_constraint(cx.tcx, respan(f_sp, rec(id=id, c=ninit(f_name))), next, res_map); auto res = rec(constrs=res_map, num_constraints=vec::len(*cx.cs) + 1u, cf=f.decl.cf); - ccx.fm.insert(f_id, res); + ccx.fm.insert(id, res); log f_name + " has " + uistr(num_constraints(res)) + " constraints"; } @@ -137,7 +138,7 @@ fn mk_fn_info(&crate_ctxt ccx, &_fn f, &span f_sp, &ident f_name, fn mk_f_to_fn_info(&crate_ctxt ccx, @crate c) { let ast_visitor vars_visitor = walk::default_visitor(); vars_visitor = - rec(visit_fn_pre=bind mk_fn_info(ccx, _, _, _, _, _) + rec(visit_fn_pre=bind mk_fn_info(ccx, _, _, _, _) with vars_visitor); walk_crate(vars_visitor, *c); } diff --git a/src/comp/middle/tstate/pre_post_conditions.rs b/src/comp/middle/tstate/pre_post_conditions.rs index 30e11ddad830..58788eca533f 100644 --- a/src/comp/middle/tstate/pre_post_conditions.rs +++ b/src/comp/middle/tstate/pre_post_conditions.rs @@ -5,8 +5,6 @@ import std::option; import std::option::none; import std::option::some; -// FIXME: needs to be tstate::ann because ann is also a type name... -// that's probably a bug. import tstate::ann::pre_and_post; import tstate::ann::get_post; import tstate::ann::postcond; @@ -40,9 +38,9 @@ import aux::expr_poststate; import aux::block_postcond; import aux::fn_info; import aux::log_pp; -import aux::ann_to_def; -import aux::ann_to_def_strict; -import aux::ann_to_ts_ann; +import aux::node_id_to_def; +import aux::node_id_to_def_strict; +import aux::node_id_to_ts_ann; import aux::set_postcond_false; import aux::controlflow_expr; import aux::expr_to_constr; @@ -62,7 +60,8 @@ import bitvectors::bit_num; import bitvectors::gen; import bitvectors::relax_precond_block; import front::ast::*; -import middle::ty::expr_ann; +import middle::ty::expr_node_id; +import util::common::new_int_hash; import util::common::new_def_hash; import util::common::uistr; import util::common::log_expr; @@ -107,10 +106,10 @@ fn find_pre_post_item(&crate_ctxt ccx, &item i) { // make a fake fcx auto fake_fcx = - rec(enclosing=rec(constrs=@new_def_hash[constraint](), + rec(enclosing=rec(constrs=@new_int_hash[constraint](), num_constraints=0u, cf=return), - id=tup(0, 0), + id=0, name="", ccx=ccx); find_pre_post_expr(fake_fcx, e); @@ -137,7 +136,7 @@ fn find_pre_post_item(&crate_ctxt ccx, &item i) { sets the precondition in a to be the result of combining the preconditions for , and the postcondition in a to be the union of all postconditions for */ -fn find_pre_post_exprs(&fn_ctxt fcx, &vec[@expr] args, ann a) { +fn find_pre_post_exprs(&fn_ctxt fcx, &vec[@expr] args, node_id id) { if (vec::len[@expr](args) > 0u) { log "find_pre_post_exprs: oper ="; log_expr(*args.(0)); @@ -154,18 +153,18 @@ fn find_pre_post_exprs(&fn_ctxt fcx, &vec[@expr] args, ann a) { auto g = bind get_pp(fcx.ccx, _); auto pps = vec::map[@expr, pre_and_post](g, args); auto h = get_post; - set_pre_and_post(fcx.ccx, a, seq_preconds(fcx, pps), + set_pre_and_post(fcx.ccx, id, seq_preconds(fcx, pps), union_postconds(nv, vec::map[pre_and_post, postcond](h, pps))); } fn find_pre_post_loop(&fn_ctxt fcx, &@local l, &@expr index, &block body, - &ann a) { + node_id id) { find_pre_post_expr(fcx, index); find_pre_post_block(fcx, body); auto v_init = rec(id=l.node.id, c=ninit(l.node.ident)); - relax_precond_block(fcx, bit_num(fcx, v_init), body); + relax_precond_block(fcx, bit_num(fcx, v_init) as node_id, body); auto loop_precond = seq_preconds(fcx, @@ -174,14 +173,14 @@ fn find_pre_post_loop(&fn_ctxt fcx, &@local l, &@expr index, &block body, auto loop_postcond = intersect_postconds([expr_postcond(fcx.ccx, index), block_postcond(fcx.ccx, body)]); - copy_pre_post_(fcx.ccx, a, loop_precond, loop_postcond); + copy_pre_post_(fcx.ccx, id, loop_precond, loop_postcond); } // Generates a pre/post assuming that a is the // annotation for an if-expression with consequent conseq // and alternative maybe_alt fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq, - &option::t[@expr] maybe_alt, &ann a, &if_ty chck) { + &option::t[@expr] maybe_alt, node_id id, &if_ty chck) { auto num_local_vars = num_constraints(fcx.enclosing); find_pre_post_expr(fcx, antec); find_pre_post_block(fcx, conseq); @@ -190,7 +189,7 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq, alt (chck) { case (if_check) { let aux::constr c = expr_to_constr(fcx.ccx.tcx, antec); - gen(fcx, expr_ann(antec), c.node); + gen(fcx, expr_node_id(antec), c.node); } case (_) {} } @@ -199,7 +198,7 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq, seq_preconds(fcx, [expr_pp(fcx.ccx, antec), block_pp(fcx.ccx, conseq)]); - set_pre_and_post(fcx.ccx, a, precond_res, + set_pre_and_post(fcx.ccx, id, precond_res, expr_poststate(fcx.ccx, antec)); } case (some(?altern)) { @@ -223,7 +222,7 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq, alt (chck) { case (if_check) { let aux::constr c = expr_to_constr(fcx.ccx.tcx, antec); - gen(fcx, expr_ann(antec), c.node); + gen(fcx, expr_node_id(antec), c.node); } case (_) {} } @@ -243,29 +242,29 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq, auto postcond_res = intersect_postconds([postcond_true_case, postcond_false_case]); - set_pre_and_post(fcx.ccx, a, precond_res, postcond_res); + set_pre_and_post(fcx.ccx, id, precond_res, postcond_res); } } } -fn gen_if_local(&fn_ctxt fcx, @expr lhs, @expr rhs, &ann larger_ann, - &ann new_var, &path pth) { - alt (ann_to_def(fcx.ccx, new_var)) { +fn gen_if_local(&fn_ctxt fcx, @expr lhs, @expr rhs, node_id larger_id, + node_id new_var, &path pth) { + alt (node_id_to_def(fcx.ccx, new_var)) { case (some(?d)) { alt (d) { case (def_local(?d_id)) { find_pre_post_expr(fcx, rhs); auto p = expr_pp(fcx.ccx, rhs); - set_pre_and_post(fcx.ccx, larger_ann, p.precondition, + set_pre_and_post(fcx.ccx, larger_id, p.precondition, p.postcondition); - gen(fcx, larger_ann, - rec(id=d_id, + gen(fcx, larger_id, + rec(id=d_id._1, c=ninit(path_to_ident(fcx.ccx.tcx, pth)))); } - case (_) { find_pre_post_exprs(fcx, [lhs, rhs], larger_ann); } + case (_) { find_pre_post_exprs(fcx, [lhs, rhs], larger_id); } } } - case (_) { find_pre_post_exprs(fcx, [lhs, rhs], larger_ann); } + case (_) { find_pre_post_exprs(fcx, [lhs, rhs], larger_id); } } } @@ -279,10 +278,10 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) { "):"; log_expr(*e); alt (e.node) { - case (expr_call(?operator, ?operands, ?a)) { + case (expr_call(?operator, ?operands, ?id)) { auto args = vec::clone[@expr](operands); vec::push[@expr](args, operator); - find_pre_post_exprs(fcx, args, a); + find_pre_post_exprs(fcx, args, id); /* see if the call has any constraints on its type */ log "a function: "; @@ -292,7 +291,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) { { auto i = bit_num(fcx, - rec(id=c.node.id, + rec(id=c.node.id._1, c=substitute_constr_args(fcx.ccx.tcx, operands, c))); require(i, pp); @@ -300,154 +299,156 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) { /* if this is a failing call, its postcondition sets everything */ alt (controlflow_expr(fcx.ccx, operator)) { - case (noreturn) { set_postcond_false(fcx.ccx, a); } + case (noreturn) { set_postcond_false(fcx.ccx, id); } case (_) { } } } - case (expr_spawn(_, _, ?operator, ?operands, ?a)) { + case (expr_spawn(_, _, ?operator, ?operands, ?id)) { auto args = vec::clone[@expr](operands); vec::push[@expr](args, operator); - find_pre_post_exprs(fcx, args, a); + find_pre_post_exprs(fcx, args, id); } - case (expr_vec(?args, _, _, ?a)) { - find_pre_post_exprs(fcx, args, a); + case (expr_vec(?args, _, _, ?id)) { + find_pre_post_exprs(fcx, args, id); } - case (expr_tup(?elts, ?a)) { - find_pre_post_exprs(fcx, elt_exprs(elts), a); + case (expr_tup(?elts, ?id)) { + find_pre_post_exprs(fcx, elt_exprs(elts), id); } - case (expr_path(?p, ?a)) { + case (expr_path(?p, ?id)) { auto res = expr_pp(fcx.ccx, e); clear_pp(res); - auto df = ann_to_def_strict(fcx.ccx.tcx, a); + auto df = node_id_to_def_strict(fcx.ccx.tcx, id); alt (df) { case (def_local(?d_id)) { auto i = bit_num(fcx, - rec(id=d_id, + rec(id=d_id._1, c=ninit(path_to_ident(fcx.ccx.tcx, p)))); require_and_preserve(i, res); } case (_) {/* nothing to check */ } } } - case (expr_self_method(?v, ?a)) { clear_pp(expr_pp(fcx.ccx, e)); } - case (expr_log(_, ?arg, ?a)) { + case (expr_self_method(?v, ?id)) { clear_pp(expr_pp(fcx.ccx, e)); } + case (expr_log(_, ?arg, ?id)) { find_pre_post_expr(fcx, arg); - copy_pre_post(fcx.ccx, a, arg); + copy_pre_post(fcx.ccx, id, arg); } - case (expr_chan(?arg, ?a)) { + case (expr_chan(?arg, ?id)) { find_pre_post_expr(fcx, arg); - copy_pre_post(fcx.ccx, a, arg); + copy_pre_post(fcx.ccx, id, arg); } - case (expr_put(?opt, ?a)) { + case (expr_put(?opt, ?id)) { alt (opt) { case (some(?arg)) { find_pre_post_expr(fcx, arg); - copy_pre_post(fcx.ccx, a, arg); + copy_pre_post(fcx.ccx, id, arg); } case (none) { clear_pp(expr_pp(fcx.ccx, e)); } } } case ( // FIXME this was just put in here as a placeholder - expr_fn(?f, ?a)) { + expr_fn(?f, ?id)) { clear_pp(expr_pp(fcx.ccx, e)); } - case (expr_block(?b, ?a)) { + case (expr_block(?b, ?id)) { find_pre_post_block(fcx, b); auto p = block_pp(fcx.ccx, b); - set_pre_and_post(fcx.ccx, a, p.precondition, p.postcondition); + set_pre_and_post(fcx.ccx, id, p.precondition, p.postcondition); } - case (expr_rec(?fields, ?maybe_base, ?a)) { + case (expr_rec(?fields, ?maybe_base, ?id)) { auto es = field_exprs(fields); vec::plus_option[@expr](es, maybe_base); - find_pre_post_exprs(fcx, es, a); + find_pre_post_exprs(fcx, es, id); } - case (expr_move(?lhs, ?rhs, ?a)) { + case (expr_move(?lhs, ?rhs, ?id)) { // FIXME: this needs to deinitialize the rhs alt (lhs.node) { case (expr_path(?p, ?a_lhs)) { - gen_if_local(fcx, lhs, rhs, a, a_lhs, p); + gen_if_local(fcx, lhs, rhs, id, a_lhs, p); } - case (_) { find_pre_post_exprs(fcx, [lhs, rhs], a); } + case (_) { find_pre_post_exprs(fcx, [lhs, rhs], id); } } } - case (expr_swap(?lhs, ?rhs, ?a)) { + case (expr_swap(?lhs, ?rhs, ?id)) { // Both sides must already be initialized - find_pre_post_exprs(fcx, [lhs, rhs], a); + find_pre_post_exprs(fcx, [lhs, rhs], id); } - case (expr_assign(?lhs, ?rhs, ?a)) { + case (expr_assign(?lhs, ?rhs, ?id)) { alt (lhs.node) { case (expr_path(?p, ?a_lhs)) { - gen_if_local(fcx, lhs, rhs, a, a_lhs, p); + gen_if_local(fcx, lhs, rhs, id, a_lhs, p); } - case (_) { find_pre_post_exprs(fcx, [lhs, rhs], a); } + case (_) { find_pre_post_exprs(fcx, [lhs, rhs], id); } } } - case (expr_recv(?lhs, ?rhs, ?a)) { + case (expr_recv(?lhs, ?rhs, ?id)) { alt (rhs.node) { - case (expr_path(?p, ?a_rhs)) { - gen_if_local(fcx, rhs, lhs, a, a_rhs, p); + case (expr_path(?p, ?id_rhs)) { + gen_if_local(fcx, rhs, lhs, id, id_rhs, p); } case (_) { // doesn't check that rhs is an lval, but // that's probably ok - find_pre_post_exprs(fcx, [lhs, rhs], a); + find_pre_post_exprs(fcx, [lhs, rhs], id); } } } - case (expr_assign_op(_, ?lhs, ?rhs, ?a)) { + case (expr_assign_op(_, ?lhs, ?rhs, ?id)) { /* Different from expr_assign in that the lhs *must* already be initialized */ - find_pre_post_exprs(fcx, [lhs, rhs], a); + find_pre_post_exprs(fcx, [lhs, rhs], id); } - case (expr_lit(_, ?a)) { clear_pp(expr_pp(fcx.ccx, e)); } - case (expr_ret(?maybe_val, ?a)) { + case (expr_lit(_, ?id)) { clear_pp(expr_pp(fcx.ccx, e)); } + case (expr_ret(?maybe_val, ?id)) { alt (maybe_val) { case (none) { - clear_precond(fcx.ccx, a); - set_postcond_false(fcx.ccx, a); + clear_precond(fcx.ccx, id); + set_postcond_false(fcx.ccx, id); } case (some(?ret_val)) { find_pre_post_expr(fcx, ret_val); - set_precondition(ann_to_ts_ann(fcx.ccx, a), + set_precondition(node_id_to_ts_ann(fcx.ccx, id), expr_precond(fcx.ccx, ret_val)); - set_postcond_false(fcx.ccx, a); + set_postcond_false(fcx.ccx, id); } } } - case (expr_be(?e, ?a)) { + case (expr_be(?e, ?id)) { find_pre_post_expr(fcx, e); - set_pre_and_post(fcx.ccx, a, expr_prestate(fcx.ccx, e), + set_pre_and_post(fcx.ccx, id, expr_prestate(fcx.ccx, e), false_postcond(num_local_vars)); } - case (expr_if(?antec, ?conseq, ?maybe_alt, ?a)) { - join_then_else(fcx, antec, conseq, maybe_alt, a, plain_if); + case (expr_if(?antec, ?conseq, ?maybe_alt, ?id)) { + join_then_else(fcx, antec, conseq, maybe_alt, id, plain_if); } - case (expr_binary(?bop, ?l, ?r, ?a)) { + case (expr_binary(?bop, ?l, ?r, ?id)) { /* *unless* bop is lazy (e.g. and, or)? FIXME */ - find_pre_post_exprs(fcx, [l, r], a); + find_pre_post_exprs(fcx, [l, r], id); } - case (expr_send(?l, ?r, ?a)) { find_pre_post_exprs(fcx, [l, r], a); } - case (expr_unary(_, ?operand, ?a)) { + case (expr_send(?l, ?r, ?id)) { + find_pre_post_exprs(fcx, [l, r], id); + } + case (expr_unary(_, ?operand, ?id)) { find_pre_post_expr(fcx, operand); - copy_pre_post(fcx.ccx, a, operand); + copy_pre_post(fcx.ccx, id, operand); } - case (expr_cast(?operand, _, ?a)) { + case (expr_cast(?operand, _, ?id)) { find_pre_post_expr(fcx, operand); - copy_pre_post(fcx.ccx, a, operand); + copy_pre_post(fcx.ccx, id, operand); } - case (expr_while(?test, ?body, ?a)) { + case (expr_while(?test, ?body, ?id)) { find_pre_post_expr(fcx, test); find_pre_post_block(fcx, body); log "666"; - set_pre_and_post(fcx.ccx, a, + set_pre_and_post(fcx.ccx, id, seq_preconds(fcx, [expr_pp(fcx.ccx, test), block_pp(fcx.ccx, body)]), @@ -456,7 +457,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) { block_postcond(fcx.ccx, body)])); } - case (expr_do_while(?body, ?test, ?a)) { + case (expr_do_while(?body, ?test, ?id)) { find_pre_post_block(fcx, body); find_pre_post_expr(fcx, test); auto loop_postcond = @@ -469,22 +470,22 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) { if (has_nonlocal_exits(body)) { loop_postcond = empty_poststate(num_local_vars); } - set_pre_and_post(fcx.ccx, a, + set_pre_and_post(fcx.ccx, id, seq_preconds(fcx, [block_pp(fcx.ccx, body), expr_pp(fcx.ccx, test)]), loop_postcond); } - case (expr_for(?d, ?index, ?body, ?a)) { - find_pre_post_loop(fcx, d, index, body, a); + case (expr_for(?d, ?index, ?body, ?id)) { + find_pre_post_loop(fcx, d, index, body, id); } - case (expr_for_each(?d, ?index, ?body, ?a)) { - find_pre_post_loop(fcx, d, index, body, a); + case (expr_for_each(?d, ?index, ?body, ?id)) { + find_pre_post_loop(fcx, d, index, body, id); } - case (expr_index(?e, ?sub, ?a)) { - find_pre_post_exprs(fcx, [e, sub], a); + case (expr_index(?e, ?sub, ?id)) { + find_pre_post_exprs(fcx, [e, sub], id); } - case (expr_alt(?ex, ?alts, ?a)) { + case (expr_alt(?ex, ?alts, ?id)) { find_pre_post_expr(fcx, ex); fn do_an_alt(&fn_ctxt fcx, &arm an_alt) -> pre_and_post { find_pre_post_block(fcx, an_alt.block); @@ -506,54 +507,54 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) { auto g = bind combine_pp(antec_pp, fcx, _, _); auto alts_overall_pp = vec::foldl[pre_and_post, pre_and_post](g, e_pp, alt_pps); - set_pre_and_post(fcx.ccx, a, alts_overall_pp.precondition, + set_pre_and_post(fcx.ccx, id, alts_overall_pp.precondition, alts_overall_pp.postcondition); } - case (expr_field(?operator, _, ?a)) { + case (expr_field(?operator, _, ?id)) { find_pre_post_expr(fcx, operator); - copy_pre_post(fcx.ccx, a, operator); + copy_pre_post(fcx.ccx, id, operator); } - case (expr_fail(?a, _)) { - set_pre_and_post(fcx.ccx, a, + case (expr_fail(?id, _)) { + set_pre_and_post(fcx.ccx, id, /* if execution continues after fail, then everything is true! */ empty_prestate(num_local_vars), false_postcond(num_local_vars)); } - case (expr_assert(?p, ?a)) { + case (expr_assert(?p, ?id)) { find_pre_post_expr(fcx, p); - copy_pre_post(fcx.ccx, a, p); + copy_pre_post(fcx.ccx, id, p); } - case (expr_check(?p, ?a)) { + case (expr_check(?p, ?id)) { find_pre_post_expr(fcx, p); - copy_pre_post(fcx.ccx, a, p); + copy_pre_post(fcx.ccx, id, p); /* predicate p holds after this expression executes */ let aux::constr c = expr_to_constr(fcx.ccx.tcx, p); - gen(fcx, a, c.node); + gen(fcx, id, c.node); } - case (expr_if_check(?p, ?conseq, ?maybe_alt, ?a)) { - join_then_else(fcx, p, conseq, maybe_alt, a, if_check); + case (expr_if_check(?p, ?conseq, ?maybe_alt, ?id)) { + join_then_else(fcx, p, conseq, maybe_alt, id, if_check); } - case (expr_bind(?operator, ?maybe_args, ?a)) { + case (expr_bind(?operator, ?maybe_args, ?id)) { auto args = vec::cat_options[@expr](maybe_args); vec::push[@expr](args, operator); /* ??? order of eval? */ - find_pre_post_exprs(fcx, args, a); + find_pre_post_exprs(fcx, args, id); } - case (expr_break(?a)) { clear_pp(expr_pp(fcx.ccx, e)); } - case (expr_cont(?a)) { clear_pp(expr_pp(fcx.ccx, e)); } - case (expr_port(?a)) { clear_pp(expr_pp(fcx.ccx, e)); } - case (expr_ext(_, _, _, ?expanded, ?a)) { + case (expr_break(?id)) { clear_pp(expr_pp(fcx.ccx, e)); } + case (expr_cont(?id)) { clear_pp(expr_pp(fcx.ccx, e)); } + case (expr_port(?id)) { clear_pp(expr_pp(fcx.ccx, e)); } + case (expr_ext(_, _, _, ?expanded, ?id)) { find_pre_post_expr(fcx, expanded); - copy_pre_post(fcx.ccx, a, expanded); + copy_pre_post(fcx.ccx, id, expanded); } - case (expr_anon_obj(?anon_obj, _, _, ?a)) { + case (expr_anon_obj(?anon_obj, _, _, ?id)) { alt (anon_obj.with_obj) { case (some(?ex)) { find_pre_post_expr(fcx, ex); - copy_pre_post(fcx.ccx, a, ex); + copy_pre_post(fcx.ccx, id, ex); } case (none) { clear_pp(expr_pp(fcx.ccx, e)); } } @@ -567,39 +568,40 @@ fn find_pre_post_stmt(&fn_ctxt fcx, &stmt s) { auto enclosing = fcx.enclosing; auto num_local_vars = num_constraints(enclosing); alt (s.node) { - case (stmt_decl(?adecl, ?a)) { + case (stmt_decl(?adecl, ?id)) { alt (adecl.node) { case (decl_local(?alocal)) { alt (alocal.node.init) { case (some(?an_init)) { find_pre_post_expr(fcx, an_init.expr); - copy_pre_post(fcx.ccx, alocal.node.ann, + copy_pre_post(fcx.ccx, alocal.node.id, an_init.expr); /* Inherit ann from initializer, and add var being initialized to the postcondition */ - copy_pre_post(fcx.ccx, a, an_init.expr); - gen(fcx, a, + copy_pre_post(fcx.ccx, id, an_init.expr); + gen(fcx, id, rec(id=alocal.node.id, c=ninit(alocal.node.ident))); } case (none) { - clear_pp(ann_to_ts_ann(fcx.ccx, - alocal.node.ann) + clear_pp(node_id_to_ts_ann(fcx.ccx, + alocal.node.id) + .conditions); + clear_pp(node_id_to_ts_ann(fcx.ccx, id) .conditions); - clear_pp(ann_to_ts_ann(fcx.ccx, a).conditions); } } } case (decl_item(?anitem)) { - clear_pp(ann_to_ts_ann(fcx.ccx, a).conditions); + clear_pp(node_id_to_ts_ann(fcx.ccx, id).conditions); find_pre_post_item(fcx.ccx, *anitem); } } } - case (stmt_expr(?e, ?a)) { + case (stmt_expr(?e, ?id)) { find_pre_post_expr(fcx, e); - copy_pre_post(fcx.ccx, a, e); + copy_pre_post(fcx.ccx, id, e); } } } @@ -661,7 +663,7 @@ fn find_pre_post_block(&fn_ctxt fcx, block b) { if (!has_nonlocal_exits(b)) { block_postcond = union_postconds(nv, postconds); } - set_pre_and_post(fcx.ccx, b.node.a, block_precond, block_postcond); + set_pre_and_post(fcx.ccx, b.node.id, block_precond, block_postcond); } fn find_pre_post_fn(&fn_ctxt fcx, &_fn f) { @@ -670,17 +672,17 @@ fn find_pre_post_fn(&fn_ctxt fcx, &_fn f) { // Treat the tail expression as a return statement alt (f.body.node.expr) { case (some(?tailexpr)) { - auto tailann = expr_ann(tailexpr); + auto tailann = expr_node_id(tailexpr); set_postcond_false(fcx.ccx, tailann); } case (none) {/* fallthrough */ } } } -fn fn_pre_post(crate_ctxt ccx, &_fn f, &span sp, &ident i, &def_id id, - &ann a) { +fn fn_pre_post(crate_ctxt ccx, &_fn f, &span sp, &ident i, node_id id) { assert (ccx.fm.contains_key(id)); - auto fcx = rec(enclosing=ccx.fm.get(id), id=id, name=i, ccx=ccx); + auto fcx = rec(enclosing=ccx.fm.get(id), id=id, name=i, + ccx=ccx); find_pre_post_fn(fcx, f); } // diff --git a/src/comp/middle/tstate/states.rs b/src/comp/middle/tstate/states.rs index 07f3890b82d8..1e1e1dfbfa8c 100644 --- a/src/comp/middle/tstate/states.rs +++ b/src/comp/middle/tstate/states.rs @@ -55,7 +55,7 @@ import aux::log_states; import aux::log_states_err; import aux::block_states; import aux::controlflow_expr; -import aux::ann_to_def; +import aux::node_id_to_def; import aux::expr_to_constr; import aux::ninit; import aux::npred; @@ -73,7 +73,7 @@ import bitvectors::gen_poststate; import bitvectors::kill_poststate; import front::ast; import front::ast::*; -import middle::ty::expr_ann; +import middle::ty::expr_node_id; import middle::ty::expr_ty; import middle::ty::type_is_nil; import middle::ty::type_is_bot; @@ -101,23 +101,23 @@ fn seq_states(&fn_ctxt fcx, prestate pres, vec[@expr] exprs) -> ret tup(changed, post); } -fn find_pre_post_state_exprs(&fn_ctxt fcx, &prestate pres, &ann a, +fn find_pre_post_state_exprs(&fn_ctxt fcx, &prestate pres, ast::node_id id, &vec[@expr] es) -> bool { auto res = seq_states(fcx, pres, es); auto changed = res._0; - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; - changed = extend_poststate_ann(fcx.ccx, a, res._1) || changed; + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; + changed = extend_poststate_ann(fcx.ccx, id, res._1) || changed; ret changed; } fn find_pre_post_state_loop(&fn_ctxt fcx, prestate pres, &@local l, - &@expr index, &block body, &ann a) -> bool { + &@expr index, &block body, node_id id) -> bool { auto changed = false; /* same issues as while */ // FIXME: also want to set l as initialized, no? - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = find_pre_post_state_expr(fcx, pres, index) || changed; /* in general, would need the intersection of (poststate of index, poststate of body) */ @@ -127,21 +127,21 @@ fn find_pre_post_state_loop(&fn_ctxt fcx, prestate pres, &@local l, || changed; if (has_nonlocal_exits(body)) { - changed = set_poststate_ann(fcx.ccx, a, pres) || changed; + changed = set_poststate_ann(fcx.ccx, id, pres) || changed; } auto res_p = intersect_postconds([expr_poststate(fcx.ccx, index), block_poststate(fcx.ccx, body)]); - changed = extend_poststate_ann(fcx.ccx, a, res_p) || changed; + changed = extend_poststate_ann(fcx.ccx, id, res_p) || changed; ret changed; } -fn gen_if_local(&fn_ctxt fcx, &ann a_new_var, &ann a, &path p) -> bool { - alt (ann_to_def(fcx.ccx, a_new_var)) { +fn gen_if_local(&fn_ctxt fcx, node_id new_var, node_id id, &path p) -> bool { + alt (node_id_to_def(fcx.ccx, new_var)) { case (some(def_local(?loc))) { - ret gen_poststate(fcx, a, - rec(id=loc, + ret gen_poststate(fcx, id, + rec(id=loc._1, c=ninit(path_to_ident(fcx.ccx.tcx, p)))); } case (_) { ret false; } @@ -149,11 +149,11 @@ fn gen_if_local(&fn_ctxt fcx, &ann a_new_var, &ann a, &path p) -> bool { } fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq, - &option::t[@expr] maybe_alt, &ann a, &if_ty chk, + &option::t[@expr] maybe_alt, ast::node_id id, &if_ty chk, &prestate pres) -> bool { auto changed = false; - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = find_pre_post_state_expr(fcx, pres, antec) || changed; /* @@ -179,7 +179,7 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq, conseq) || changed; changed = - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, antec)) || changed; } @@ -219,7 +219,7 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq, block_poststate(fcx.ccx, conseq))); */ changed = - extend_poststate_ann(fcx.ccx, a, poststate_res) || + extend_poststate_ann(fcx.ccx, id, poststate_res) || changed; } } @@ -238,13 +238,13 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool { /* FIXME could get rid of some of the copy/paste */ alt (e.node) { - case (expr_vec(?elts, _, _, ?a)) { - ret find_pre_post_state_exprs(fcx, pres, a, elts); + case (expr_vec(?elts, _, _, ?id)) { + ret find_pre_post_state_exprs(fcx, pres, id, elts); } - case (expr_tup(?elts, ?a)) { - ret find_pre_post_state_exprs(fcx, pres, a, elt_exprs(elts)); + case (expr_tup(?elts, ?id)) { + ret find_pre_post_state_exprs(fcx, pres, id, elt_exprs(elts)); } - case (expr_call(?operator, ?operands, ?a)) { + case (expr_call(?operator, ?operands, ?id)) { /* do the prestate for the rator */ /* fcx.ccx.tcx.sess.span_note(operator.span, @@ -258,13 +258,13 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool { changed = find_pre_post_state_exprs(fcx, expr_poststate(fcx.ccx, operator), - a, operands) || changed; + id, operands) || changed; /* if this is a failing call, it sets everything as initialized */ alt (controlflow_expr(fcx.ccx, operator)) { case (noreturn) { changed = - set_poststate_ann(fcx.ccx, a, + set_poststate_ann(fcx.ccx, id, false_postcond(num_local_vars)) || changed; } @@ -276,80 +276,80 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool { */ ret changed; } - case (expr_spawn(_, _, ?operator, ?operands, ?a)) { + case (expr_spawn(_, _, ?operator, ?operands, ?id)) { changed = find_pre_post_state_expr(fcx, pres, operator); ret find_pre_post_state_exprs(fcx, expr_poststate(fcx.ccx, operator), - a, operands) || changed; + id, operands) || changed; } - case (expr_bind(?operator, ?maybe_args, ?a)) { + case (expr_bind(?operator, ?maybe_args, ?id)) { changed = find_pre_post_state_expr(fcx, pres, operator) || changed; ret find_pre_post_state_exprs(fcx, expr_poststate(fcx.ccx, operator), - a, cat_options[@expr](maybe_args)) + id, cat_options[@expr](maybe_args)) || changed; } - case (expr_path(_, ?a)) { ret pure_exp(fcx.ccx, a, pres); } - case (expr_log(_, ?e, ?a)) { + case (expr_path(_, ?id)) { ret pure_exp(fcx.ccx, id, pres); } + case (expr_log(_, ?e, ?id)) { /* factor out the "one exp" pattern */ changed = find_pre_post_state_expr(fcx, pres, e); - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = - extend_poststate_ann(fcx.ccx, a, expr_poststate(fcx.ccx, e)) + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, e)) || changed; ret changed; } - case (expr_chan(?e, ?a)) { + case (expr_chan(?e, ?id)) { changed = find_pre_post_state_expr(fcx, pres, e); - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = - extend_poststate_ann(fcx.ccx, a, expr_poststate(fcx.ccx, e)) + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, e)) || changed; ret changed; } - case (expr_ext(_, _, _, ?expanded, ?a)) { + case (expr_ext(_, _, _, ?expanded, ?id)) { changed = find_pre_post_state_expr(fcx, pres, expanded); - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, expanded)) || changed; ret changed; } - case (expr_put(?maybe_e, ?a)) { + case (expr_put(?maybe_e, ?id)) { alt (maybe_e) { case (some(?arg)) { changed = find_pre_post_state_expr(fcx, pres, arg); changed = - extend_prestate_ann(fcx.ccx, a, pres) || changed; + extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, arg)) || changed; ret changed; } - case (none) { ret pure_exp(fcx.ccx, a, pres); } + case (none) { ret pure_exp(fcx.ccx, id, pres); } } } - case (expr_lit(?l, ?a)) { ret pure_exp(fcx.ccx, a, pres); } + case (expr_lit(?l, ?id)) { ret pure_exp(fcx.ccx, id, pres); } case ( // FIXME This was just put in here as a placeholder - expr_fn(?f, ?a)) { - ret pure_exp(fcx.ccx, a, pres); + expr_fn(?f, ?id)) { + ret pure_exp(fcx.ccx, id, pres); } - case (expr_block(?b, ?a)) { + case (expr_block(?b, ?id)) { changed = find_pre_post_state_block(fcx, pres, b) || changed; - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = - extend_poststate_ann(fcx.ccx, a, block_poststate(fcx.ccx, b)) + extend_poststate_ann(fcx.ccx, id, block_poststate(fcx.ccx, b)) || changed; ret changed; } - case (expr_rec(?fields, ?maybe_base, ?a)) { + case (expr_rec(?fields, ?maybe_base, ?id)) { changed = - find_pre_post_state_exprs(fcx, pres, a, field_exprs(fields)) + find_pre_post_state_exprs(fcx, pres, id, field_exprs(fields)) || changed; alt (maybe_base) { case (none) {/* do nothing */ } @@ -357,29 +357,29 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool { changed = find_pre_post_state_expr(fcx, pres, base) || changed; changed = - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, base)) || changed; } } ret changed; } - case (expr_move(?lhs, ?rhs, ?a)) { + case (expr_move(?lhs, ?rhs, ?id)) { // FIXME: this needs to deinitialize the rhs - extend_prestate_ann(fcx.ccx, a, pres); + extend_prestate_ann(fcx.ccx, id, pres); alt (lhs.node) { - case (expr_path(?p, ?a_lhs)) { + case (expr_path(?p, ?id_lhs)) { // assignment to local var - changed = pure_exp(fcx.ccx, a_lhs, pres) || changed; + changed = pure_exp(fcx.ccx, id_lhs, pres) || changed; changed = find_pre_post_state_expr(fcx, pres, rhs) || changed; changed = - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, rhs)) || changed; - changed = gen_if_local(fcx, a_lhs, a, p) || changed; + changed = gen_if_local(fcx, id_lhs, id, p) || changed; } case (_) { // assignment to something that must already have been @@ -392,15 +392,15 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool { expr_poststate(fcx.ccx, lhs), rhs) || changed; changed = - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, rhs)) || changed; } } ret changed; } - case (expr_assign(?lhs, ?rhs, ?a)) { - extend_prestate_ann(fcx.ccx, a, pres); + case (expr_assign(?lhs, ?rhs, ?id)) { + extend_prestate_ann(fcx.ccx, id, pres); alt (lhs.node) { case (expr_path(?p, ?a_lhs)) { // assignment to local var @@ -409,10 +409,10 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool { changed = find_pre_post_state_expr(fcx, pres, rhs) || changed; changed = - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, rhs)) || changed; - changed = gen_if_local(fcx, a_lhs, a, p) || changed; + changed = gen_if_local(fcx, a_lhs, id, p) || changed; } case (_) { // assignment to something that must already have been @@ -425,40 +425,40 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool { expr_poststate(fcx.ccx, lhs), rhs) || changed; changed = - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, rhs)) || changed; } } ret changed; } - case (expr_swap(?lhs, ?rhs, ?a)) { + case (expr_swap(?lhs, ?rhs, ?id)) { /* quite similar to binary -- should abstract this */ - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = find_pre_post_state_expr(fcx, pres, lhs) || changed; changed = find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, lhs), rhs) || changed; changed = - extend_poststate_ann(fcx.ccx, a, expr_poststate(fcx.ccx, rhs)) - || changed; + extend_poststate_ann(fcx.ccx, id, + expr_poststate(fcx.ccx, rhs)) || changed; ret changed; } - case (expr_recv(?lhs, ?rhs, ?a)) { - extend_prestate_ann(fcx.ccx, a, pres); + case (expr_recv(?lhs, ?rhs, ?id)) { + extend_prestate_ann(fcx.ccx, id, pres); alt (rhs.node) { - case (expr_path(?p, ?a_rhs)) { + case (expr_path(?p, ?id_rhs)) { // receive to local var - changed = pure_exp(fcx.ccx, a_rhs, pres) || changed; + changed = pure_exp(fcx.ccx, id_rhs, pres) || changed; changed = find_pre_post_state_expr(fcx, pres, lhs) || changed; changed = - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, lhs)) || changed; - changed = gen_if_local(fcx, a_rhs, a, p) || changed; + changed = gen_if_local(fcx, id_rhs, id, p) || changed; } case (_) { // receive to something that must already have been init'd @@ -470,25 +470,26 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool { expr_poststate(fcx.ccx, rhs), lhs) || changed; changed = - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, lhs)) || changed; } } ret changed; } - case (expr_ret(?maybe_ret_val, ?a)) { - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + case (expr_ret(?maybe_ret_val, ?id)) { + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; /* normally, everything is true if execution continues after a ret expression (since execution never continues locally after a ret expression */ - set_poststate_ann(fcx.ccx, a, false_postcond(num_local_vars)); + set_poststate_ann(fcx.ccx, id, false_postcond(num_local_vars)); /* return from an always-failing function clears the return bit */ alt (fcx.enclosing.cf) { case (noreturn) { - kill_poststate(fcx, a, rec(id=fcx.id, c=ninit(fcx.name))); + kill_poststate(fcx, id, rec(id=fcx.id, + c=ninit(fcx.name))); } case (_) { } } @@ -502,58 +503,59 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool { } ret changed; } - case (expr_be(?e, ?a)) { - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; - set_poststate_ann(fcx.ccx, a, false_postcond(num_local_vars)); + case (expr_be(?e, ?id)) { + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; + set_poststate_ann(fcx.ccx, id, false_postcond(num_local_vars)); changed = find_pre_post_state_expr(fcx, pres, e) || changed; ret changed; } - case (expr_if(?antec, ?conseq, ?maybe_alt, ?a)) { - changed = join_then_else(fcx, antec, conseq, maybe_alt, a, + case (expr_if(?antec, ?conseq, ?maybe_alt, ?id)) { + changed = join_then_else(fcx, antec, conseq, maybe_alt, id, plain_if, pres) || changed; ret changed; } - case (expr_binary(?bop, ?l, ?r, ?a)) { + case (expr_binary(?bop, ?l, ?r, ?id)) { /* FIXME: what if bop is lazy? */ - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = find_pre_post_state_expr(fcx, pres, l) || changed; changed = find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, l), r) || changed; changed = - extend_poststate_ann(fcx.ccx, a, expr_poststate(fcx.ccx, r)) + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, r)) || changed; ret changed; } - case (expr_send(?l, ?r, ?a)) { - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + case (expr_send(?l, ?r, ?id)) { + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = find_pre_post_state_expr(fcx, pres, l) || changed; changed = find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, l), r) || changed; changed = - extend_poststate_ann(fcx.ccx, a, expr_poststate(fcx.ccx, r)) + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, r)) || changed; ret changed; } - case (expr_assign_op(?op, ?lhs, ?rhs, ?a)) { + case (expr_assign_op(?op, ?lhs, ?rhs, ?id)) { /* quite similar to binary -- should abstract this */ - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = find_pre_post_state_expr(fcx, pres, lhs) || changed; changed = find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, lhs), rhs) || changed; changed = - extend_poststate_ann(fcx.ccx, a, expr_poststate(fcx.ccx, rhs)) + extend_poststate_ann(fcx.ccx, id, + expr_poststate(fcx.ccx, rhs)) || changed; ret changed; } - case (expr_while(?test, ?body, ?a)) { - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + case (expr_while(?test, ?body, ?id)) { + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; /* to handle general predicates, we need to pass in pres `intersect` (poststate(a)) like: auto test_pres = intersect_postconds(pres, @@ -570,22 +572,22 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool { /* conservative approximation: if a loop contains a break or cont, we assume nothing about the poststate */ if (has_nonlocal_exits(body)) { - changed = set_poststate_ann(fcx.ccx, a, pres) || changed; + changed = set_poststate_ann(fcx.ccx, id, pres) || changed; } changed = { auto e_post = expr_poststate(fcx.ccx, test); auto b_post = block_poststate(fcx.ccx, body); - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, intersect_postconds([e_post, b_post])) || changed }; ret changed; } - case (expr_do_while(?body, ?test, ?a)) { - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + case (expr_do_while(?body, ?test, ?id)) { + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; auto changed0 = changed; changed = find_pre_post_state_block(fcx, pres, body) || changed; /* conservative approximination: if the body of the loop @@ -600,7 +602,7 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool { // FIXME // This doesn't set "changed", as if the previous state // was different, this might come back true every time - set_poststate_ann(fcx.ccx, body.node.a, pres); + set_poststate_ann(fcx.ccx, body.node.id, pres); changed = changed0; } @@ -609,34 +611,34 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool { test) || changed; if (breaks) { - set_poststate_ann(fcx.ccx, a, pres); + set_poststate_ann(fcx.ccx, id, pres); } else { - changed = extend_poststate_ann(fcx.ccx, a, + changed = extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, test)) || changed; } ret changed; } - case (expr_for(?d, ?index, ?body, ?a)) { - ret find_pre_post_state_loop(fcx, pres, d, index, body, a); + case (expr_for(?d, ?index, ?body, ?id)) { + ret find_pre_post_state_loop(fcx, pres, d, index, body, id); } - case (expr_for_each(?d, ?index, ?body, ?a)) { - ret find_pre_post_state_loop(fcx, pres, d, index, body, a); + case (expr_for_each(?d, ?index, ?body, ?id)) { + ret find_pre_post_state_loop(fcx, pres, d, index, body, id); } - case (expr_index(?e, ?sub, ?a)) { - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + case (expr_index(?e, ?sub, ?id)) { + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = find_pre_post_state_expr(fcx, pres, e) || changed; changed = find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, e), sub) || changed; changed = - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, sub)); ret changed; } - case (expr_alt(?e, ?alts, ?a)) { - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + case (expr_alt(?e, ?alts, ?id)) { + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = find_pre_post_state_expr(fcx, pres, e) || changed; auto e_post = expr_poststate(fcx.ccx, e); auto a_post; @@ -657,85 +659,85 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool { a_post = e_post; } - changed = extend_poststate_ann(fcx.ccx, a, a_post) || changed; + changed = extend_poststate_ann(fcx.ccx, id, a_post) || changed; ret changed; } - case (expr_field(?e, _, ?a)) { + case (expr_field(?e, _, ?id)) { changed = find_pre_post_state_expr(fcx, pres, e); - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = - extend_poststate_ann(fcx.ccx, a, expr_poststate(fcx.ccx, e)) + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, e)) || changed; ret changed; } - case (expr_unary(_, ?operand, ?a)) { + case (expr_unary(_, ?operand, ?id)) { changed = find_pre_post_state_expr(fcx, pres, operand) || changed; - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, operand)) || changed; ret changed; } - case (expr_cast(?operand, _, ?a)) { + case (expr_cast(?operand, _, ?id)) { changed = find_pre_post_state_expr(fcx, pres, operand) || changed; - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, operand)) || changed; ret changed; } - case (expr_fail(?a, _)) { - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + case (expr_fail(?id, _)) { + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; /* if execution continues after fail, then everything is true! woo! */ changed = - set_poststate_ann(fcx.ccx, a, false_postcond(num_local_vars)) + set_poststate_ann(fcx.ccx, id, false_postcond(num_local_vars)) || changed; ret changed; } - case (expr_assert(?p, ?a)) { - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + case (expr_assert(?p, ?id)) { + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = find_pre_post_state_expr(fcx, pres, p) || changed; - changed = extend_poststate_ann(fcx.ccx, a, pres) || changed; + changed = extend_poststate_ann(fcx.ccx, id, pres) || changed; ret changed; } - case (expr_check(?p, ?a)) { - changed = extend_prestate_ann(fcx.ccx, a, pres) || changed; + case (expr_check(?p, ?id)) { + changed = extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = find_pre_post_state_expr(fcx, pres, p) || changed; - changed = extend_poststate_ann(fcx.ccx, a, pres) || changed; + changed = extend_poststate_ann(fcx.ccx, id, pres) || changed; /* predicate p holds after this expression executes */ let aux::constr c = expr_to_constr(fcx.ccx.tcx, p); - changed = gen_poststate(fcx, a, c.node) || changed; + changed = gen_poststate(fcx, id, c.node) || changed; ret changed; } - case (expr_if_check(?p, ?conseq, ?maybe_alt, ?a)) { - changed = join_then_else(fcx, p, conseq, maybe_alt, a, if_check, + case (expr_if_check(?p, ?conseq, ?maybe_alt, ?id)) { + changed = join_then_else(fcx, p, conseq, maybe_alt, id, if_check, pres) || changed; ret changed; } - case (expr_break(?a)) { ret pure_exp(fcx.ccx, a, pres); } - case (expr_cont(?a)) { ret pure_exp(fcx.ccx, a, pres); } - case (expr_port(?a)) { ret pure_exp(fcx.ccx, a, pres); } - case (expr_self_method(_, ?a)) { ret pure_exp(fcx.ccx, a, pres); } - case (expr_anon_obj(?anon_obj, _, _, ?a)) { + case (expr_break(?id)) { ret pure_exp(fcx.ccx, id, pres); } + case (expr_cont(?id)) { ret pure_exp(fcx.ccx, id, pres); } + case (expr_port(?id)) { ret pure_exp(fcx.ccx, id, pres); } + case (expr_self_method(_, ?id)) { ret pure_exp(fcx.ccx, id, pres); } + case (expr_anon_obj(?anon_obj, _, _, ?id)) { alt (anon_obj.with_obj) { case (some(?e)) { changed = find_pre_post_state_expr(fcx, pres, e); changed = - extend_prestate_ann(fcx.ccx, a, pres) || changed; + extend_prestate_ann(fcx.ccx, id, pres) || changed; changed = - extend_poststate_ann(fcx.ccx, a, + extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, e)) || changed; ret changed; } - case (none) { ret pure_exp(fcx.ccx, a, pres); } + case (none) { ret pure_exp(fcx.ccx, id, pres); } } } } @@ -757,7 +759,7 @@ fn find_pre_post_state_stmt(&fn_ctxt fcx, &prestate pres, @stmt s) -> bool { */ alt (s.node) { - case (stmt_decl(?adecl, ?a)) { + case (stmt_decl(?adecl, ?id)) { alt (adecl.node) { case (decl_local(?alocal)) { alt (alocal.node.init) { @@ -775,7 +777,7 @@ fn find_pre_post_state_stmt(&fn_ctxt fcx, &prestate pres, @stmt s) -> bool { an_init.expr)) || changed; changed = - gen_poststate(fcx, a, + gen_poststate(fcx, id, rec(id=alocal.node.id, c=ninit(alocal.node.ident))) || changed; @@ -868,8 +870,8 @@ fn find_pre_post_state_block(&fn_ctxt fcx, &prestate pres0, &block b) -> } } - set_prestate_ann(fcx.ccx, b.node.a, pres0); - set_poststate_ann(fcx.ccx, b.node.a, post); + set_prestate_ann(fcx.ccx, b.node.id, pres0); + set_poststate_ann(fcx.ccx, b.node.id, post); /* log_err "For block:"; @@ -894,7 +896,7 @@ fn find_pre_post_state_fn(&fn_ctxt fcx, &_fn f) -> bool { alt (f.body.node.expr) { case (some(?tailexpr)) { - auto tailann = expr_ann(tailexpr); + auto tailann = expr_node_id(tailexpr); auto tailty = expr_ty(fcx.ccx.tcx, tailexpr); // Since blocks and alts and ifs that don't have results @@ -906,7 +908,7 @@ fn find_pre_post_state_fn(&fn_ctxt fcx, &_fn f) -> bool { auto p = false_postcond(num_local_vars); set_poststate_ann(fcx.ccx, tailann, p); // be sure to set the block poststate to the same thing - set_poststate_ann(fcx.ccx, f.body.node.a, p); + set_poststate_ann(fcx.ccx, f.body.node.id, p); alt (fcx.enclosing.cf) { case (noreturn) { kill_poststate(fcx, tailann, diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index d3e6dbfed3f0..4dbe8444ef8d 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -24,10 +24,10 @@ import util::data::interner; import pretty::ppaux::ty_to_str; -export ann_to_monotype; -export ann_to_type; -export ann_to_type_params; -export ann_to_ty_param_substs_opt_and_ty; +export node_id_to_monotype; +export node_id_to_type; +export node_id_to_type_params; +export node_id_to_ty_param_substs_opt_and_ty; export any_item_native; export any_item_rust; export arg; @@ -42,7 +42,7 @@ export ctxt; export decl_local_ty; export def_has_ty_params; export eq_ty; -export expr_ann; +export expr_node_id; export expr_has_ty_params; export expr_ty; export fold_ty; @@ -95,7 +95,7 @@ export mo_val; export mo_alias; export mt; export node_type_table; -export pat_ann; +export pat_node_id; export pat_ty; export path_to_str; export rename; @@ -106,7 +106,7 @@ export sequence_element_type; export sequence_is_interior; export struct; export sort_methods; -export stmt_ann; +export stmt_node_id; export strip_boxes; export sty; export substitute_type_params; @@ -195,9 +195,8 @@ tag any_item { any_item_native(@ast::native_item, ast::native_abi); } -type item_table = hashmap[ast::def_id, any_item]; - -type constr_table = hashmap[ast::def_id, vec[constr_def]]; +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); @@ -400,7 +399,7 @@ fn mk_ctxt(session::session s, resolve::def_map dm, constr_table cs) -> 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_def_hash[any_item](); + auto items = new_int_hash[any_item](); auto ts = @interner::mk[raw_t](hash_raw_ty, eq_raw_ty); auto cx = rec(ts=ts, @@ -1602,32 +1601,32 @@ fn eq_ty(&t a, &t b) -> bool { ret a == b; } // Type lookups -fn ann_to_ty_param_substs_opt_and_ty(&ctxt cx, &ast::ann ann) -> +fn node_id_to_ty_param_substs_opt_and_ty(&ctxt cx, &ast::node_id id) -> ty_param_substs_opt_and_ty { // Pull out the node type table. - alt (smallintmap::find(*cx.node_types, ann.id)) { + alt (smallintmap::find(*cx.node_types, id as uint)) { case (none) { - cx.sess.bug("ann_to_ty_param_substs_opt_and_ty() called on an " + - "untyped node"); + cx.sess.bug("node_id_to_ty_param_substs_opt_and_ty() called on " + + "an untyped node (" + std::int::to_str(id, 10u) + ")"); } case (some(?tpot)) { ret tpot; } } } -fn ann_to_type(&ctxt cx, &ast::ann ann) -> t { - ret ann_to_ty_param_substs_opt_and_ty(cx, ann)._1; +fn node_id_to_type(&ctxt cx, &ast::node_id id) -> t { + ret node_id_to_ty_param_substs_opt_and_ty(cx, id)._1; } -fn ann_to_type_params(&ctxt cx, &ast::ann ann) -> vec[t] { - alt (ann_to_ty_param_substs_opt_and_ty(cx, ann)._0) { +fn node_id_to_type_params(&ctxt cx, &ast::node_id id) -> vec[t] { + alt (node_id_to_ty_param_substs_opt_and_ty(cx, id)._0) { case (none) { let vec[t] result = []; ret result; } case (some(?tps)) { ret tps; } } } -fn ann_has_type_params(&ctxt cx, &ast::ann ann) -> bool { - auto tpt = ann_to_ty_param_substs_opt_and_ty(cx, ann); +fn node_id_has_type_params(&ctxt cx, &ast::node_id id) -> bool { + auto tpt = node_id_to_ty_param_substs_opt_and_ty(cx, id); ret !option::is_none[vec[t]](tpt._0); } @@ -1645,8 +1644,8 @@ fn ty_param_substs_opt_and_ty_to_monotype(&ctxt cx, // Returns the type of an annotation, with type parameter substitutions // performed if applicable. -fn ann_to_monotype(&ctxt cx, ast::ann a) -> t { - auto tpot = ann_to_ty_param_substs_opt_and_ty(cx, a); +fn node_id_to_monotype(&ctxt cx, ast::node_id id) -> t { + auto tpot = node_id_to_ty_param_substs_opt_and_ty(cx, id); ret ty_param_substs_opt_and_ty_to_monotype(cx, tpot); } @@ -1726,59 +1725,61 @@ fn ty_var_id(&ctxt cx, t typ) -> int { // Type accessors for AST nodes -fn block_ty(&ctxt cx, &ast::block b) -> t { ret ann_to_type(cx, b.node.a); } +fn block_ty(&ctxt cx, &ast::block b) -> t { + ret node_id_to_type(cx, b.node.id); +} // Returns the type of a pattern as a monotype. Like @expr_ty, this function // doesn't provide type parameter substitutions. fn pat_ty(&ctxt cx, &@ast::pat pat) -> t { - ret ann_to_monotype(cx, pat_ann(pat)); + ret node_id_to_monotype(cx, pat_node_id(pat)); } -fn expr_ann(&@ast::expr e) -> ast::ann { - alt (e.node) { - case (ast::expr_vec(_, _, _, ?a)) { ret a; } - case (ast::expr_tup(_, ?a)) { ret a; } - case (ast::expr_rec(_, _, ?a)) { ret a; } - case (ast::expr_call(_, _, ?a)) { ret a; } - case (ast::expr_bind(_, _, ?a)) { ret a; } - case (ast::expr_binary(_, _, _, ?a)) { ret a; } - case (ast::expr_unary(_, _, ?a)) { ret a; } - case (ast::expr_lit(_, ?a)) { ret a; } - case (ast::expr_cast(_, _, ?a)) { ret a; } - case (ast::expr_if(_, _, _, ?a)) { ret a; } - case (ast::expr_if_check(_, _, _, ?a)) { ret a; } - case (ast::expr_while(_, _, ?a)) { ret a; } - case (ast::expr_for(_, _, _, ?a)) { ret a; } - case (ast::expr_for_each(_, _, _, ?a)) { ret a; } - case (ast::expr_do_while(_, _, ?a)) { ret a; } - case (ast::expr_alt(_, _, ?a)) { ret a; } - case (ast::expr_fn(_, ?a)) { ret a; } - case (ast::expr_block(_, ?a)) { ret a; } - case (ast::expr_move(_, _, ?a)) { ret a; } - case (ast::expr_assign(_, _, ?a)) { ret a; } - case (ast::expr_swap(_, _, ?a)) { ret a; } - case (ast::expr_assign_op(_, _, _, ?a)) { ret a; } - case (ast::expr_send(_, _, ?a)) { ret a; } - case (ast::expr_recv(_, _, ?a)) { ret a; } - case (ast::expr_field(_, _, ?a)) { ret a; } - case (ast::expr_index(_, _, ?a)) { ret a; } - case (ast::expr_path(_, ?a)) { ret a; } - case (ast::expr_ext(_, _, _, _, ?a)) { ret a; } - case (ast::expr_fail(?a, _)) { ret a; } - case (ast::expr_ret(_, ?a)) { ret a; } - case (ast::expr_put(_, ?a)) { ret a; } - case (ast::expr_be(_, ?a)) { ret a; } - case (ast::expr_log(_, _, ?a)) { ret a; } - case (ast::expr_assert(_, ?a)) { ret a; } - case (ast::expr_check(_, ?a)) { ret a; } - case (ast::expr_port(?a)) { ret a; } - case (ast::expr_chan(_, ?a)) { ret a; } - case (ast::expr_anon_obj(_, _, _, ?a)) { ret a; } - case (ast::expr_break(?a)) { ret a; } - case (ast::expr_cont(?a)) { ret a; } - case (ast::expr_self_method(_, ?a)) { ret a; } - case (ast::expr_spawn(_, _, _, _, ?a)) { ret a; } +fn expr_node_id(&@ast::expr e) -> ast::node_id { + ret alt (e.node) { + case (ast::expr_vec(_, _, _, ?id)) { id } + case (ast::expr_tup(_, ?id)) { id } + case (ast::expr_rec(_, _, ?id)) { id } + case (ast::expr_call(_, _, ?id)) { id } + case (ast::expr_bind(_, _, ?id)) { id } + case (ast::expr_binary(_, _, _, ?id)) { id } + case (ast::expr_unary(_, _, ?id)) { id } + case (ast::expr_lit(_, ?id)) { id } + case (ast::expr_cast(_, _, ?id)) { id } + case (ast::expr_if(_, _, _, ?id)) { id } + case (ast::expr_if_check(_, _, _, ?id)) { id } + case (ast::expr_while(_, _, ?id)) { id } + case (ast::expr_for(_, _, _, ?id)) { id } + case (ast::expr_for_each(_, _, _, ?id)) { id } + case (ast::expr_do_while(_, _, ?id)) { id } + case (ast::expr_alt(_, _, ?id)) { id } + case (ast::expr_fn(_, ?id)) { id } + case (ast::expr_block(_, ?id)) { id } + case (ast::expr_move(_, _, ?id)) { id } + case (ast::expr_assign(_, _, ?id)) { id } + case (ast::expr_swap(_, _, ?id)) { id } + case (ast::expr_assign_op(_, _, _, ?id)) { id } + case (ast::expr_send(_, _, ?id)) { id } + case (ast::expr_recv(_, _, ?id)) { id } + case (ast::expr_field(_, _, ?id)) { id } + case (ast::expr_index(_, _, ?id)) { id } + case (ast::expr_path(_, ?id)) { id } + case (ast::expr_ext(_, _, _, _, ?id)) { id } + case (ast::expr_fail(?id, _)) { id } + case (ast::expr_ret(_, ?id)) { id } + case (ast::expr_put(_, ?id)) { id } + case (ast::expr_be(_, ?id)) { id } + case (ast::expr_log(_, _, ?id)) { id } + case (ast::expr_assert(_, ?id)) { id } + case (ast::expr_check(_, ?id)) { id } + case (ast::expr_port(?id)) { id } + case (ast::expr_chan(_, ?id)) { id } + case (ast::expr_anon_obj(_, _, _, ?id)) { id } + case (ast::expr_break(?id)) { id } + case (ast::expr_cont(?id)) { id } + case (ast::expr_self_method(_, ?id)) { id } + case (ast::expr_spawn(_, _, _, _, ?id)) { id } } } @@ -1790,39 +1791,39 @@ fn expr_ann(&@ast::expr e) -> ast::ann { // instead of "fn(&T) -> T with T = int". If this isn't what you want, see // expr_ty_params_and_ty() below. fn expr_ty(&ctxt cx, &@ast::expr expr) -> t { - ret ann_to_monotype(cx, expr_ann(expr)); + ret node_id_to_monotype(cx, expr_node_id(expr)); } fn expr_ty_params_and_ty(&ctxt cx, &@ast::expr expr) -> tup(vec[t], t) { - auto a = expr_ann(expr); - ret tup(ann_to_type_params(cx, a), ann_to_type(cx, a)); + auto a = expr_node_id(expr); + ret tup(node_id_to_type_params(cx, a), node_id_to_type(cx, a)); } fn expr_has_ty_params(&ctxt cx, &@ast::expr expr) -> bool { - ret ann_has_type_params(cx, expr_ann(expr)); + ret node_id_has_type_params(cx, expr_node_id(expr)); } fn decl_local_ty(&ctxt cx, &@ast::local l) -> t { - ret ann_to_type(cx, l.node.ann); + ret node_id_to_type(cx, l.node.id); } -fn stmt_ann(&@ast::stmt s) -> ast::ann { +fn stmt_node_id(&@ast::stmt s) -> ast::node_id { alt (s.node) { - case (ast::stmt_decl(_, ?a)) { ret a; } - case (ast::stmt_expr(_, ?a)) { ret a; } + case (ast::stmt_decl(_, ?id)) { ret id; } + case (ast::stmt_expr(_, ?id)) { ret id; } case (ast::stmt_crate_directive(_)) { - log_err "ty::stmt_ann(): crate directive found"; + log_err "ty::stmt_node_id(): crate directive found"; fail; } } } -fn pat_ann(&@ast::pat p) -> ast::ann { +fn pat_node_id(&@ast::pat p) -> ast::node_id { alt (p.node) { - case (ast::pat_wild(?a)) { ret a; } - case (ast::pat_bind(_, _, ?a)) { ret a; } - case (ast::pat_lit(_, ?a)) { ret a; } - case (ast::pat_tag(_, _, ?a)) { ret a; } + case (ast::pat_wild(?id)) { ret id; } + case (ast::pat_bind(_, ?id)) { ret id; } + case (ast::pat_lit(_, ?id)) { ret id; } + case (ast::pat_tag(_, _, ?id)) { ret id; } } } @@ -2688,14 +2689,15 @@ fn tag_variants(&ctxt cx, &ast::def_id id) -> vec[variant_info] { if (cx.sess.get_targ_crate_num() != id._0) { ret creader::get_tag_variants(cx, id); } - assert (cx.items.contains_key(id)); - alt (cx.items.get(id)) { + assert (cx.items.contains_key(id._1)); + alt (cx.items.get(id._1)) { case (any_item_rust(?item)) { alt (item.node) { case (ast::item_tag(?variants, _)) { let vec[variant_info] result = []; for (ast::variant variant in variants) { - auto ctor_ty = ann_to_monotype(cx, variant.node.ann); + auto ctor_ty = node_id_to_monotype + (cx, variant.node.id); let vec[t] arg_tys = []; if (vec::len[ast::variant_arg](variant.node.args) > 0u) { @@ -2705,7 +2707,9 @@ fn tag_variants(&ctxt cx, &ast::def_id id) -> vec[variant_info] { } auto did = variant.node.id; result += - [rec(args=arg_tys, ctor_ty=ctor_ty, id=did)]; + [rec(args=arg_tys, + ctor_ty=ctor_ty, + id=ast::local_def(did))]; } ret result; } @@ -2759,8 +2763,8 @@ fn ret_ty_of_fn_ty(ctxt cx, t a_ty) -> t { } } -fn ret_ty_of_fn(ctxt cx, ast::ann ann) -> t { - ret ret_ty_of_fn_ty(cx, ann_to_type(cx, ann)); +fn ret_ty_of_fn(ctxt cx, ast::node_id id) -> t { + ret ret_ty_of_fn_ty(cx, node_id_to_type(cx, id)); } diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index deb1f96eb183..ca07350f2e82 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -1,16 +1,17 @@ import front::ast; -import front::ast::ann; import front::ast::mutability; +import front::ast::local_def; import front::creader; import driver::session; import util::common; import util::common::span; import util::common::respan; +import util::common::new_int_hash; import util::common::new_def_hash; import util::common::log_expr_err; import middle::ty; -import middle::ty::ann_to_type; +import middle::ty::node_id_to_type; import middle::ty::arg; import middle::ty::bind_params_in_type; import middle::ty::block_ty; @@ -49,7 +50,7 @@ type ty_table = hashmap[ast::def_id, ty::t]; type fn_purity_table = hashmap[ast::def_id, ast::purity]; -type obj_info = rec(vec[ast::obj_field] obj_fields, ast::def_id this_obj); +type obj_info = rec(vec[ast::obj_field] obj_fields, ast::node_id this_obj); type crate_ctxt = rec(mutable vec[obj_info] obj_infos, @@ -60,10 +61,10 @@ type fn_ctxt = rec(ty::t ret_ty, ast::purity purity, @ty::unify::var_bindings var_bindings, - hashmap[ast::def_id, int] locals, - hashmap[ast::def_id, ast::ident] local_names, + hashmap[ast::node_id, int] locals, + hashmap[ast::node_id, ast::ident] local_names, mutable int next_var_id, - mutable vec[uint] fixups, + mutable vec[ast::node_id] fixups, @crate_ctxt ccx); @@ -76,18 +77,18 @@ fn ty_param_count_and_ty_for_def(&@fn_ctxt fcx, &span sp, &ast::def defn) -> ty_param_count_and_ty { alt (defn) { case (ast::def_arg(?id)) { - assert (fcx.locals.contains_key(id)); - auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id)); + assert (fcx.locals.contains_key(id._1)); + auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id._1)); ret tup(0u, typ); } case (ast::def_local(?id)) { - assert (fcx.locals.contains_key(id)); - auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id)); + assert (fcx.locals.contains_key(id._1)); + auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id._1)); ret tup(0u, typ); } case (ast::def_obj_field(?id)) { - assert (fcx.locals.contains_key(id)); - auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id)); + assert (fcx.locals.contains_key(id._1)); + auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id._1)); ret tup(0u, typ); } case (ast::def_fn(?id)) { ret ty::lookup_item_type(fcx.ccx.tcx, id); } @@ -101,8 +102,8 @@ fn ty_param_count_and_ty_for_def(&@fn_ctxt fcx, &span sp, &ast::def defn) -> ret ty::lookup_item_type(fcx.ccx.tcx, vid); } case (ast::def_binding(?id)) { - assert (fcx.locals.contains_key(id)); - auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id)); + assert (fcx.locals.contains_key(id._1)); + auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id._1)); ret tup(0u, typ); } case (ast::def_obj(?id)) { @@ -319,8 +320,8 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t { let vec[@ty::constr_def] out_constrs = vec::map(g, constrs); typ = ty::mk_fn(tcx, proto, i, out_ty, cf, out_constrs); } - case (ast::ty_path(?path, ?ann)) { - alt (tcx.def_map.get(ann.id)) { + case (ast::ty_path(?path, ?id)) { + alt (tcx.def_map.get(id)) { case (ast::def_ty(?id)) { typ = instantiate(tcx, ast_ty.span, getter, id, @@ -384,13 +385,14 @@ fn ast_ty_to_ty_crate(@crate_ctxt ccx, &@ast::ty ast_ty) -> ty::t { // Functions that write types into the node type table. mod write { - fn inner(&node_type_table ntt, uint node_id, + fn inner(&node_type_table ntt, ast::node_id node_id, &ty_param_substs_opt_and_ty tpot) { - smallintmap::insert(*ntt, node_id, tpot); + smallintmap::insert(*ntt, node_id as uint, tpot); } // Writes a type parameter count and type pair into the node type table. - fn ty(&ty::ctxt tcx, uint node_id, &ty_param_substs_opt_and_ty tpot) { + fn ty(&ty::ctxt tcx, ast::node_id node_id, + &ty_param_substs_opt_and_ty tpot) { assert (!ty::type_contains_vars(tcx, tpot._1)); ret inner(tcx.node_types, node_id, tpot); } @@ -398,7 +400,7 @@ mod write { // Writes a type parameter count and type pair into the node type table. // This function allows for the possibility of type variables, which will // be rewritten later during the fixup phase. - fn ty_fixup(@fn_ctxt fcx, uint node_id, + fn ty_fixup(@fn_ctxt fcx, ast::node_id node_id, &ty_param_substs_opt_and_ty tpot) { inner(fcx.ccx.tcx.node_types, node_id, tpot); if (ty::type_contains_vars(fcx.ccx.tcx, tpot._1)) { @@ -407,23 +409,23 @@ mod write { } // Writes a type with no type parameters into the node type table. - fn ty_only(&ty::ctxt tcx, uint node_id, ty::t typ) { + fn ty_only(&ty::ctxt tcx, ast::node_id node_id, ty::t typ) { ret ty(tcx, node_id, tup(none[vec[ty::t]], typ)); } // Writes a type with no type parameters into the node type table. This // function allows for the possibility of type variables. - fn ty_only_fixup(@fn_ctxt fcx, uint node_id, ty::t typ) { + fn ty_only_fixup(@fn_ctxt fcx, ast::node_id node_id, ty::t typ) { ret ty_fixup(fcx, node_id, tup(none[vec[ty::t]], typ)); } // Writes a nil type into the node type table. - fn nil_ty(&ty::ctxt tcx, uint node_id) { + fn nil_ty(&ty::ctxt tcx, ast::node_id node_id) { ret ty(tcx, node_id, tup(none[vec[ty::t]], ty::mk_nil(tcx))); } // Writes the bottom type into the node type table. - fn bot_ty(&ty::ctxt tcx, uint node_id) { + fn bot_ty(&ty::ctxt tcx, ast::node_id node_id) { ret ty(tcx, node_id, tup(none[vec[ty::t]], ty::mk_bot(tcx))); } } @@ -487,7 +489,7 @@ mod collect { ret creader::get_type(cx.tcx, id); } - auto it = cx.tcx.items.get(id); + auto it = cx.tcx.items.get(id._1); auto tpt; alt (it) { case (ty::any_item_rust(?item)) { tpt = ty_of_item(cx, item); } @@ -536,7 +538,7 @@ mod collect { ret tup(ty_param_count, t_obj); } fn ty_of_obj_ctor(@ctxt cx, &ast::ident id, &ast::_obj obj_info, - &ast::def_id ctor_id, &vec[ast::ty_param] ty_params) -> + ast::node_id ctor_id, &vec[ast::ty_param] ty_params) -> ty::ty_param_count_and_ty { auto t_obj = ty_of_obj(cx, id, obj_info, ty_params); let vec[arg] t_inputs = []; @@ -548,7 +550,7 @@ mod collect { auto t_fn = ty::mk_fn(cx.tcx, ast::proto_fn, t_inputs, t_obj._1, ast::return, []); auto tpt = tup(t_obj._0, t_fn); - cx.tcx.tcache.insert(ctor_id, tpt); + cx.tcx.tcache.insert(local_def(ctor_id), tpt); ret tpt; } fn ty_of_item(&@ctxt cx, &@ast::item it) -> ty::ty_param_count_and_ty { @@ -558,21 +560,21 @@ mod collect { case (ast::item_const(?t, _)) { auto typ = convert(t); auto tpt = tup(0u, typ); - cx.tcx.tcache.insert(it.id, tpt); + cx.tcx.tcache.insert(local_def(it.id), tpt); ret tpt; } case (ast::item_fn(?fn_info, ?tps)) { auto f = bind ty_of_arg(cx, _); ret ty_of_fn_decl(cx, convert, f, fn_info.decl, fn_info.proto, - tps, some(it.id)); + tps, some(local_def(it.id))); } case (ast::item_obj(?obj_info, ?tps, _)) { auto t_obj = ty_of_obj(cx, it.ident, obj_info, tps); - cx.tcx.tcache.insert(it.id, t_obj); + cx.tcx.tcache.insert(local_def(it.id), t_obj); ret t_obj; } case (ast::item_ty(?t, ?tps)) { - alt (cx.tcx.tcache.find(it.id)) { + alt (cx.tcx.tcache.find(local_def(it.id))) { case (some(?tpt)) { ret tpt; } case (none) { } } @@ -582,7 +584,7 @@ mod collect { auto typ = convert(t); auto ty_param_count = vec::len[ast::ty_param](tps); auto tpt = tup(ty_param_count, typ); - cx.tcx.tcache.insert(it.id, tpt); + cx.tcx.tcache.insert(local_def(it.id), tpt); ret tpt; } case (ast::item_tag(_, ?tps)) { @@ -594,10 +596,10 @@ mod collect { subtys += [ty::mk_param(cx.tcx, i)]; i += 1u; } - auto t = ty::mk_tag(cx.tcx, it.id, subtys); + auto t = ty::mk_tag(cx.tcx, local_def(it.id), subtys); auto ty_param_count = vec::len[ast::ty_param](tps); auto tpt = tup(ty_param_count, t); - cx.tcx.tcache.insert(it.id, tpt); + cx.tcx.tcache.insert(local_def(it.id), tpt); ret tpt; } case (ast::item_mod(_)) { fail; } @@ -607,21 +609,21 @@ mod collect { fn ty_of_native_item(&@ctxt cx, &@ast::native_item it, ast::native_abi abi) -> ty::ty_param_count_and_ty { alt (it.node) { - case (ast::native_item_fn(_, _, ?fn_decl, ?params, ?did, _)) { + case (ast::native_item_fn(_, _, ?fn_decl, ?params, ?id)) { auto get = bind getter(cx, _); auto convert = bind ast_ty_to_ty(cx.tcx, get, _); auto f = bind ty_of_arg(cx, _); ret ty_of_native_fn_decl(cx, convert, f, fn_decl, abi, params, - did); + ast::local_def(id)); } - case (ast::native_item_ty(?tpt, ?def_id)) { - alt (cx.tcx.tcache.find(def_id)) { + case (ast::native_item_ty(?tpt, ?id)) { + alt (cx.tcx.tcache.find(local_def(id))) { case (some(?tpt)) { ret tpt; } case (none) { } } auto t = ty::mk_native(cx.tcx); auto tpt = tup(0u, t); - cx.tcx.tcache.insert(def_id, tpt); + cx.tcx.tcache.insert(local_def(id), tpt); ret tpt; } } @@ -661,8 +663,8 @@ mod collect { ast::return, []); } auto tpt = tup(ty_param_count, result_ty); - cx.tcx.tcache.insert(variant.node.id, tpt); - write::ty_only(cx.tcx, variant.node.ann.id, result_ty); + cx.tcx.tcache.insert(local_def(variant.node.id), tpt); + write::ty_only(cx.tcx, variant.node.id, result_ty); } } fn get_obj_method_types(&@ctxt cx, &ast::_obj object) -> vec[ty::method] { @@ -685,11 +687,10 @@ mod collect { } fn collect_native(ty::item_table id_to_ty_item, &@ast::native_item i) { alt (i.node) { - case (ast::native_item_ty(_, ?def_id)) { + case (ast::native_item_ty(_, ?id)) { // The abi of types is not used. auto abi = ast::native_abi_cdecl; - id_to_ty_item.insert(def_id, - ty::any_item_native(i, abi)); + id_to_ty_item.insert(id, ty::any_item_native(i, abi)); } case (_) {/* no-op */ } } @@ -709,8 +710,9 @@ mod collect { } case (ast::item_tag(?variants, ?ty_params)) { auto tpt = ty_of_item(cx, it); - write::ty_only(cx.tcx, it.ann.id, tpt._1); - get_tag_variant_types(cx, it.id, variants, ty_params); + write::ty_only(cx.tcx, it.id, tpt._1); + get_tag_variant_types(cx, local_def(it.id), variants, + ty_params); } case (ast::item_obj(?object, ?ty_params, ?ctor_id)) { // This calls ty_of_obj(). @@ -721,7 +723,7 @@ mod collect { auto tpt = ty_of_obj_ctor(cx, it.ident, object, ctor_id, ty_params); - write::ty_only(cx.tcx, it.ann.id, tpt._1); + write::ty_only(cx.tcx, it.id, tpt._1); // Write the methods into the type table. // // FIXME: Inefficient; this ends up calling @@ -731,7 +733,7 @@ mod collect { auto method_types = get_obj_method_types(cx, object); auto i = 0u; while (i < vec::len[@ast::method](object.methods)) { - write::ty_only(cx.tcx, object.methods.(i).node.ann.id, + write::ty_only(cx.tcx, object.methods.(i).node.id, ty::method_ty_to_fn_ty(cx.tcx, method_types.(i))); i += 1u; @@ -745,7 +747,7 @@ mod collect { i = 0u; while (i < vec::len[ty::arg](args)) { auto fld = object.fields.(i); - write::ty_only(cx.tcx, fld.ann.id, args.(i).ty); + write::ty_only(cx.tcx, fld.id, args.(i).ty); i += 1u; } @@ -755,7 +757,7 @@ mod collect { case (some(?m)) { auto t = ty::mk_fn(cx.tcx, ast::proto_fn, [], ty::mk_nil(cx.tcx), ast::return, []); - write::ty_only(cx.tcx, m.node.ann.id, t); + write::ty_only(cx.tcx, m.node.id, t); } } } @@ -765,7 +767,7 @@ mod collect { // it into the node type table. auto tpt = ty_of_item(cx, it); - write::ty_only(cx.tcx, it.ann.id, tpt._1); + write::ty_only(cx.tcx, it.id, tpt._1); } } } @@ -782,8 +784,8 @@ mod collect { // FIXME: Native types have no annotation. Should they? --pcw } - case (ast::native_item_fn(_, _, _, _, _, ?ann)) { - write::ty_only(cx.tcx, ann.id, tpt._1); + case (ast::native_item_fn(_, _, _, _, ?id)) { + write::ty_only(cx.tcx, id, tpt._1); } } } @@ -984,8 +986,9 @@ mod writeback { } } } - fn resolve_type_vars_for_node(&@fn_ctxt fcx, &span sp, &ast::ann ann) { - auto tpot = ty::ann_to_ty_param_substs_opt_and_ty(fcx.ccx.tcx, ann); + fn resolve_type_vars_for_node(&@fn_ctxt fcx, &span sp, ast::node_id id) { + auto tpot = ty::node_id_to_ty_param_substs_opt_and_ty + (fcx.ccx.tcx, id); auto new_ty = resolve_type_vars_in_type(fcx, sp, tpot._1); auto new_substs_opt; alt (tpot._0) { @@ -998,19 +1001,19 @@ mod writeback { new_substs_opt = some[vec[ty::t]](new_substs); } } - write::ty(fcx.ccx.tcx, ann.id, tup(new_substs_opt, new_ty)); + write::ty(fcx.ccx.tcx, id, tup(new_substs_opt, new_ty)); } fn visit_stmt_pre(@fn_ctxt fcx, &@ast::stmt s) { - resolve_type_vars_for_node(fcx, s.span, ty::stmt_ann(s)); + resolve_type_vars_for_node(fcx, s.span, ty::stmt_node_id(s)); } fn visit_expr_pre(@fn_ctxt fcx, &@ast::expr e) { - resolve_type_vars_for_node(fcx, e.span, ty::expr_ann(e)); + resolve_type_vars_for_node(fcx, e.span, ty::expr_node_id(e)); } fn visit_block_pre(@fn_ctxt fcx, &ast::block b) { - resolve_type_vars_for_node(fcx, b.span, b.node.a); + resolve_type_vars_for_node(fcx, b.span, b.node.id); } fn visit_pat_pre(@fn_ctxt fcx, &@ast::pat p) { - resolve_type_vars_for_node(fcx, p.span, ty::pat_ann(p)); + resolve_type_vars_for_node(fcx, p.span, ty::pat_node_id(p)); } fn visit_local_pre(@fn_ctxt fcx, &@ast::local l) { auto var_id = fcx.locals.get(l.node.id); @@ -1019,7 +1022,7 @@ mod writeback { var_id); alt (fix_rslt) { case (fix_ok(?lty)) { - write::ty_only(fcx.ccx.tcx, l.node.ann.id, lty); + write::ty_only(fcx.ccx.tcx, l.node.id, lty); } case (fix_err(_)) { fcx.ccx.tcx.sess.span_fatal(l.span, @@ -1058,24 +1061,25 @@ mod writeback { // for them before typechecking the function. type gather_result = rec(@ty::unify::var_bindings var_bindings, - hashmap[ast::def_id, int] locals, - hashmap[ast::def_id, ast::ident] local_names, + hashmap[ast::node_id, int] locals, + hashmap[ast::node_id, ast::ident] local_names, int next_var_id); fn gather_locals(&@crate_ctxt ccx, &ast::fn_decl decl, &ast::block body, - &ast::ann ann) -> gather_result { + &ast::node_id id) -> gather_result { fn next_var_id(@mutable int nvi) -> int { auto rv = *nvi; *nvi += 1; ret rv; } fn assign(&ty::ctxt tcx, &@ty::unify::var_bindings var_bindings, - &hashmap[ast::def_id, int] locals, - &hashmap[ast::def_id, ast::ident] local_names, @mutable int nvi, - ast::def_id lid, &ast::ident ident, option::t[ty::t] ty_opt) { + &hashmap[ast::node_id, int] locals, + &hashmap[ast::node_id, ast::ident] local_names, + @mutable int nvi, + ast::node_id nid, &ast::ident ident, option::t[ty::t] ty_opt) { auto var_id = next_var_id(nvi); - locals.insert(lid, var_id); - local_names.insert(lid, ident); + locals.insert(nid, var_id); + local_names.insert(nid, ident); alt (ty_opt) { case (none[ty::t]) {/* nothing to do */ } case (some[ty::t](?typ)) { @@ -1085,24 +1089,24 @@ fn gather_locals(&@crate_ctxt ccx, &ast::fn_decl decl, &ast::block body, } } auto vb = ty::unify::mk_var_bindings(); - auto locals = new_def_hash[int](); - auto local_names = new_def_hash[ast::ident](); + auto locals = new_int_hash[int](); + auto local_names = new_int_hash[ast::ident](); auto nvi = @mutable 0; // Add object fields, if any. alt (get_obj_info(ccx)) { case (option::some(?oinfo)) { for (ast::obj_field f in oinfo.obj_fields) { - auto field_ty = ty::ann_to_type(ccx.tcx, f.ann); - assign(ccx.tcx, vb, locals, local_names, nvi, f.id, f.ident, - some[ty::t](field_ty)); + auto field_ty = ty::node_id_to_type(ccx.tcx, f.id); + assign(ccx.tcx, vb, locals, local_names, nvi, f.id, + f.ident, some(field_ty)); } } case (option::none) {/* no fields */ } } // Add formal parameters. - auto args = ty::ty_fn_args(ccx.tcx, ty::ann_to_type(ccx.tcx, ann)); + auto args = ty::ty_fn_args(ccx.tcx, ty::node_id_to_type(ccx.tcx, id)); auto i = 0u; for (ty::arg arg in args) { assign(ccx.tcx, vb, locals, local_names, nvi, decl.inputs.(i).id, @@ -1112,8 +1116,8 @@ fn gather_locals(&@crate_ctxt ccx, &ast::fn_decl decl, &ast::block body, // Add explicitly-declared locals. fn visit_local_pre(@crate_ctxt ccx, @ty::unify::var_bindings vb, - hashmap[ast::def_id, int] locals, - hashmap[ast::def_id, ast::ident] local_names, + hashmap[ast::node_id, int] locals, + hashmap[ast::node_id, ast::ident] local_names, @mutable int nvi, &@ast::local local) { alt (local.node.ty) { case (none) { @@ -1134,13 +1138,13 @@ fn gather_locals(&@crate_ctxt ccx, &ast::fn_decl decl, &ast::block body, // Add pattern bindings. fn visit_pat_pre(@crate_ctxt ccx, @ty::unify::var_bindings vb, - hashmap[ast::def_id, int] locals, - hashmap[ast::def_id, ast::ident] local_names, + hashmap[ast::node_id, int] locals, + hashmap[ast::node_id, ast::ident] local_names, @mutable int nvi, &@ast::pat p) { alt (p.node) { - case (ast::pat_bind(?ident, ?did, _)) { - assign(ccx.tcx, vb, locals, local_names, nvi, did, ident, - none[ty::t]); + case (ast::pat_bind(?ident, ?id)) { + assign(ccx.tcx, vb, locals, local_names, nvi, + id, ident, none[ty::t]); } case (_) {/* no-op */ } } @@ -1166,7 +1170,7 @@ fn replace_expr_type(&@fn_ctxt fcx, &@ast::expr expr, if (ty::expr_has_ty_params(fcx.ccx.tcx, expr)) { new_tps = some[vec[ty::t]](new_tyt._0); } else { new_tps = none[vec[ty::t]]; } - write::ty_fixup(fcx, ty::expr_ann(expr).id, tup(new_tps, new_tyt._1)); + write::ty_fixup(fcx, ty::expr_node_id(expr), tup(new_tps, new_tyt._1)); } @@ -1191,24 +1195,24 @@ fn check_lit(@crate_ctxt ccx, &@ast::lit lit) -> ty::t { // their types immediately. fn check_pat(&@fn_ctxt fcx, &@ast::pat pat, ty::t expected) { alt (pat.node) { - case (ast::pat_wild(?ann)) { - write::ty_only_fixup(fcx, ann.id, expected); + case (ast::pat_wild(?id)) { + write::ty_only_fixup(fcx, id, expected); } - case (ast::pat_lit(?lt, ?ann)) { + case (ast::pat_lit(?lt, ?id)) { auto typ = check_lit(fcx.ccx, lt); typ = demand::simple(fcx, pat.span, expected, typ); - write::ty_only_fixup(fcx, ann.id, typ); + write::ty_only_fixup(fcx, id, typ); } - case (ast::pat_bind(?id, ?def_id, ?ann)) { - auto vid = fcx.locals.get(def_id); + case (ast::pat_bind(?name, ?id)) { + auto vid = fcx.locals.get(id); auto typ = ty::mk_var(fcx.ccx.tcx, vid); typ = demand::simple(fcx, pat.span, expected, typ); - write::ty_only_fixup(fcx, ann.id, typ); + write::ty_only_fixup(fcx, id, typ); } - case (ast::pat_tag(?path, ?subpats, ?ann)) { + case (ast::pat_tag(?path, ?subpats, ?id)) { // Typecheck the path. - auto v_def = fcx.ccx.tcx.def_map.get(ann.id); + auto v_def = fcx.ccx.tcx.def_map.get(id); auto v_def_ids = ast::variant_def_ids(v_def); auto tag_tpt = ty::lookup_item_type(fcx.ccx.tcx, v_def_ids._0); auto path_tpot = instantiate_path(fcx, path, tag_tpt, pat.span); @@ -1283,7 +1287,7 @@ fn check_pat(&@fn_ctxt fcx, &@ast::pat pat, ty::t expected) { "" } else { "s" })); } - write::ty_fixup(fcx, ann.id, path_tpot); + write::ty_fixup(fcx, id, path_tpot); } } } @@ -1309,9 +1313,9 @@ fn require_pure_call(@crate_ctxt ccx, &ast::purity caller_purity, case (ast::impure_fn) { ret; } case (ast::pure_fn) { alt (callee.node) { - case (ast::expr_path(_, ?ann)) { + case (ast::expr_path(_, ?id)) { auto d_id; - alt (ccx.tcx.def_map.get(ann.id)) { + alt (ccx.tcx.def_map.get(id)) { case (ast::def_fn(?_d_id)) { d_id = _d_id; } } alt (get_function_purity(ccx, d_id)) { @@ -1408,12 +1412,12 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { // A generic function for checking assignment expressions fn check_assignment(&@fn_ctxt fcx, &span sp, &@ast::expr lhs, - &@ast::expr rhs, &ast::ann a) { + &@ast::expr rhs, &ast::node_id id) { check_expr(fcx, lhs); check_expr(fcx, rhs); demand::simple(fcx, sp, expr_ty(fcx.ccx.tcx, lhs), expr_ty(fcx.ccx.tcx, rhs)); - write::ty_only_fixup(fcx, a.id, ty::mk_nil(fcx.ccx.tcx)); + write::ty_only_fixup(fcx, id, ty::mk_nil(fcx.ccx.tcx)); } // A generic function for checking call expressions @@ -1431,7 +1435,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { fn check_for_or_for_each(&@fn_ctxt fcx, &@ast::local local, &ty::t element_ty, &ast::block body, - uint node_id) { + ast::node_id node_id) { check_decl_local(fcx, local); check_block(fcx, body); // Unify type of decl with element type of the seq @@ -1454,9 +1458,9 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { alt (e.node) { case (ast::expr_call(?operator, ?operands, _)) { alt (operator.node) { - case (ast::expr_path(?oper_name, ?ann)) { + case (ast::expr_path(?oper_name, ?id)) { auto d_id; - alt (fcx.ccx.tcx.def_map.get(ann.id)) { + alt (fcx.ccx.tcx.def_map.get(id)) { case (ast::def_fn(?_d_id)) { d_id = _d_id; } } for (@ast::expr operand in operands) { @@ -1485,7 +1489,8 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { // A generic function for checking the then and else in an if // or if-check fn check_then_else(&@fn_ctxt fcx, &ast::block thn, - &option::t[@ast::expr] elsopt, &ann a, &span sp) { + &option::t[@ast::expr] elsopt, + ast::node_id id, &span sp) { check_block(fcx, thn); auto if_t = alt (elsopt) { @@ -1500,15 +1505,15 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { } case (none) { ty::mk_nil(fcx.ccx.tcx) } }; - write::ty_only_fixup(fcx, a.id, if_t); + write::ty_only_fixup(fcx, id, if_t); } alt (expr.node) { - case (ast::expr_lit(?lit, ?a)) { + case (ast::expr_lit(?lit, ?id)) { auto typ = check_lit(fcx.ccx, lit); - write::ty_only_fixup(fcx, a.id, typ); + write::ty_only_fixup(fcx, id, typ); } - case (ast::expr_binary(?binop, ?lhs, ?rhs, ?a)) { + case (ast::expr_binary(?binop, ?lhs, ?rhs, ?id)) { check_expr(fcx, lhs); check_expr(fcx, rhs); @@ -1529,9 +1534,9 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { case (ast::gt) { t = ty::mk_bool(fcx.ccx.tcx); } case (_) {/* fall through */ } } - write::ty_only_fixup(fcx, a.id, t); + write::ty_only_fixup(fcx, id, t); } - case (ast::expr_unary(?unop, ?oper, ?a)) { + case (ast::expr_unary(?unop, ?oper, ?id)) { check_expr(fcx, oper); auto oper_t = expr_ty(fcx.ccx.tcx, oper); alt (unop) { @@ -1562,15 +1567,15 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { } case (_) { oper_t = strip_boxes(fcx, expr.span, oper_t); } } - write::ty_only_fixup(fcx, a.id, oper_t); + write::ty_only_fixup(fcx, id, oper_t); } - case (ast::expr_path(?pth, ?old_ann)) { + case (ast::expr_path(?pth, ?old_id)) { auto t = ty::mk_nil(fcx.ccx.tcx); - auto defn = fcx.ccx.tcx.def_map.get(old_ann.id); + auto defn = fcx.ccx.tcx.def_map.get(old_id); auto tpt = ty_param_count_and_ty_for_def(fcx, expr.span, defn); if (ty::def_has_ty_params(defn)) { auto path_tpot = instantiate_path(fcx, pth, tpt, expr.span); - write::ty_fixup(fcx, old_ann.id, path_tpot); + write::ty_fixup(fcx, old_id, path_tpot); ret; } // The definition doesn't take type parameters. If the programmer @@ -1581,17 +1586,17 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { "this kind of value does not \ take type parameters"); } - write::ty_only_fixup(fcx, old_ann.id, tpt._1); + write::ty_only_fixup(fcx, old_id, tpt._1); } - case (ast::expr_ext(?p, ?args, ?body, ?expanded, ?a)) { + case (ast::expr_ext(?p, ?args, ?body, ?expanded, ?id)) { check_expr(fcx, expanded); auto t = expr_ty(fcx.ccx.tcx, expanded); - write::ty_only_fixup(fcx, a.id, t); + write::ty_only_fixup(fcx, id, t); } - case (ast::expr_fail(?a, _)) { write::bot_ty(fcx.ccx.tcx, a.id); } - case (ast::expr_break(?a)) { write::bot_ty(fcx.ccx.tcx, a.id); } - case (ast::expr_cont(?a)) { write::bot_ty(fcx.ccx.tcx, a.id); } - case (ast::expr_ret(?expr_opt, ?a)) { + case (ast::expr_fail(?id, _)) { write::bot_ty(fcx.ccx.tcx, id); } + case (ast::expr_break(?id)) { write::bot_ty(fcx.ccx.tcx, id); } + case (ast::expr_cont(?id)) { write::bot_ty(fcx.ccx.tcx, id); } + case (ast::expr_ret(?expr_opt, ?id)) { alt (expr_opt) { case (none) { auto nil = ty::mk_nil(fcx.ccx.tcx); @@ -1600,17 +1605,17 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { "ret; in function \ returning non-nil"); } - write::bot_ty(fcx.ccx.tcx, a.id); + write::bot_ty(fcx.ccx.tcx, id); } case (some(?e)) { check_expr(fcx, e); demand::simple(fcx, expr.span, fcx.ret_ty, expr_ty(fcx.ccx.tcx, e)); - write::bot_ty(fcx.ccx.tcx, a.id); + write::bot_ty(fcx.ccx.tcx, id); } } } - case (ast::expr_put(?expr_opt, ?a)) { + case (ast::expr_put(?expr_opt, ?id)) { require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span); alt (expr_opt) { case (none) { @@ -1620,57 +1625,57 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { "put; in iterator \ yielding non-nil"); } - write::nil_ty(fcx.ccx.tcx, a.id); + write::nil_ty(fcx.ccx.tcx, id); } case (some(?e)) { check_expr(fcx, e); - write::nil_ty(fcx.ccx.tcx, a.id); + write::nil_ty(fcx.ccx.tcx, id); } } } - case (ast::expr_be(?e, ?a)) { + case (ast::expr_be(?e, ?id)) { // FIXME: prove instead of assert assert (ast::is_call_expr(e)); check_expr(fcx, e); demand::simple(fcx, e.span, fcx.ret_ty, expr_ty(fcx.ccx.tcx, e)); - write::nil_ty(fcx.ccx.tcx, a.id); + write::nil_ty(fcx.ccx.tcx, id); } - case (ast::expr_log(?l, ?e, ?a)) { + case (ast::expr_log(?l, ?e, ?id)) { auto expr_t = check_expr(fcx, e); - write::nil_ty(fcx.ccx.tcx, a.id); + write::nil_ty(fcx.ccx.tcx, id); } - case (ast::expr_check(?e, ?a)) { + case (ast::expr_check(?e, ?id)) { check_pred_expr(fcx, e); - write::nil_ty(fcx.ccx.tcx, a.id); + write::nil_ty(fcx.ccx.tcx, id); } - case (ast::expr_if_check(?cond, ?thn, ?elsopt, ?a)) { + case (ast::expr_if_check(?cond, ?thn, ?elsopt, ?id)) { check_pred_expr(fcx, cond); - check_then_else(fcx, thn, elsopt, a, expr.span); + check_then_else(fcx, thn, elsopt, id, expr.span); } - case (ast::expr_assert(?e, ?a)) { + case (ast::expr_assert(?e, ?id)) { check_expr(fcx, e); auto ety = expr_ty(fcx.ccx.tcx, e); demand::simple(fcx, expr.span, ty::mk_bool(fcx.ccx.tcx), ety); - write::nil_ty(fcx.ccx.tcx, a.id); + write::nil_ty(fcx.ccx.tcx, id); } - case (ast::expr_move(?lhs, ?rhs, ?a)) { + case (ast::expr_move(?lhs, ?rhs, ?id)) { require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span); - check_assignment(fcx, expr.span, lhs, rhs, a); + check_assignment(fcx, expr.span, lhs, rhs, id); } - case (ast::expr_assign(?lhs, ?rhs, ?a)) { + case (ast::expr_assign(?lhs, ?rhs, ?id)) { require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span); - check_assignment(fcx, expr.span, lhs, rhs, a); + check_assignment(fcx, expr.span, lhs, rhs, id); } - case (ast::expr_swap(?lhs, ?rhs, ?a)) { + case (ast::expr_swap(?lhs, ?rhs, ?id)) { require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span); - check_assignment(fcx, expr.span, lhs, rhs, a); + check_assignment(fcx, expr.span, lhs, rhs, id); } - case (ast::expr_assign_op(?op, ?lhs, ?rhs, ?a)) { + case (ast::expr_assign_op(?op, ?lhs, ?rhs, ?id)) { require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span); - check_assignment(fcx, expr.span, lhs, rhs, a); + check_assignment(fcx, expr.span, lhs, rhs, id); } - case (ast::expr_send(?lhs, ?rhs, ?a)) { + case (ast::expr_send(?lhs, ?rhs, ?id)) { require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span); check_expr(fcx, lhs); check_expr(fcx, rhs); @@ -1688,25 +1693,25 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { fcx.ccx.tcx.sess.span_fatal(expr.span,s); } } - write::ty_only_fixup(fcx, a.id, chan_t); + write::ty_only_fixup(fcx, id, chan_t); } - case (ast::expr_recv(?lhs, ?rhs, ?a)) { + case (ast::expr_recv(?lhs, ?rhs, ?id)) { require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span); check_expr(fcx, lhs); check_expr(fcx, rhs); auto item_t = expr_ty(fcx.ccx.tcx, rhs); auto port_t = ty::mk_port(fcx.ccx.tcx, item_t); demand::simple(fcx, expr.span, port_t, expr_ty(fcx.ccx.tcx, lhs)); - write::ty_only_fixup(fcx, a.id, item_t); + write::ty_only_fixup(fcx, id, item_t); } - case (ast::expr_if(?cond, ?thn, ?elsopt, ?a)) { + case (ast::expr_if(?cond, ?thn, ?elsopt, ?id)) { check_expr(fcx, cond); demand::simple(fcx, cond.span, ty::mk_bool(fcx.ccx.tcx), expr_ty(fcx.ccx.tcx, cond)); - check_then_else(fcx, thn, elsopt, a, expr.span); + check_then_else(fcx, thn, elsopt, id, expr.span); } - case (ast::expr_for(?decl, ?seq, ?body, ?a)) { + case (ast::expr_for(?decl, ?seq, ?body, ?id)) { check_expr(fcx, seq); auto elt_ty; alt (structure_of(fcx, expr.span, expr_ty(fcx.ccx.tcx, seq))) { @@ -1720,28 +1725,28 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { is not a vector or string"); } } - check_for_or_for_each(fcx, decl, elt_ty, body, a.id); + check_for_or_for_each(fcx, decl, elt_ty, body, id); } - case (ast::expr_for_each(?decl, ?seq, ?body, ?a)) { + case (ast::expr_for_each(?decl, ?seq, ?body, ?id)) { check_expr(fcx, seq); check_for_or_for_each(fcx, decl, expr_ty(fcx.ccx.tcx, seq), body, - a.id); + id); } - case (ast::expr_while(?cond, ?body, ?a)) { + case (ast::expr_while(?cond, ?body, ?id)) { check_expr(fcx, cond); check_block(fcx, body); demand::simple(fcx, cond.span, ty::mk_bool(fcx.ccx.tcx), expr_ty(fcx.ccx.tcx, cond)); auto typ = ty::mk_nil(fcx.ccx.tcx); - write::ty_only_fixup(fcx, a.id, typ); + write::ty_only_fixup(fcx, id, typ); } - case (ast::expr_do_while(?body, ?cond, ?a)) { + case (ast::expr_do_while(?body, ?cond, ?id)) { check_expr(fcx, cond); check_block(fcx, body); auto typ = block_ty(fcx.ccx.tcx, body); - write::ty_only_fixup(fcx, a.id, typ); + write::ty_only_fixup(fcx, id, typ); } - case (ast::expr_alt(?expr, ?arms, ?a)) { + case (ast::expr_alt(?expr, ?arms, ?id)) { check_expr(fcx, expr); // Typecheck the patterns first, so that we get types for all the // bindings. @@ -1766,9 +1771,9 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { demand::simple(fcx, arm.block.span, result_ty, bty); } } - write::ty_only_fixup(fcx, a.id, result_ty); + write::ty_only_fixup(fcx, id, result_ty); } - case (ast::expr_fn(?f, ?a)) { + case (ast::expr_fn(?f, ?id)) { auto cx = @rec(tcx=fcx.ccx.tcx); auto convert = bind ast_ty_to_ty(cx.tcx, bind collect::getter(cx, _), _); @@ -1776,23 +1781,23 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { auto fty = collect::ty_of_fn_decl(cx, convert, ty_of_arg, f.decl, f.proto, [], none)._1; - write::ty_only_fixup(fcx, a.id, fty); - check_fn(fcx.ccx, f.decl, f.proto, f.body, a); + write::ty_only_fixup(fcx, id, fty); + check_fn(fcx.ccx, f.decl, f.proto, f.body, id); } - case (ast::expr_block(?b, ?a)) { + case (ast::expr_block(?b, ?id)) { check_block(fcx, b); alt (b.node.expr) { case (some(?expr)) { auto typ = expr_ty(fcx.ccx.tcx, expr); - write::ty_only_fixup(fcx, a.id, typ); + write::ty_only_fixup(fcx, id, typ); } case (none) { auto typ = ty::mk_nil(fcx.ccx.tcx); - write::ty_only_fixup(fcx, a.id, typ); + write::ty_only_fixup(fcx, id, typ); } } } - case (ast::expr_bind(?f, ?args, ?a)) { + case (ast::expr_bind(?f, ?args, ?id)) { // Call the generic checker. check_call_or_bind(fcx, expr.span, f, args); @@ -1831,9 +1836,9 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { fail; } } - write::ty_only_fixup(fcx, a.id, t_1); + write::ty_only_fixup(fcx, id, t_1); } - case (ast::expr_call(?f, ?args, ?a)) { + case (ast::expr_call(?f, ?args, ?id)) { /* here we're kind of hosed, as f can be any expr need to restrict it to being an explicit expr_path if we're inside a pure function, and need an environment mapping from @@ -1853,9 +1858,9 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { fail; } } - write::ty_only_fixup(fcx, a.id, rt_1); + write::ty_only_fixup(fcx, id, rt_1); } - case (ast::expr_self_method(?id, ?a)) { + case (ast::expr_self_method(?ident, ?id)) { auto t = ty::mk_nil(fcx.ccx.tcx); let ty::t this_obj_ty; let option::t[obj_info] this_obj_info = get_obj_info(fcx.ccx); @@ -1869,7 +1874,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { this_obj_ty = ty::lookup_item_type(fcx.ccx.tcx, - obj_info.this_obj)._1; + local_def(obj_info.this_obj))._1; } case (none) { fail; } } @@ -1878,17 +1883,17 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { alt (structure_of(fcx, expr.span, this_obj_ty)) { case (ty::ty_obj(?methods)) { for (ty::method method in methods) { - if (method.ident == id) { + if (method.ident == ident) { t = ty::method_ty_to_fn_ty(fcx.ccx.tcx, method); } } } case (_) { fail; } } - write::ty_only_fixup(fcx, a.id, t); + write::ty_only_fixup(fcx, id, t); require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span); } - case (ast::expr_spawn(_, _, ?f, ?args, ?a)) { + case (ast::expr_spawn(_, _, ?f, ?args, ?id)) { check_call(fcx, expr.span, f, args); auto fty = expr_ty(fcx.ccx.tcx, f); auto ret_ty = ty::ret_ty_of_fn_ty(fcx.ccx.tcx, fty); @@ -1896,9 +1901,9 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { // FIXME: Other typechecks needed auto typ = ty::mk_task(fcx.ccx.tcx); - write::ty_only_fixup(fcx, a.id, typ); + write::ty_only_fixup(fcx, id, typ); } - case (ast::expr_cast(?e, ?t, ?a)) { + case (ast::expr_cast(?e, ?t, ?id)) { check_expr(fcx, e); auto t_1 = ast_ty_to_ty_crate(fcx.ccx, t); // FIXME: there are more forms of cast to support, eventually. @@ -1912,9 +1917,9 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { e)) + " as " + ty_to_str(fcx.ccx.tcx, t_1)); } - write::ty_only_fixup(fcx, a.id, t_1); + write::ty_only_fixup(fcx, id, t_1); } - case (ast::expr_vec(?args, ?mut, ?kind, ?a)) { + case (ast::expr_vec(?args, ?mut, ?kind, ?id)) { let ty::t t; if (vec::len[@ast::expr](args) == 0u) { t = next_ty_var(fcx); @@ -1936,9 +1941,9 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { typ = ty::mk_ivec(fcx.ccx.tcx, rec(ty=t, mut=mut)); } } - write::ty_only_fixup(fcx, a.id, typ); + write::ty_only_fixup(fcx, id, typ); } - case (ast::expr_tup(?elts, ?a)) { + case (ast::expr_tup(?elts, ?id)) { let vec[ty::mt] elts_mt = []; for (ast::elt e in elts) { check_expr(fcx, e.expr); @@ -1946,9 +1951,9 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { elts_mt += [rec(ty=ety, mut=e.mut)]; } auto typ = ty::mk_tup(fcx.ccx.tcx, elts_mt); - write::ty_only_fixup(fcx, a.id, typ); + write::ty_only_fixup(fcx, id, typ); } - case (ast::expr_rec(?fields, ?base, ?a)) { + case (ast::expr_rec(?fields, ?base, ?id)) { alt (base) { case (none) {/* no-op */ } case (some(?b_0)) { check_expr(fcx, b_0); } @@ -1964,7 +1969,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { alt (base) { case (none) { auto typ = ty::mk_rec(fcx.ccx.tcx, fields_t); - write::ty_only_fixup(fcx, a.id, typ); + write::ty_only_fixup(fcx, id, typ); } case (some(?bexpr)) { check_expr(fcx, bexpr); @@ -1978,7 +1983,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { non-record base"); } } - write::ty_only_fixup(fcx, a.id, bexpr_t); + write::ty_only_fixup(fcx, id, bexpr_t); for (ty::field f in fields_t) { auto found = false; for (ty::field bf in base_fields) { @@ -1998,7 +2003,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { } } } - case (ast::expr_field(?base, ?field, ?a)) { + case (ast::expr_field(?base, ?field, ?id)) { check_expr(fcx, base); auto base_t = expr_ty(fcx.ccx.tcx, base); base_t = strip_boxes(fcx, expr.span, base_t); @@ -2010,7 +2015,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { fcx.ccx.tcx.sess.span_fatal(expr.span, "bad index on tuple"); } - write::ty_only_fixup(fcx, a.id, args.(ix).ty); + write::ty_only_fixup(fcx, id, args.(ix).ty); } case (ty::ty_rec(?fields)) { let uint ix = @@ -2020,7 +2025,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { fcx.ccx.tcx.sess.span_fatal(expr.span, "bad index on record"); } - write::ty_only_fixup(fcx, a.id, fields.(ix).mt.ty); + write::ty_only_fixup(fcx, id, fields.(ix).mt.ty); } case (ty::ty_obj(?methods)) { let uint ix = @@ -2034,7 +2039,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { auto t = ty::mk_fn(fcx.ccx.tcx, meth.proto, meth.inputs, meth.output, meth.cf, meth.constrs); - write::ty_only_fixup(fcx, a.id, t); + write::ty_only_fixup(fcx, id, t); } case (_) { fcx.ccx.tcx.sess.span_unimpl(expr.span, @@ -2045,7 +2050,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { } } } - case (ast::expr_index(?base, ?idx, ?a)) { + case (ast::expr_index(?base, ?idx, ?id)) { check_expr(fcx, base); auto base_t = expr_ty(fcx.ccx.tcx, base); base_t = strip_boxes(fcx, expr.span, base_t); @@ -2059,18 +2064,18 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { } alt (structure_of(fcx, expr.span, base_t)) { case (ty::ty_vec(?mt)) { - write::ty_only_fixup(fcx, a.id, mt.ty); + write::ty_only_fixup(fcx, id, mt.ty); } case (ty::ty_ivec(?mt)) { - write::ty_only_fixup(fcx, a.id, mt.ty); + write::ty_only_fixup(fcx, id, mt.ty); } case (ty::ty_str) { auto typ = ty::mk_mach(fcx.ccx.tcx, common::ty_u8); - write::ty_only_fixup(fcx, a.id, typ); + write::ty_only_fixup(fcx, id, typ); } case (ty::ty_istr) { auto typ = ty::mk_mach(fcx.ccx.tcx, common::ty_u8); - write::ty_only_fixup(fcx, a.id, typ); + write::ty_only_fixup(fcx, id, typ); } case (_) { fcx.ccx.tcx.sess.span_fatal(expr.span, @@ -2080,18 +2085,18 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { } } } - case (ast::expr_port(?a)) { + case (ast::expr_port(?id)) { auto t = next_ty_var(fcx); auto pt = ty::mk_port(fcx.ccx.tcx, t); - write::ty_only_fixup(fcx, a.id, pt); + write::ty_only_fixup(fcx, id, pt); } - case (ast::expr_chan(?x, ?a)) { + case (ast::expr_chan(?x, ?id)) { check_expr(fcx, x); auto port_t = expr_ty(fcx.ccx.tcx, x); alt (structure_of(fcx, expr.span, port_t)) { case (ty::ty_port(?subtype)) { auto ct = ty::mk_chan(fcx.ccx.tcx, subtype); - write::ty_only_fixup(fcx, a.id, ct); + write::ty_only_fixup(fcx, id, ct); } case (_) { fcx.ccx.tcx.sess.span_fatal(expr.span, @@ -2101,7 +2106,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { } } } - case (ast::expr_anon_obj(?anon_obj, ?tps, ?obj_def_ids, ?a)) { + case (ast::expr_anon_obj(?anon_obj, ?tps, ?obj_def_ids, ?id)) { // TODO: We probably need to do more work here to be able to // handle additional methods that use 'self' @@ -2112,7 +2117,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { case (none) { } case (some(?v)) { fields = v; } } - let ast::def_id di = obj_def_ids.ty; + let ast::node_id di = obj_def_ids.ty; vec::push[obj_info](fcx.ccx.obj_infos, rec(obj_fields=fields, this_obj=di)); // Typecheck 'with_obj', if it exists. @@ -2158,13 +2163,13 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) { } auto method_types = get_anon_obj_method_types(fcx.ccx, anon_obj); auto ot = ty::mk_obj(fcx.ccx.tcx, ty::sort_methods(method_types)); - write::ty_only_fixup(fcx, a.id, ot); + write::ty_only_fixup(fcx, id, ot); // Write the methods into the node type table. (This happens in // collect::convert for regular objects.) auto i = 0u; while (i < vec::len[@ast::method](anon_obj.methods)) { - write::ty_only(fcx.ccx.tcx, anon_obj.methods.(i).node.ann.id, + write::ty_only(fcx.ccx.tcx, anon_obj.methods.(i).node.id, ty::method_ty_to_fn_ty(fcx.ccx.tcx, method_types.(i))); i += 1u; @@ -2201,7 +2206,7 @@ fn get_obj_info(&@crate_ctxt ccx) -> option::t[obj_info] { fn ast_constr_to_constr(ty::ctxt tcx, &@ast::constr c) -> @ty::constr_def { - alt (tcx.def_map.find(c.node.ann.id)) { + alt (tcx.def_map.find(c.node.id)) { case (some(ast::def_fn(?pred_id))) { ret @respan(c.span, rec(path=c.node.path, args=c.node.args, id=pred_id)); @@ -2214,10 +2219,10 @@ fn ast_constr_to_constr(ty::ctxt tcx, &@ast::constr c) } } -fn check_decl_initializer(&@fn_ctxt fcx, &ast::def_id lid, +fn check_decl_initializer(&@fn_ctxt fcx, ast::node_id nid, &ast::initializer init) { check_expr(fcx, init.expr); - auto lty = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(lid)); + auto lty = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(nid)); alt (init.op) { case (ast::init_assign) { demand::simple(fcx, init.expr.span, lty, @@ -2236,8 +2241,8 @@ fn check_decl_initializer(&@fn_ctxt fcx, &ast::def_id lid, } fn check_decl_local(&@fn_ctxt fcx, &@ast::local local) -> @ast::local { - auto a_res = local.node.ann; - alt (fcx.locals.find(local.node.id)) { + auto a_id = local.node.id; + alt (fcx.locals.find(a_id)) { case (none) { fcx.ccx.tcx.sess.bug("check_decl_local: local id not found " + @@ -2245,7 +2250,7 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast::local local) -> @ast::local { } case (some(?i)) { auto t = ty::mk_var(fcx.ccx.tcx, i); - write::ty_only_fixup(fcx, a_res.id, t); + write::ty_only_fixup(fcx, a_id, t); auto initopt = local.node.init; alt (initopt) { case (some(?init)) { @@ -2253,7 +2258,7 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast::local local) -> @ast::local { } case (_) {/* fall through */ } } - auto newlocal = rec(init=initopt, ann=a_res with local.node); + auto newlocal = rec(init=initopt with local.node); ret @rec(node=newlocal, span=local.span); } } @@ -2262,15 +2267,15 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast::local local) -> @ast::local { fn check_stmt(&@fn_ctxt fcx, &@ast::stmt stmt) { auto node_id; alt (stmt.node) { - case (ast::stmt_decl(?decl, ?a)) { - node_id = a.id; + case (ast::stmt_decl(?decl, ?id)) { + node_id = id; alt (decl.node) { case (ast::decl_local(?l)) { check_decl_local(fcx, l); } case (ast::decl_item(_)) {/* ignore for now */ } } } - case (ast::stmt_expr(?expr, ?a)) { - node_id = a.id; + case (ast::stmt_expr(?expr, ?id)) { + node_id = id; check_expr(fcx, expr); } } @@ -2280,27 +2285,27 @@ fn check_stmt(&@fn_ctxt fcx, &@ast::stmt stmt) { fn check_block(&@fn_ctxt fcx, &ast::block block) { for (@ast::stmt s in block.node.stmts) { check_stmt(fcx, s); } alt (block.node.expr) { - case (none) { write::nil_ty(fcx.ccx.tcx, block.node.a.id); } + case (none) { write::nil_ty(fcx.ccx.tcx, block.node.id); } case (some(?e)) { check_expr(fcx, e); auto ety = expr_ty(fcx.ccx.tcx, e); - write::ty_only_fixup(fcx, block.node.a.id, ety); + write::ty_only_fixup(fcx, block.node.id, ety); } } } -fn check_const(&@crate_ctxt ccx, &span sp, &@ast::expr e, &ast::ann ann) { +fn check_const(&@crate_ctxt ccx, &span sp, &@ast::expr e, &ast::node_id id) { // FIXME: this is kinda a kludge; we manufacture a fake function context // and statement context for checking the initializer expression. - auto rty = ann_to_type(ccx.tcx, ann); - let vec[uint] fixups = []; + auto rty = node_id_to_type(ccx.tcx, id); + let vec[ast::node_id] fixups = []; let @fn_ctxt fcx = @rec(ret_ty=rty, purity=ast::pure_fn, var_bindings=ty::unify::mk_var_bindings(), - locals=new_def_hash[int](), - local_names=new_def_hash[ast::ident](), + locals=new_int_hash[int](), + local_names=new_int_hash[ast::ident](), mutable next_var_id=0, mutable fixups=fixups, ccx=ccx); @@ -2308,9 +2313,9 @@ fn check_const(&@crate_ctxt ccx, &span sp, &@ast::expr e, &ast::ann ann) { } fn check_fn(&@crate_ctxt ccx, &ast::fn_decl decl, ast::proto proto, - &ast::block body, &ast::ann ann) { - auto gather_result = gather_locals(ccx, decl, body, ann); - let vec[uint] fixups = []; + &ast::block body, &ast::node_id id) { + auto gather_result = gather_locals(ccx, decl, body, id); + let vec[ast::node_id] fixups = []; let @fn_ctxt fcx = @rec(ret_ty=ast_ty_to_ty_crate(ccx, decl.output), purity=decl.purity, @@ -2351,16 +2356,16 @@ fn check_fn(&@crate_ctxt ccx, &ast::fn_decl decl, ast::proto proto, fn check_method(&@crate_ctxt ccx, &@ast::method method) { auto m = method.node.meth; - check_fn(ccx, m.decl, m.proto, m.body, method.node.ann); + check_fn(ccx, m.decl, m.proto, m.body, method.node.id); } fn check_item(@crate_ctxt ccx, &@ast::item it) { alt (it.node) { case (ast::item_const(_, ?e)) { - check_const(ccx, it.span, e, it.ann); + check_const(ccx, it.span, e, it.id); } case (ast::item_fn(?f, _)) { - check_fn(ccx, f.decl, f.proto, f.body, it.ann); + check_fn(ccx, f.decl, f.proto, f.body, it.id); } case (ast::item_obj(?ob, _, _)) { // We're entering an object, so gather up the info we need. @@ -2386,7 +2391,7 @@ fn mk_fn_purity_table(&@ast::crate crate) -> @fn_purity_table { fn do_one(@fn_purity_table t, &@ast::item i) { alt (i.node) { case (ast::item_fn(?f, _)) { - t.insert(i.id, f.decl.purity); + t.insert(local_def(i.id), f.decl.purity); } case (_) { } } diff --git a/src/comp/middle/visit.rs b/src/comp/middle/visit.rs index 06ca4db45542..9487295b9a9f 100644 --- a/src/comp/middle/visit.rs +++ b/src/comp/middle/visit.rs @@ -34,7 +34,7 @@ type visitor[E] = fn(&@expr, &E, &vt[E]) visit_expr, fn(&@ty, &E, &vt[E]) visit_ty, fn(&@constr, &E, &vt[E]) visit_constr, - fn(&_fn, &vec[ty_param], &span, &ident, &def_id, &ann, &E, &vt[E]) + fn(&_fn, &vec[ty_param], &span, &ident, node_id, &E, &vt[E]) visit_fn); fn default_visitor[E]() -> visitor[E] { @@ -51,7 +51,7 @@ fn default_visitor[E]() -> visitor[E] { visit_expr=bind visit_expr[E](_, _, _), visit_ty=bind visit_ty[E](_, _, _), visit_constr=bind visit_constr[E](_, _, _), - visit_fn=bind visit_fn[E](_, _, _, _, _, _, _, _)); + visit_fn=bind visit_fn[E](_, _, _, _, _, _, _)); } fn visit_crate[E](&crate c, &E e, &vt[E] v) { @@ -103,7 +103,7 @@ fn visit_item[E](&@item i, &E e, &vt[E] v) { vt(v).visit_expr(ex, e, v); } case (item_fn(?f, ?tp)) { - vt(v).visit_fn(f, tp, i.span, i.ident, i.id, i.ann, e, v); + vt(v).visit_fn(f, tp, i.span, i.ident, i.id, e, v); } case (item_mod(?m)) { vt(v).visit_mod(m, i.span, e, v); } case (item_native_mod(?nm)) { @@ -126,13 +126,13 @@ fn visit_item[E](&@item i, &E e, &vt[E] v) { for (obj_field f in ob.fields) { vt(v).visit_ty(f.ty, e, v); } for (@method m in ob.methods) { vt(v).visit_fn(m.node.meth, [], m.span, m.node.ident, - m.node.id, m.node.ann, e, v); + m.node.id, e, v); } alt (ob.dtor) { case (none) { } case (some(?m)) { vt(v).visit_fn(m.node.meth, [], m.span, m.node.ident, - m.node.id, m.node.ann, e, v); + m.node.id, e, v); } } } @@ -202,7 +202,7 @@ fn visit_pat[E](&@pat p, &E e, &vt[E] v) { fn visit_native_item[E](&@native_item ni, &E e, &vt[E] v) { alt (ni.node) { - case (native_item_fn(_, _, ?fd, _, _, _)) { visit_fn_decl(fd, e, v); } + case (native_item_fn(_, _, ?fd, _, _)) { visit_fn_decl(fd, e, v); } case (native_item_ty(_, _)) { } } } @@ -213,8 +213,8 @@ fn visit_fn_decl[E](&fn_decl fd, &E e, &vt[E] v) { vt(v).visit_ty(fd.output, e, v); } -fn visit_fn[E](&_fn f, &vec[ty_param] tp, &span sp, &ident i, &def_id d, - &ann a, &E e, &vt[E] v) { +fn visit_fn[E](&_fn f, &vec[ty_param] tp, &span sp, &ident i, + node_id id, &E e, &vt[E] v) { visit_fn_decl(f.decl, e, v); vt(v).visit_block(f.body, e, v); } @@ -383,7 +383,7 @@ fn visit_expr[E](&@expr ex, &E e, &vt[E] v) { } for (@method m in anon_obj.methods) { vt(v).visit_fn(m.node.meth, [], m.span, m.node.ident, - m.node.id, m.node.ann, e, v); + m.node.id, e, v); } } } diff --git a/src/comp/middle/walk.rs b/src/comp/middle/walk.rs index 58a219127c4d..8f02b25455c1 100644 --- a/src/comp/middle/walk.rs +++ b/src/comp/middle/walk.rs @@ -40,10 +40,8 @@ type ast_visitor = fn(&@ast::ty) visit_ty_pre, fn(&@ast::ty) visit_ty_post, fn(&@ast::constr) visit_constr, - fn(&ast::_fn, &span, &ast::ident, &ast::def_id, &ast::ann) - visit_fn_pre, - fn(&ast::_fn, &span, &ast::ident, &ast::def_id, &ast::ann) - visit_fn_post); + fn(&ast::_fn, &span, &ast::ident, ast::node_id) visit_fn_pre, + fn(&ast::_fn, &span, &ast::ident, ast::node_id) visit_fn_post); fn walk_crate(&ast_visitor v, &ast::crate c) { if (!v.keep_going()) { ret; } @@ -104,7 +102,7 @@ fn walk_item(&ast_visitor v, @ast::item i) { alt (i.node) { case (ast::item_const(?t, ?e)) { walk_ty(v, t); walk_expr(v, e); } case (ast::item_fn(?f, _)) { - walk_fn(v, f, i.span, i.ident, i.id, i.ann); + walk_fn(v, f, i.span, i.ident, i.id); } case (ast::item_mod(?m)) { walk_mod(v, m); } case (ast::item_native_mod(?nm)) { walk_native_mod(v, nm); } @@ -120,15 +118,13 @@ fn walk_item(&ast_visitor v, @ast::item i) { for (ast::obj_field f in ob.fields) { walk_ty(v, f.ty); } for (@ast::method m in ob.methods) { v.visit_method_pre(m); - walk_fn(v, m.node.meth, m.span, m.node.ident, m.node.id, - m.node.ann); + walk_fn(v, m.node.meth, m.span, m.node.ident, m.node.id); v.visit_method_post(m); } alt (ob.dtor) { case (none) { } case (some(?m)) { - walk_fn(v, m.node.meth, m.span, m.node.ident, m.node.id, - m.node.ann); + walk_fn(v, m.node.meth, m.span, m.node.ident, m.node.id); } } } @@ -207,7 +203,7 @@ fn walk_native_item(&ast_visitor v, @ast::native_item ni) { if (!v.keep_going()) { ret; } v.visit_native_item_pre(ni); alt (ni.node) { - case (ast::native_item_fn(_, _, ?fd, _, _, _)) { + case (ast::native_item_fn(_, _, ?fd, _, _)) { walk_fn_decl(v, fd); } case (ast::native_item_ty(_, _)) { } @@ -222,12 +218,12 @@ fn walk_fn_decl(&ast_visitor v, &ast::fn_decl fd) { } fn walk_fn(&ast_visitor v, &ast::_fn f, &span sp, &ast::ident i, - &ast::def_id d, &ast::ann a) { + ast::node_id d) { if (!v.keep_going()) { ret; } - v.visit_fn_pre(f, sp, i, d, a); + v.visit_fn_pre(f, sp, i, d); walk_fn_decl(v, f.decl); walk_block(v, f.body); - v.visit_fn_post(f, sp, i, d, a); + v.visit_fn_post(f, sp, i, d); } fn walk_block(&ast_visitor v, &ast::block b) { @@ -402,8 +398,7 @@ fn walk_expr(&ast_visitor v, @ast::expr e) { // Methods for (@ast::method m in anon_obj.methods) { v.visit_method_pre(m); - walk_fn(v, m.node.meth, m.span, m.node.ident, m.node.id, - m.node.ann); + walk_fn(v, m.node.meth, m.span, m.node.ident, m.node.id); v.visit_method_post(m); } } @@ -445,9 +440,7 @@ fn def_visit_ty(&@ast::ty t) { } fn def_visit_constr(&@ast::constr c) { } -fn def_visit_fn(&ast::_fn f, &span sp, &ast::ident i, &ast::def_id d, - &ast::ann a) { -} +fn def_visit_fn(&ast::_fn f, &span sp, &ast::ident i, ast::node_id d) { } fn default_visitor() -> ast_visitor { ret rec(keep_going=def_keep_going, diff --git a/src/comp/pretty/pprust.rs b/src/comp/pretty/pprust.rs index d47ab331f776..8886d9de4cd5 100644 --- a/src/comp/pretty/pprust.rs +++ b/src/comp/pretty/pprust.rs @@ -1,5 +1,6 @@ import std::uint; +import std::int; import std::vec; import std::str; import std::io; @@ -323,8 +324,8 @@ fn print_item(&ps s, &@ast::item item) { word_nbsp(s, "type"); word(s.s, id); } - case (ast::native_item_fn(?id, ?lname, ?decl, ?typarams, - _, _)) { + case (ast::native_item_fn(?id, ?lname, ?decl, + ?typarams, _)) { print_fn(s, decl, ast::proto_fn, id, typarams); alt (lname) { case (none) { } @@ -426,7 +427,7 @@ fn print_item(&ps s, &@ast::item item) { alt (s.mode) { case (mo_identified) { space(s.s); - synth_comment(s, uint::to_str(item.ann.id, 10u)); + synth_comment(s, int::to_str(item.id, 10u)); } case (_) {/* no-op */ } } @@ -497,7 +498,7 @@ fn print_block(&ps s, ast::block blk) { alt (s.mode) { case (mo_identified) { space(s.s); - synth_comment(s, "block " + uint::to_str(blk.node.a.id, 10u)); + synth_comment(s, "block " + int::to_str(blk.node.id, 10u)); } case (_) {/* no-op */ } } @@ -865,7 +866,7 @@ fn print_expr(&ps s, &@ast::expr expr) { } case (mo_identified) { space(s.s); - synth_comment(s, uint::to_str(ty::expr_ann(expr).id, 10u)); + synth_comment(s, int::to_str(ty::expr_node_id(expr), 10u)); pclose(s); } } @@ -891,7 +892,7 @@ fn print_decl(&ps s, &@ast::decl decl) { alt (s.mode) { case (mo_untyped) {/* no-op */ } case (mo_typed(?tcx)) { - auto lty = ty::ann_to_type(tcx, loc.node.ann); + auto lty = ty::node_id_to_type(tcx, loc.node.id); word_space(s, ppaux::ty_to_str(tcx, lty)); } case (mo_identified) {/* no-op */ } @@ -943,7 +944,7 @@ fn print_pat(&ps s, &@ast::pat pat) { maybe_print_comment(s, pat.span.lo); alt (pat.node) { case (ast::pat_wild(_)) { word(s.s, "_"); } - case (ast::pat_bind(?id, _, _)) { word(s.s, "?" + id); } + case (ast::pat_bind(?id, _)) { word(s.s, "?" + id); } case (ast::pat_lit(?lit, _)) { print_literal(s, lit); } case (ast::pat_tag(?path, ?args, _)) { print_path(s, path); @@ -959,7 +960,7 @@ fn print_pat(&ps s, &@ast::pat pat) { alt (s.mode) { case (mo_identified) { space(s.s); - synth_comment(s, uint::to_str(ty::pat_ann(pat).id, 10u)); + synth_comment(s, int::to_str(ty::pat_node_id(pat), 10u)); } case (_) {/* no-op */ } } @@ -1029,7 +1030,7 @@ fn print_view_item(&ps s, &@ast::view_item item) { hardbreak_if_not_bol(s); maybe_print_comment(s, item.span.lo); alt (item.node) { - case (ast::view_item_use(?id, ?mta, _, _)) { + case (ast::view_item_use(?id, ?mta, _)) { head(s, "use"); word(s.s, id); if (vec::len(mta) > 0u) { @@ -1059,7 +1060,7 @@ fn print_view_item(&ps s, &@ast::view_item item) { } word(s.s, "::*"); } - case (ast::view_item_export(?id)) { + case (ast::view_item_export(?id, _)) { head(s, "export"); word(s.s, id); } From 77af54bf6f7d5e7cb704e08689ea96746bc57819 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 20 Jun 2011 08:14:24 +0200 Subject: [PATCH 2/6] Reduce confusing variable naming in resolve 'id' is now used for node_ids, 'name' for idents --- src/comp/middle/resolve.rs | 106 +++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs index 356dab840396..f24d0e71859b 100644 --- a/src/comp/middle/resolve.rs +++ b/src/comp/middle/resolve.rs @@ -502,12 +502,12 @@ fn resolve_import(&env e, &@ast::view_item it, &scopes sc) { } } } - fn register(&env e, def_id defid, &span sp, &ident id, + fn register(&env e, def_id defid, &span sp, &ident name, &option::t[def] val, &option::t[def] typ, &option::t[def] md) { if (option::is_none(val) && option::is_none(typ) && option::is_none(md)) { - unresolved_err(e, sp, id, "import"); + unresolved_err(e, sp, name, "import"); } else { e.imports.insert(defid._1, resolved(val, typ, md)); } @@ -538,8 +538,8 @@ fn ns_name(namespace ns) -> str { } } -fn unresolved_err(&env e, &span sp, &ident id, &str kind) { - e.sess.span_err(sp, mk_unresolved_msg(id, kind)); +fn unresolved_err(&env e, &span sp, &ident name, &str kind) { + e.sess.span_err(sp, mk_unresolved_msg(name, kind)); } fn unresolved_fatal(&env e, &span sp, &ident id, &str kind) -> ! { @@ -566,11 +566,11 @@ fn lookup_path_strict(&env e, &scopes sc, &span sp, vec[ident] idents, ret dcur; } -fn lookup_in_scope_strict(&env e, scopes sc, &span sp, &ident id, +fn lookup_in_scope_strict(&env e, scopes sc, &span sp, &ident name, namespace ns) -> option::t[def] { - alt (lookup_in_scope(e, sc, sp, id, ns)) { + alt (lookup_in_scope(e, sc, sp, name, ns)) { case (none) { - unresolved_err(e, sp, id, ns_name(ns)); + unresolved_err(e, sp, name, ns_name(ns)); ret none; } case (some(?d)) { ret some(d); } @@ -598,35 +598,37 @@ fn def_is_obj_field(&def d) -> bool { ret alt (d) { case (ast::def_obj_field(_)) { true } case (_) { false } }; } -fn lookup_in_scope(&env e, scopes sc, &span sp, &ident id, namespace ns) -> +fn lookup_in_scope(&env e, scopes sc, &span sp, &ident name, namespace ns) -> option::t[def] { - fn in_scope(&env e, &span sp, &ident id, &scope s, namespace ns) -> + fn in_scope(&env e, &span sp, &ident name, &scope s, namespace ns) -> option::t[def] { //not recursing through globs alt (s) { case (scope_crate(?c)) { - ret lookup_in_local_mod(e, -1, sp, id, ns, inside); + ret lookup_in_local_mod(e, -1, sp, name, ns, inside); } case (scope_item(?it)) { alt (it.node) { case (ast::item_obj(?ob, ?ty_params, _)) { - ret lookup_in_obj(id, ob, ty_params, ns); + ret lookup_in_obj(name, ob, ty_params, ns); } case (ast::item_tag(_, ?ty_params)) { if (ns == ns_type) { - ret lookup_in_ty_params(id, ty_params); + ret lookup_in_ty_params(name, ty_params); } } case (ast::item_mod(_)) { - ret lookup_in_local_mod(e, it.id, sp, id, ns, inside); + ret lookup_in_local_mod + (e, it.id, sp, name, ns, inside); } case (ast::item_native_mod(?m)) { - ret lookup_in_local_native_mod(e, it.id, sp, id, ns); + ret lookup_in_local_native_mod + (e, it.id, sp, name, ns); } case (ast::item_ty(_, ?ty_params)) { if (ns == ns_type) { - ret lookup_in_ty_params(id, ty_params); + ret lookup_in_ty_params(name, ty_params); } } case (_) { } @@ -636,23 +638,23 @@ fn lookup_in_scope(&env e, scopes sc, &span sp, &ident id, namespace ns) -> alt (it.node) { case (ast::native_item_fn(_, _, ?decl, ?ty_params, _)) { - ret lookup_in_fn(id, decl, ty_params, ns); + ret lookup_in_fn(name, decl, ty_params, ns); } } } case (scope_fn(?decl, ?ty_params)) { - ret lookup_in_fn(id, decl, ty_params, ns); + ret lookup_in_fn(name, decl, ty_params, ns); } case (scope_loop(?local)) { if (ns == ns_value) { - if (str::eq(local.node.ident, id)) { + if (str::eq(local.node.ident, name)) { ret some(ast::def_local(local_def(local.node.id))); } } } - case (scope_block(?b)) { ret lookup_in_block(id, b.node, ns); } + case (scope_block(?b)) { ret lookup_in_block(name, b.node, ns); } case (scope_arm(?a)) { - if (ns == ns_value) { ret lookup_in_pat(id, *a.pat); } + if (ns == ns_value) { ret lookup_in_pat(name, *a.pat); } } } ret none[def]; @@ -665,7 +667,7 @@ fn lookup_in_scope(&env e, scopes sc, &span sp, &ident id, namespace ns) -> alt ({ sc }) { case (nil) { ret none[def]; } case (cons(?hd, ?tl)) { - auto fnd = in_scope(e, sp, id, hd, ns); + auto fnd = in_scope(e, sp, name, hd, ns); if (!option::is_none(fnd)) { auto df = option::get(fnd); if (left_fn && def_is_local(df) || @@ -686,20 +688,20 @@ fn lookup_in_scope(&env e, scopes sc, &span sp, &ident id, namespace ns) -> } -fn lookup_in_ty_params(&ident id, &vec[ast::ty_param] ty_params) -> +fn lookup_in_ty_params(&ident name, &vec[ast::ty_param] ty_params) -> option::t[def] { auto i = 0u; for (ast::ty_param tp in ty_params) { - if (str::eq(tp, id)) { ret some(ast::def_ty_arg(i)); } + if (str::eq(tp, name)) { ret some(ast::def_ty_arg(i)); } i += 1u; } ret none[def]; } -fn lookup_in_pat(&ident ident, &ast::pat pat) -> option::t[def] { +fn lookup_in_pat(&ident name, &ast::pat pat) -> option::t[def] { alt (pat.node) { - case (ast::pat_bind(?name, ?id)) { - if (str::eq(name, ident)) { + case (ast::pat_bind(?p_name, ?id)) { + if (str::eq(p_name, name)) { ret some(ast::def_binding(local_def(id))); } } @@ -707,7 +709,7 @@ fn lookup_in_pat(&ident ident, &ast::pat pat) -> option::t[def] { case (ast::pat_lit(_, _)) { } case (ast::pat_tag(_, ?pats, _)) { for (@ast::pat p in pats) { - auto found = lookup_in_pat(ident, *p); + auto found = lookup_in_pat(name, *p); if (!option::is_none(found)) { ret found; } } } @@ -715,46 +717,47 @@ fn lookup_in_pat(&ident ident, &ast::pat pat) -> option::t[def] { ret none[def]; } -fn lookup_in_fn(&ident id, &ast::fn_decl decl, &vec[ast::ty_param] ty_params, +fn lookup_in_fn(&ident name, &ast::fn_decl decl, + &vec[ast::ty_param] ty_params, namespace ns) -> option::t[def] { alt (ns) { case (ns_value) { for (ast::arg a in decl.inputs) { - if (str::eq(a.ident, id)) { + if (str::eq(a.ident, name)) { ret some(ast::def_arg(local_def(a.id))); } } ret none[def]; } - case (ns_type) { ret lookup_in_ty_params(id, ty_params); } + case (ns_type) { ret lookup_in_ty_params(name, ty_params); } case (_) { ret none[def]; } } } -fn lookup_in_obj(&ident id, &ast::_obj ob, &vec[ast::ty_param] ty_params, +fn lookup_in_obj(&ident name, &ast::_obj ob, &vec[ast::ty_param] ty_params, namespace ns) -> option::t[def] { alt (ns) { case (ns_value) { for (ast::obj_field f in ob.fields) { - if (str::eq(f.ident, id)) { + if (str::eq(f.ident, name)) { ret some(ast::def_obj_field(local_def(f.id))); } } ret none[def]; } - case (ns_type) { ret lookup_in_ty_params(id, ty_params); } + case (ns_type) { ret lookup_in_ty_params(name, ty_params); } case (_) { ret none[def]; } } } -fn lookup_in_block(&ident id, &ast::block_ b, namespace ns) -> +fn lookup_in_block(&ident name, &ast::block_ b, namespace ns) -> option::t[def] { for (@ast::stmt st in b.stmts) { alt (st.node) { case (ast::stmt_decl(?d, _)) { alt (d.node) { case (ast::decl_local(?loc)) { - if (ns == ns_value && str::eq(id, loc.node.ident)) { + if (ns == ns_value && str::eq(name, loc.node.ident)) { ret some(ast::def_local(local_def(loc.node.id))); } } @@ -762,13 +765,13 @@ fn lookup_in_block(&ident id, &ast::block_ b, namespace ns) -> alt (it.node) { case (ast::item_tag(?variants, _)) { if (ns == ns_type) { - if (str::eq(it.ident, id)) { + if (str::eq(it.ident, name)) { ret some(ast::def_ty (local_def(it.id))); } } else if (ns == ns_value) { for (ast::variant v in variants) { - if (str::eq(v.node.name, id)) { + if (str::eq(v.node.name, name)) { auto i = v.node.id; ret some(ast::def_variant (local_def(it.id), @@ -778,7 +781,7 @@ fn lookup_in_block(&ident id, &ast::block_ b, namespace ns) -> } } case (_) { - if (str::eq(it.ident, id)) { + if (str::eq(it.ident, name)) { auto found = found_def_item(it, ns); if (!option::is_none(found)) { ret found; @@ -839,39 +842,40 @@ fn found_def_item(&@ast::item i, namespace ns) -> option::t[def] { ret none[def]; } -fn lookup_in_mod_strict(&env e, def m, &span sp, &ident id, namespace ns, +fn lookup_in_mod_strict(&env e, def m, &span sp, &ident name, namespace ns, dir dr) -> option::t[def] { - alt (lookup_in_mod(e, m, sp, id, ns, dr)) { + alt (lookup_in_mod(e, m, sp, name, ns, dr)) { case (none) { - unresolved_err(e, sp, id, ns_name(ns)); + unresolved_err(e, sp, name, ns_name(ns)); ret none; } case (some(?d)) { ret some(d); } } } -fn lookup_in_mod(&env e, def m, &span sp, &ident id, namespace ns, dir dr) -> +fn lookup_in_mod(&env e, def m, &span sp, &ident name, namespace ns, + dir dr) -> option::t[def] { auto defid = ast::def_id_of_def(m); if (defid._0 != ast::local_crate) { // examining a module in an external crate - auto cached = e.ext_cache.find(tup(defid, id, ns)); + auto cached = e.ext_cache.find(tup(defid, name, ns)); if (!option::is_none(cached)) { ret cached; } - auto path = [id]; + auto path = [name]; if (defid._1 != -1) { path = e.ext_map.get(defid) + path; } auto fnd = lookup_external(e, defid._0, path, ns); if (!option::is_none(fnd)) { - e.ext_cache.insert(tup(defid, id, ns), option::get(fnd)); + e.ext_cache.insert(tup(defid, name, ns), option::get(fnd)); } ret fnd; } alt (m) { case (ast::def_mod(?defid)) { - ret lookup_in_local_mod(e, defid._1, sp, id, ns, dr); + ret lookup_in_local_mod(e, defid._1, sp, name, ns, dr); } case (ast::def_native_mod(?defid)) { - ret lookup_in_local_native_mod(e, defid._1, sp, id, ns); + ret lookup_in_local_native_mod(e, defid._1, sp, name, ns); } } } @@ -1319,13 +1323,13 @@ fn checker(&env e, str kind) -> checker { ret @rec(mutable seen=seen, kind=kind, sess=e.sess); } -fn add_name(&checker ch, &span sp, &ident id) { +fn add_name(&checker ch, &span sp, &ident name) { for (ident s in ch.seen) { - if (str::eq(s, id)) { - ch.sess.span_fatal(sp, "duplicate " + ch.kind + " name: " + id); + if (str::eq(s, name)) { + ch.sess.span_fatal(sp, "duplicate " + ch.kind + " name: " + name); } } - vec::push(ch.seen, id); + vec::push(ch.seen, name); } fn ident_id(&ident i) -> ident { ret i; } From 40db3aa6fbe2f0d8d7f9bb85a9fd47b8cca2938b Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 20 Jun 2011 09:59:16 +0200 Subject: [PATCH 3/6] Add a separate AST mapping phase This will replace the various node_id-to-node mappings done in several other passes. This commit already uses the new map in resolve, dropping the ast_map that was built there before. --- src/comp/driver/rustc.rs | 7 +++++-- src/comp/middle/resolve.rs | 30 ++++++++++-------------------- src/comp/rustc.rc | 1 + 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index f5f79fb0a2a6..040b551a5297 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -80,9 +80,11 @@ fn compile_input(session::session sess, eval::env env, str input, auto crate = time(time_passes, "parsing", bind parse_input(sess, p, input)); if (sess.get_opts().output_type == link::output_type_none) { ret; } + auto ast_map = time(time_passes, "ast indexing", + bind middle::ast_map::map_crate(*crate)); auto d = time(time_passes, "resolution", - bind resolve::resolve_crate(sess, crate)); + bind resolve::resolve_crate(sess, ast_map, crate)); auto ty_cx = ty::mk_ctxt(sess, d._0, d._1); time[()](time_passes, "typechecking", bind typeck::check_crate(ty_cx, crate)); @@ -107,7 +109,8 @@ fn pretty_print_input(session::session sess, eval::env env, str input, auto mode; alt (ppm) { case (ppm_typed) { - auto d = resolve::resolve_crate(sess, crate); + 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); typeck::check_crate(ty_cx, crate); mode = ppaux::mo_typed(ty_cx); diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs index f24d0e71859b..243411760797 100644 --- a/src/comp/middle/resolve.rs +++ b/src/comp/middle/resolve.rs @@ -116,7 +116,7 @@ type env = rec(crate_map crate_map, def_map def_map, constr_table fn_constrs, - hashmap[ast::node_id, @ast::item] ast_map, + ast_map::map ast_map, hashmap[ast::node_id, import_state] imports, hashmap[ast::node_id, @indexed_mod] mod_map, hashmap[def_id, vec[ident]] ext_map, @@ -130,13 +130,13 @@ tag dir { inside; outside; } tag namespace { ns_value; ns_type; ns_module; } -fn resolve_crate(session sess, @ast::crate crate) -> +fn resolve_crate(session sess, &ast_map::map amap, @ast::crate crate) -> tup(def_map, constr_table) { auto e = @rec(crate_map=new_int_hash[ast::crate_num](), def_map=new_int_hash[def](), fn_constrs = new_int_hash[vec[ty::constr_def]](), - ast_map=new_int_hash[@ast::item](), + ast_map=amap, imports=new_int_hash[import_state](), mod_map=new_int_hash[@indexed_mod](), ext_map=new_def_hash[vec[ident]](), @@ -187,7 +187,6 @@ fn map_crate(&@env e, &@ast::crate c) { index=index_mod(md), mutable glob_imports=vec::empty[def](), glob_imported_names=s)); - e.ast_map.insert(i.id, i); } case (ast::item_native_mod(?nmd)) { auto s = new_str_hash[import_state](); @@ -196,13 +195,8 @@ fn map_crate(&@env e, &@ast::crate c) { index=index_nmod(nmd), mutable glob_imports=vec::empty[def](), glob_imported_names=s)); - e.ast_map.insert(i.id, i); } - case (ast::item_obj(_, _, ?ctor_id)) { - e.ast_map.insert(i.id, i); - e.ast_map.insert(ctor_id, i); - } - case (_) { e.ast_map.insert(i.id, i); } + case (_) { } } } // Next, assemble the links for globbed imports. @@ -969,16 +963,12 @@ fn lookup_glob_in_mod(&env e, @indexed_mod info, &span sp, &ident id, ret some[def](matches.(0)); } else { for (def match in matches) { - alt (e.ast_map.find(ast::def_id_of_def(match)._1)) { - case (some(?it)) { - e.sess.span_note(it.span, - "'" + id + "' is defined here."); - } - case (_) { - e.sess.bug("Internal error: imports and matches " + - "don't agree"); - } - } + auto span = alt (e.ast_map.get(ast::def_id_of_def(match)._1)){ + case (ast_map::node_item(?it)) { it.span } + case (ast_map::node_obj_ctor(?it)) { it.span } + case (ast_map::node_native_item(?it)) { it.span } + }; + e.sess.span_note(span, "'" + id + "' is defined here."); } e.sess.span_fatal(sp, "'" + id + "' is glob-imported from" + diff --git a/src/comp/rustc.rc b/src/comp/rustc.rc index b75b2f221fca..da2a8640a7d6 100644 --- a/src/comp/rustc.rc +++ b/src/comp/rustc.rc @@ -19,6 +19,7 @@ mod middle { mod walk; mod visit; mod metadata; + mod ast_map; mod resolve; mod typeck; mod alias; From 854b3a9b73ca78551a8ca8a933e07a12a0e77aeb Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 20 Jun 2011 10:20:16 +0200 Subject: [PATCH 4/6] 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 040b551a5297..d265ac2aeeef 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 4dbe8444ef8d..77b8639f2605 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 ca07350f2e82..381cc442fdc4 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()); From 588dc3897b1a510b7f65ca5e53ba5a99224c1923 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 20 Jun 2011 10:43:33 +0200 Subject: [PATCH 5/6] Make trans use the new ast_map instead of building its own --- src/comp/driver/rustc.rs | 4 ++-- src/comp/middle/metadata.rs | 20 ++++++++++++-------- src/comp/middle/trans.rs | 28 ++++++++++------------------ 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index d265ac2aeeef..3644a1d271b6 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -96,8 +96,8 @@ fn compile_input(session::session sess, eval::env env, str input, bind middle::alias::check_crate(@ty_cx, crate)); auto llmod = time[llvm::llvm::ModuleRef](time_passes, "translation", - bind trans::trans_crate(sess, crate, - ty_cx, output)); + bind trans::trans_crate + (sess, crate, ty_cx, output, ast_map)); time[()](time_passes, "LLVM passes", bind link::write::run_passes(sess, llmod, output)); } diff --git a/src/comp/middle/metadata.rs b/src/comp/middle/metadata.rs index 29ef13f59e07..2d18831a7b82 100644 --- a/src/comp/middle/metadata.rs +++ b/src/comp/middle/metadata.rs @@ -603,14 +603,18 @@ fn encode_info_for_items(&@trans::crate_ctxt cx, &ebml::writer ebml_w) -> vec[tup(int, uint)] { let vec[tup(int, uint)] index = []; ebml::start_tag(ebml_w, tag_items_data); - for each (@tup(node_id, @item) kvp in cx.items.items()) { - index += [tup(kvp._0, ebml_w.writer.tell())]; - encode_info_for_item(cx, ebml_w, kvp._1, index); - } - for each (@tup(node_id, @native_item) kvp in - cx.native_items.items()) { - index += [tup(kvp._0, ebml_w.writer.tell())]; - encode_info_for_native_item(cx, ebml_w, kvp._1); + for each (@tup(node_id, ast_map::ast_node) kvp in cx.ast_map.items()) { + alt (kvp._1) { + case (ast_map::node_item(?i)) { + index += [tup(kvp._0, ebml_w.writer.tell())]; + encode_info_for_item(cx, ebml_w, i, index); + } + case (ast_map::node_native_item(?i)) { + index += [tup(kvp._0, ebml_w.writer.tell())]; + encode_info_for_native_item(cx, ebml_w, i); + } + case (_) {} + } } ebml::end_tag(ebml_w); ret index; diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 726f7b491ef8..0743e19aa359 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -126,8 +126,7 @@ type crate_ctxt = // of the first instruction of the item's definition in the executable // we're generating. hashmap[ast::node_id, ValueRef] item_ids, - hashmap[ast::node_id, @ast::item] items, - hashmap[ast::node_id, @ast::native_item] native_items, + ast_map::map ast_map, hashmap[ast::node_id, str] item_symbols, mutable option::t[ValueRef] main_fn, str crate_meta_name, @@ -7625,7 +7624,9 @@ fn register_fn_pair(&@crate_ctxt cx, str ps, TypeRef llfnty, ValueRef llfn, // Returns the number of type parameters that the given native function has. fn native_fn_ty_param_count(&@crate_ctxt cx, ast::node_id id) -> uint { auto count; - auto native_item = cx.native_items.get(id); + auto native_item = alt (cx.ast_map.get(id)) { + case (ast_map::node_native_item(?i)) { i } + }; alt (native_item.node) { case (ast::native_item_ty(_, _)) { cx.sess.bug("decl_native_fn_and_pair(): native fn isn't " + @@ -7668,7 +7669,9 @@ fn decl_native_fn_and_pair(&@crate_ctxt ccx, &span sp, vec[str] path, auto lltop = bcx.llbb; // Declare the function itself. - auto item = ccx.native_items.get(id); + auto item = alt (ccx.ast_map.get(id)) { + case (ast_map::node_native_item(?i)) { i } + }; auto fn_type = node_id_type(ccx, id); // NB: has no type params auto abi = ty::ty_fn_abi(ccx.tcx, fn_type); @@ -7807,14 +7810,11 @@ fn collect_native_item(@crate_ctxt ccx, &@ast::native_item i, &vec[str] pt, &vt[vec[str]] v) { alt (i.node) { case (ast::native_item_fn(?name, _, _, _, ?id)) { - ccx.native_items.insert(id, i); if (!ccx.obj_methods.contains_key(id)) { decl_native_fn_and_pair(ccx, i.span, pt, name, id); } } - case (ast::native_item_ty(_, ?id)) { - ccx.native_items.insert(id, i); - } + case (_) {} } } @@ -7830,13 +7830,8 @@ fn collect_item_1(@crate_ctxt ccx, &@ast::item i, &vec[str] pt, llvm::LLVMSetLinkage(g, lib::llvm::LLVMInternalLinkage as llvm::Linkage); - ccx.items.insert(i.id, i); ccx.consts.insert(i.id, g); } - case (ast::item_mod(?m)) { ccx.items.insert(i.id, i); } - case (ast::item_native_mod(_)) { ccx.items.insert(i.id, i); } - case (ast::item_ty(_, _)) { ccx.items.insert(i.id, i); } - case (ast::item_tag(_, _)) { ccx.items.insert(i.id, i); } case (_) { } } } @@ -7847,13 +7842,11 @@ fn collect_item_2(&@crate_ctxt ccx, &@ast::item i, &vec[str] pt, visit::visit_item(i, new_pt, v); alt (i.node) { case (ast::item_fn(?f, ?tps)) { - ccx.items.insert(i.id, i); if (!ccx.obj_methods.contains_key(i.id)) { decl_fn_and_pair(ccx, i.span, new_pt, "fn", tps, i.id, i.id); } } case (ast::item_obj(?ob, ?tps, ?ctor_id)) { - ccx.items.insert(ctor_id, i); decl_fn_and_pair(ccx, i.span, new_pt, "obj_ctor", tps, i.id, ctor_id); for (@ast::method m in ob.methods) { @@ -8105,7 +8098,7 @@ fn create_crate_map(&@crate_ctxt ccx) -> ValueRef { } fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx, - &str output) -> ModuleRef { + &str output, &ast_map::map amap) -> ModuleRef { auto llmod = llvm::LLVMModuleCreateWithNameInContext(str::buf("rust_out"), llvm::LLVMGetGlobalContext()); @@ -8132,8 +8125,7 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx, externs=new_str_hash[ValueRef](), intrinsics=intrinsics, item_ids=new_int_hash[ValueRef](), - items=new_int_hash[@ast::item](), - native_items=new_int_hash[@ast::native_item](), + ast_map=amap, item_symbols=new_int_hash[str](), mutable main_fn=none[ValueRef], crate_meta_name=crate_meta_name(sess, *crate, output), From 56eb98658449d2a6cc38279d6ec8085f1837f991 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 20 Jun 2011 10:44:38 +0200 Subject: [PATCH 6/6] Fix some uses of span_warn in alias.rs that should be span_fatal --- src/comp/middle/alias.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/comp/middle/alias.rs b/src/comp/middle/alias.rs index da41d0652296..f19d764ee047 100644 --- a/src/comp/middle/alias.rs +++ b/src/comp/middle/alias.rs @@ -234,7 +234,7 @@ fn check_tail_call(&ctx cx, &@ast::expr call) { alt (cx.local_map.find(dnum)) { case (some(arg(ast::alias(?mut)))) { if (mut_a && !mut) { - cx.tcx.sess.span_warn(args.(i).span, + cx.tcx.sess.span_fatal(args.(i).span, "passing an immutable \ alias by mutable alias"); } @@ -245,7 +245,7 @@ fn check_tail_call(&ctx cx, &@ast::expr call) { case (_) { ok = false; } } if (!ok) { - cx.tcx.sess.span_warn(args.(i).span, + cx.tcx.sess.span_fatal(args.(i).span, "can not pass a local value by \ alias to a tail call"); }