diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 0ce20eb2f159..6b7ae110ab21 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -97,21 +97,18 @@ fn compile_input(session::session sess, bind resolve::resolve_crate(sess, crate)); auto ty_cx = ty::mk_ctxt(sess, def_map); - auto typeck_result = - time[typeck::typecheck_result](time_passes, "typechecking", - bind typeck::check_crate(ty_cx, crate)); - auto node_type_table = typeck_result._0; - auto type_cache = typeck_result._1; + time[()](time_passes, "typechecking", + bind typeck::check_crate(ty_cx, crate)); if (sess.get_opts().run_typestate) { time(time_passes, "typestate checking", - bind middle::tstate::ck::check_crate(node_type_table, - ty_cx, crate)); + bind middle::tstate::ck::check_crate(ty_cx, crate)); } - auto llmod = time[llvm::ModuleRef](time_passes, "translation", - bind trans::trans_crate(sess, crate, ty_cx, node_type_table, - type_cache, output)); + auto llmod = + time[llvm::ModuleRef](time_passes, "translation", + bind trans::trans_crate(sess, crate, + ty_cx, output)); time[()](time_passes, "LLVM passes", bind link::write::run_passes(sess, llmod, output)); @@ -128,8 +125,8 @@ fn pretty_print_input(session::session sess, eval::env env, str input, crate = creader::read_crates(sess, crate); auto def_map = resolve::resolve_crate(sess, crate); auto ty_cx = ty::mk_ctxt(sess, def_map); - auto typeck_result = typeck::check_crate(ty_cx, crate); - mode = pprust::mo_typed(ty_cx, typeck_result._0, typeck_result._1); + typeck::check_crate(ty_cx, crate); + mode = pprust::mo_typed(ty_cx); } else { mode = pprust::mo_untyped; } diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 648385ec408a..7ce0fe0a11dd 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -19,7 +19,6 @@ import back::x86; import back::abi; import back::upcall; -import middle::ty::node_type_table; import middle::ty::pat_ty; import util::common; @@ -110,7 +109,6 @@ state type crate_ctxt = rec(session::session sess, hashmap[ast::def_id, @ast::item] items, hashmap[ast::def_id, @ast::native_item] native_items, - ty::type_cache type_cache, hashmap[ast::def_id, str] item_symbols, // TODO: hashmap[tup(tag_id,subtys), @tag_info] hashmap[ty::t, uint] tag_sizes, @@ -130,8 +128,7 @@ state type crate_ctxt = rec(session::session sess, hashmap[ty::t, str] type_short_names, ty::ctxt tcx, stats stats, - @upcall::upcalls upcalls, - node_type_table node_types); + @upcall::upcalls upcalls); type local_ctxt = rec(vec[str] path, vec[str] module_path, @@ -3358,7 +3355,7 @@ fn target_type(&@crate_ctxt cx, &ty::t t) -> ty::t { // Converts an annotation to a type fn node_ann_type(&@crate_ctxt cx, &ast::ann a) -> ty::t { - ret target_type(cx, ty::ann_to_monotype(cx.tcx, cx.node_types, a)); + ret target_type(cx, ty::ann_to_monotype(cx.tcx, a)); } fn node_type(&@crate_ctxt cx, &ast::span sp, &ast::ann a) -> TypeRef { @@ -3369,25 +3366,22 @@ fn trans_unary(&@block_ctxt cx, ast::unop op, &@ast::expr e, &ast::ann a) -> result { auto sub = trans_expr(cx, e); - auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, e); + auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e); alt (op) { case (ast::bitnot) { sub = autoderef(sub.bcx, sub.val, - ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, e)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, e)); ret res(sub.bcx, sub.bcx.build.Not(sub.val)); } case (ast::not) { sub = autoderef(sub.bcx, sub.val, - ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, e)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, e)); ret res(sub.bcx, sub.bcx.build.Not(sub.val)); } case (ast::neg) { sub = autoderef(sub.bcx, sub.val, - ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, e)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, e)); if(ty::struct(cx.fcx.lcx.ccx.tcx, e_ty) == ty::ty_float) { ret res(sub.bcx, sub.bcx.build.FNeg(sub.val)); } @@ -3396,8 +3390,7 @@ fn trans_unary(&@block_ctxt cx, ast::unop op, } } case (ast::box(_)) { - auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, e); + 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); sub = trans_malloc_boxed(sub.bcx, e_ty); @@ -3659,14 +3652,12 @@ fn trans_binary(&@block_ctxt cx, ast::binop op, // Lazy-eval and auto lhs_res = trans_expr(cx, a); lhs_res = autoderef(lhs_res.bcx, lhs_res.val, - ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, a)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, a)); auto rhs_cx = new_scope_block_ctxt(cx, "rhs"); auto rhs_res = trans_expr(rhs_cx, b); rhs_res = autoderef(rhs_res.bcx, rhs_res.val, - ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, b)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, b)); auto lhs_false_cx = new_scope_block_ctxt(cx, "lhs false"); auto lhs_false_res = res(lhs_false_cx, C_bool(false)); @@ -3688,14 +3679,12 @@ fn trans_binary(&@block_ctxt cx, ast::binop op, // Lazy-eval or auto lhs_res = trans_expr(cx, a); lhs_res = autoderef(lhs_res.bcx, lhs_res.val, - ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, a)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, a)); auto rhs_cx = new_scope_block_ctxt(cx, "rhs"); auto rhs_res = trans_expr(rhs_cx, b); rhs_res = autoderef(rhs_res.bcx, rhs_res.val, - ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, b)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, b)); auto lhs_true_cx = new_scope_block_ctxt(cx, "lhs true"); auto lhs_true_res = res(lhs_true_cx, C_bool(true)); @@ -3714,12 +3703,10 @@ fn trans_binary(&@block_ctxt cx, ast::binop op, case (_) { // Remaining cases are eager: auto lhs = trans_expr(cx, a); - auto lhty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, a); + auto lhty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, a); lhs = autoderef(lhs.bcx, lhs.val, lhty); auto rhs = trans_expr(lhs.bcx, b); - auto rhty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, b); + auto rhty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, b); rhs = autoderef(rhs.bcx, rhs.val, rhty); ret trans_eager_binop(rhs.bcx, op, autoderefed_ty(cx.fcx.lcx.ccx, lhty), lhs.val, rhs.val); @@ -3803,8 +3790,7 @@ fn trans_if(&@block_ctxt cx, &@ast::expr cond, // If we have an else expression, then the entire // if expression can have a non-nil type. // FIXME: This isn't quite right, particularly re: dynamic types - auto expr_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, elexpr); + auto expr_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, elexpr); if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, expr_ty)) { expr_llty = T_typaram_ptr(cx.fcx.lcx.ccx.tn); } else { @@ -3862,8 +3848,7 @@ fn trans_for(&@block_ctxt cx, } auto next_cx = new_sub_block_ctxt(cx, "next"); - auto seq_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, - seq); + auto seq_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, seq); auto seq_res = trans_expr(cx, seq); auto it = iter_sequence(seq_res.bcx, seq_res.val, seq_ty, bind inner(_, local, _, _, body, next_cx)); @@ -4192,7 +4177,7 @@ fn trans_pat_match(&@block_ctxt cx, &@ast::pat pat, ValueRef 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.node_types, ann); + auto lltype = ty::ann_to_type(cx.fcx.lcx.ccx.tcx.node_types, ann); auto lleq = trans_compare(cx, ast::eq, lltype, llval, lllit); auto matched_cx = new_sub_block_ctxt(lleq.bcx, "matched_cx"); @@ -4229,8 +4214,8 @@ fn trans_pat_match(&@block_ctxt cx, &@ast::pat pat, ValueRef llval, 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.node_types, - ann); + auto ty_params = + ty::ann_to_type_params(cx.fcx.lcx.ccx.tcx.node_types, ann); if (vec::len[@ast::pat](subpats) > 0u) { auto llblobptr = matched_cx.build.GEP(lltagptr, @@ -4243,9 +4228,7 @@ fn trans_pat_match(&@block_ctxt cx, &@ast::pat pat, ValueRef llval, matched_cx = rslt.bcx; auto llsubval = load_if_immediate(matched_cx, - llsubvalptr, pat_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, - subpat)); + llsubvalptr, pat_ty(cx.fcx.lcx.ccx.tcx, subpat)); auto subpat_res = trans_pat_match(matched_cx, subpat, llsubval, next_cx); matched_cx = subpat_res.bcx; @@ -4295,7 +4278,7 @@ fn trans_pat_binding(&@block_ctxt cx, &@ast::pat pat, 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.node_types, ann); + ty::ann_to_type_params(cx.fcx.lcx.ccx.tcx.node_types, ann); auto this_cx = cx; auto i = 0; @@ -4342,7 +4325,7 @@ fn trans_alt(&@block_ctxt cx, &@ast::expr expr, "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.node_types, ann); + auto expr_ty = ty::ann_to_type(cx.fcx.lcx.ccx.tcx.node_types, ann); 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); @@ -4407,8 +4390,8 @@ fn lval_generic_fn(&@block_ctxt cx, lv = trans_external_path(cx, fn_id, tpt); } - auto tys = ty::ann_to_type_params(cx.fcx.lcx.ccx.node_types, ann); - auto monoty = ty::ann_to_type(cx.fcx.lcx.ccx.node_types, ann); + auto tys = ty::ann_to_type_params(cx.fcx.lcx.ccx.tcx.node_types, ann); + auto monoty = ty::ann_to_type(cx.fcx.lcx.ccx.tcx.node_types, ann); if (vec::len[ty::t](tys) != 0u) { auto bcx = lv.res.bcx; @@ -4485,20 +4468,17 @@ fn trans_path(&@block_ctxt cx, &ast::path p, &ast::ann ann) -> lval_result { } case (ast::def_fn(?did)) { auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.sess, - cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.type_cache, did); + cx.fcx.lcx.ccx.tcx, did); ret lval_generic_fn(cx, tyt, did, ann); } case (ast::def_obj(?did)) { auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.sess, - cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.type_cache, did); + cx.fcx.lcx.ccx.tcx, did); ret lval_generic_fn(cx, tyt, did, ann); } case (ast::def_variant(?tid, ?vid)) { auto v_tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.sess, - cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.type_cache, vid); + cx.fcx.lcx.ccx.tcx, vid); alt (ty::struct(cx.fcx.lcx.ccx.tcx, v_tyt._1)) { case (ty::ty_fn(_, _, _)) { // N-ary variant. @@ -4540,8 +4520,7 @@ fn trans_path(&@block_ctxt cx, &ast::path p, &ast::ann ann) -> lval_result { } case (ast::def_native_fn(?did)) { auto tyt = ty::lookup_item_type(cx.fcx.lcx.ccx.sess, - cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.type_cache, did); + cx.fcx.lcx.ccx.tcx, did); ret lval_generic_fn(cx, tyt, did, ann); } case (_) { @@ -4595,9 +4574,7 @@ fn trans_index(&@block_ctxt cx, &ast::span sp, &@ast::expr base, &@ast::expr idx, &ast::ann ann) -> lval_result { auto lv = trans_expr(cx, base); - lv = autoderef(lv.bcx, lv.val, ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, - base)); + lv = autoderef(lv.bcx, lv.val, ty::expr_ty(cx.fcx.lcx.ccx.tcx, base)); auto ix = trans_expr(lv.bcx, idx); auto v = lv.val; auto bcx = ix.bcx; @@ -4663,8 +4640,7 @@ fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result { } case (ast::expr_field(?base, ?ident, ?ann)) { auto r = trans_expr(cx, base); - auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, base); + auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, base); ret trans_field(r.bcx, e.span, r.val, t, ident, ann); } case (ast::expr_index(?base, ?idx, ?ann)) { @@ -4725,8 +4701,7 @@ fn trans_cast(&@block_ctxt cx, &@ast::expr e, &ast::ann ann) -> result { if (!ty::type_is_fp(cx.fcx.lcx.ccx.tcx, t)) { // TODO: native-to-native casts if (ty::type_is_native(cx.fcx.lcx.ccx.tcx, - ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, e))) { + ty::expr_ty(cx.fcx.lcx.ccx.tcx, e))) { e_res.val = e_res.bcx.build.PtrToInt(e_res.val, lldsttype); } else if (ty::type_is_native(cx.fcx.lcx.ccx.tcx, t)) { e_res.val = e_res.bcx.build.IntToPtr(e_res.val, lldsttype); @@ -4818,7 +4793,7 @@ fn trans_bind_thunk(&@local_ctxt cx, // Arg provided at binding time; thunk copies it from closure. case (some[@ast::expr](?e)) { - auto e_ty = ty::expr_ty(cx.ccx.tcx, cx.ccx.node_types, e); + auto e_ty = ty::expr_ty(cx.ccx.tcx, e); auto bound_arg = GEP_tup_like(bcx, closure_ty, llclosure, [0, @@ -4914,8 +4889,7 @@ fn trans_bind(&@block_ctxt cx, &@ast::expr f, let vec[ValueRef] lltydescs; alt (f_res.generic) { case (none[generic_info]) { - outgoing_fty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, f); + outgoing_fty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, f); lltydescs = []; } case (some[generic_info](?ginfo)) { @@ -4944,8 +4918,7 @@ fn trans_bind(&@block_ctxt cx, &@ast::expr f, vec::push[ValueRef](bound_vals, arg.val); vec::push[ty::t](bound_tys, - ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, e)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, e)); i += 1u; } @@ -5095,7 +5068,7 @@ fn trans_arg_expr(&@block_ctxt cx, auto val; auto bcx = cx; - auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, e); + auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e); if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, e_ty)) { auto re = trans_expr(bcx, e); @@ -5295,13 +5268,12 @@ fn trans_call(&@block_ctxt cx, &@ast::expr f, } case (_) { - fn_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, - f); + fn_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, f); } } - auto ret_ty = ty::ann_to_type(cx.fcx.lcx.ccx.node_types, ann); + auto ret_ty = ty::ann_to_type(cx.fcx.lcx.ccx.tcx.node_types, ann); auto args_res = trans_args(f_res.res.bcx, llenv, f_res.llobj, f_res.generic, @@ -5356,8 +5328,7 @@ fn trans_tup(&@block_ctxt cx, &vec[ast::elt] elts, let int i = 0; for (ast::elt e in elts) { - auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, - e.expr); + auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e.expr); auto src_res = trans_expr(bcx, e.expr); bcx = src_res.bcx; auto dst_res = GEP_tup_like(bcx, t, tup_val, [0, i]); @@ -5675,7 +5646,7 @@ fn trans_expr(&@block_ctxt cx, &@ast::expr e) -> result { // lval cases fall through to trans_lval and then // possibly load the result (if it's non-structural). - auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, e); + auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e); auto sub = trans_lval(cx, e); ret res(sub.res.bcx, load_if_immediate(sub.res.bcx, sub.res.val, t)); } @@ -5736,7 +5707,7 @@ fn trans_log(int lvl, &@block_ctxt cx, &@ast::expr e) -> result { cx.build.CondBr(test, log_cx.llbb, after_cx.llbb); auto sub = trans_expr(log_cx, e); - auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, e); + auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e); auto log_bcx = sub.bcx; if (ty::type_is_fp(cx.fcx.lcx.ccx.tcx, e_ty)) { @@ -5854,8 +5825,7 @@ fn trans_put(&@block_ctxt cx, &option::t[@ast::expr] e) -> result { alt (e) { case (none[@ast::expr]) { } case (some[@ast::expr](?x)) { - auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, x); + auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, x); auto arg = rec(mode=ty::mo_alias, ty=e_ty); auto arg_tys = type_of_explicit_args(cx.fcx.lcx.ccx, x.span, [arg]); @@ -5916,8 +5886,7 @@ fn trans_ret(&@block_ctxt cx, &option::t[@ast::expr] e) -> result { alt (e) { case (some[@ast::expr](?x)) { - auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, x); + auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, x); auto r = trans_expr(cx, x); bcx = r.bcx; val = r.val; @@ -6310,8 +6279,7 @@ fn trans_block(&@block_ctxt cx, &ast::block b) -> result { if (is_terminated(bcx)) { ret r; } else { - auto r_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, - cx.fcx.lcx.ccx.node_types, e); + auto r_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e); if (!ty::type_is_nil(cx.fcx.lcx.ccx.tcx, r_ty)) { // The value resulting from the block gets copied into an // alloca created in an outer scope and its refcount @@ -6539,7 +6507,7 @@ fn is_terminated(&@block_ctxt cx) -> bool { } fn arg_tys_of_fn(&@crate_ctxt ccx, ast::ann ann) -> vec[ty::arg] { - alt (ty::struct(ccx.tcx, ty::ann_to_type(ccx.node_types, ann))) { + alt (ty::struct(ccx.tcx, ty::ann_to_type(ccx.tcx.node_types, ann))) { case (ty::ty_fn(_, ?arg_tys, _)) { ret arg_tys; } @@ -6558,7 +6526,7 @@ fn ret_ty_of_fn_ty(&@crate_ctxt ccx, ty::t t) -> ty::t { fn ret_ty_of_fn(&@crate_ctxt ccx, ast::ann ann) -> ty::t { - ret ret_ty_of_fn_ty(ccx, ty::ann_to_type(ccx.node_types, ann)); + ret ret_ty_of_fn_ty(ccx, ty::ann_to_type(ccx.tcx.node_types, ann)); } fn populate_fn_ctxt_from_llself(@fn_ctxt fcx, self_vt llself) { @@ -8006,9 +7974,8 @@ fn create_crate_map(&@crate_ctxt ccx) -> ValueRef { ret map; } -fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx, - &ty::node_type_table node_types, &ty::type_cache type_cache, - &str output) +fn trans_crate(&session::session sess, &@ast::crate crate, + &ty::ctxt tcx, &str output) -> ModuleRef { auto llmod = llvm::LLVMModuleCreateWithNameInContext(str::buf("rust_out"), @@ -8043,7 +8010,6 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx, item_ids = new_def_hash[ValueRef](), items = new_def_hash[@ast::item](), native_items = new_def_hash[@ast::native_item](), - type_cache = type_cache, item_symbols = new_def_hash[str](), tag_sizes = tag_sizes, discrims = new_def_hash[ValueRef](), @@ -8066,8 +8032,7 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx, mutable n_glues_created = 0u, mutable n_null_glues = 0u, mutable n_real_glues = 0u), - upcalls = upcall::declare_upcalls(tn, llmod), - node_types = node_types); + upcalls = upcall::declare_upcalls(tn, llmod)); auto cx = new_local_ctxt(ccx); create_typedefs(ccx); diff --git a/src/comp/middle/tstate/auxiliary.rs b/src/comp/middle/tstate/auxiliary.rs index a2c6e2253f01..39e72c0edc71 100644 --- a/src/comp/middle/tstate/auxiliary.rs +++ b/src/comp/middle/tstate/auxiliary.rs @@ -167,7 +167,6 @@ type fn_ctxt = rec(fn_info enclosing, crate_ctxt ccx); type crate_ctxt = rec(ty::ctxt tcx, - ty::node_type_table node_types, node_ann_table node_anns, fn_info_map fm); @@ -370,9 +369,8 @@ fn num_locals(fn_info m) -> uint { ret m.vars.size(); } -fn new_crate_ctxt(ty::node_type_table nt, ty::ctxt cx) -> crate_ctxt { - ret rec(tcx=cx, node_types=nt, - node_anns=@new_uint_hash[ts_ann](), +fn new_crate_ctxt(ty::ctxt cx) -> crate_ctxt { + ret rec(tcx=cx, node_anns=@new_uint_hash[ts_ann](), fm=@new_def_hash[fn_info]()); } diff --git a/src/comp/middle/tstate/ck.rs b/src/comp/middle/tstate/ck.rs index 24af4c1f9482..bfd19bbf2135 100644 --- a/src/comp/middle/tstate/ck.rs +++ b/src/comp/middle/tstate/ck.rs @@ -128,7 +128,7 @@ fn check_states_against_conditions(&fn_ctxt fcx, &_fn f, &ann a) -> () { if (f.proto == ast::proto_fn && ! promises(*post, fcx.id, enclosing) && ! type_is_nil(fcx.ccx.tcx, - ret_ty_of_fn(fcx.ccx.node_types, fcx.ccx.tcx, a)) ) { + ret_ty_of_fn(fcx.ccx.tcx, a)) ) { /* FIXME: call span_err, not span_warn, once I finish implementing ! annotations */ fcx.ccx.tcx.sess.span_warn(f.body.span, "In function " + fcx.name + @@ -159,8 +159,8 @@ fn fn_states(&crate_ctxt ccx, &_fn f, &ident i, &def_id id, &ann a) -> () { check_fn_states(fcx, f, a); } -fn check_crate(ty::node_type_table nt, ty::ctxt cx, @crate crate) -> () { - let crate_ctxt ccx = new_crate_ctxt(nt, cx); +fn check_crate(ty::ctxt cx, @crate crate) -> () { + let crate_ctxt ccx = new_crate_ctxt(cx); /* Build the global map from function id to var-to-bit-num-map */ mk_f_to_fn_info(ccx, crate); diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index 094af6d910ff..155b29f1b2ad 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -58,13 +58,15 @@ type creader_cache = hashmap[tup(int,uint,uint),ty::t]; type ctxt = rec(@type_store ts, session::session sess, resolve::def_map def_map, + node_type_table node_types, + type_cache tcache, creader_cache rcache, hashmap[t,str] short_names_cache); type ty_ctxt = ctxt; // Needed for disambiguation from unify::ctxt. // Convert from method type to function type. Pretty easy; we just drop // 'ident'. -fn method_ty_to_fn_ty(ctxt cx, method m) -> t { +fn method_ty_to_fn_ty(&ctxt cx, method m) -> t { ret mk_fn(cx, m.proto, m.inputs, m.output); } @@ -215,9 +217,19 @@ fn mk_rcache() -> creader_cache { } fn mk_ctxt(session::session s, resolve::def_map dm) -> ctxt { + + let vec[mutable option::t[ty::ty_param_substs_opt_and_ty]] ntt_sub = + [mutable]; + let node_type_table ntt = @mutable ntt_sub; + + auto tcache = + common::new_def_hash[ty::ty_param_count_and_ty](); + ret rec(ts = mk_type_store(), sess = s, def_map = dm, + node_types = ntt, + tcache = tcache, rcache = mk_rcache(), short_names_cache = map::mk_hashmap[ty::t,str](ty::hash_ty, ty::eq_ty)); @@ -489,9 +501,9 @@ fn path_to_str(&ast::path pth) -> str { ret result; } -fn ty_to_str(ctxt cx, &t typ) -> str { +fn ty_to_str(&ctxt cx, &t typ) -> str { - fn fn_input_to_str(ctxt cx, &rec(mode mode, t ty) input) -> str { + fn fn_input_to_str(&ctxt cx, &rec(mode mode, t ty) input) -> str { auto s; alt (input.mode) { case (mo_val) { s = ""; } @@ -502,7 +514,7 @@ fn ty_to_str(ctxt cx, &t typ) -> str { ret s + ty_to_str(cx, input.ty); } - fn fn_to_str(ctxt cx, + fn fn_to_str(&ctxt cx, ast::proto proto, option::t[ast::ident] ident, vec[arg] inputs, t output) -> str { @@ -536,16 +548,16 @@ fn ty_to_str(ctxt cx, &t typ) -> str { ret s; } - fn method_to_str(ctxt cx, &method m) -> str { + fn method_to_str(&ctxt cx, &method m) -> str { ret fn_to_str(cx, m.proto, some[ast::ident](m.ident), m.inputs, m.output) + ";"; } - fn field_to_str(ctxt cx, &field f) -> str { + fn field_to_str(&ctxt cx, &field f) -> str { ret mt_to_str(cx, f.mt) + " " + f.ident; } - fn mt_to_str(ctxt cx, &mt m) -> str { + fn mt_to_str(&ctxt cx, &mt m) -> str { auto mstr; alt (m.mut) { case (ast::mut) { mstr = "mutable "; } @@ -648,7 +660,7 @@ fn ty_to_str(ctxt cx, &t typ) -> str { ret s; } -fn ty_to_short_str(ctxt cx, t typ) -> str { +fn ty_to_short_str(&ctxt cx, t typ) -> str { auto f = def_to_str; auto ecx = @rec(ds=f, tcx=cx, abbrevs=metadata::ac_no_abbrevs); auto s = metadata::Encode::ty_str(ecx, typ); @@ -660,7 +672,7 @@ fn ty_to_short_str(ctxt cx, t typ) -> str { type ty_walk = fn(t); -fn walk_ty(ctxt cx, ty_walk walker, t ty) { +fn walk_ty(&ctxt cx, ty_walk walker, t ty) { alt (struct(cx, ty)) { case (ty_nil) { /* no-op */ } case (ty_bot) { /* no-op */ } @@ -724,7 +736,7 @@ fn walk_ty(ctxt cx, ty_walk walker, t ty) { type ty_fold = fn(t) -> t; -fn fold_ty(ctxt cx, ty_fold fld, t ty_0) -> t { +fn fold_ty(&ctxt cx, ty_fold fld, t ty_0) -> t { auto ty = ty_0; alt (struct(cx, ty)) { case (ty_nil) { /* no-op */ } @@ -819,13 +831,13 @@ fn fold_ty(ctxt cx, ty_fold fld, t ty_0) -> t { // Type utilities -fn rename(ctxt cx, t typ, str new_cname) -> t { +fn rename(&ctxt cx, t typ, str new_cname) -> t { ret gen_ty_full(cx, struct(cx, typ), some[str](new_cname)); } // Returns a type with the structural part taken from `struct_ty` and the // canonical name from `cname_ty`. -fn copy_cname(ctxt cx, t struct_ty, t cname_ty) -> t { +fn copy_cname(&ctxt cx, t struct_ty, t cname_ty) -> t { ret gen_ty_full(cx, struct(cx, struct_ty), cname(cx, cname_ty)); } @@ -1484,8 +1496,8 @@ fn ann_has_type_params(&node_type_table ntt, &ast::ann ann) -> bool { // Returns the type of an annotation, with type parameter substitutions // performed if applicable. -fn ann_to_monotype(ctxt cx, &node_type_table ntt, ast::ann a) -> t { - auto tpot = ann_to_ty_param_substs_opt_and_ty(ntt, a); +fn ann_to_monotype(&ctxt cx, ast::ann a) -> t { + auto tpot = ann_to_ty_param_substs_opt_and_ty(cx.node_types, a); alt (tpot._0) { case (none[vec[t]]) { ret tpot._1; } case (some[vec[t]](?tps)) { @@ -1518,8 +1530,8 @@ fn bot_ann(uint node_id, ctxt tcx) -> ast::ann { // Returns the number of distinct type parameters in the given type. -fn count_ty_params(ctxt cx, t ty) -> uint { - fn counter(ctxt cx, @mutable vec[uint] param_indices, t ty) { +fn count_ty_params(&ctxt cx, t ty) -> uint { + fn counter(&ctxt cx, @mutable vec[uint] param_indices, t ty) { alt (struct(cx, ty)) { case (ty_param(?param_idx)) { auto seen = false; @@ -1650,10 +1662,10 @@ fn item_ty(&node_type_table ntt, &@ast::item it) -> ty_param_count_and_ty { ret tup(ty_param_count, result_ty); } -fn stmt_ty(&ctxt cx, &node_type_table ntt, &@ast::stmt s) -> t { +fn stmt_ty(&ctxt cx, &@ast::stmt s) -> t { alt (s.node) { case (ast::stmt_expr(?e,_)) { - ret expr_ty(cx, ntt, e); + ret expr_ty(cx, e); } case (_) { ret mk_nil(cx); @@ -1661,17 +1673,17 @@ fn stmt_ty(&ctxt cx, &node_type_table ntt, &@ast::stmt s) -> t { } } -fn block_ty(&ctxt cx, &node_type_table ntt, &ast::block b) -> t { +fn block_ty(&ctxt cx, &ast::block b) -> t { alt (b.node.expr) { - case (some[@ast::expr](?e)) { ret expr_ty(cx, ntt, e); } + case (some[@ast::expr](?e)) { ret expr_ty(cx, e); } case (none[@ast::expr]) { ret mk_nil(cx); } } } // 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, &node_type_table ntt, &@ast::pat pat) -> t { - ret ann_to_monotype(cx, ntt, pat_ann(pat)); +fn pat_ty(&ctxt cx, &@ast::pat pat) -> t { + ret ann_to_monotype(cx, pat_ann(pat)); } fn item_ann(&@ast::item it) -> ast::ann { @@ -1743,15 +1755,16 @@ fn expr_ann(&@ast::expr e) -> ast::ann { // ask for the type of "id" in "id(3)", it will return "fn(&int) -> int" // 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, &node_type_table ntt, &@ast::expr expr) -> t { - ret ann_to_monotype(cx, ntt, expr_ann(expr)); +fn expr_ty(&ctxt cx, &@ast::expr expr) -> t { + ret ann_to_monotype(cx, expr_ann(expr)); } -fn expr_ty_params_and_ty(&ctxt cx, &node_type_table ntt, &@ast::expr 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(ntt, a), ann_to_type(ntt, a)); + ret tup(ann_to_type_params(cx.node_types, a), + ann_to_type(cx.node_types, a)); } fn expr_has_ty_params(&node_type_table ntt, &@ast::expr expr) -> bool { @@ -2644,7 +2657,7 @@ fn substitute_type_params(&ctxt cx, &vec[t] bindings, &t typ) -> t { if (!type_contains_bound_params(cx, typ)) { ret typ; } - fn replacer(ctxt cx, vec[t] bindings, t typ) -> t { + fn replacer(&ctxt cx, vec[t] bindings, t typ) -> t { alt (struct(cx, typ)) { case (ty_bound_param(?param_index)) { ret bindings.(param_index); @@ -2662,7 +2675,7 @@ fn bind_params_in_type(&ctxt cx, &t typ) -> t { if (!type_contains_params(cx, typ)) { ret typ; } - fn binder(ctxt cx, t typ) -> t { + fn binder(&ctxt cx, t typ) -> t { alt (struct(cx, typ)) { case (ty_bound_param(?index)) { log_err "bind_params_in_type() called on type that already " + @@ -2701,20 +2714,18 @@ fn def_has_ty_params(&ast::def def) -> bool { // If the given item is in an external crate, looks up its type and adds it to // the type cache. Returns the type parameters and type. fn lookup_item_type(session::session sess, - ctxt cx, - &type_cache cache, - ast::def_id did) -> ty_param_count_and_ty { + ctxt cx, ast::def_id did) -> ty_param_count_and_ty { if (did._0 == sess.get_targ_crate_num()) { // The item is in this crate. The caller should have added it to the // type cache already; we simply return it. - ret cache.get(did); + ret cx.tcache.get(did); } - alt (cache.find(did)) { + alt (cx.tcache.find(did)) { case (some[ty_param_count_and_ty](?tpt)) { ret tpt; } case (none[ty_param_count_and_ty]) { auto tyt = creader::get_type(sess, cx, did); - cache.insert(did, tyt); + cx.tcache.insert(did, tyt); ret tyt; } } @@ -2731,8 +2742,8 @@ fn ret_ty_of_fn_ty(ty_ctxt tcx, t a_ty) -> t { } } -fn ret_ty_of_fn(node_type_table ntt, ty_ctxt tcx, ast::ann ann) -> t { - ret ret_ty_of_fn_ty(tcx, ann_to_type(ntt, ann)); +fn ret_ty_of_fn(ty_ctxt tcx, ast::ann ann) -> t { + ret ret_ty_of_fn_ty(tcx, ann_to_type(tcx.node_types, ann)); } // Local Variables: diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index e8dbe2ac10c2..28f95e7c15d6 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -66,15 +66,13 @@ type unify_cache = hashmap[unify_cache_entry,ty::unify::result]; type obj_info = rec(vec[ast::obj_field] obj_fields, ast::def_id this_obj); type crate_ctxt = rec(session::session sess, - ty::type_cache type_cache, @ty_item_table item_items, mutable vec[obj_info] obj_infos, @fn_purity_table fn_purity_table, unify_cache unify_cache, mutable uint cache_hits, mutable uint cache_misses, - ty::ctxt tcx, - node_type_table node_types); + ty::ctxt tcx); type fn_ctxt = rec(ty::t ret_ty, ast::purity purity, @@ -151,28 +149,23 @@ fn ty_param_count_and_ty_for_def(&@fn_ctxt fcx, &ast::span sp, &ast::def defn) ret tup(0u, fcx.locals.get(id)); } case (ast::def_fn(?id)) { - ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx, - fcx.ccx.type_cache, id); + ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx, id); } case (ast::def_native_fn(?id)) { - ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx, - fcx.ccx.type_cache, id); + ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx, id); } case (ast::def_const(?id)) { - ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx, - fcx.ccx.type_cache, id); + ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx, id); } case (ast::def_variant(_, ?vid)) { - ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx, - fcx.ccx.type_cache, vid); + ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx, vid); } case (ast::def_binding(?id)) { // assert (fcx.locals.contains_key(id)); ret tup(0u, fcx.locals.get(id)); } case (ast::def_obj(?id)) { - ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx, - fcx.ccx.type_cache, id); + ret ty::lookup_item_type(fcx.ccx.sess, fcx.ccx.tcx, id); } case (ast::def_mod(_)) { @@ -385,7 +378,7 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t { // ast_ty_to_ty. fn ast_ty_to_ty_crate(@crate_ctxt ccx, &@ast::ty ast_ty) -> ty::t { fn getter(@crate_ctxt ccx, &ast::def_id id) -> ty::ty_param_count_and_ty { - ret ty::lookup_item_type(ccx.sess, ccx.tcx, ccx.type_cache, id); + ret ty::lookup_item_type(ccx.sess, ccx.tcx, id); } auto f = bind getter(ccx, _); ret ast_ty_to_ty(ccx.tcx, f, ast_ty); @@ -405,10 +398,10 @@ mod write { } // Writes a type parameter count and type pair into the node type table. - fn ty(&ty::ctxt tcx, &node_type_table ntt, uint node_id, + fn ty(&ty::ctxt tcx, uint node_id, &ty_param_substs_opt_and_ty tpot) { assert (!ty::type_contains_vars(tcx, tpot._1)); - be inner(ntt, node_id, tpot); + be inner(tcx.node_types, node_id, tpot); } // Writes a type parameter count and type pair into the node type table. @@ -416,15 +409,15 @@ mod write { // be rewritten later during the fixup phase. fn ty_fixup(&@stmt_ctxt scx, uint node_id, &ty_param_substs_opt_and_ty tpot) { - inner(scx.fcx.ccx.node_types, node_id, tpot); + inner(scx.fcx.ccx.tcx.node_types, node_id, tpot); if (ty::type_contains_vars(scx.fcx.ccx.tcx, tpot._1)) { scx.fixups += [node_id]; } } // Writes a type with no type parameters into the node type table. - fn ty_only(&ty::ctxt tcx, &node_type_table ntt, uint node_id, ty::t typ) { - be ty(tcx, ntt, node_id, tup(none[vec[ty::t]], typ)); + fn ty_only(&ty::ctxt tcx, uint node_id, ty::t typ) { + be ty(tcx, node_id, tup(none[vec[ty::t]], typ)); } // Writes a type with no type parameters into the node type table. This @@ -434,14 +427,14 @@ mod write { } // Writes a nil type into the node type table. - fn nil_ty(&ty::ctxt tcx, &node_type_table ntt, uint node_id) { - be ty(tcx, ntt, node_id, tup(none[vec[ty::t]], ty::mk_nil(tcx))); + fn nil_ty(&ty::ctxt tcx, uint node_id) { + be 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, &node_type_table ntt, uint node_id) { + fn bot_ty(&ty::ctxt tcx, uint node_id) { // FIXME: Should be mk_bot(), but this breaks lots of stuff. - be ty(tcx, ntt, node_id, tup(none[vec[ty::t]], ty::mk_nil(tcx))); + be ty(tcx, node_id, tup(none[vec[ty::t]], ty::mk_nil(tcx))); } } @@ -464,9 +457,7 @@ mod write { mod collect { type ctxt = rec(session::session sess, @ty_item_table id_to_ty_item, - ty::type_cache type_cache, - ty::ctxt tcx, - node_type_table node_types); + ty::ctxt tcx); type env = rec(@ctxt cx, ast::native_abi abi); fn ty_of_fn_decl(&@ctxt cx, @@ -481,7 +472,7 @@ mod collect { auto t_fn = ty::mk_fn(cx.tcx, proto, input_tys, output_ty); auto ty_param_count = vec::len[ast::ty_param](ty_params); auto tpt = tup(ty_param_count, t_fn); - cx.type_cache.insert(def_id, tpt); + cx.tcx.tcache.insert(def_id, tpt); ret tpt; } @@ -497,7 +488,7 @@ mod collect { auto t_fn = ty::mk_native_fn(cx.tcx, abi, input_tys, output_ty); auto ty_param_count = vec::len[ast::ty_param](ty_params); auto tpt = tup(ty_param_count, t_fn); - cx.type_cache.insert(def_id, tpt); + cx.tcx.tcache.insert(def_id, tpt); ret tpt; } @@ -565,7 +556,7 @@ mod collect { auto t_fn = ty::mk_fn(cx.tcx, ast::proto_fn, t_inputs, t_obj._1); auto tpt = tup(t_obj._0, t_fn); - cx.type_cache.insert(ctor_id, tpt); + cx.tcx.tcache.insert(ctor_id, tpt); ret tpt; } @@ -579,7 +570,7 @@ mod collect { case (ast::item_const(?ident, ?t, _, ?def_id, _)) { auto typ = convert(t); auto tpt = tup(0u, typ); - cx.type_cache.insert(def_id, tpt); + cx.tcx.tcache.insert(def_id, tpt); ret tpt; } @@ -591,12 +582,12 @@ mod collect { case (ast::item_obj(?ident, ?obj_info, ?tps, ?odid, _)) { auto t_obj = ty_of_obj(cx, ident, obj_info, tps); - cx.type_cache.insert(odid.ty, t_obj); + cx.tcx.tcache.insert(odid.ty, t_obj); ret t_obj; } case (ast::item_ty(?ident, ?t, ?tps, ?def_id, _)) { - alt (cx.type_cache.find(def_id)) { + alt (cx.tcx.tcache.find(def_id)) { case (some[ty::ty_param_count_and_ty](?tpt)) { ret tpt; } @@ -608,7 +599,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.type_cache.insert(def_id, tpt); + cx.tcx.tcache.insert(def_id, tpt); ret tpt; } @@ -626,7 +617,7 @@ mod collect { auto ty_param_count = vec::len[ast::ty_param](tps); auto tpt = tup(ty_param_count, t); - cx.type_cache.insert(def_id, tpt); + cx.tcx.tcache.insert(def_id, tpt); ret tpt; } @@ -647,7 +638,7 @@ mod collect { def_id); } case (ast::native_item_ty(_, ?def_id)) { - alt (cx.type_cache.find(def_id)) { + alt (cx.tcx.tcache.find(def_id)) { case (some[ty::ty_param_count_and_ty](?tpt)) { ret tpt; } @@ -656,7 +647,7 @@ mod collect { auto t = ty::mk_native(cx.tcx); auto tpt = tup(0u, t); - cx.type_cache.insert(def_id, tpt); + cx.tcx.tcache.insert(def_id, tpt); ret tpt; } } @@ -699,13 +690,12 @@ mod collect { } auto tpt = tup(ty_param_count, result_ty); - cx.type_cache.insert(variant.node.id, tpt); + cx.tcx.tcache.insert(variant.node.id, tpt); auto variant_t = rec( ann=triv_ann(variant.node.ann.id, result_ty) with variant.node ); - write::ty_only(cx.tcx, cx.node_types, variant.node.ann.id, - result_ty); + write::ty_only(cx.tcx, variant.node.ann.id, result_ty); result += [fold::respan(variant.span, variant_t)]; } @@ -756,7 +746,7 @@ mod collect { } case (ast::item_tag(_, ?variants, ?ty_params, ?tag_id, ?ann)) { auto tpt = ty_of_item(cx, it); - write::ty_only(cx.tcx, cx.node_types, ann.id, tpt._1); + write::ty_only(cx.tcx, ann.id, tpt._1); get_tag_variant_types(cx, tag_id, variants, ty_params); } @@ -768,7 +758,7 @@ mod collect { // we write into the table for this item. auto tpt = ty_of_obj_ctor(cx, ident, object, odid.ctor, ty_params); - write::ty_only(cx.tcx, cx.node_types, ann.id, tpt._1); + write::ty_only(cx.tcx, ann.id, tpt._1); // Write the methods into the type table. // @@ -778,8 +768,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, cx.node_types, - object.methods.(i).node.ann.id, + write::ty_only(cx.tcx, object.methods.(i).node.ann.id, ty::method_ty_to_fn_ty(cx.tcx, method_types.(i))); i += 1u; @@ -793,8 +782,7 @@ mod collect { i = 0u; while (i < vec::len[ty::arg](args)) { auto fld = object.fields.(i); - write::ty_only(cx.tcx, cx.node_types, fld.ann.id, - args.(i).ty); + write::ty_only(cx.tcx, fld.ann.id, args.(i).ty); i += 1u; } @@ -806,8 +794,7 @@ mod collect { let vec[arg] no_args = []; auto t = ty::mk_fn(cx.tcx, ast::proto_fn, no_args, ty::mk_nil(cx.tcx)); - write::ty_only(cx.tcx, cx.node_types, m.node.ann.id, - t); + write::ty_only(cx.tcx, m.node.ann.id, t); } } } @@ -816,8 +803,7 @@ mod collect { // of the item in passing. All we have to do here is to write // it into the node type table. auto tpt = ty_of_item(cx, it); - write::ty_only(cx.tcx, cx.node_types, ty::item_ann(it).id, - tpt._1); + write::ty_only(cx.tcx, ty::item_ann(it).id, tpt._1); } } } @@ -835,22 +821,17 @@ mod collect { // FIXME: Native types have no annotation. Should they? --pcw } case (ast::native_item_fn(_,_,_,_,_,?a)) { - write::ty_only(cx.tcx, cx.node_types, a.id, tpt._1); + write::ty_only(cx.tcx, a.id, tpt._1); } } } fn collect_item_types(&session::session sess, &ty::ctxt tcx, - &@ast::crate crate) - -> tup(ty::type_cache, @ty_item_table, node_type_table) { + &@ast::crate crate) -> @ty_item_table { // First pass: collect all type item IDs. auto module = crate.node.module; auto id_to_ty_item = @common::new_def_hash[any_item](); - let vec[mutable option::t[ty::ty_param_substs_opt_and_ty]] ntt_sub = - [mutable]; - let node_type_table ntt = @mutable ntt_sub; - auto visit = rec( visit_item_pre = bind collect(id_to_ty_item, _), visit_native_item_pre = bind collect_native(id_to_ty_item, _) @@ -858,18 +839,13 @@ mod collect { ); walk::walk_crate(visit, *crate); - // Second pass: translate the types of all items. - auto type_cache = common::new_def_hash[ty::ty_param_count_and_ty](); - // 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(sess=sess, id_to_ty_item=id_to_ty_item, - type_cache=type_cache, - tcx=tcx, - node_types=ntt); + tcx=tcx); visit = rec( visit_item_pre = bind convert(cx,abi,_), @@ -878,7 +854,7 @@ mod collect { ); walk::walk_crate(visit, *crate); - ret tup(type_cache, id_to_ty_item, ntt); + ret id_to_ty_item; } } @@ -1113,7 +1089,7 @@ fn variant_arg_types(&@crate_ctxt ccx, &span sp, &ast::def_id vid, let vec[ty::t] result = []; - auto tpt = ty::lookup_item_type(ccx.sess, ccx.tcx, ccx.type_cache, vid); + auto tpt = ty::lookup_item_type(ccx.sess, ccx.tcx, vid); alt (struct(ccx.tcx, tpt._1)) { case (ty::ty_fn(_, ?ins, _)) { // N-ary variant. @@ -1160,17 +1136,17 @@ mod Pushdown { alt (pat.node) { case (ast::pat_wild(?ann)) { auto t = Demand::simple(scx, pat.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); write::ty_only_fixup(scx, ann.id, t); } case (ast::pat_lit(?lit, ?ann)) { auto t = Demand::simple(scx, pat.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); write::ty_only_fixup(scx, ann.id, t); } case (ast::pat_bind(?id, ?did, ?ann)) { auto t = Demand::simple(scx, pat.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); scx.fcx.locals.insert(did, t); write::ty_only_fixup(scx, ann.id, t); } @@ -1187,18 +1163,18 @@ mod Pushdown { } // Get the types of the arguments of the variant. - + let vec[ty::t] tparams = []; auto j = 0u; auto actual_ty_params = - ty::ann_to_type_params(scx.fcx.ccx.node_types, ann); + ty::ann_to_type_params(scx.fcx.ccx.tcx.node_types, ann); for (ty::t some_ty in tag_tps) { let ty::t t1 = some_ty; let ty::t t2 = actual_ty_params.(j); - + let ty::t res = Demand::simple(scx, pat.span, t1, t2); - + vec::push(tparams, res); j += 1u; } @@ -1218,9 +1194,9 @@ mod Pushdown { } auto tps = - ty::ann_to_type_params(scx.fcx.ccx.node_types, ann); - auto tt = ann_to_type(scx.fcx.ccx.node_types, ann); - + ty::ann_to_type_params(scx.fcx.ccx.tcx.node_types, ann); + auto tt = ann_to_type(scx.fcx.ccx.tcx.node_types, ann); + let ty_param_substs_and_ty res_t = Demand::full(scx, pat.span, expected, tt, tps, NO_AUTODEREF); @@ -1230,7 +1206,7 @@ mod Pushdown { // TODO: push down type from "expected". write::ty_fixup(scx, ann.id, ty::ann_to_ty_param_substs_opt_and_ty - (scx.fcx.ccx.node_types, a_1)); + (scx.fcx.ccx.tcx.node_types, a_1)); } } } @@ -1252,7 +1228,7 @@ mod Pushdown { // TODO: enforce mutability auto t = Demand::simple(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); alt (struct(scx.fcx.ccx.tcx, t)) { case (ty::ty_vec(?mt)) { for (@ast::expr e_0 in es_0) { @@ -1268,7 +1244,7 @@ mod Pushdown { } case (ast::expr_tup(?es_0, ?ann)) { auto t = Demand::simple(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); alt (struct(scx.fcx.ccx.tcx, t)) { case (ty::ty_tup(?mts)) { auto i = 0u; @@ -1287,7 +1263,7 @@ mod Pushdown { case (ast::expr_rec(?fields_0, ?base_0, ?ann)) { auto t = Demand::simple(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); alt (struct(scx.fcx.ccx.tcx, t)) { case (ty::ty_rec(?field_mts)) { alt (base_0) { @@ -1328,7 +1304,7 @@ mod Pushdown { } case (ast::expr_bind(?sube, ?es, ?ann)) { auto t = Demand::simple(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_call(?sube, ?es, ?ann)) { @@ -1337,39 +1313,39 @@ mod Pushdown { // produce a box; things like expr_binary or expr_bind can't, // so there's no need. auto t = Demand::autoderef(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann), adk); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann), adk); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_self_method(?id, ?ann)) { auto t = Demand::simple(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_binary(?bop, ?lhs, ?rhs, ?ann)) { auto t = Demand::simple(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_unary(?uop, ?sube, ?ann)) { // See note in expr_unary for why we're calling // Demand::autoderef. auto t = Demand::autoderef(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann), adk); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann), adk); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_lit(?lit, ?ann)) { auto t = Demand::simple(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_cast(?sube, ?ast_ty, ?ann)) { auto t = Demand::simple(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_if(?cond, ?then_0, ?else_0, ?ann)) { auto t = Demand::autoderef(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann), adk); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann), adk); pushdown_block(scx, expected, then_0); alt (else_0) { @@ -1382,57 +1358,57 @@ mod Pushdown { } case (ast::expr_for(?decl, ?seq, ?bloc, ?ann)) { auto t = Demand::simple(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_for_each(?decl, ?seq, ?bloc, ?ann)) { auto t = Demand::simple(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_while(?cond, ?bloc, ?ann)) { auto t = Demand::simple(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_do_while(?bloc, ?cond, ?ann)) { auto t = Demand::simple(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_block(?bloc, ?ann)) { auto t = Demand::autoderef(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann), adk); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann), adk); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_assign(?lhs_0, ?rhs_0, ?ann)) { auto t = Demand::autoderef(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann), adk); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann), adk); pushdown_expr(scx, expected, lhs_0); pushdown_expr(scx, expected, rhs_0); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_assign_op(?op, ?lhs_0, ?rhs_0, ?ann)) { auto t = Demand::autoderef(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann), adk); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann), adk); pushdown_expr(scx, expected, lhs_0); pushdown_expr(scx, expected, rhs_0); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_field(?lhs, ?rhs, ?ann)) { auto t = Demand::autoderef(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann), adk); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann), adk); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_index(?base, ?index, ?ann)) { auto t = Demand::autoderef(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann), adk); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann), adk); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_path(?pth, ?ann)) { auto tp_substs_0 = - ty::ann_to_type_params(scx.fcx.ccx.node_types, ann); - auto t_0 = ann_to_type(scx.fcx.ccx.node_types, ann); + ty::ann_to_type_params(scx.fcx.ccx.tcx.node_types, ann); + auto t_0 = ann_to_type(scx.fcx.ccx.tcx.node_types, ann); auto result_0 = Demand::full(scx, e.span, expected, t_0, tp_substs_0, adk); @@ -1442,7 +1418,7 @@ mod Pushdown { // provided by the programmer. auto ty_params_opt; alt (ty::ann_to_ty_param_substs_opt_and_ty - (scx.fcx.ccx.node_types, ann)._0) { + (scx.fcx.ccx.tcx.node_types, ann)._0) { case (none[vec[ty::t]]) { ty_params_opt = none[vec[ty::t]]; } @@ -1455,7 +1431,7 @@ mod Pushdown { } case (ast::expr_ext(?p, ?args, ?body, ?expanded, ?ann)) { auto t = Demand::autoderef(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann), adk); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann), adk); write::ty_only_fixup(scx, ann.id, t); } /* FIXME: should this check the type annotations? */ @@ -1471,13 +1447,13 @@ mod Pushdown { case (ast::expr_port(?ann)) { auto t = Demand::simple(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_chan(?es, ?ann)) { auto t = Demand::simple(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann)); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann)); alt (struct(scx.fcx.ccx.tcx, t)) { case (ty::ty_chan(?subty)) { auto pt = ty::mk_port(scx.fcx.ccx.tcx, subty); @@ -1495,9 +1471,7 @@ mod Pushdown { auto t = expected; for (ast::arm arm_0 in arms_0) { pushdown_block(scx, expected, arm_0.block); - auto bty = block_ty(scx.fcx.ccx.tcx, - scx.fcx.ccx.node_types, - arm_0.block); + auto bty = block_ty(scx.fcx.ccx.tcx, arm_0.block); t = Demand::simple(scx, e.span, t, bty); } write::ty_only_fixup(scx, ann.id, t); @@ -1505,15 +1479,13 @@ mod Pushdown { case (ast::expr_recv(?lval, ?expr, ?ann)) { pushdown_expr(scx, next_ty_var(scx), lval); - auto t = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - lval); + auto t = expr_ty(scx.fcx.ccx.tcx, lval); write::ty_only_fixup(scx, ann.id, t); } case (ast::expr_send(?lval, ?expr, ?ann)) { pushdown_expr(scx, next_ty_var(scx), expr); - auto t = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - expr); + auto t = expr_ty(scx.fcx.ccx.tcx, expr); pushdown_expr(scx, ty::mk_chan(scx.fcx.ccx.tcx, t), lval); } @@ -1523,7 +1495,7 @@ mod Pushdown { // produce a box; things like expr_binary or expr_bind can't, // so there's no need. auto t = Demand::autoderef(scx, e.span, expected, - ann_to_type(scx.fcx.ccx.node_types, ann), adk); + ann_to_type(scx.fcx.ccx.tcx.node_types, ann), adk); write::ty_only_fixup(scx, ann.id, t); } @@ -1541,14 +1513,12 @@ mod Pushdown { alt (bloc.node.expr) { case (some[@ast::expr](?e_0)) { pushdown_expr(scx, expected, e_0); - write::nil_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - bloc.node.a.id); + write::nil_ty(scx.fcx.ccx.tcx, bloc.node.a.id); } case (none[@ast::expr]) { Demand::simple(scx, bloc.span, expected, ty::mk_nil(scx.fcx.ccx.tcx)); - write::nil_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - bloc.node.a.id); + write::nil_ty(scx.fcx.ccx.tcx, bloc.node.a.id); } } } @@ -1572,8 +1542,7 @@ mod writeback { } } - write::ty_only(fcx.ccx.tcx, fcx.ccx.node_types, local.ann.id, - local_ty); + write::ty_only(fcx.ccx.tcx, local.ann.id, local_ty); } fn resolve_local_types(&@fn_ctxt fcx, &ast::ann ann) { @@ -1584,15 +1553,15 @@ mod writeback { } } - auto tpot = ty::ann_to_ty_param_substs_opt_and_ty(fcx.ccx.node_types, - ann); + auto tpot = + ty::ann_to_ty_param_substs_opt_and_ty(fcx.ccx.tcx.node_types, + ann); auto tt = tpot._1; if (!ty::type_contains_locals(fcx.ccx.tcx, tt)) { ret; } auto f = bind resolver(fcx, _); auto new_type = ty::fold_ty(fcx.ccx.tcx, f, tt); - write::ty(fcx.ccx.tcx, fcx.ccx.node_types, ann.id, - tup(tpot._0, new_type)); + write::ty(fcx.ccx.tcx, ann.id, tup(tpot._0, new_type)); } fn visit_stmt_pre(@fn_ctxt fcx, &@ast::stmt s) { @@ -1651,7 +1620,7 @@ fn replace_expr_type(&@stmt_ctxt scx, &@ast::expr expr, &tup(vec[ty::t], ty::t) new_tyt) { auto new_tps; - if (ty::expr_has_ty_params(scx.fcx.ccx.node_types, expr)) { + if (ty::expr_has_ty_params(scx.fcx.ccx.tcx.node_types, expr)) { new_tps = some[vec[ty::t]](new_tyt._0); } else { new_tps = none[vec[ty::t]]; @@ -1698,12 +1667,12 @@ fn check_pat(&@stmt_ctxt scx, &@ast::pat pat) { auto vdef = ast::variant_def_ids (scx.fcx.ccx.tcx.def_map.get(old_ann.id)); auto t = ty::lookup_item_type(scx.fcx.ccx.sess, scx.fcx.ccx.tcx, - scx.fcx.ccx.type_cache, vdef._1)._1; + vdef._1)._1; auto len = vec::len[ast::ident](p.node.idents); auto last_id = p.node.idents.(len - 1u); auto tpt = ty::lookup_item_type(scx.fcx.ccx.sess, scx.fcx.ccx.tcx, - scx.fcx.ccx.type_cache, vdef._0); + vdef._0); auto path_tpot = instantiate_path(scx, p, tpt, pat.span); @@ -1833,8 +1802,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { alt (a_opt) { case (some[@ast::expr](?a)) { check_expr(scx, a); - auto typ = expr_ty(scx.fcx.ccx.tcx, - scx.fcx.ccx.node_types, a); + auto typ = expr_ty(scx.fcx.ccx.tcx, a); vec::push[arg](arg_tys_0, rec(mode=mo_either, ty=typ)); } case (none[@ast::expr]) { @@ -1846,8 +1814,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { auto rt_0 = next_ty_var(scx); auto t_0; - alt (struct(scx.fcx.ccx.tcx, - expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, f))) { + alt (struct(scx.fcx.ccx.tcx, expr_ty(scx.fcx.ccx.tcx, f))) { case (ty::ty_fn(?proto, _, _)) { t_0 = ty::mk_fn(scx.fcx.ccx.tcx, proto, arg_tys_0, rt_0); } @@ -1859,15 +1826,13 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { "check_call_or_bind(): fn expr doesn't have fn type," + " instead having: " + ty_to_str(scx.fcx.ccx.tcx, - expr_ty(scx.fcx.ccx.tcx, - scx.fcx.ccx.node_types, f))); + expr_ty(scx.fcx.ccx.tcx, f))); fail; } } // Unify the callee and arguments. - auto tpt_0 = ty::expr_ty_params_and_ty(scx.fcx.ccx.tcx, - scx.fcx.ccx.node_types, f); + auto tpt_0 = ty::expr_ty_params_and_ty(scx.fcx.ccx.tcx, f); auto tpt_1 = Demand::full(scx, f.span, tpt_0._1, t_0, tpt_0._0, NO_AUTODEREF); replace_expr_type(scx, f, tpt_1); @@ -1878,13 +1843,13 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { &ast::ann a) { check_expr(scx, lhs); check_expr(scx, rhs); - auto lhs_t0 = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, lhs); - auto rhs_t0 = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, rhs); + auto lhs_t0 = expr_ty(scx.fcx.ccx.tcx, lhs); + auto rhs_t0 = expr_ty(scx.fcx.ccx.tcx, rhs); Pushdown::pushdown_expr(scx, rhs_t0, lhs); - auto lhs_t1 = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, lhs); + auto lhs_t1 = expr_ty(scx.fcx.ccx.tcx, lhs); Pushdown::pushdown_expr(scx, lhs_t1, rhs); - auto rhs_t1 = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, rhs); + auto rhs_t1 = expr_ty(scx.fcx.ccx.tcx, rhs); auto ann = triv_ann(a.id, rhs_t1); write::ty_only_fixup(scx, a.id, rhs_t1); @@ -1910,15 +1875,12 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { case (ast::expr_binary(?binop, ?lhs, ?rhs, ?a)) { check_expr(scx, lhs); check_expr(scx, rhs); - auto lhs_t0 = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - lhs); - auto rhs_t0 = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - rhs); + auto lhs_t0 = expr_ty(scx.fcx.ccx.tcx, lhs); + auto rhs_t0 = expr_ty(scx.fcx.ccx.tcx, rhs); // FIXME: Binops have a bit more subtlety than this. Pushdown::pushdown_expr_full(scx, rhs_t0, lhs, AUTODEREF_OK); - auto lhs_t1 = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - lhs); + auto lhs_t1 = expr_ty(scx.fcx.ccx.tcx, lhs); Pushdown::pushdown_expr_full(scx, lhs_t1, rhs, AUTODEREF_OK); auto t = strip_boxes(scx.fcx.ccx.tcx, lhs_t0); @@ -1938,8 +1900,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { case (ast::expr_unary(?unop, ?oper, ?a)) { check_expr(scx, oper); - auto oper_t = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - oper); + auto oper_t = expr_ty(scx.fcx.ccx.tcx, oper); alt (unop) { case (ast::box(?mut)) { oper_t = ty::mk_box(scx.fcx.ccx.tcx, @@ -1988,21 +1949,20 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { case (ast::expr_ext(?p, ?args, ?body, ?expanded, ?a)) { check_expr(scx, expanded); - auto t = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - expanded); + auto t = expr_ty(scx.fcx.ccx.tcx, expanded); write::ty_only_fixup(scx, a.id, t); } case (ast::expr_fail(?a)) { - write::bot_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, a.id); + write::bot_ty(scx.fcx.ccx.tcx, a.id); } case (ast::expr_break(?a)) { - write::bot_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, a.id); + write::bot_ty(scx.fcx.ccx.tcx, a.id); } case (ast::expr_cont(?a)) { - write::bot_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, a.id); + write::bot_ty(scx.fcx.ccx.tcx, a.id); } case (ast::expr_ret(?expr_opt, ?a)) { @@ -2015,16 +1975,14 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { "returning non-nil"); } - write::bot_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - a.id); + write::bot_ty(scx.fcx.ccx.tcx, a.id); } case (some[@ast::expr](?e)) { check_expr(scx, e); Pushdown::pushdown_expr(scx, scx.fcx.ret_ty, e); - write::bot_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - a.id); + write::bot_ty(scx.fcx.ccx.tcx, a.id); } } } @@ -2041,16 +1999,14 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { "put; in iterator yielding non-nil"); } - write::nil_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - a.id); + write::nil_ty(scx.fcx.ccx.tcx, a.id); } case (some[@ast::expr](?e)) { check_expr(scx, e); Pushdown::pushdown_expr(scx, scx.fcx.ret_ty, e); - write::nil_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - a.id); + write::nil_ty(scx.fcx.ccx.tcx, a.id); } } } @@ -2062,18 +2018,18 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { check_expr(scx, e); Pushdown::pushdown_expr(scx, scx.fcx.ret_ty, e); - write::nil_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, a.id); + write::nil_ty(scx.fcx.ccx.tcx, a.id); } case (ast::expr_log(?l, ?e, ?a)) { auto expr_t = check_expr(scx, e); - write::nil_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, a.id); + write::nil_ty(scx.fcx.ccx.tcx, a.id); } case (ast::expr_check(?e, ?a)) { check_expr(scx, e); Demand::simple(scx, expr.span, ty::mk_bool(scx.fcx.ccx.tcx), - expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, e)); + expr_ty(scx.fcx.ccx.tcx, e)); /* e must be a call expr where all arguments are either literals or slots */ alt (e.node) { @@ -2095,8 +2051,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { require_pure_function(scx.fcx.ccx, d_id, expr.span); - write::nil_ty(scx.fcx.ccx.tcx, - scx.fcx.ccx.node_types, a.id); + write::nil_ty(scx.fcx.ccx.tcx, a.id); } case (_) { scx.fcx.ccx.sess.span_err(expr.span, @@ -2114,10 +2069,10 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { case (ast::expr_assert(?e, ?a)) { check_expr(scx, e); - auto ety = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, e); + auto ety = expr_ty(scx.fcx.ccx.tcx, e); Demand::simple(scx, expr.span, ty::mk_bool(scx.fcx.ccx.tcx), ety); - write::nil_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, a.id); + write::nil_ty(scx.fcx.ccx.tcx, a.id); } case (ast::expr_assign(?lhs, ?rhs, ?a)) { @@ -2135,14 +2090,12 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { check_expr(scx, lhs); check_expr(scx, rhs); - auto rhs_t = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - rhs); + auto rhs_t = expr_ty(scx.fcx.ccx.tcx, rhs); auto chan_t = ty::mk_chan(scx.fcx.ccx.tcx, rhs_t); Pushdown::pushdown_expr(scx, chan_t, lhs); auto item_t; - auto lhs_t = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - lhs); + auto lhs_t = expr_ty(scx.fcx.ccx.tcx, lhs); alt (struct(scx.fcx.ccx.tcx, lhs_t)) { case (ty::ty_chan(?it)) { item_t = it; } case (_) { fail; } @@ -2157,14 +2110,12 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { check_expr(scx, lhs); check_expr(scx, rhs); - auto lhs_t1 = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - lhs); + auto lhs_t1 = expr_ty(scx.fcx.ccx.tcx, lhs); auto port_t = ty::mk_port(scx.fcx.ccx.tcx, lhs_t1); Pushdown::pushdown_expr(scx, port_t, rhs); auto item_t; - auto rhs_t = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - rhs); + auto rhs_t = expr_ty(scx.fcx.ccx.tcx, rhs); alt (struct(scx.fcx.ccx.tcx, rhs_t)) { case (ty::ty_port(?it)) { item_t = it; } case (_) { fail; } @@ -2180,16 +2131,14 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { cond); check_block(scx, thn); - auto thn_t = block_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - thn); + auto thn_t = block_ty(scx.fcx.ccx.tcx, thn); auto elsopt_t; alt (elsopt) { case (some[@ast::expr](?els)) { check_expr(scx, els); Pushdown::pushdown_expr(scx, thn_t, els); - elsopt_t = expr_ty(scx.fcx.ccx.tcx, - scx.fcx.ccx.node_types, els); + elsopt_t = expr_ty(scx.fcx.ccx.tcx, els); } case (none[@ast::expr]) { elsopt_t = ty::mk_nil(scx.fcx.ccx.tcx); @@ -2236,8 +2185,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { Pushdown::pushdown_expr(scx, ty::mk_bool(scx.fcx.ccx.tcx), cond); check_block(scx, body); - auto typ = block_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - body); + auto typ = block_ty(scx.fcx.ccx.tcx, body); write::ty_only_fixup(scx, a.id, typ); } @@ -2246,14 +2194,13 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { // Typecheck the patterns first, so that we get types for all the // bindings. - auto pattern_ty = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - expr); + auto pattern_ty = expr_ty(scx.fcx.ccx.tcx, expr); let vec[@ast::pat] pats = []; for (ast::arm arm in arms) { check_pat(scx, arm.pat); pattern_ty = Demand::simple(scx, arm.pat.span, pattern_ty, - pat_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, arm.pat)); + pat_ty(scx.fcx.ccx.tcx, arm.pat)); pats += [arm.pat]; } @@ -2268,8 +2215,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { for (ast::arm arm in arms) { check_block(scx, arm.block); - auto bty = block_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - arm.block); + auto bty = block_ty(scx.fcx.ccx.tcx, arm.block); result_ty = Demand::simple(scx, arm.block.span, result_ty, bty); } @@ -2288,8 +2234,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { check_block(scx, b); alt (b.node.expr) { case (some[@ast::expr](?expr)) { - auto typ = expr_ty(scx.fcx.ccx.tcx, - scx.fcx.ccx.node_types, expr); + auto typ = expr_ty(scx.fcx.ccx.tcx, expr); write::ty_only_fixup(scx, a.id, typ); } case (none[@ast::expr]) { @@ -2307,7 +2252,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { auto proto_1; let vec[ty::arg] arg_tys_1 = []; auto rt_1; - auto fty = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, f); + auto fty = expr_ty(scx.fcx.ccx.tcx, f); alt (struct(scx.fcx.ccx.tcx, fty)) { case (ty::ty_fn(?proto, ?arg_tys, ?rt)) { proto_1 = proto; @@ -2347,7 +2292,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { // Pull the return type out of the type of the function. auto rt_1 = ty::mk_nil(scx.fcx.ccx.tcx); // FIXME: typestate botch - auto fty = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, f); + auto fty = expr_ty(scx.fcx.ccx.tcx, f); alt (struct(scx.fcx.ccx.tcx, fty)) { case (ty::ty_fn(_,_,?rt)) { rt_1 = rt; } case (ty::ty_native_fn(_, _, ?rt)) { rt_1 = rt; } @@ -2367,7 +2312,8 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { auto oinfo_opt = get_obj_info(scx.fcx.ccx); auto this_obj_id = option::get[obj_info](oinfo_opt).this_obj; this_obj_ty = ty::lookup_item_type(scx.fcx.ccx.sess, - scx.fcx.ccx.tcx, scx.fcx.ccx.type_cache, this_obj_id)._1; + scx.fcx.ccx.tcx, + this_obj_id)._1; // Grab this method's type out of the current object type. alt (struct(scx.fcx.ccx.tcx, this_obj_ty)) { @@ -2391,7 +2337,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { check_call(scx, f, args); // Check the return type - auto fty = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, f); + auto fty = expr_ty(scx.fcx.ccx.tcx, f); alt (struct(scx.fcx.ccx.tcx, fty)) { case (ty::ty_fn(_,_,?rt)) { alt (struct(scx.fcx.ccx.tcx, rt)) { @@ -2419,12 +2365,12 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { auto t_1 = ast_ty_to_ty_crate(scx.fcx.ccx, t); // FIXME: there are more forms of cast to support, eventually. if (! (type_is_scalar(scx.fcx.ccx.tcx, - expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, e)) && + expr_ty(scx.fcx.ccx.tcx, e)) && type_is_scalar(scx.fcx.ccx.tcx, t_1))) { scx.fcx.ccx.sess.span_err(expr.span, "non-scalar cast: " + ty_to_str(scx.fcx.ccx.tcx, - expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, e)) + + expr_ty(scx.fcx.ccx.tcx, e)) + " as " + ty_to_str(scx.fcx.ccx.tcx, t_1)); } @@ -2437,14 +2383,12 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { t = next_ty_var(scx); } else { check_expr(scx, args.(0)); - t = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - args.(0)); + t = expr_ty(scx.fcx.ccx.tcx, args.(0)); } for (@ast::expr e in args) { check_expr(scx, e); - auto expr_t = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - e); + auto expr_t = expr_ty(scx.fcx.ccx.tcx, e); Demand::simple(scx, expr.span, t, expr_t); } @@ -2457,8 +2401,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { for (ast::elt e in elts) { check_expr(scx, e.expr); - auto ety = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - e.expr); + auto ety = expr_ty(scx.fcx.ccx.tcx, e.expr); elts_mt += [rec(ty=ety, mut=e.mut)]; } @@ -2477,8 +2420,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { for (ast::field f in fields) { check_expr(scx, f.expr); - auto expr_t = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - f.expr); + auto expr_t = expr_ty(scx.fcx.ccx.tcx, f.expr); auto expr_mt = rec(ty=expr_t, mut=f.mut); vec::push[field](fields_t, rec(ident=f.ident, mt=expr_mt)); @@ -2492,8 +2434,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { case (some[@ast::expr](?bexpr)) { check_expr(scx, bexpr); - auto bexpr_t = expr_ty(scx.fcx.ccx.tcx, - scx.fcx.ccx.node_types, bexpr); + auto bexpr_t = expr_ty(scx.fcx.ccx.tcx, bexpr); let vec[field] base_fields = []; @@ -2530,8 +2471,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { case (ast::expr_field(?base, ?field, ?a)) { check_expr(scx, base); - auto base_t = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - base); + auto base_t = expr_ty(scx.fcx.ccx.tcx, base); base_t = strip_boxes(scx.fcx.ccx.tcx, base_t); alt (struct(scx.fcx.ccx.tcx, base_t)) { case (ty::ty_tup(?args)) { @@ -2577,13 +2517,11 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { case (ast::expr_index(?base, ?idx, ?a)) { check_expr(scx, base); - auto base_t = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - base); + auto base_t = expr_ty(scx.fcx.ccx.tcx, base); base_t = strip_boxes(scx.fcx.ccx.tcx, base_t); check_expr(scx, idx); - auto idx_t = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, - idx); + auto idx_t = expr_ty(scx.fcx.ccx.tcx, idx); alt (struct(scx.fcx.ccx.tcx, base_t)) { case (ty::ty_vec(?mt)) { if (! type_is_integral(scx.fcx.ccx.tcx, idx_t)) { @@ -2621,7 +2559,7 @@ fn check_expr(&@stmt_ctxt scx, &@ast::expr expr) { case (ast::expr_chan(?x, ?a)) { check_expr(scx, x); - auto port_t = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, x); + auto port_t = expr_ty(scx.fcx.ccx.tcx, x); alt (struct(scx.fcx.ccx.tcx, port_t)) { case (ty::ty_port(?subtype)) { auto ct = ty::mk_chan(scx.fcx.ccx.tcx, subtype); @@ -2685,7 +2623,7 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast::decl decl) -> @ast::decl { } auto a_res = local.ann; - write::ty_only(fcx.ccx.tcx, fcx.ccx.node_types, a_res.id, t); + write::ty_only(fcx.ccx.tcx, a_res.id, t); auto initopt = local.init; alt (local.init) { @@ -2703,7 +2641,7 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast::decl decl) -> @ast::decl { fn check_and_pushdown_expr(&@stmt_ctxt scx, &@ast::expr expr) { check_expr(scx, expr); - auto ety = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, expr); + auto ety = expr_ty(scx.fcx.ccx.tcx, expr); Pushdown::pushdown_expr(scx, ety, expr); } @@ -2723,7 +2661,7 @@ fn check_stmt(&@fn_ctxt fcx, &@ast::stmt stmt) { } } - write::nil_ty(fcx.ccx.tcx, fcx.ccx.node_types, node_id); + write::nil_ty(fcx.ccx.tcx, node_id); } fn check_block(&@stmt_ctxt scx, &ast::block block) { @@ -2733,18 +2671,18 @@ fn check_block(&@stmt_ctxt scx, &ast::block block) { case (none[@ast::expr]) { /* empty */ } case (some[@ast::expr](?e)) { check_expr(scx, e); - auto ety = expr_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, e); + auto ety = expr_ty(scx.fcx.ccx.tcx, e); Pushdown::pushdown_expr(scx, ety, e); } } - write::nil_ty(scx.fcx.ccx.tcx, scx.fcx.ccx.node_types, block.node.a.id); + write::nil_ty(scx.fcx.ccx.tcx, block.node.a.id); } fn check_const(&@crate_ctxt ccx, &span sp, &@ast::expr e, &ast::ann ann) { // 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.node_types, ann); + auto rty = ann_to_type(ccx.tcx.node_types, ann); let @fn_ctxt fcx = @rec(ret_ty = rty, purity = ast::pure_fn, locals = @common::new_def_hash[ty::t](), @@ -2764,7 +2702,7 @@ fn check_fn(&@crate_ctxt ccx, &ast::fn_decl decl, ast::proto proto, alt (get_obj_info(ccx)) { case (option::some[obj_info](?oinfo)) { for (ast::obj_field f in oinfo.obj_fields) { - auto field_ty = ty::ann_to_type(ccx.node_types, f.ann); + auto field_ty = ty::ann_to_type(ccx.tcx.node_types, f.ann); local_ty_table.insert(f.id, field_ty); } } @@ -2884,11 +2822,9 @@ fn mk_fn_purity_table(&@ast::crate crate) -> @fn_purity_table { ret res; } -type typecheck_result = tup(node_type_table, ty::type_cache); - -fn check_crate(&ty::ctxt tcx, &@ast::crate crate) -> typecheck_result { +fn check_crate(&ty::ctxt tcx, &@ast::crate crate) { auto sess = tcx.sess; - auto result = collect::collect_item_types(sess, tcx, crate); + auto all_items = collect::collect_item_types(sess, tcx, crate); let vec[obj_info] obj_infos = []; @@ -2897,18 +2833,15 @@ fn check_crate(&ty::ctxt tcx, &@ast::crate crate) -> typecheck_result { auto unify_cache = map::mk_hashmap[unify_cache_entry,ty::unify::result](hasher, eqer); auto fpt = mk_fn_purity_table(crate); // use a variation on collect - let node_type_table node_types = result._2; auto ccx = @rec(sess=sess, - type_cache=result._0, - item_items=result._1, + item_items=all_items, mutable obj_infos=obj_infos, fn_purity_table=fpt, unify_cache=unify_cache, mutable cache_hits=0u, mutable cache_misses=0u, - tcx=tcx, - node_types=node_types); + tcx=tcx); auto visit = rec(visit_item_pre = bind check_item(ccx, _) with walk::default_visitor()); @@ -2917,8 +2850,6 @@ fn check_crate(&ty::ctxt tcx, &@ast::crate crate) -> typecheck_result { log #fmt("cache hit rate: %u/%u", ccx.cache_hits, ccx.cache_hits + ccx.cache_misses); - - ret tup(node_types, ccx.type_cache); } // diff --git a/src/comp/pretty/pprust.rs b/src/comp/pretty/pprust.rs index 042bda62ca5b..695f7bf9c275 100644 --- a/src/comp/pretty/pprust.rs +++ b/src/comp/pretty/pprust.rs @@ -14,7 +14,7 @@ const uint default_columns = 78u; tag mode { mo_untyped; - mo_typed(ty::ctxt, ty::node_type_table, ty::type_cache); + mo_typed(ty::ctxt); } type ps = @rec(pp::ps s, @@ -406,7 +406,7 @@ fn print_expr(ps s, &@ast::expr expr) { alt (s.mode) { case (mo_untyped) { /* no-op */ } - case (mo_typed(_, _, _)) { popen(s); } + case (mo_typed(_)) { popen(s); } } alt (expr.node) { @@ -719,10 +719,10 @@ fn print_expr(ps s, &@ast::expr expr) { // Print the type if necessary. alt (s.mode) { case (mo_untyped) { /* no-op */ } - case (mo_typed(?tcx, ?ntt, ?tc)) { + case (mo_typed(?tcx)) { space(s.s); wrd1(s, "as"); - wrd(s.s, ty::ty_to_str(tcx, ty::expr_ty(tcx, ntt, expr))); + wrd(s.s, ty::ty_to_str(tcx, ty::expr_ty(tcx, expr))); pclose(s); } } @@ -747,8 +747,9 @@ fn print_decl(ps s, @ast::decl decl) { // Print the type if necessary. alt (s.mode) { case (mo_untyped) { /* no-op */ } - case (mo_typed(?tcx, ?ntt, ?tc)) { - auto lty = ty::ann_to_type(ntt, loc.ann); + case (mo_typed(?tcx)) { + auto lty = + ty::ann_to_type(tcx.node_types, loc.ann); wrd1(s, ty::ty_to_str(tcx, lty)); } }