rustc: Remove all uses of plain_ty() and friends from outside of ty.rs

This commit is contained in:
Patrick Walton
2011-04-20 11:23:36 -07:00
parent ac62488bb1
commit 38e842244c
5 changed files with 136 additions and 165 deletions

View File

@@ -456,7 +456,7 @@ fn encode_info_for_native_item(@trans.crate_ctxt cx, &ebml.writer ebml_w,
case (ast.native_item_ty(_, ?did)) { case (ast.native_item_ty(_, ?did)) {
encode_def_id(ebml_w, did); encode_def_id(ebml_w, did);
encode_kind(ebml_w, 'T' as u8); encode_kind(ebml_w, 'T' as u8);
encode_type(ebml_w, ty.plain_ty(ty.ty_native)); encode_type(ebml_w, ty.mk_native());
} }
case (ast.native_item_fn(_, _, _, ?tps, ?did, ?ann)) { case (ast.native_item_fn(_, _, _, ?tps, ?did, ?ann)) {
encode_def_id(ebml_w, did); encode_def_id(ebml_w, did);

View File

@@ -21,7 +21,6 @@ import back.abi;
import pretty.pprust; import pretty.pprust;
import middle.ty.pat_ty; import middle.ty.pat_ty;
import middle.ty.plain_ty;
import util.common; import util.common;
import util.common.istr; import util.common.istr;
@@ -639,7 +638,7 @@ fn type_of_fn_full(@crate_ctxt cx,
vec(T_fn_pair(cx.tn, vec(T_fn_pair(cx.tn,
type_of_fn_full(cx, ast.proto_fn, none[TypeRef], type_of_fn_full(cx, ast.proto_fn, none[TypeRef],
vec(rec(mode=ast.val, ty=output)), vec(rec(mode=ast.val, ty=output)),
plain_ty(ty.ty_nil), 0u))); ty.mk_nil(), 0u)));
} }
// ... then explicit args. // ... then explicit args.
@@ -1150,7 +1149,7 @@ fn simplify_type(@ty.t typ) -> @ty.t {
fn simplifier(@ty.t typ) -> @ty.t { fn simplifier(@ty.t typ) -> @ty.t {
alt (typ.struct) { alt (typ.struct) {
case (ty.ty_box(_)) { case (ty.ty_box(_)) {
ret ty.plain_box_ty(ty.plain_ty(ty.ty_nil), ast.imm); ret ty.mk_imm_box(ty.mk_nil());
} }
case (_) { ret typ; } case (_) { ret typ; }
} }
@@ -1187,7 +1186,7 @@ fn static_size_of_tag(@crate_ctxt cx, @ty.t t) -> uint {
auto max_size = 0u; auto max_size = 0u;
auto variants = tag_variants(cx, tid); auto variants = tag_variants(cx, tid);
for (variant_info variant in variants) { for (variant_info variant in variants) {
auto tup_ty = simplify_type(ty.plain_tup_ty(variant.args)); auto tup_ty = simplify_type(ty.mk_imm_tup(variant.args));
// Perform any type parameter substitutions. // Perform any type parameter substitutions.
tup_ty = ty.bind_params_in_type(tup_ty); tup_ty = ty.bind_params_in_type(tup_ty);
@@ -1403,7 +1402,7 @@ fn GEP_tup_like(@block_ctxt cx, @ty.t t,
// flattened the incoming structure. // flattened the incoming structure.
auto s = split_type(t, ixs, 0u); auto s = split_type(t, ixs, 0u);
auto prefix_ty = ty.plain_tup_ty(s.prefix); auto prefix_ty = ty.mk_imm_tup(s.prefix);
auto bcx = cx; auto bcx = cx;
auto sz = size_of(bcx, prefix_ty); auto sz = size_of(bcx, prefix_ty);
bcx = sz.bcx; bcx = sz.bcx;
@@ -1434,7 +1433,7 @@ fn GEP_tag(@block_ctxt cx,
// Synthesize a tuple type so that GEP_tup_like() can work its magic. // Synthesize a tuple type so that GEP_tup_like() can work its magic.
// Separately, store the type of the element we're interested in. // Separately, store the type of the element we're interested in.
auto arg_tys = variant.args; auto arg_tys = variant.args;
auto elem_ty = ty.plain_ty(ty.ty_nil); // typestate infelicity auto elem_ty = ty.mk_nil(); // typestate infelicity
auto i = 0; auto i = 0;
let vec[@ty.t] true_arg_tys = vec(); let vec[@ty.t] true_arg_tys = vec();
for (@ty.t aty in arg_tys) { for (@ty.t aty in arg_tys) {
@@ -1448,7 +1447,7 @@ fn GEP_tag(@block_ctxt cx,
i += 1; i += 1;
} }
auto tup_ty = ty.plain_tup_ty(true_arg_tys); auto tup_ty = ty.mk_imm_tup(true_arg_tys);
// Cast the blob pointer to the appropriate type, if we need to (i.e. if // Cast the blob pointer to the appropriate type, if we need to (i.e. if
// the blob pointer isn't dynamically sized). // the blob pointer isn't dynamically sized).
@@ -1488,8 +1487,8 @@ fn trans_raw_malloc(@block_ctxt cx, TypeRef llptr_ty, ValueRef llsize)
fn trans_malloc_boxed(@block_ctxt cx, @ty.t t) -> result { fn trans_malloc_boxed(@block_ctxt cx, @ty.t t) -> result {
// Synthesize a fake box type structurally so we have something // Synthesize a fake box type structurally so we have something
// to measure the size of. // to measure the size of.
auto boxed_body = ty.plain_tup_ty(vec(plain_ty(ty.ty_int), t)); auto boxed_body = ty.mk_imm_tup(vec(ty.mk_int(), t));
auto box_ptr = ty.plain_box_ty(t, ast.imm); auto box_ptr = ty.mk_imm_box(t);
auto sz = size_of(cx, boxed_body); auto sz = size_of(cx, boxed_body);
auto llty = type_of(cx.fcx.lcx.ccx, box_ptr); auto llty = type_of(cx.fcx.lcx.ccx, box_ptr);
ret trans_raw_malloc(sz.bcx, llty, sz.val); ret trans_raw_malloc(sz.bcx, llty, sz.val);
@@ -2294,13 +2293,6 @@ fn tag_variant_with_id(@crate_ctxt cx,
fail; fail;
} }
// Returns a new plain tag type of the given ID with no type parameters. Don't
// use this function in new code; it's a hack to keep things working for now.
fn mk_plain_tag(ast.def_id tid) -> @ty.t {
let vec[@ty.t] tps = vec();
ret ty.plain_ty(ty.ty_tag(tid, tps));
}
type val_pair_fn = fn(@block_ctxt cx, ValueRef dst, ValueRef src) -> result; type val_pair_fn = fn(@block_ctxt cx, ValueRef dst, ValueRef src) -> result;
@@ -2341,8 +2333,8 @@ fn iter_structural_ty_full(@block_ctxt cx,
val_pair_and_ty_fn f) -> result { val_pair_and_ty_fn f) -> result {
auto box_a_ptr = cx.build.Load(box_a_cell); auto box_a_ptr = cx.build.Load(box_a_cell);
auto box_b_ptr = cx.build.Load(box_b_cell); auto box_b_ptr = cx.build.Load(box_b_cell);
auto tnil = plain_ty(ty.ty_nil); auto tnil = ty.mk_nil();
auto tbox = ty.plain_box_ty(tnil, ast.imm); auto tbox = ty.mk_imm_box(tnil);
auto inner_cx = new_sub_block_ctxt(cx, "iter box"); auto inner_cx = new_sub_block_ctxt(cx, "iter box");
auto next_cx = new_sub_block_ctxt(cx, "next"); auto next_cx = new_sub_block_ctxt(cx, "next");
@@ -2407,8 +2399,7 @@ fn iter_structural_ty_full(@block_ctxt cx,
// NB: we must hit the discriminant first so that structural // NB: we must hit the discriminant first so that structural
// comparison know not to proceed when the discriminants differ. // comparison know not to proceed when the discriminants differ.
auto bcx = cx; auto bcx = cx;
bcx = f(bcx, lldiscrim_a, lldiscrim_b, bcx = f(bcx, lldiscrim_a, lldiscrim_b, ty.mk_int()).bcx;
plain_ty(ty.ty_int)).bcx;
auto unr_cx = new_sub_block_ctxt(bcx, "tag-iter-unr"); auto unr_cx = new_sub_block_ctxt(bcx, "tag-iter-unr");
unr_cx.build.Unreachable(); unr_cx.build.Unreachable();
@@ -2628,7 +2619,7 @@ fn iter_sequence(@block_ctxt cx,
ret iter_sequence_body(cx, v, elt.ty, f, false); ret iter_sequence_body(cx, v, elt.ty, f, false);
} }
case (ty.ty_str) { case (ty.ty_str) {
auto et = plain_ty(ty.ty_machine(common.ty_u8)); auto et = ty.mk_mach(common.ty_u8);
ret iter_sequence_body(cx, v, et, f, true); ret iter_sequence_body(cx, v, et, f, true);
} }
case (_) { fail; } case (_) { fail; }
@@ -3449,7 +3440,7 @@ fn trans_for_each(@block_ctxt cx,
auto lcx = cx.fcx.lcx; auto lcx = cx.fcx.lcx;
// FIXME: possibly support alias-mode here? // FIXME: possibly support alias-mode here?
auto decl_ty = plain_ty(ty.ty_nil); auto decl_ty = ty.mk_nil();
auto decl_id; auto decl_id;
alt (decl.node) { alt (decl.node) {
case (ast.decl_local(?local)) { case (ast.decl_local(?local)) {
@@ -3536,7 +3527,7 @@ fn trans_for_each(@block_ctxt cx,
auto iter_body_llty = type_of_fn_full(lcx.ccx, ast.proto_fn, auto iter_body_llty = type_of_fn_full(lcx.ccx, ast.proto_fn,
none[TypeRef], none[TypeRef],
vec(rec(mode=ast.val, ty=decl_ty)), vec(rec(mode=ast.val, ty=decl_ty)),
plain_ty(ty.ty_nil), 0u); ty.mk_nil(), 0u);
let ValueRef lliterbody = decl_internal_fastcall_fn(lcx.ccx.llmod, let ValueRef lliterbody = decl_internal_fastcall_fn(lcx.ccx.llmod,
s, iter_body_llty); s, iter_body_llty);
@@ -4235,8 +4226,7 @@ fn trans_bind_thunk(@local_ctxt cx,
auto bcx = new_top_block_ctxt(fcx); auto bcx = new_top_block_ctxt(fcx);
auto lltop = bcx.llbb; auto lltop = bcx.llbb;
auto llclosure_ptr_ty = type_of(cx.ccx, ty.plain_box_ty(closure_ty, auto llclosure_ptr_ty = type_of(cx.ccx, ty.mk_imm_box(closure_ty));
ast.imm));
auto llclosure = bcx.build.PointerCast(fcx.llenv, llclosure_ptr_ty); auto llclosure = bcx.build.PointerCast(fcx.llenv, llclosure_ptr_ty);
auto lltarget = GEP_tup_like(bcx, closure_ty, llclosure, auto lltarget = GEP_tup_like(bcx, closure_ty, llclosure,
@@ -4411,12 +4401,12 @@ fn trans_bind(@block_ctxt cx, @ast.expr f,
} }
// Synthesize a closure type. // Synthesize a closure type.
let @ty.t bindings_ty = ty.plain_tup_ty(bound_tys); let @ty.t bindings_ty = ty.mk_imm_tup(bound_tys);
// NB: keep this in sync with T_closure_ptr; we're making // NB: keep this in sync with T_closure_ptr; we're making
// a ty.t structure that has the same "shape" as the LLVM type // a ty.t structure that has the same "shape" as the LLVM type
// it constructs. // it constructs.
let @ty.t tydesc_ty = plain_ty(ty.ty_type); let @ty.t tydesc_ty = ty.mk_type();
let vec[@ty.t] captured_tys = let vec[@ty.t] captured_tys =
_vec.init_elt[@ty.t](tydesc_ty, ty_param_count); _vec.init_elt[@ty.t](tydesc_ty, ty_param_count);
@@ -4425,9 +4415,9 @@ fn trans_bind(@block_ctxt cx, @ast.expr f,
vec(tydesc_ty, vec(tydesc_ty,
outgoing_fty, outgoing_fty,
bindings_ty, bindings_ty,
ty.plain_tup_ty(captured_tys)); ty.mk_imm_tup(captured_tys));
let @ty.t closure_ty = ty.plain_tup_ty(closure_tys); let @ty.t closure_ty = ty.mk_imm_tup(closure_tys);
auto r = trans_malloc_boxed(bcx, closure_ty); auto r = trans_malloc_boxed(bcx, closure_ty);
auto box = r.val; auto box = r.val;
@@ -4829,7 +4819,7 @@ fn trans_vec(@block_ctxt cx, vec[@ast.expr] args,
C_int(abi.vec_elt_data))); C_int(abi.vec_elt_data)));
auto pseudo_tup_ty = auto pseudo_tup_ty =
ty.plain_tup_ty(_vec.init_elt[@ty.t](unit_ty, ty.mk_imm_tup(_vec.init_elt[@ty.t](unit_ty,
_vec.len[@ast.expr](args))); _vec.len[@ast.expr](args)));
let int i = 0; let int i = 0;
@@ -5927,7 +5917,7 @@ fn populate_fn_ctxt_from_llself(@fn_ctxt fcx, self_vt llself) {
// Synthesize a tuple type for the fields so that GEP_tup_like() can work // Synthesize a tuple type for the fields so that GEP_tup_like() can work
// its magic. // its magic.
auto fields_tup_ty = ty.plain_tup_ty(field_tys); auto fields_tup_ty = ty.mk_imm_tup(field_tys);
auto n_typarams = _vec.len[ast.ty_param](bcx.fcx.lcx.obj_typarams); auto n_typarams = _vec.len[ast.ty_param](bcx.fcx.lcx.obj_typarams);
let TypeRef llobj_box_ty = T_obj_ptr(bcx.fcx.lcx.ccx.tn, n_typarams); let TypeRef llobj_box_ty = T_obj_ptr(bcx.fcx.lcx.ccx.tn, n_typarams);
@@ -6152,18 +6142,18 @@ fn trans_obj(@local_ctxt cx, &ast._obj ob, ast.def_id oid,
} }
// Synthesize an obj body type. // Synthesize an obj body type.
auto tydesc_ty = plain_ty(ty.ty_type); auto tydesc_ty = ty.mk_type();
let vec[@ty.t] tps = vec(); let vec[@ty.t] tps = vec();
for (ast.ty_param tp in ty_params) { for (ast.ty_param tp in ty_params) {
_vec.push[@ty.t](tps, tydesc_ty); _vec.push[@ty.t](tps, tydesc_ty);
} }
let @ty.t typarams_ty = ty.plain_tup_ty(tps); let @ty.t typarams_ty = ty.mk_imm_tup(tps);
let @ty.t fields_ty = ty.plain_tup_ty(obj_fields); let @ty.t fields_ty = ty.mk_imm_tup(obj_fields);
let @ty.t body_ty = ty.plain_tup_ty(vec(tydesc_ty, let @ty.t body_ty = ty.mk_imm_tup(vec(tydesc_ty,
typarams_ty, typarams_ty,
fields_ty)); fields_ty));
let @ty.t boxed_body_ty = ty.plain_box_ty(body_ty, ast.imm); let @ty.t boxed_body_ty = ty.mk_imm_box(body_ty);
// Malloc a box for the body. // Malloc a box for the body.
auto box = trans_malloc_boxed(bcx, body_ty); auto box = trans_malloc_boxed(bcx, body_ty);
@@ -6265,7 +6255,7 @@ fn trans_tag_variant(@local_ctxt cx, ast.def_id tag_id,
let vec[@ty.t] ty_param_substs = vec(); let vec[@ty.t] ty_param_substs = vec();
i = 0u; i = 0u;
for (ast.ty_param tp in ty_params) { for (ast.ty_param tp in ty_params) {
ty_param_substs += vec(plain_ty(ty.ty_param(i))); ty_param_substs += vec(ty.mk_param(i));
i += 1u; i += 1u;
} }

View File

@@ -32,11 +32,11 @@ type mt = rec(@t ty, ast.mutability mut);
// Convert from method type to function type. Pretty easy; we just drop // Convert from method type to function type. Pretty easy; we just drop
// 'ident'. // 'ident'.
fn method_ty_to_fn_ty(method m) -> @ty.t { fn method_ty_to_fn_ty(method m) -> @ty.t {
ret plain_ty(ty_fn(m.proto, m.inputs, m.output)); ret mk_fn(m.proto, m.inputs, m.output);
} }
// Do not construct these manually. Soon we want to intern these, at which // Do not construct these manually. Soon we want to intern these, at which
// point this will break. // point that will break.
// //
// TODO: It'd be really nice to be able to hide this definition from the // TODO: It'd be really nice to be able to hide this definition from the
// outside world, to enforce the above invariant. // outside world, to enforce the above invariant.
@@ -121,11 +121,23 @@ fn mk_tag(ast.def_id did, vec[@t] tys) -> @t {
} }
fn mk_box(mt tm) -> @t { ret plain_ty(ty_box(tm)); } fn mk_box(mt tm) -> @t { ret plain_ty(ty_box(tm)); }
fn mk_imm_box(@t ty) -> @t { ret mk_box(rec(ty=ty, mut=ast.imm)); }
fn mk_vec(mt tm) -> @t { ret plain_ty(ty_vec(tm)); } fn mk_vec(mt tm) -> @t { ret plain_ty(ty_vec(tm)); }
fn mk_port(@t ty) -> @t { ret plain_ty(ty_port(ty)); } fn mk_port(@t ty) -> @t { ret plain_ty(ty_port(ty)); }
fn mk_chan(@t ty) -> @t { ret plain_ty(ty_chan(ty)); } fn mk_chan(@t ty) -> @t { ret plain_ty(ty_chan(ty)); }
fn mk_task() -> @t { ret plain_ty(ty_task); } fn mk_task() -> @t { ret plain_ty(ty_task); }
fn mk_tup(vec[mt] tms) -> @t { ret plain_ty(ty_tup(tms)); } fn mk_tup(vec[mt] tms) -> @t { ret plain_ty(ty_tup(tms)); }
fn mk_imm_tup(vec[@t] tys) -> @t {
// TODO: map
let vec[ty.mt] mts = vec();
for (@ty.t typ in tys) {
mts += vec(rec(ty=typ, mut=ast.imm));
}
ret mk_tup(mts);
}
fn mk_rec(vec[field] fs) -> @t { ret plain_ty(ty_rec(fs)); } fn mk_rec(vec[field] fs) -> @t { ret plain_ty(ty_rec(fs)); }
fn mk_fn(ast.proto proto, vec[arg] args, @t ty) -> @t { fn mk_fn(ast.proto proto, vec[arg] args, @t ty) -> @t {
@@ -515,7 +527,7 @@ fn type_is_sequence(@t ty) -> bool {
fn sequence_element_type(@t ty) -> @t { fn sequence_element_type(@t ty) -> @t {
alt (ty.struct) { alt (ty.struct) {
case (ty_str) { ret plain_ty(ty_machine(common.ty_u8)); } case (ty_str) { ret mk_mach(common.ty_u8); }
case (ty_vec(?mt)) { ret mt.ty; } case (ty_vec(?mt)) { ret mt.ty; }
} }
fail; fail;
@@ -691,18 +703,6 @@ fn plain_ty(&sty st) -> @t {
ret @rec(struct=st, cname=none[str]); ret @rec(struct=st, cname=none[str]);
} }
fn plain_box_ty(@t subty, ast.mutability mut) -> @t {
ret plain_ty(ty_box(rec(ty=subty, mut=mut)));
}
fn plain_tup_ty(vec[@t] elem_tys) -> @t {
let vec[ty.mt] mts = vec();
for (@ty.t typ in elem_tys) {
mts += vec(rec(ty=typ, mut=ast.imm));
}
ret plain_ty(ty_tup(mts));
}
fn def_to_str(ast.def_id did) -> str { fn def_to_str(ast.def_id did) -> str {
ret #fmt("%d:%d", did._0, did._1); ret #fmt("%d:%d", did._0, did._1);
} }
@@ -957,7 +957,7 @@ fn stmt_ty(@ast.stmt s) -> @t {
ret expr_ty(e); ret expr_ty(e);
} }
case (_) { case (_) {
ret plain_ty(ty_nil); ret mk_nil();
} }
} }
} }
@@ -965,7 +965,7 @@ fn stmt_ty(@ast.stmt s) -> @t {
fn block_ty(&ast.block b) -> @t { fn block_ty(&ast.block b) -> @t {
alt (b.node.expr) { alt (b.node.expr) {
case (some[@ast.expr](?e)) { ret expr_ty(e); } case (some[@ast.expr](?e)) { ret expr_ty(e); }
case (none[@ast.expr]) { ret plain_ty(ty_nil); } case (none[@ast.expr]) { ret mk_nil(); }
} }
} }
@@ -1035,7 +1035,7 @@ fn expr_ann(@ast.expr expr) -> option.t[ast.ann] {
// expr_ty_params_and_ty() below. // expr_ty_params_and_ty() below.
fn expr_ty(@ast.expr expr) -> @t { fn expr_ty(@ast.expr expr) -> @t {
alt (expr_ann(expr)) { alt (expr_ann(expr)) {
case (none[ast.ann]) { ret plain_ty(ty_nil); } case (none[ast.ann]) { ret mk_nil(); }
case (some[ast.ann](?a)) { ret ann_to_monotype(a); } case (some[ast.ann](?a)) { ret ann_to_monotype(a); }
} }
} }
@@ -1044,7 +1044,7 @@ fn expr_ty_params_and_ty(@ast.expr expr) -> tup(vec[@t], @t) {
alt (expr_ann(expr)) { alt (expr_ann(expr)) {
case (none[ast.ann]) { case (none[ast.ann]) {
let vec[@t] tps = vec(); let vec[@t] tps = vec();
ret tup(tps, plain_ty(ty_nil)); ret tup(tps, mk_nil());
} }
case (some[ast.ann](?a)) { case (some[ast.ann](?a)) {
ret tup(ann_to_type_params(a), ann_to_type(a)); ret tup(ann_to_type_params(a), ann_to_type(a));
@@ -1313,7 +1313,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
ret r; ret r;
} }
case (fn_common_res_ok(?result_ins, ?result_out)) { case (fn_common_res_ok(?result_ins, ?result_out)) {
auto t2 = plain_ty(ty.ty_fn(e_proto, result_ins, result_out)); auto t2 = mk_fn(e_proto, result_ins, result_out);
ret ures_ok(t2); ret ures_ok(t2);
} }
} }
@@ -1340,8 +1340,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
ret r; ret r;
} }
case (fn_common_res_ok(?result_ins, ?result_out)) { case (fn_common_res_ok(?result_ins, ?result_out)) {
auto t2 = plain_ty(ty.ty_native_fn(e_abi, result_ins, auto t2 = mk_native_fn(e_abi, result_ins, result_out);
result_out));
ret ures_ok(t2); ret ures_ok(t2);
} }
} }
@@ -1390,7 +1389,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
} }
i += 1u; i += 1u;
} }
auto t = plain_ty(ty_obj(result_meths)); auto t = mk_obj(result_meths);
ret ures_ok(t); ret ures_ok(t);
} }
@@ -1520,8 +1519,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
i += 1u; i += 1u;
} }
ret ures_ok(plain_ty(ty.ty_tag(expected_id, ret ures_ok(mk_tag(expected_id, result_tps));
result_tps)));
} }
case (_) { /* fall through */ } case (_) { /* fall through */ }
} }
@@ -1548,7 +1546,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
alt (result) { alt (result) {
case (ures_ok(?result_sub)) { case (ures_ok(?result_sub)) {
auto mt = rec(ty=result_sub, mut=mut); auto mt = rec(ty=result_sub, mut=mut);
ret ures_ok(plain_ty(ty.ty_box(mt))); ret ures_ok(mk_box(mt));
} }
case (_) { case (_) {
ret result; ret result;
@@ -1581,7 +1579,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
alt (result) { alt (result) {
case (ures_ok(?result_sub)) { case (ures_ok(?result_sub)) {
auto mt = rec(ty=result_sub, mut=mut); auto mt = rec(ty=result_sub, mut=mut);
ret ures_ok(plain_ty(ty.ty_vec(mt))); ret ures_ok(mk_vec(mt));
} }
case (_) { case (_) {
ret result; ret result;
@@ -1604,7 +1602,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
handler); handler);
alt (result) { alt (result) {
case (ures_ok(?result_sub)) { case (ures_ok(?result_sub)) {
ret ures_ok(plain_ty(ty.ty_port(result_sub))); ret ures_ok(mk_port(result_sub));
} }
case (_) { case (_) {
ret result; ret result;
@@ -1627,7 +1625,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
handler); handler);
alt (result) { alt (result) {
case (ures_ok(?result_sub)) { case (ures_ok(?result_sub)) {
ret ures_ok(plain_ty(ty.ty_chan(result_sub))); ret ures_ok(mk_chan(result_sub));
} }
case (_) { case (_) {
ret result; ret result;
@@ -1687,7 +1685,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
i += 1u; i += 1u;
} }
ret ures_ok(plain_ty(ty.ty_tup(result_elems))); ret ures_ok(mk_tup(result_elems));
} }
case (_) { case (_) {
@@ -1752,7 +1750,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
i += 1u; i += 1u;
} }
ret ures_ok(plain_ty(ty.ty_rec(result_fields))); ret ures_ok(mk_rec(result_fields));
} }
case (_) { case (_) {
@@ -1988,7 +1986,7 @@ fn bind_params_in_type(@t typ) -> @t {
"has bound params in it"; "has bound params in it";
fail; fail;
} }
case (ty_param(?index)) { ret plain_ty(ty_bound_param(index)); } case (ty_param(?index)) { ret mk_bound_param(index); }
case (_) { ret typ; } case (_) { ret typ; }
} }
} }

View File

@@ -19,7 +19,6 @@ import middle.ty.method;
import middle.ty.mode_is_alias; import middle.ty.mode_is_alias;
import middle.ty.pat_ty; import middle.ty.pat_ty;
import middle.ty.path_to_str; import middle.ty.path_to_str;
import middle.ty.plain_ty;
import middle.ty.triv_ann; import middle.ty.triv_ann;
import middle.ty.ty_to_str; import middle.ty.ty_to_str;
import middle.ty.type_is_integral; import middle.ty.type_is_integral;
@@ -65,9 +64,7 @@ type ty_getter = fn(ast.def_id) -> ty.ty_param_count_and_ty;
// Used to fill in the annotation for things that have uninteresting // Used to fill in the annotation for things that have uninteresting
// types // types
fn boring_ann() -> ann { fn boring_ann() -> ann { ret triv_ann(ty.mk_nil()); }
ret triv_ann(plain_ty(ty_nil));
}
// Substitutes the user's explicit types for the parameters in a path // Substitutes the user's explicit types for the parameters in a path
// expression. // expression.
@@ -109,7 +106,7 @@ fn ty_param_count_and_ty_for_def(@fn_ctxt fcx, &ast.def defn)
auto t; auto t;
alt (fcx.locals.find(id)) { alt (fcx.locals.find(id)) {
case (some[@ty.t](?t1)) { t = t1; } case (some[@ty.t](?t1)) { t = t1; }
case (none[@ty.t]) { t = plain_ty(ty.ty_local(id)); } case (none[@ty.t]) { t = ty.mk_local(id); }
} }
ret tup(0u, t); ret tup(0u, t);
} }
@@ -140,7 +137,7 @@ fn ty_param_count_and_ty_for_def(@fn_ctxt fcx, &ast.def defn)
case (ast.def_mod(_)) { case (ast.def_mod(_)) {
// Hopefully part of a path. // Hopefully part of a path.
// TODO: return a type that's more poisonous, perhaps? // TODO: return a type that's more poisonous, perhaps?
ret tup(0u, plain_ty(ty.ty_nil)); ret tup(0u, ty.mk_nil());
} }
case (ast.def_ty(_)) { case (ast.def_ty(_)) {
@@ -345,7 +342,7 @@ fn ty_of_fn_decl(@ty_item_table id_to_ty_item,
ast.def_id def_id) -> ty.ty_param_count_and_ty { ast.def_id def_id) -> ty.ty_param_count_and_ty {
auto input_tys = _vec.map[ast.arg,arg](ty_of_arg, decl.inputs); auto input_tys = _vec.map[ast.arg,arg](ty_of_arg, decl.inputs);
auto output_ty = convert(decl.output); auto output_ty = convert(decl.output);
auto t_fn = plain_ty(ty.ty_fn(proto, input_tys, output_ty)); auto t_fn = ty.mk_fn(proto, input_tys, output_ty);
auto ty_param_count = _vec.len[ast.ty_param](ty_params); auto ty_param_count = _vec.len[ast.ty_param](ty_params);
auto tpt = tup(ty_param_count, t_fn); auto tpt = tup(ty_param_count, t_fn);
type_cache.insert(def_id, tpt); type_cache.insert(def_id, tpt);
@@ -362,7 +359,7 @@ fn ty_of_native_fn_decl(@ty_item_table id_to_ty_item,
ast.def_id def_id) -> ty.ty_param_count_and_ty { ast.def_id def_id) -> ty.ty_param_count_and_ty {
auto input_tys = _vec.map[ast.arg,arg](ty_of_arg, decl.inputs); auto input_tys = _vec.map[ast.arg,arg](ty_of_arg, decl.inputs);
auto output_ty = convert(decl.output); auto output_ty = convert(decl.output);
auto t_fn = plain_ty(ty.ty_native_fn(abi, input_tys, output_ty)); auto t_fn = ty.mk_native_fn(abi, input_tys, output_ty);
auto ty_param_count = _vec.len[ast.ty_param](ty_params); auto ty_param_count = _vec.len[ast.ty_param](ty_params);
auto tpt = tup(ty_param_count, t_fn); auto tpt = tup(ty_param_count, t_fn);
type_cache.insert(def_id, tpt); type_cache.insert(def_id, tpt);
@@ -455,7 +452,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
type_cache.insert(obj_ty_id, t_obj); type_cache.insert(obj_ty_id, t_obj);
auto t_fn = plain_ty(ty.ty_fn(ast.proto_fn, t_inputs, t_obj._1)); auto t_fn = ty.mk_fn(ast.proto_fn, t_inputs, t_obj._1);
ret tup(t_obj._0, t_fn); ret tup(t_obj._0, t_fn);
} }
@@ -513,11 +510,11 @@ fn collect_item_types(session.session sess, @ast.crate crate)
auto i = 0u; auto i = 0u;
for (ast.ty_param tp in tps) { for (ast.ty_param tp in tps) {
subtys += vec(plain_ty(ty.ty_param(i))); subtys += vec(ty.mk_param(i));
i += 1u; i += 1u;
} }
auto t = plain_ty(ty.ty_tag(def_id, subtys)); auto t = ty.mk_tag(def_id, subtys);
auto ty_param_count = _vec.len[ast.ty_param](tps); auto ty_param_count = _vec.len[ast.ty_param](tps);
auto tpt = tup(ty_param_count, t); auto tpt = tup(ty_param_count, t);
@@ -571,7 +568,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
let vec[@ty.t] ty_param_tys = vec(); let vec[@ty.t] ty_param_tys = vec();
auto i = 0u; auto i = 0u;
for (ast.ty_param tp in ty_params) { for (ast.ty_param tp in ty_params) {
ty_param_tys += vec(plain_ty(ty.ty_param(i))); ty_param_tys += vec(ty.mk_param(i));
i += 1u; i += 1u;
} }
@@ -582,7 +579,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
// constructors get turned into functions. // constructors get turned into functions.
auto result_ty; auto result_ty;
if (_vec.len[ast.variant_arg](variant.node.args) == 0u) { if (_vec.len[ast.variant_arg](variant.node.args) == 0u) {
result_ty = plain_ty(ty.ty_tag(tag_id, ty_param_tys)); result_ty = ty.mk_tag(tag_id, ty_param_tys);
} else { } else {
// As above, tell ast_ty_to_ty() that trans_ty_item_to_ty() // As above, tell ast_ty_to_ty() that trans_ty_item_to_ty()
// should be called to resolve named types. // should be called to resolve named types.
@@ -593,8 +590,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
auto arg_ty = ast_ty_to_ty(f, va.ty); auto arg_ty = ast_ty_to_ty(f, va.ty);
args += vec(rec(mode=ast.alias, ty=arg_ty)); args += vec(rec(mode=ast.alias, ty=arg_ty));
} }
auto tag_t = plain_ty(ty.ty_tag(tag_id, ty_param_tys)); auto tag_t = ty.mk_tag(tag_id, ty_param_tys);
result_ty = plain_ty(ty.ty_fn(ast.proto_fn, args, tag_t)); result_ty = ty.mk_fn(ast.proto_fn, args, tag_t);
} }
auto tpt = tup(ty_param_count, result_ty); auto tpt = tup(ty_param_count, result_ty);
@@ -750,9 +747,9 @@ fn collect_item_types(session.session sess, @ast.crate crate)
let method meth_ty = meth_tys.(ix); let method meth_ty = meth_tys.(ix);
let ast.method_ m_; let ast.method_ m_;
let @ast.method m; let @ast.method m;
auto meth_tfn = plain_ty(ty.ty_fn(meth_ty.proto, auto meth_tfn = ty.mk_fn(meth_ty.proto,
meth_ty.inputs, meth_ty.inputs,
meth_ty.output)); meth_ty.output);
m_ = rec(ann=triv_ann(meth_tfn) m_ = rec(ann=triv_ann(meth_tfn)
with meth.node with meth.node
); );
@@ -773,8 +770,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
case (some[@ast.method](?d)) { case (some[@ast.method](?d)) {
let vec[arg] inputs = vec(); let vec[arg] inputs = vec();
let @ty.t output = @rec(struct=ty.ty_nil, cname=none[str]); let @ty.t output = @rec(struct=ty.ty_nil, cname=none[str]);
auto dtor_tfn = plain_ty(ty.ty_fn(ast.proto_fn, auto dtor_tfn = ty.mk_fn(ast.proto_fn, inputs, output);
inputs, output));
auto d_ = rec(ann=triv_ann(dtor_tfn) with d.node); auto d_ = rec(ann=triv_ann(dtor_tfn) with d.node);
dtor = some[@ast.method](@rec(node=d_ with *d)); dtor = some[@ast.method](@rec(node=d_ with *d));
} }
@@ -836,8 +832,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
mod Unify { mod Unify {
fn simple(@fn_ctxt fcx, @ty.t expected, @ty.t actual) -> ty.unify_result { fn simple(@fn_ctxt fcx, @ty.t expected, @ty.t actual) -> ty.unify_result {
// FIXME: horrid botch // FIXME: horrid botch
let vec[mutable @ty.t] param_substs = let vec[mutable @ty.t] param_substs = vec(mutable ty.mk_nil());
vec(mutable plain_ty(ty.ty_nil));
_vec.pop[mutable @ty.t](param_substs); _vec.pop[mutable @ty.t](param_substs);
ret with_params(fcx, expected, actual, param_substs); ret with_params(fcx, expected, actual, param_substs);
} }
@@ -891,7 +886,7 @@ mod Unify {
alt (result) { alt (result) {
case (ty.ures_ok(?new_subst)) { case (ty.ures_ok(?new_subst)) {
param_substs.(index) = new_subst; param_substs.(index) = new_subst;
ret ty.ures_ok(plain_ty(ty.ty_bound_param(index))); ret ty.ures_ok(ty.mk_bound_param(index));
} }
case (_) { ret result; } case (_) { ret result; }
} }
@@ -924,7 +919,7 @@ fn strip_boxes(@ty.t t) -> @ty.t {
fn add_boxes(uint n, @ty.t t) -> @ty.t { fn add_boxes(uint n, @ty.t t) -> @ty.t {
auto t1 = t; auto t1 = t;
while (n != 0u) { while (n != 0u) {
t1 = ty.plain_box_ty(t1, ast.imm); t1 = ty.mk_imm_box(t1);
n -= 1u; n -= 1u;
} }
ret t1; ret t1;
@@ -978,8 +973,7 @@ mod Demand {
implicit_boxes = count_boxes(actual); implicit_boxes = count_boxes(actual);
} }
let vec[mutable @ty.t] ty_param_substs = let vec[mutable @ty.t] ty_param_substs = vec(mutable ty.mk_nil());
vec(mutable plain_ty(ty.ty_nil));
_vec.pop[mutable @ty.t](ty_param_substs); // FIXME: horrid botch _vec.pop[mutable @ty.t](ty_param_substs); // FIXME: horrid botch
for (@ty.t ty_param_subst in ty_param_substs_0) { for (@ty.t ty_param_subst in ty_param_substs_0) {
ty_param_substs += vec(mutable ty_param_subst); ty_param_substs += vec(mutable ty_param_subst);
@@ -1402,7 +1396,7 @@ mod Pushdown {
let @ast.expr es_1; let @ast.expr es_1;
alt (t.struct) { alt (t.struct) {
case (ty.ty_chan(?subty)) { case (ty.ty_chan(?subty)) {
auto pt = plain_ty(ty.ty_port(subty)); auto pt = ty.mk_port(subty);
es_1 = pushdown_expr(fcx, pt, es); es_1 = pushdown_expr(fcx, pt, es);
} }
case (_) { case (_) {
@@ -1430,8 +1424,7 @@ mod Pushdown {
auto lval_1 = pushdown_expr(fcx, next_ty_var(fcx.ccx), auto lval_1 = pushdown_expr(fcx, next_ty_var(fcx.ccx),
lval_0); lval_0);
auto t = expr_ty(lval_1); auto t = expr_ty(lval_1);
auto expr_1 = pushdown_expr(fcx, plain_ty(ty.ty_port(t)), auto expr_1 = pushdown_expr(fcx, ty.mk_port(t), expr_0);
expr_0);
e_1 = ast.expr_recv(lval_1, expr_1, ann); e_1 = ast.expr_recv(lval_1, expr_1, ann);
} }
@@ -1439,8 +1432,7 @@ mod Pushdown {
auto expr_1 = pushdown_expr(fcx, next_ty_var(fcx.ccx), auto expr_1 = pushdown_expr(fcx, next_ty_var(fcx.ccx),
expr_0); expr_0);
auto t = expr_ty(expr_1); auto t = expr_ty(expr_1);
auto lval_1 = pushdown_expr(fcx, plain_ty(ty.ty_chan(t)), auto lval_1 = pushdown_expr(fcx, ty.mk_chan(t), lval_0);
lval_0);
e_1 = ast.expr_send(lval_1, expr_1, ann); e_1 = ast.expr_send(lval_1, expr_1, ann);
} }
@@ -1468,7 +1460,7 @@ mod Pushdown {
ret fold.respan[ast.block_](bloc.span, block_); ret fold.respan[ast.block_](bloc.span, block_);
} }
case (none[@ast.expr]) { case (none[@ast.expr]) {
Demand.simple(fcx, bloc.span, expected, plain_ty(ty.ty_nil)); Demand.simple(fcx, bloc.span, expected, ty.mk_nil());
ret fold.respan[ast.block_](bloc.span, ret fold.respan[ast.block_](bloc.span,
rec(a = boring_ann() with bloc.node)); rec(a = boring_ann() with bloc.node));
} }
@@ -1547,21 +1539,20 @@ fn resolve_local_types_in_block(&@fn_ctxt fcx, &ast.block block)
// AST fragment checking // AST fragment checking
fn check_lit(@ast.lit lit) -> @ty.t { fn check_lit(@ast.lit lit) -> @ty.t {
auto sty;
alt (lit.node) { alt (lit.node) {
case (ast.lit_str(_)) { sty = ty.ty_str; } case (ast.lit_str(_)) { ret ty.mk_str(); }
case (ast.lit_char(_)) { sty = ty.ty_char; } case (ast.lit_char(_)) { ret ty.mk_char(); }
case (ast.lit_int(_)) { sty = ty.ty_int; } case (ast.lit_int(_)) { ret ty.mk_int(); }
case (ast.lit_float(_)) { sty = ty.ty_float; } case (ast.lit_float(_)) { ret ty.mk_float(); }
case (ast.lit_mach_float(?tm, _)) case (ast.lit_mach_float(?tm, _))
{ sty = ty.ty_machine(tm); } { ret ty.mk_mach(tm); }
case (ast.lit_uint(_)) { sty = ty.ty_uint; } case (ast.lit_uint(_)) { ret ty.mk_uint(); }
case (ast.lit_mach_int(?tm, _)) { sty = ty.ty_machine(tm); } case (ast.lit_mach_int(?tm, _)) { ret ty.mk_mach(tm); }
case (ast.lit_nil) { sty = ty.ty_nil; } case (ast.lit_nil) { ret ty.mk_nil(); }
case (ast.lit_bool(_)) { sty = ty.ty_bool; } case (ast.lit_bool(_)) { ret ty.mk_bool(); }
} }
ret plain_ty(sty); fail; // not reached
} }
fn check_pat(&@fn_ctxt fcx, @ast.pat pat) -> @ast.pat { fn check_pat(&@fn_ctxt fcx, @ast.pat pat) -> @ast.pat {
@@ -1677,10 +1668,10 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
auto t_0; auto t_0;
alt (expr_ty(f_0).struct) { alt (expr_ty(f_0).struct) {
case (ty.ty_fn(?proto, _, _)) { case (ty.ty_fn(?proto, _, _)) {
t_0 = plain_ty(ty.ty_fn(proto, arg_tys_0, rt_0)); t_0 = ty.mk_fn(proto, arg_tys_0, rt_0);
} }
case (ty.ty_native_fn(?abi, _, _)) { case (ty.ty_native_fn(?abi, _, _)) {
t_0 = plain_ty(ty.ty_native_fn(abi, arg_tys_0, rt_0)); t_0 = ty.mk_native_fn(abi, arg_tys_0, rt_0);
} }
case (_) { case (_) {
log_err "check_call_or_bind(): fn expr doesn't have fn type"; log_err "check_call_or_bind(): fn expr doesn't have fn type";
@@ -1755,12 +1746,12 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
auto t = strip_boxes(lhs_t0); auto t = strip_boxes(lhs_t0);
alt (binop) { alt (binop) {
case (ast.eq) { t = plain_ty(ty.ty_bool); } case (ast.eq) { t = ty.mk_bool(); }
case (ast.lt) { t = plain_ty(ty.ty_bool); } case (ast.lt) { t = ty.mk_bool(); }
case (ast.le) { t = plain_ty(ty.ty_bool); } case (ast.le) { t = ty.mk_bool(); }
case (ast.ne) { t = plain_ty(ty.ty_bool); } case (ast.ne) { t = ty.mk_bool(); }
case (ast.ge) { t = plain_ty(ty.ty_bool); } case (ast.ge) { t = ty.mk_bool(); }
case (ast.gt) { t = plain_ty(ty.ty_bool); } case (ast.gt) { t = ty.mk_bool(); }
case (_) { /* fall through */ } case (_) { /* fall through */ }
} }
@@ -1776,7 +1767,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
auto oper_t = expr_ty(oper_1); auto oper_t = expr_ty(oper_1);
alt (unop) { alt (unop) {
case (ast.box(?mut)) { case (ast.box(?mut)) {
oper_t = ty.plain_box_ty(oper_t, mut); oper_t = ty.mk_box(rec(ty=oper_t, mut=mut));
} }
case (ast.deref) { case (ast.deref) {
alt (oper_t.struct) { alt (oper_t.struct) {
@@ -1800,7 +1791,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
} }
case (ast.expr_path(?pth, ?defopt, _)) { case (ast.expr_path(?pth, ?defopt, _)) {
auto t = plain_ty(ty.ty_nil); auto t = ty.mk_nil();
check (defopt != none[ast.def]); check (defopt != none[ast.def]);
auto defn = option.get[ast.def](defopt); auto defn = option.get[ast.def](defopt);
@@ -1851,7 +1842,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
case (ast.expr_ret(?expr_opt, _)) { case (ast.expr_ret(?expr_opt, _)) {
alt (expr_opt) { alt (expr_opt) {
case (none[@ast.expr]) { case (none[@ast.expr]) {
auto nil = plain_ty(ty.ty_nil); auto nil = ty.mk_nil();
if (!are_compatible(fcx, fcx.ret_ty, nil)) { if (!are_compatible(fcx, fcx.ret_ty, nil)) {
fcx.ccx.sess.err("ret; in function " fcx.ccx.sess.err("ret; in function "
+ "returning non-nil"); + "returning non-nil");
@@ -1875,7 +1866,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
case (ast.expr_put(?expr_opt, _)) { case (ast.expr_put(?expr_opt, _)) {
alt (expr_opt) { alt (expr_opt) {
case (none[@ast.expr]) { case (none[@ast.expr]) {
auto nil = plain_ty(ty.ty_nil); auto nil = ty.mk_nil();
if (!are_compatible(fcx, fcx.ret_ty, nil)) { if (!are_compatible(fcx, fcx.ret_ty, nil)) {
fcx.ccx.sess.err("put; in function " fcx.ccx.sess.err("put; in function "
+ "putting non-nil"); + "putting non-nil");
@@ -1914,8 +1905,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
case (ast.expr_check_expr(?e, _)) { case (ast.expr_check_expr(?e, _)) {
auto expr_t = check_expr(fcx, e); auto expr_t = check_expr(fcx, e);
Demand.simple(fcx, expr.span, plain_ty(ty.ty_bool), Demand.simple(fcx, expr.span, ty.mk_bool(), expr_ty(expr_t));
expr_ty(expr_t));
ret @fold.respan[ast.expr_] ret @fold.respan[ast.expr_]
(expr.span, ast.expr_check_expr(expr_t, boring_ann())); (expr.span, ast.expr_check_expr(expr_t, boring_ann()));
} }
@@ -1942,7 +1932,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
auto rhs_0 = check_expr(fcx, rhs); auto rhs_0 = check_expr(fcx, rhs);
auto rhs_t = expr_ty(rhs_0); auto rhs_t = expr_ty(rhs_0);
auto chan_t = plain_ty(ty.ty_chan(rhs_t)); auto chan_t = ty.mk_chan(rhs_t);
auto lhs_1 = Pushdown.pushdown_expr(fcx, chan_t, lhs_0); auto lhs_1 = Pushdown.pushdown_expr(fcx, chan_t, lhs_0);
auto item_t; auto item_t;
alt (expr_ty(lhs_1).struct) { alt (expr_ty(lhs_1).struct) {
@@ -1965,7 +1955,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
auto rhs_0 = check_expr(fcx, rhs); auto rhs_0 = check_expr(fcx, rhs);
auto lhs_t1 = expr_ty(lhs_0); auto lhs_t1 = expr_ty(lhs_0);
auto port_t = plain_ty(ty.ty_port(lhs_t1)); auto port_t = ty.mk_port(lhs_t1);
auto rhs_1 = Pushdown.pushdown_expr(fcx, port_t, rhs_0); auto rhs_1 = Pushdown.pushdown_expr(fcx, port_t, rhs_0);
auto item_t; auto item_t;
alt (expr_ty(rhs_0).struct) { alt (expr_ty(rhs_0).struct) {
@@ -1985,8 +1975,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
case (ast.expr_if(?cond, ?thn, ?elsopt, _)) { case (ast.expr_if(?cond, ?thn, ?elsopt, _)) {
auto cond_0 = check_expr(fcx, cond); auto cond_0 = check_expr(fcx, cond);
auto cond_1 = Pushdown.pushdown_expr(fcx, plain_ty(ty.ty_bool), auto cond_1 = Pushdown.pushdown_expr(fcx, ty.mk_bool(), cond_0);
cond_0);
auto thn_0 = check_block(fcx, thn); auto thn_0 = check_block(fcx, thn);
auto thn_t = block_ty(thn_0); auto thn_t = block_ty(thn_0);
@@ -2002,7 +1991,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
} }
case (none[@ast.expr]) { case (none[@ast.expr]) {
elsopt_1 = none[@ast.expr]; elsopt_1 = none[@ast.expr];
elsopt_t = plain_ty(ty.ty_nil); elsopt_t = ty.mk_nil();
} }
} }
@@ -2022,7 +2011,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
// FIXME: enforce that the type of the decl is the element type // FIXME: enforce that the type of the decl is the element type
// of the seq. // of the seq.
auto ann = triv_ann(plain_ty(ty.ty_nil)); auto ann = triv_ann(ty.mk_nil());
ret @fold.respan[ast.expr_](expr.span, ret @fold.respan[ast.expr_](expr.span,
ast.expr_for(decl_1, seq_1, ast.expr_for(decl_1, seq_1,
body_1, ann)); body_1, ann));
@@ -2033,7 +2022,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
auto seq_1 = check_expr(fcx, seq); auto seq_1 = check_expr(fcx, seq);
auto body_1 = check_block(fcx, body); auto body_1 = check_block(fcx, body);
auto ann = triv_ann(plain_ty(ty.ty_nil)); auto ann = triv_ann(ty.mk_nil());
ret @fold.respan[ast.expr_](expr.span, ret @fold.respan[ast.expr_](expr.span,
ast.expr_for_each(decl_1, seq_1, ast.expr_for_each(decl_1, seq_1,
body_1, ann)); body_1, ann));
@@ -2041,19 +2030,17 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
case (ast.expr_while(?cond, ?body, _)) { case (ast.expr_while(?cond, ?body, _)) {
auto cond_0 = check_expr(fcx, cond); auto cond_0 = check_expr(fcx, cond);
auto cond_1 = Pushdown.pushdown_expr(fcx, plain_ty(ty.ty_bool), auto cond_1 = Pushdown.pushdown_expr(fcx, ty.mk_bool(), cond_0);
cond_0);
auto body_1 = check_block(fcx, body); auto body_1 = check_block(fcx, body);
auto ann = triv_ann(plain_ty(ty.ty_nil)); auto ann = triv_ann(ty.mk_nil());
ret @fold.respan[ast.expr_](expr.span, ret @fold.respan[ast.expr_](expr.span,
ast.expr_while(cond_1, body_1, ann)); ast.expr_while(cond_1, body_1, ann));
} }
case (ast.expr_do_while(?body, ?cond, _)) { case (ast.expr_do_while(?body, ?cond, _)) {
auto cond_0 = check_expr(fcx, cond); auto cond_0 = check_expr(fcx, cond);
auto cond_1 = Pushdown.pushdown_expr(fcx, plain_ty(ty.ty_bool), auto cond_1 = Pushdown.pushdown_expr(fcx, ty.mk_bool(), cond_0);
cond_0);
auto body_1 = check_block(fcx, body); auto body_1 = check_block(fcx, body);
auto ann = triv_ann(block_ty(body_1)); auto ann = triv_ann(block_ty(body_1));
@@ -2120,7 +2107,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
ann = triv_ann(expr_ty(expr)); ann = triv_ann(expr_ty(expr));
} }
case (none[@ast.expr]) { case (none[@ast.expr]) {
ann = triv_ann(plain_ty(ty.ty_nil)); ann = triv_ann(ty.mk_nil());
} }
} }
ret @fold.respan[ast.expr_](expr.span, ret @fold.respan[ast.expr_](expr.span,
@@ -2159,7 +2146,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
} }
} }
auto t_1 = plain_ty(ty.ty_fn(proto_1, arg_tys_1, rt_1)); auto t_1 = ty.mk_fn(proto_1, arg_tys_1, rt_1);
auto ann = triv_ann(t_1); auto ann = triv_ann(t_1);
ret @fold.respan[ast.expr_](expr.span, ret @fold.respan[ast.expr_](expr.span,
ast.expr_bind(result._0, result._1, ast.expr_bind(result._0, result._1,
@@ -2172,7 +2159,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
auto args_1 = result._1; auto args_1 = result._1;
// Pull the return type out of the type of the function. // Pull the return type out of the type of the function.
auto rt_1 = plain_ty(ty.ty_nil); // FIXME: typestate botch auto rt_1 = ty.mk_nil(); // FIXME: typestate botch
alt (expr_ty(f_1).struct) { alt (expr_ty(f_1).struct) {
case (ty.ty_fn(_,_,?rt)) { rt_1 = rt; } case (ty.ty_fn(_,_,?rt)) { rt_1 = rt; }
case (ty.ty_native_fn(_, _, ?rt)) { rt_1 = rt; } case (ty.ty_native_fn(_, _, ?rt)) { rt_1 = rt; }
@@ -2188,7 +2175,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
} }
case (ast.expr_self_method(?id, _)) { case (ast.expr_self_method(?id, _)) {
auto t = plain_ty(ty.ty_nil); auto t = ty.mk_nil();
let @ty.t this_obj_ty; let @ty.t this_obj_ty;
// Grab the type of the current object // Grab the type of the current object
@@ -2246,7 +2233,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
// FIXME: Other typechecks needed // FIXME: Other typechecks needed
auto ann = triv_ann(plain_ty(ty.ty_task)); auto ann = triv_ann(ty.mk_task());
ret @fold.respan[ast.expr_](expr.span, ret @fold.respan[ast.expr_](expr.span,
ast.expr_spawn(dom, name, ast.expr_spawn(dom, name,
f_1, args_1, ann)); f_1, args_1, ann));
@@ -2288,8 +2275,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
_vec.push[@ast.expr](args_1,expr_1); _vec.push[@ast.expr](args_1,expr_1);
} }
auto vec_sty = ty.ty_vec(rec(ty=t, mut=mut)); auto ann = triv_ann(ty.mk_vec(rec(ty=t, mut=mut)));
auto ann = triv_ann(plain_ty(vec_sty));
ret @fold.respan[ast.expr_](expr.span, ret @fold.respan[ast.expr_](expr.span,
ast.expr_vec(args_1, mut, ann)); ast.expr_vec(args_1, mut, ann));
} }
@@ -2305,7 +2291,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
elts_mt += vec(rec(ty=expr_t, mut=e.mut)); elts_mt += vec(rec(ty=expr_t, mut=e.mut));
} }
auto ann = triv_ann(plain_ty(ty.ty_tup(elts_mt))); auto ann = triv_ann(ty.mk_tup(elts_mt));
ret @fold.respan[ast.expr_](expr.span, ret @fold.respan[ast.expr_](expr.span,
ast.expr_tup(elts_1, ann)); ast.expr_tup(elts_1, ann));
} }
@@ -2336,7 +2322,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
alt (base) { alt (base) {
case (none[@ast.expr]) { case (none[@ast.expr]) {
ann = triv_ann(plain_ty(ty.ty_rec(fields_t))); ann = triv_ann(ty.mk_rec(fields_t));
} }
case (some[@ast.expr](?bexpr)) { case (some[@ast.expr](?bexpr)) {
@@ -2421,8 +2407,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
"bad index on obj"); "bad index on obj");
} }
auto meth = methods.(ix); auto meth = methods.(ix);
auto t = plain_ty(ty.ty_fn(meth.proto, auto t = ty.mk_fn(meth.proto, meth.inputs, meth.output);
meth.inputs, meth.output));
auto ann = triv_ann(t); auto ann = triv_ann(t);
ret @fold.respan[ast.expr_](expr.span, ret @fold.respan[ast.expr_](expr.span,
ast.expr_field(base_1, ast.expr_field(base_1,
@@ -2466,8 +2451,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
"non-integral type of str index: " "non-integral type of str index: "
+ ty_to_str(idx_t)); + ty_to_str(idx_t));
} }
auto t = ty.ty_machine(common.ty_u8); auto ann = triv_ann(ty.mk_mach(common.ty_u8));
auto ann = triv_ann(plain_ty(t));
ret @fold.respan[ast.expr_](expr.span, ret @fold.respan[ast.expr_](expr.span,
ast.expr_index(base_1, ast.expr_index(base_1,
idx_1, idx_1,
@@ -2484,7 +2468,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
case (ast.expr_port(_)) { case (ast.expr_port(_)) {
auto t = next_ty_var(fcx.ccx); auto t = next_ty_var(fcx.ccx);
auto pt = plain_ty(ty.ty_port(t)); auto pt = ty.mk_port(t);
auto ann = triv_ann(pt); auto ann = triv_ann(pt);
ret @fold.respan[ast.expr_](expr.span, ast.expr_port(ann)); ret @fold.respan[ast.expr_](expr.span, ast.expr_port(ann));
} }
@@ -2494,7 +2478,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
auto port_t = expr_ty(expr_1); auto port_t = expr_ty(expr_1);
alt (port_t.struct) { alt (port_t.struct) {
case (ty.ty_port(?subtype)) { case (ty.ty_port(?subtype)) {
auto ct = plain_ty(ty.ty_chan(subtype)); auto ct = ty.mk_chan(subtype);
auto ann = triv_ann(ct); auto ann = triv_ann(ct);
ret @fold.respan[ast.expr_](expr.span, ret @fold.respan[ast.expr_](expr.span,
ast.expr_chan(expr_1, ann)); ast.expr_chan(expr_1, ann));
@@ -2516,7 +2500,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
} }
fn next_ty_var(@crate_ctxt ccx) -> @ty.t { fn next_ty_var(@crate_ctxt ccx) -> @ty.t {
auto t = plain_ty(ty.ty_var(ccx.next_var_id)); auto t = ty.mk_var(ccx.next_var_id);
ccx.next_var_id += 1; ccx.next_var_id += 1;
ret t; ret t;
} }
@@ -2527,7 +2511,7 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast.decl decl) -> @ast.decl {
auto t; auto t;
t = plain_ty(middle.ty.ty_nil); t = middle.ty.mk_nil();
alt (local.ty) { alt (local.ty) {
case (none[@ast.ty]) { case (none[@ast.ty]) {
@@ -2553,14 +2537,14 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast.decl decl) -> @ast.decl {
alt (local.init) { alt (local.init) {
case (some[ast.initializer](?init)) { case (some[ast.initializer](?init)) {
auto expr_0 = check_expr(fcx, init.expr); auto expr_0 = check_expr(fcx, init.expr);
auto lty = plain_ty(ty.ty_local(local.id)); auto lty = ty.mk_local(local.id);
auto expr_1; auto expr_1;
alt (init.op) { alt (init.op) {
case (ast.init_assign) { case (ast.init_assign) {
expr_1 = Pushdown.pushdown_expr(fcx, lty, expr_0); expr_1 = Pushdown.pushdown_expr(fcx, lty, expr_0);
} }
case (ast.init_recv) { case (ast.init_recv) {
auto port_ty = plain_ty(ty.ty_port(lty)); auto port_ty = ty.mk_port(lty);
expr_1 = Pushdown.pushdown_expr(fcx, port_ty, expr_1 = Pushdown.pushdown_expr(fcx, port_ty,
expr_0); expr_0);
} }
@@ -2692,8 +2676,7 @@ fn check_item_fn(&@crate_ctxt ccx, &span sp, ast.ident ident, &ast._fn f,
} }
auto output_ty = ast_ty_to_ty_crate(ccx, f.decl.output); auto output_ty = ast_ty_to_ty_crate(ccx, f.decl.output);
auto fn_sty = ty.ty_fn(f.proto, inputs, output_ty); auto fn_ann = triv_ann(ty.mk_fn(f.proto, inputs, output_ty));
auto fn_ann = triv_ann(plain_ty(fn_sty));
auto item = ast.item_fn(ident, f, ty_params, id, fn_ann); auto item = ast.item_fn(ident, f, ty_params, id, fn_ann);
ret @fold.respan[ast.item_](sp, item); ret @fold.respan[ast.item_](sp, item);

View File

@@ -111,7 +111,7 @@ fn field_exprs(vec[ast.field] fields) -> vec [@ast.expr] {
} }
fn plain_ann() -> ast.ann { fn plain_ann() -> ast.ann {
ret ast.ann_type(middle.ty.plain_ty(middle.ty.ty_nil), ret ast.ann_type(middle.ty.mk_nil(),
none[vec[@middle.ty.t]], none[@ts_ann]); none[vec[@middle.ty.t]], none[@ts_ann]);
} }