Move type cache and node type table into type context.

This commit is contained in:
Graydon Hoare 2011-05-19 15:47:15 -07:00
parent 8a7b544995
commit a4dd57705c
7 changed files with 270 additions and 367 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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]());
}

View file

@ -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);

View file

@ -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:

File diff suppressed because it is too large Load diff

View file

@ -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));
}
}