提交 29ea8754 编写于 作者: M Marijn Haverbeke

Tuple fields are immutable

上级 9538b003
......@@ -239,7 +239,7 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
'T' {
assert (next(st) as char == '[');
let params = ~[];
while peek(st) as char != ']' { params += ~[parse_mt(st, sd)]; }
while peek(st) as char != ']' { params += ~[parse_ty(st, sd)]; }
st.pos = st.pos + 1u;
ret ty::mk_tup(st.tcx, params);
}
......
......@@ -120,9 +120,9 @@ fn enc_sty(w: &io::writer, cx: &@ctxt, st: &ty::sty) {
for t: ty::t in tys { enc_ty(w, cx, t); }
w.write_char(']');
}
ty::ty_tup(mts) {
ty::ty_tup(ts) {
w.write_str("T[");
for mt in mts { enc_mt(w, cx, mt); }
for t in ts { enc_ty(w, cx, t); }
w.write_char(']');
}
ty::ty_box(mt) { w.write_char('@'); enc_mt(w, cx, mt); }
......
......@@ -678,9 +678,9 @@ fn helper(tcx: &ty::ctxt, needle: ty::t, haystack: ty::t, mut: bool) ->
}
ret false;
}
ty::ty_tup(mts) {
for mt in mts {
if helper(tcx, needle, mt.ty, get_mut(mut, mt)) {
ty::ty_tup(ts) {
for t in ts {
if helper(tcx, needle, t, mut) {
ret true;
}
}
......
......@@ -48,7 +48,7 @@ fn type_is_gc_relevant(cx: &ty::ctxt, ty: &ty::t) -> bool {
}
ty::ty_tup(elts) {
for elt in elts {
if type_is_gc_relevant(cx, elt.ty) { ret true; }
if type_is_gc_relevant(cx, elt) { ret true; }
}
ret false;
}
......
......@@ -174,7 +174,7 @@ fn largest_variants(ccx : &@crate_ctxt, tag_id : &ast::def_id) -> [uint] {
ret result;
}
// Computes the static size of a tag, without using mk_imm_tup(), which is
// Computes the static size of a tag, without using mk_tup(), which is
// bad for performance.
//
// TODO: Migrate trans over to use this.
......@@ -374,7 +374,7 @@ fn shape_of(ccx : &@crate_ctxt, t : ty::t) -> [u8] {
ty::ty_tup(elts) {
s += ~[shape_struct];
let sub = ~[];
for elt in elts { sub += shape_of(ccx, elt.ty); }
for elt in elts { sub += shape_of(ccx, elt); }
add_substr(s, sub);
}
......
......@@ -256,7 +256,7 @@ fn type_of_inner(cx: &@crate_ctxt, sp: &span, t: &ty::t) -> TypeRef {
ty::ty_tup(elts) {
let tys = ~[];
for elt in elts {
tys += ~[type_of_inner(cx, sp, elt.ty)];
tys += ~[type_of_inner(cx, sp, elt)];
}
llty = T_struct(tys);
}
......@@ -490,20 +490,20 @@ fn simplifier(ccx: @crate_ctxt, typ: ty::t) -> ty::t {
ty::ty_uniq(_) { ret ty::mk_uniq(ccx.tcx, ty::mk_nil(ccx.tcx)); }
ty::ty_vec(_) { ret ty::mk_imm_vec(ccx.tcx, ty::mk_nil(ccx.tcx)); }
ty::ty_fn(_, _, _, _, _) {
ret ty::mk_imm_tup(ccx.tcx,
~[ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx)),
ty::mk_imm_box(ccx.tcx,
ty::mk_nil(ccx.tcx))]);
ret ty::mk_tup(ccx.tcx,
~[ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx)),
ty::mk_imm_box(ccx.tcx,
ty::mk_nil(ccx.tcx))]);
}
ty::ty_obj(_) {
ret ty::mk_imm_tup(ccx.tcx,
ret ty::mk_tup(ccx.tcx,
~[ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx)),
ty::mk_imm_box(ccx.tcx,
ty::mk_nil(ccx.tcx))]);
}
ty::ty_res(_, sub, tps) {
let sub1 = ty::substitute_type_params(ccx.tcx, tps, sub);
ret ty::mk_imm_tup(ccx.tcx,
ret ty::mk_tup(ccx.tcx,
~[ty::mk_int(ccx.tcx),
simplify_type(ccx, sub1)]);
}
......@@ -530,7 +530,7 @@ fn static_size_of_tag(cx: &@crate_ctxt, sp: &span, t: &ty::t) -> uint {
let variants = ty::tag_variants(cx.tcx, tid);
for variant: ty::variant_info in variants {
let tup_ty =
simplify_type(cx, ty::mk_imm_tup(cx.tcx, variant.args));
simplify_type(cx, ty::mk_tup(cx.tcx, variant.args));
// Perform any type parameter substitutions.
tup_ty = ty::substitute_type_params(cx.tcx, subtys, tup_ty);
......@@ -586,7 +586,7 @@ fn align_elements(cx: &@block_ctxt, elts: &[ty::t]) -> result {
}
ty::ty_tup(elts) {
let tys = ~[];
for mt in elts { tys += ~[mt.ty]; }
for tp in elts { tys += ~[tp]; }
ret align_elements(cx, tys);
}
ty::ty_tag(tid, tps) {
......@@ -661,7 +661,7 @@ fn dynamic_align_of(cx: &@block_ctxt, t: &ty::t) -> result {
let a = C_int(1);
let bcx = cx;
for e in elts {
let align = align_of(bcx, e.ty);
let align = align_of(bcx, e);
bcx = align.bcx;
a = umax(bcx, a, align.val);
}
......@@ -766,7 +766,7 @@ fn split_type(ccx: &@crate_ctxt, t: &ty::t, ixs: &[int], n: uint) ->
let args = ~[];
for typ: ty::t in s.prefix { args += ~[typ]; }
let prefix_ty = ty::mk_imm_tup(bcx_tcx(cx), args);
let prefix_ty = ty::mk_tup(bcx_tcx(cx), args);
let bcx = cx;
let sz = size_of(bcx, prefix_ty);
......@@ -795,7 +795,7 @@ fn GEP_tag(cx: @block_ctxt, llblobptr: ValueRef, tag_id: &ast::def_id,
if i == ix { elem_ty = arg_ty; }
i += 1;
}
let tup_ty = ty::mk_imm_tup(bcx_tcx(cx), true_arg_tys);
let tup_ty = ty::mk_tup(bcx_tcx(cx), true_arg_tys);
// Cast the blob pointer to the appropriate type, if we need to (i.e. if
// the blob pointer isn't dynamically sized).
......@@ -858,7 +858,7 @@ fn trans_malloc_boxed_raw(cx: &@block_ctxt, t: ty::t) -> result {
// The mk_int here is the space being
// reserved for the refcount.
let boxed_body =
ty::mk_imm_tup(bcx_tcx(cx), ~[ty::mk_int(bcx_tcx(cx)), t]);
ty::mk_tup(bcx_tcx(cx), ~[ty::mk_int(bcx_tcx(cx)), t]);
let box_ptr = ty::mk_imm_box(bcx_tcx(cx), t);
let sz = size_of(cx, boxed_body);
......@@ -1497,7 +1497,7 @@ fn trans_res_drop(cx: @block_ctxt, rs: ValueRef, did: &ast::def_id,
inner_t: ty::t, tps: &[ty::t]) -> result {
let ccx = bcx_ccx(cx);
let inner_t_s = ty::substitute_type_params(ccx.tcx, tps, inner_t);
let tup_ty = ty::mk_imm_tup(ccx.tcx, ~[ty::mk_int(ccx.tcx), inner_t_s]);
let tup_ty = ty::mk_tup(ccx.tcx, ~[ty::mk_int(ccx.tcx), inner_t_s]);
let drop_cx = new_sub_block_ctxt(cx, "drop res");
let next_cx = new_sub_block_ctxt(cx, "next");
......@@ -1846,8 +1846,7 @@ fn iter_variant(cx: @block_ctxt, a_tup: ValueRef,
for arg in args {
r = GEP_tup_like(r.bcx, t, av, ~[0, i]);
let llfld_a = r.val;
r = f(r.bcx, load_if_immediate(r.bcx, llfld_a, arg.ty),
arg.ty);
r = f(r.bcx, load_if_immediate(r.bcx, llfld_a, arg), arg);
i += 1;
}
}
......@@ -1855,7 +1854,7 @@ fn iter_variant(cx: @block_ctxt, a_tup: ValueRef,
let tcx = bcx_tcx(cx);
let inner1 = ty::substitute_type_params(tcx, tps, inner);
let inner_t_s = ty::substitute_type_params(tcx, tps, inner);
let tup_t = ty::mk_imm_tup(tcx, ~[ty::mk_int(tcx), inner_t_s]);
let tup_t = ty::mk_tup(tcx, ~[ty::mk_int(tcx), inner_t_s]);
r = GEP_tup_like(r.bcx, tup_t, av, ~[0, 1]);
let llfld_a = r.val;
r = f(r.bcx, load_if_immediate(r.bcx, llfld_a, inner1), inner1);
......@@ -3516,7 +3515,7 @@ fn build_environment(bcx: @block_ctxt, lltydescs: [ValueRef],
// First, synthesize a tuple type containing the types of all the
// bound expressions.
// bindings_ty = ~[bound_ty1, bound_ty2, ...]
let bindings_ty: ty::t = ty::mk_imm_tup(bcx_tcx(bcx), bound_tys);
let bindings_ty: ty::t = ty::mk_tup(bcx_tcx(bcx), bound_tys);
// 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
......@@ -3536,17 +3535,17 @@ fn build_environment(bcx: @block_ctxt, lltydescs: [ValueRef],
// closure_tys = [tydesc_ty, [bound_ty1, bound_ty2, ...], [tydesc_ty,
// tydesc_ty, ...]]
let closure_tys: [ty::t] =
~[tydesc_ty, bindings_ty, ty::mk_imm_tup(bcx_tcx(bcx), captured_tys)];
~[tydesc_ty, bindings_ty, ty::mk_tup(bcx_tcx(bcx), captured_tys)];
// Finally, synthesize a type for that whole vector.
let closure_ty: ty::t = ty::mk_imm_tup(bcx_tcx(bcx), closure_tys);
let closure_ty: ty::t = ty::mk_tup(bcx_tcx(bcx), closure_tys);
// Allocate a box that can hold something closure-sized.
let r = if copying {
trans_malloc_boxed(bcx, closure_ty)
} else {
// We need to dummy up a box on the stack
let ty = ty::mk_imm_tup(bcx_tcx(bcx),
let ty = ty::mk_tup(bcx_tcx(bcx),
~[ty::mk_int(bcx_tcx(bcx)), closure_ty]);
let r = alloc_ty(bcx, ty);
let body = GEPi(bcx, r.val, ~[0, abi::box_rc_field_body]);
......@@ -4769,7 +4768,7 @@ fn trans_call(cx: &@block_ctxt, f: &@ast::expr,
ret rslt(bcx, retval);
}
fn trans_tup(cx: &@block_ctxt, elts: &[ast::elt], id: ast::node_id)
fn trans_tup(cx: &@block_ctxt, elts: &[@ast::expr], id: ast::node_id)
-> result {
let bcx = cx;
let t = node_id_type(bcx.fcx.lcx.ccx, id);
......@@ -4779,8 +4778,8 @@ fn trans_tup(cx: &@block_ctxt, elts: &[ast::elt], id: ast::node_id)
add_clean_temp(cx, tup_val, t);
let i: int = 0;
for e in elts {
let e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e.expr);
let src = trans_lval(bcx, e.expr);
let e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
let src = trans_lval(bcx, e);
bcx = src.res.bcx;
let dst_res = GEP_tup_like(bcx, t, tup_val, ~[0, i]);
bcx = move_val_if_temp(dst_res.bcx, INIT, dst_res.val, src, e_ty).bcx;
......@@ -4813,7 +4812,7 @@ fn trans_vec(cx: &@block_ctxt, args: &[@ast::expr], id: ast::node_id) ->
add_clean_temp(bcx, vec_val, t);
let body = bcx.build.GEP(vec_val, ~[C_int(0), C_int(abi::vec_elt_data)]);
let pseudo_tup_ty =
ty::mk_imm_tup(bcx_tcx(cx),
ty::mk_tup(bcx_tcx(cx),
std::ivec::init_elt[ty::t](unit_ty,
std::ivec::len(args)));
let i: int = 0;
......@@ -5958,7 +5957,7 @@ fn populate_fn_ctxt_from_llself(fcx: @fn_ctxt, llself: val_self_pair) {
// Synthesize a tuple type for the fields so that GEP_tup_like() can work
// its magic.
let fields_tup_ty = ty::mk_imm_tup(fcx.lcx.ccx.tcx, field_tys);
let fields_tup_ty = ty::mk_tup(fcx.lcx.ccx.tcx, field_tys);
let n_typarams = std::ivec::len[ast::ty_param](bcx.fcx.lcx.obj_typarams);
let llobj_box_ty: TypeRef = T_obj_ptr(*bcx_ccx(bcx), n_typarams);
let box_cell =
......@@ -6128,7 +6127,7 @@ fn trans_res_ctor(cx: @local_ctxt, sp: &span, dtor: &ast::_fn,
let bcx = new_top_block_ctxt(fcx);
let lltop = bcx.llbb;
let arg_t = arg_tys_of_fn(cx.ccx, ctor_id).(0).ty;
let tup_t = ty::mk_imm_tup(cx.ccx.tcx, ~[ty::mk_int(cx.ccx.tcx), arg_t]);
let tup_t = ty::mk_tup(cx.ccx.tcx, ~[ty::mk_int(cx.ccx.tcx), arg_t]);
let arg;
alt fcx.llargs.find(dtor.decl.inputs.(0).id) {
some(x) { arg = load_if_immediate(bcx, x, arg_t); }
......
......@@ -122,7 +122,7 @@ fn trans_spawn(cx: &@block_ctxt, dom: &ast::spawn_dom, name: &option::t[str],
}
// Make the tuple.
let args_ty = ty::mk_imm_tup(cx.fcx.lcx.ccx.tcx, arg_tys);
let args_ty = ty::mk_tup(cx.fcx.lcx.ccx.tcx, arg_tys);
// Allocate and fill the tuple.
let llargs = alloc_ty(bcx, args_ty);
......
......@@ -152,7 +152,7 @@ fn trans_obj(cx: @local_ctxt, sp: &span, ob: &ast::_obj,
~[0, abi::obj_body_elt_typarams]);
bcx = body_typarams.bcx;
// TODO: can we just get typarams_ty out of body_ty instead?
let typarams_ty: ty::t = ty::mk_imm_tup(ccx.tcx, tps);
let typarams_ty: ty::t = ty::mk_tup(ccx.tcx, tps);
let i: int = 0;
for tp: ast::ty_param in ty_params {
let typaram = bcx.fcx.lltydescs.(i);
......@@ -174,7 +174,7 @@ fn trans_obj(cx: @local_ctxt, sp: &span, ob: &ast::_obj,
some(arg1) {
let arg = load_if_immediate(bcx, arg1, arg_tys.(i).ty);
// TODO: can we just get fields_ty out of body_ty instead?
let fields_ty: ty::t = ty::mk_imm_tup(ccx.tcx, obj_fields);
let fields_ty: ty::t = ty::mk_tup(ccx.tcx, obj_fields);
let field =
GEP_tup_like(bcx, fields_ty, body_fields.val, ~[0, i]);
bcx = field.bcx;
......@@ -347,7 +347,7 @@ fn trans_anon_obj(bcx: @block_ctxt, sp: &span, anon_obj: &ast::anon_obj,
// have additional field exprs in the AST.
load_if_immediate(bcx, additional_field_vals.(i).val,
additional_field_tys.(i));
let fields_ty: ty::t = ty::mk_imm_tup(ccx.tcx,
let fields_ty: ty::t = ty::mk_tup(ccx.tcx,
additional_field_tys);
let field =
GEP_tup_like(bcx, fields_ty, body_fields.val, ~[0, i]);
......@@ -895,18 +895,18 @@ fn create_object_body_type(tcx: &ty::ctxt, fields_ty: &[ty::t],
maybe_inner_obj_ty: option::t[ty::t]) -> ty::t {
let tydesc_ty: ty::t = ty::mk_type(tcx);
let typarams_ty_tup: ty::t = ty::mk_imm_tup(tcx, typarams_ty);
let fields_ty_tup: ty::t = ty::mk_imm_tup(tcx, fields_ty);
let typarams_ty_tup: ty::t = ty::mk_tup(tcx, typarams_ty);
let fields_ty_tup: ty::t = ty::mk_tup(tcx, fields_ty);
let body_ty: ty::t;
alt maybe_inner_obj_ty {
some(inner_obj_ty) {
body_ty = ty::mk_imm_tup(tcx, ~[tydesc_ty, typarams_ty_tup,
fields_ty_tup, inner_obj_ty]);
body_ty = ty::mk_tup(tcx, ~[tydesc_ty, typarams_ty_tup,
fields_ty_tup, inner_obj_ty]);
}
none {
body_ty = ty::mk_imm_tup(tcx, ~[tydesc_ty, typarams_ty_tup,
fields_ty_tup]);
body_ty = ty::mk_tup(tcx, ~[tydesc_ty, typarams_ty_tup,
fields_ty_tup]);
}
}
......
......@@ -35,7 +35,6 @@
import util::common::new_def_hash;
import util::common::log_expr;
import util::common::log_fn;
import util::common::elt_exprs;
import util::common::field_exprs;
import util::common::has_nonlocal_exits;
import util::common::log_stmt;
......@@ -405,7 +404,7 @@ fn find_pre_post_expr(fcx: &fn_ctxt, e: @expr) {
find_pre_post_exprs(fcx, es, e.id);
}
expr_tup(elts) {
find_pre_post_exprs(fcx, elt_exprs(elts), e.id);
find_pre_post_exprs(fcx, elts, e.id);
}
expr_move(lhs, rhs) { handle_update(fcx, e, lhs, rhs, oper_move); }
expr_swap(lhs, rhs) { handle_update(fcx, e, lhs, rhs, oper_swap); }
......
......@@ -23,7 +23,6 @@
import util::common::log_block;
import util::common::log_block_err;
import util::common::log_fn;
import util::common::elt_exprs;
import util::common::field_exprs;
import util::common::has_nonlocal_exits;
import util::common::log_stmt;
......@@ -392,7 +391,7 @@ fn find_pre_post_state_expr(fcx: &fn_ctxt, pres: &prestate, e: @expr) ->
ret find_pre_post_state_exprs(fcx, pres, e.id,
ivec::init_elt(init_assign,
ivec::len(elts)),
elt_exprs(elts), return);
elts, return);
}
expr_move(lhs, rhs) {
ret find_pre_post_state_two(fcx, pres, lhs, rhs, e.id, oper_move);
......
......@@ -70,7 +70,6 @@
export mk_fn;
export mk_imm_box;
export mk_mut_ptr;
export mk_imm_tup;
export mk_imm_vec;
export mk_int;
export mk_istr;
......@@ -282,7 +281,7 @@ fn method_ty_to_fn_ty(cx: &ctxt, m: method) -> t {
ty_native_fn(ast::native_abi, [arg], t);
ty_obj([method]);
ty_res(def_id, t, [t]);
ty_tup([mt]);
ty_tup([t]);
ty_var(int); // type variable
ty_param(uint, ast::kind); // fn/tag type param
......@@ -306,7 +305,6 @@ fn method_ty_to_fn_ty(cx: &ctxt, m: method) -> t {
terr_box_mutability;
terr_vec_mutability;
terr_tuple_size(uint, uint);
terr_tuple_mutability;
terr_record_size(uint, uint);
terr_record_mutability;
terr_record_fields(ast::ident, ast::ident);
......@@ -491,9 +489,9 @@ fn derive_flags_sig(cx: &ctxt, has_params: &mutable bool,
derive_flags_mt(cx, has_params, has_vars, f.mt);
}
}
ty_tup(mts) {
for m in mts {
derive_flags_mt(cx, has_params, has_vars, m);
ty_tup(ts) {
for tt in ts {
derive_flags_t(cx, has_params, has_vars, tt);
}
}
ty_fn(_, args, tt, _, _) {
......@@ -605,14 +603,7 @@ fn mk_constr(cx: &ctxt, t: &t, cs: &[@type_constr]) -> t {
ret gen_ty(cx, ty_constr(t, cs));
}
fn mk_tup(cx: &ctxt, tms: &[mt]) -> t { ret gen_ty(cx, ty_tup(tms)); }
fn mk_imm_tup(cx: &ctxt, tys: &[t]) -> t {
// TODO: map
let mts = ~[];
for typ in tys { mts += ~[{ty: typ, mut: ast::imm}]; }
ret mk_tup(cx, mts);
}
fn mk_tup(cx: &ctxt, ts: &[t]) -> t { ret gen_ty(cx, ty_tup(ts)); }
fn mk_fn(cx: &ctxt, proto: &ast::proto, args: &[arg], ty: &t,
cf: &controlflow, constrs: &[@constr]) -> t {
......@@ -687,8 +678,8 @@ fn walk_ty(cx: &ctxt, walker: ty_walk, ty: t) {
ty_rec(fields) {
for fl: field in fields { walk_ty(cx, walker, fl.mt.ty); }
}
ty_tup(mts) {
for tm in mts { walk_ty(cx, walker, tm.ty); }
ty_tup(ts) {
for tt in ts { walk_ty(cx, walker, tt); }
}
ty_fn(proto, args, ret_ty, _, _) {
for a: arg in args { walk_ty(cx, walker, a.ty); }
......@@ -775,13 +766,12 @@ fn fold_ty(cx: &ctxt, fld: fold_mode, ty_0: t) -> t {
}
ty = copy_cname(cx, mk_rec(cx, new_fields), ty);
}
ty_tup(mts) {
let new_mts = ~[];
for tm in mts {
let new_subty = fold_ty(cx, fld, tm.ty);
new_mts += ~[{ty: new_subty, mut: tm.mut}];
ty_tup(ts) {
let new_ts = ~[];
for tt in ts {
new_ts += ~[fold_ty(cx, fld, tt)];
}
ty = copy_cname(cx, mk_tup(cx, new_mts), ty);
ty = copy_cname(cx, mk_tup(cx, new_ts), ty);
}
ty_fn(proto, args, ret_ty, cf, constrs) {
let new_args: [arg] = ~[];
......@@ -956,7 +946,7 @@ fn type_is_tup_like(cx: &ctxt, ty: &t) -> bool {
fn get_element_type(cx: &ctxt, ty: &t, i: uint) -> t {
alt struct(cx, ty) {
ty_rec(flds) { ret flds.(i).mt.ty; }
ty_tup(mts) { ret mts.(i).ty; }
ty_tup(ts) { ret ts.(i); }
_ {
cx.sess.bug("get_element_type called on type " + ty_to_str(cx, ty) +
" - expected a \
......@@ -1032,7 +1022,7 @@ fn type_has_pointers(cx: &ctxt, ty: &t) -> bool {
}
ty_tup(elts) {
for m in elts {
if type_has_pointers(cx, m.ty) { result = true; }
if type_has_pointers(cx, m) { result = true; }
}
}
ty_tag(did, tps) {
......@@ -1225,11 +1215,9 @@ fn type_has_dynamic_size(cx: &ctxt, ty: &t) -> bool {
}
ret false;
}
ty_tup(mts) {
let i = 0u;
while i < ivec::len(mts) {
if type_has_dynamic_size(cx, mts.(i).ty) { ret true; }
i += 1u;
ty_tup(ts) {
for tt in ts {
if type_has_dynamic_size(cx, tt) { ret true; }
}
ret false;
}
......@@ -1356,7 +1344,7 @@ fn type_owns_heap_mem(cx: &ctxt, ty: &t) -> bool {
}
ty_tup(elts) {
for m in elts {
if type_owns_heap_mem(cx, m.ty) { result = true; }
if type_owns_heap_mem(cx, m) { result = true; }
}
}
ty_res(_, inner, tps) {
......@@ -1397,7 +1385,7 @@ fn type_is_pod(cx : &ctxt, ty : &t) -> bool {
ty_tag(did, tps) {
let variants = tag_variants(cx, did);
for variant : variant_info in variants {
let tup_ty = mk_imm_tup(cx, variant.args);
let tup_ty = mk_tup(cx, variant.args);
// Perform any type parameter substitutions.
tup_ty = substitute_type_params(cx, tps, tup_ty);
......@@ -1411,7 +1399,7 @@ fn type_is_pod(cx : &ctxt, ty : &t) -> bool {
}
ty_tup(elts) {
for elt in elts {
if !type_is_pod(cx, elt.ty) { result = false; }
if !type_is_pod(cx, elt) { result = false; }
}
}
ty_res(_, inner, tps) {
......@@ -1563,9 +1551,9 @@ fn hash_fn(id: uint, args: &[arg], rty: &t) -> uint {
for f: field in fields { h += h << 5u + hash_ty(f.mt.ty); }
ret h;
}
ty_tup(mts) {
ty_tup(ts) {
let h = 25u;
for tm in mts { h += h << 5u + hash_ty(tm.ty); }
for tt in ts { h += h << 5u + hash_ty(tt); }
ret h;
}
......@@ -1749,14 +1737,14 @@ fn equal_def(did_a: &ast::def_id, did_b: &ast::def_id) -> bool {
_ { ret false; }
}
}
ty_tup(mts_a) {
ty_tup(ts_a) {
alt (b) {
ty_tup(mts_b) {
let len = ivec::len(mts_a);
if len != ivec::len(mts_b) { ret false; }
ty_tup(ts_b) {
let len = ivec::len(ts_a);
if len != ivec::len(ts_b) { ret false; }
let i = 0u;
while i < len {
if !equal_mt(mts_a.(i), mts_b.(i)) { ret false; }
if !eq_ty(ts_a.(i), ts_b.(i)) { ret false; }
i += 1u;
}
ret true;
......@@ -2743,17 +2731,11 @@ fn unify_step(cx: &@ctxt, expected: &t, actual: &t) -> result {
while i < expected_len {
let expected_elem = expected_elems.(i);
let actual_elem = actual_elems.(i);
let mut;
alt unify_mut(expected_elem.mut, actual_elem.mut) {
none. { ret ures_err(terr_tuple_mutability); }
some(m) { mut = m; }
}
let result = unify_step(cx, expected_elem.ty,
actual_elem.ty);
let result = unify_step(cx, expected_elem,
actual_elem);
alt result {
ures_ok(rty) {
let mt = {ty: rty, mut: mut};
result_elems += ~[mt];
result_elems += ~[rty];
}
_ { ret result; }
}
......@@ -2912,9 +2894,6 @@ fn type_err_to_str(err: &ty::type_err) -> str {
" elements but found one with " + uint::to_str(a_sz, 10u)
+ " elements";
}
terr_tuple_mutability. {
ret "tuple elements differ in mutability";
}
terr_record_size(e_sz, a_sz) {
ret "expected a record with " + uint::to_str(e_sz, 10u) +
" fields but found one with " + uint::to_str(a_sz, 10u) +
......
......@@ -340,7 +340,7 @@ fn instantiate(tcx: &ty::ctxt, sp: &span, getter: &ty_getter,
typ = ty::mk_chan(tcx, ast_ty_to_ty(tcx, getter, t));
}
ast::ty_tup(fields) {
let flds = ivec::map(bind ast_mt_to_mt(tcx, getter, _), fields);
let flds = ivec::map(bind ast_ty_to_ty(tcx, getter, _), fields);
typ = ty::mk_tup(tcx, flds);
}
ast::ty_rec(fields) {
......@@ -2178,14 +2178,14 @@ fn check_binop_type_compat(fcx: &@fn_ctxt, span: span, ty: ty::t,
write::ty_only_fixup(fcx, id, typ);
}
ast::expr_tup(elts) {
let elts_mt = ~[];
ivec::reserve(elts_mt, ivec::len(elts));
let elt_ts = ~[];
ivec::reserve(elt_ts, ivec::len(elts));
for e in elts {
check_expr(fcx, e.expr);
let ety = expr_ty(fcx.ccx.tcx, e.expr);
elts_mt += ~[{ty: ety, mut: e.mut}];
check_expr(fcx, e);
let ety = expr_ty(fcx.ccx.tcx, e);
elt_ts += ~[ety];
}
let typ = ty::mk_tup(fcx.ccx.tcx, elts_mt);
let typ = ty::mk_tup(fcx.ccx.tcx, elt_ts);
write::ty_only_fixup(fcx, id, typ);
}
ast::expr_rec(fields, base) {
......
......@@ -273,8 +273,6 @@ fn unop_to_str(op: unop) -> str {
type arm = {pats: [@pat], block: blk};
type elt = {mut: mutability, expr: @expr};
type field_ = {mut: mutability, ident: ident, expr: @expr};
type field = spanned[field_];
......@@ -292,7 +290,7 @@ fn unop_to_str(op: unop) -> str {
expr_vec([@expr], mutability, seq_kind);
expr_rec([field], option::t[@expr]);
expr_call(@expr, [@expr]);
expr_tup([elt]);
expr_tup([@expr]);
expr_self_method(ident);
expr_bind(@expr, [option::t[@expr]]);
expr_spawn(spawn_dom, option::t[str], @expr, [@expr]);
......@@ -448,7 +446,7 @@ fn ty_mach_to_str(tm: ty_mach) -> str {
ty_rec([ty_field]);
ty_fn(proto, [ty_arg], @ty, controlflow, [@constr]);
ty_obj([ty_method]);
ty_tup([mt]);
ty_tup([@ty]);
ty_path(path, node_id);
ty_type;
ty_constr(@ty, [@ty_constr]);
......
......@@ -339,11 +339,7 @@ fn fold_anon_obj_field_(aof: &anon_obj_field, fld: ast_fold) ->
option::map(fld.fold_expr, maybe_expr))
}
expr_tup(elts) {
let elts_ = ~[];
for elt in elts {
elts_ += ~[{mut: elt.mut, expr: fld.fold_expr(elt.expr)}];
}
expr_tup(elts_)
expr_tup(ivec::map(fld.fold_expr, elts))
}
expr_call(f, args) {
expr_call(fld.fold_expr(f), fld.map_exprs(fld.fold_expr, args))
......
......@@ -324,7 +324,7 @@ fn print_field(s: &ps, f: &ast::ty_field) {
}
ast::ty_tup(elts) {
popen(s);
commasep(s, inconsistent, elts, print_mt);
commasep(s, inconsistent, elts, print_boxed_type);
pclose(s);
}
ast::ty_fn(proto, inputs, output, cf, constrs) {
......@@ -753,15 +753,8 @@ fn print_field(s: &ps, field: &ast::field) {
word(s.s, "}");
}
ast::expr_tup(exprs) {
fn printElt(s: &ps, elt: &ast::elt) {
ibox(s, indent_unit);
if elt.mut == ast::mut { word_nbsp(s, "mutable"); }
print_expr(s, elt.expr);
end(s);
}
fn get_span(elt: &ast::elt) -> codemap::span { ret elt.expr.span; }
popen(s);
commasep_cmnt(s, inconsistent, exprs, printElt, get_span);
commasep_exprs(s, inconsistent, exprs);
pclose(s);
}
ast::expr_call(func, args) {
......
......@@ -133,8 +133,8 @@ fn visit_ty[E](t: &@ty, e: &E, v: &vt[E]) {
ty_rec(flds) {
for f: ty_field in flds { v.visit_ty(f.node.mt.ty, e, v); }
}
ty_tup(mts) {
for mt in mts { v.visit_ty(mt.ty, e, v); }
ty_tup(ts) {
for tt in ts { v.visit_ty(tt, e, v); }
}
ty_fn(_, args, out, _, constrs) {
for a: ty_arg in args { v.visit_ty(a.node.ty, e, v); }
......@@ -248,7 +248,7 @@ fn visit_expr[E](ex: &@expr, e: &E, v: &vt[E]) {
visit_expr_opt(base, e, v);
}
expr_tup(elts) {
for el in elts { v.visit_expr(el.expr, e, v); }
for el in elts { v.visit_expr(el, e, v); }
}
expr_call(callee, args) {
v.visit_expr(callee, e, v);
......
......@@ -47,14 +47,6 @@ fn new_def_hash[@V]() -> std::map::hashmap[ast::def_id, V] {
ret std::map::mk_hashmap[ast::def_id, V](hasher, eqer);
}
fn elt_expr(e: &ast::elt) -> @ast::expr { ret e.expr; }
fn elt_exprs(elts: &[ast::elt]) -> [@ast::expr] {
let es = ~[];
for e: ast::elt in elts { es += ~[e.expr]; }
ret es;
}
fn field_expr(f: &ast::field) -> @ast::expr { ret f.node.expr; }
fn field_exprs(fields: &[ast::field]) -> [@ast::expr] {
......
......@@ -105,7 +105,7 @@ fn mt_to_str(cx: &ctxt, m: &mt) -> str {
}
ty_tup(elems) {
let strs = ~[];
for tm in elems { strs += ~[mt_to_str(cx, tm)]; }
for elem in elems { strs += ~[ty_to_str(cx, elem)]; }
s += "(" + str::connect(strs, ",") + ")";
}
ty_tag(id, tps) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册