diff options
Diffstat (limited to 'src/comp/middle/trans.rs')
| -rw-r--r-- | src/comp/middle/trans.rs | 104 |
1 files changed, 66 insertions, 38 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 09156cab..7a55be10 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -19,6 +19,7 @@ import back::x86; import back::abi; import back::upcall; +import middle::ty::node_type_table; import middle::ty::pat_ty; import util::common; @@ -128,7 +129,8 @@ state type crate_ctxt = rec(session::session sess, hashmap[ty::t, str] type_short_names, ty::ctxt tcx, stats stats, - @upcall::upcalls upcalls); + @upcall::upcalls upcalls, + node_type_table node_types); type local_ctxt = rec(vec[str] path, vec[str] module_path, @@ -3270,7 +3272,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, a)); + ret target_type(cx, ty::ann_to_monotype(cx.tcx, cx.node_types, a)); } fn node_ann_ty_params(&ast::ann a) -> vec[ty::t] { @@ -3299,22 +3301,25 @@ 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, e); + auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, e); alt (op) { case (ast::bitnot) { sub = autoderef(sub.bcx, sub.val, - ty::expr_ty(cx.fcx.lcx.ccx.tcx, e)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, 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, e)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, 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, e)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, e)); if(ty::struct(cx.fcx.lcx.ccx.tcx, e_ty) == ty::ty_float) { ret res(sub.bcx, sub.bcx.build.FNeg(sub.val)); } @@ -3323,7 +3328,8 @@ fn trans_unary(&@block_ctxt cx, ast::unop op, } } case (ast::box(_)) { - auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e); + auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, 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); @@ -3579,12 +3585,14 @@ 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, a)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, 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, b)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, b)); auto lhs_false_cx = new_scope_block_ctxt(cx, "lhs false"); auto lhs_false_res = res(lhs_false_cx, C_bool(false)); @@ -3601,12 +3609,14 @@ 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, a)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, 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, b)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, b)); auto lhs_true_cx = new_scope_block_ctxt(cx, "lhs true"); auto lhs_true_res = res(lhs_true_cx, C_bool(true)); @@ -3622,10 +3632,12 @@ 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, a); + auto lhty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, 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, b); + auto rhty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, 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); @@ -3702,7 +3714,8 @@ 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, elexpr); + auto expr_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, 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 { @@ -3759,7 +3772,8 @@ 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, seq); + auto seq_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, + 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)); @@ -4091,7 +4105,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(ann); + auto lltype = ty::ann_to_type(cx.fcx.lcx.ccx.node_types, ann); auto lleq = trans_compare(cx, ast::eq, lltype, llval, lllit); auto matched_cx = new_sub_block_ctxt(lleq.bcx, "matched_cx"); @@ -4141,7 +4155,9 @@ 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, subpat)); + llsubvalptr, pat_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, + subpat)); auto subpat_res = trans_pat_match(matched_cx, subpat, llsubval, next_cx); matched_cx = subpat_res.bcx; @@ -4237,7 +4253,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(ann); + auto expr_ty = ty::ann_to_type(cx.fcx.lcx.ccx.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); @@ -4499,7 +4515,9 @@ 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, base)); + lv = autoderef(lv.bcx, lv.val, ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, + base)); auto ix = trans_expr(lv.bcx, idx); auto v = lv.val; auto bcx = ix.bcx; @@ -4565,7 +4583,8 @@ 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, base); + auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, base); ret trans_field(r.bcx, e.span, r.val, t, ident, ann); } case (ast::expr_index(?base, ?idx, ?ann)) { @@ -4626,7 +4645,8 @@ 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, e))) { + ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, 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); @@ -4716,7 +4736,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, e); + auto e_ty = ty::expr_ty(cx.ccx.tcx, cx.ccx.node_types, e); auto bound_arg = GEP_tup_like(bcx, closure_ty, llclosure, vec(0, @@ -4812,7 +4832,8 @@ 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, f); + outgoing_fty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, f); lltydescs = vec(); } case (some[generic_info](?ginfo)) { @@ -4841,7 +4862,8 @@ 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, e)); + ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, e)); i += 1u; } @@ -4988,7 +5010,7 @@ fn trans_arg_expr(&@block_ctxt cx, auto val; auto bcx = cx; - auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e); + auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, e); if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, e_ty)) { auto re = trans_expr(bcx, e); @@ -5188,13 +5210,13 @@ fn trans_call(&@block_ctxt cx, &@ast::expr f, } case (_) { - fn_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, f); - + fn_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, + f); } } - auto ret_ty = ty::ann_to_type(ann); + auto ret_ty = ty::ann_to_type(cx.fcx.lcx.ccx.node_types, ann); auto args_res = trans_args(f_res.res.bcx, llenv, f_res.llobj, f_res.generic, @@ -5249,7 +5271,8 @@ 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, e.expr); + auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, + e.expr); auto src_res = trans_expr(bcx, e.expr); bcx = src_res.bcx; auto dst_res = GEP_tup_like(bcx, t, tup_val, vec(0, i)); @@ -5565,7 +5588,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, e); + auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, e); auto sub = trans_lval(cx, e); ret res(sub.res.bcx, load_if_immediate(sub.res.bcx, sub.res.val, t)); } @@ -5626,7 +5649,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, e); + auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, cx.fcx.lcx.ccx.node_types, e); auto log_bcx = sub.bcx; if (ty::type_is_fp(cx.fcx.lcx.ccx.tcx, e_ty)) { @@ -5744,7 +5767,8 @@ 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, x); + auto e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, x); auto arg = rec(mode=ty::mo_alias, ty=e_ty); auto arg_tys = type_of_explicit_args(cx.fcx.lcx.ccx, vec(arg)); auto r = trans_arg_expr(bcx, arg, arg_tys.(0), x); @@ -5804,7 +5828,8 @@ 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, x); + auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, x); auto r = trans_expr(cx, x); bcx = r.bcx; val = r.val; @@ -6192,7 +6217,8 @@ 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, e); + auto r_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, + cx.fcx.lcx.ccx.node_types, 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 @@ -6416,7 +6442,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(ann))) { + alt (ty::struct(ccx.tcx, ty::ann_to_type(ccx.node_types, ann))) { case (ty::ty_fn(_, ?arg_tys, _)) { ret arg_tys; } @@ -6435,7 +6461,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(ann)); + ret ret_ty_of_fn_ty(ccx, ty::ann_to_type(ccx.node_types, ann)); } fn populate_fn_ctxt_from_llself(@fn_ctxt fcx, self_vt llself) { @@ -7920,7 +7946,8 @@ fn create_crate_map(&@crate_ctxt ccx) -> ValueRef { } fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx, - &ty::type_cache type_cache, &str output) + &ty::node_type_table node_types, &ty::type_cache type_cache, + &str output) -> ModuleRef { auto llmod = llvm::LLVMModuleCreateWithNameInContext(_str::buf("rust_out"), @@ -7978,7 +8005,8 @@ 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)); + upcalls = upcall::declare_upcalls(tn, llmod), + node_types = node_types); auto cx = new_local_ctxt(ccx); create_typedefs(ccx); |