1
Fork 0

Tuple fields are immutable

This commit is contained in:
Marijn Haverbeke 2011-08-15 12:08:05 +02:00
parent 9538b00363
commit 29ea87542f
18 changed files with 93 additions and 138 deletions

View file

@ -239,7 +239,7 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
'T' { 'T' {
assert (next(st) as char == '['); assert (next(st) as char == '[');
let params = ~[]; 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; st.pos = st.pos + 1u;
ret ty::mk_tup(st.tcx, params); ret ty::mk_tup(st.tcx, params);
} }

View file

@ -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); } for t: ty::t in tys { enc_ty(w, cx, t); }
w.write_char(']'); w.write_char(']');
} }
ty::ty_tup(mts) { ty::ty_tup(ts) {
w.write_str("T["); 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(']'); w.write_char(']');
} }
ty::ty_box(mt) { w.write_char('@'); enc_mt(w, cx, mt); } ty::ty_box(mt) { w.write_char('@'); enc_mt(w, cx, mt); }

View file

@ -678,9 +678,9 @@ fn ty_can_unsafely_include(cx: &ctx, needle: ty::t, haystack: ty::t,
} }
ret false; ret false;
} }
ty::ty_tup(mts) { ty::ty_tup(ts) {
for mt in mts { for t in ts {
if helper(tcx, needle, mt.ty, get_mut(mut, mt)) { if helper(tcx, needle, t, mut) {
ret true; ret true;
} }
} }

View file

@ -48,7 +48,7 @@ fn type_is_gc_relevant(cx: &ty::ctxt, ty: &ty::t) -> bool {
} }
ty::ty_tup(elts) { ty::ty_tup(elts) {
for elt in 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; ret false;
} }

View file

@ -174,7 +174,7 @@ fn largest_variants(ccx : &@crate_ctxt, tag_id : &ast::def_id) -> [uint] {
ret result; 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. // bad for performance.
// //
// TODO: Migrate trans over to use this. // 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) { ty::ty_tup(elts) {
s += ~[shape_struct]; s += ~[shape_struct];
let sub = ~[]; 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); add_substr(s, sub);
} }

View file

@ -256,7 +256,7 @@ fn type_of_inner(cx: &@crate_ctxt, sp: &span, t: &ty::t) -> TypeRef {
ty::ty_tup(elts) { ty::ty_tup(elts) {
let tys = ~[]; let tys = ~[];
for elt in elts { for elt in elts {
tys += ~[type_of_inner(cx, sp, elt.ty)]; tys += ~[type_of_inner(cx, sp, elt)];
} }
llty = T_struct(tys); llty = T_struct(tys);
} }
@ -490,20 +490,20 @@ fn simplify_type(ccx: &@crate_ctxt, typ: &ty::t) -> ty::t {
ty::ty_uniq(_) { ret ty::mk_uniq(ccx.tcx, ty::mk_nil(ccx.tcx)); } 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_vec(_) { ret ty::mk_imm_vec(ccx.tcx, ty::mk_nil(ccx.tcx)); }
ty::ty_fn(_, _, _, _, _) { ty::ty_fn(_, _, _, _, _) {
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::mk_imm_box(ccx.tcx, ty::mk_imm_box(ccx.tcx,
ty::mk_nil(ccx.tcx))]); ty::mk_nil(ccx.tcx))]);
} }
ty::ty_obj(_) { 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::mk_imm_box(ccx.tcx, ty::mk_imm_box(ccx.tcx,
ty::mk_nil(ccx.tcx))]); ty::mk_nil(ccx.tcx))]);
} }
ty::ty_res(_, sub, tps) { ty::ty_res(_, sub, tps) {
let sub1 = ty::substitute_type_params(ccx.tcx, tps, sub); 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), ~[ty::mk_int(ccx.tcx),
simplify_type(ccx, sub1)]); 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); let variants = ty::tag_variants(cx.tcx, tid);
for variant: ty::variant_info in variants { for variant: ty::variant_info in variants {
let tup_ty = 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. // Perform any type parameter substitutions.
tup_ty = ty::substitute_type_params(cx.tcx, subtys, tup_ty); tup_ty = ty::substitute_type_params(cx.tcx, subtys, tup_ty);
@ -586,7 +586,7 @@ fn dynamic_size_of(cx: &@block_ctxt, t: ty::t) -> result {
} }
ty::ty_tup(elts) { ty::ty_tup(elts) {
let tys = ~[]; let tys = ~[];
for mt in elts { tys += ~[mt.ty]; } for tp in elts { tys += ~[tp]; }
ret align_elements(cx, tys); ret align_elements(cx, tys);
} }
ty::ty_tag(tid, tps) { 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 a = C_int(1);
let bcx = cx; let bcx = cx;
for e in elts { for e in elts {
let align = align_of(bcx, e.ty); let align = align_of(bcx, e);
bcx = align.bcx; bcx = align.bcx;
a = umax(bcx, a, align.val); a = umax(bcx, a, align.val);
} }
@ -766,7 +766,7 @@ fn GEP_tup_like(cx: &@block_ctxt, t: &ty::t, base: ValueRef, ixs: &[int]) ->
let args = ~[]; let args = ~[];
for typ: ty::t in s.prefix { args += ~[typ]; } 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 bcx = cx;
let sz = size_of(bcx, prefix_ty); 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; } if i == ix { elem_ty = arg_ty; }
i += 1; 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 // 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).
@ -858,7 +858,7 @@ fn trans_malloc_boxed_raw(cx: &@block_ctxt, t: ty::t) -> result {
// The mk_int here is the space being // The mk_int here is the space being
// reserved for the refcount. // reserved for the refcount.
let boxed_body = 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 box_ptr = ty::mk_imm_box(bcx_tcx(cx), t);
let sz = size_of(cx, boxed_body); 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 { inner_t: ty::t, tps: &[ty::t]) -> result {
let ccx = bcx_ccx(cx); let ccx = bcx_ccx(cx);
let inner_t_s = ty::substitute_type_params(ccx.tcx, tps, inner_t); 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 drop_cx = new_sub_block_ctxt(cx, "drop res");
let next_cx = new_sub_block_ctxt(cx, "next"); let next_cx = new_sub_block_ctxt(cx, "next");
@ -1846,8 +1846,7 @@ fn iter_structural_ty_full(cx: &@block_ctxt, av: ValueRef, t: &ty::t,
for arg in args { for arg in args {
r = GEP_tup_like(r.bcx, t, av, ~[0, i]); r = GEP_tup_like(r.bcx, t, av, ~[0, i]);
let llfld_a = r.val; let llfld_a = r.val;
r = f(r.bcx, load_if_immediate(r.bcx, llfld_a, arg.ty), r = f(r.bcx, load_if_immediate(r.bcx, llfld_a, arg), arg);
arg.ty);
i += 1; i += 1;
} }
} }
@ -1855,7 +1854,7 @@ fn iter_structural_ty_full(cx: &@block_ctxt, av: ValueRef, t: &ty::t,
let tcx = bcx_tcx(cx); let tcx = bcx_tcx(cx);
let inner1 = ty::substitute_type_params(tcx, tps, inner); let inner1 = ty::substitute_type_params(tcx, tps, inner);
let inner_t_s = 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]); r = GEP_tup_like(r.bcx, tup_t, av, ~[0, 1]);
let llfld_a = r.val; let llfld_a = r.val;
r = f(r.bcx, load_if_immediate(r.bcx, llfld_a, inner1), inner1); 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 // First, synthesize a tuple type containing the types of all the
// bound expressions. // bound expressions.
// bindings_ty = ~[bound_ty1, bound_ty2, ...] // 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 // 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
@ -3536,17 +3535,17 @@ fn build_environment(bcx: @block_ctxt, lltydescs: [ValueRef],
// closure_tys = [tydesc_ty, [bound_ty1, bound_ty2, ...], [tydesc_ty, // closure_tys = [tydesc_ty, [bound_ty1, bound_ty2, ...], [tydesc_ty,
// tydesc_ty, ...]] // tydesc_ty, ...]]
let closure_tys: [ty::t] = 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. // 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. // Allocate a box that can hold something closure-sized.
let r = if copying { let r = if copying {
trans_malloc_boxed(bcx, closure_ty) trans_malloc_boxed(bcx, closure_ty)
} else { } else {
// We need to dummy up a box on the stack // 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]); ~[ty::mk_int(bcx_tcx(bcx)), closure_ty]);
let r = alloc_ty(bcx, ty); let r = alloc_ty(bcx, ty);
let body = GEPi(bcx, r.val, ~[0, abi::box_rc_field_body]); 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); 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 { -> result {
let bcx = cx; let bcx = cx;
let t = node_id_type(bcx.fcx.lcx.ccx, id); 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); add_clean_temp(cx, tup_val, t);
let i: int = 0; let i: int = 0;
for e in elts { for e in elts {
let e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e.expr); let e_ty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, e);
let src = trans_lval(bcx, e.expr); let src = trans_lval(bcx, e);
bcx = src.res.bcx; bcx = src.res.bcx;
let dst_res = GEP_tup_like(bcx, t, tup_val, ~[0, i]); 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; 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); add_clean_temp(bcx, vec_val, t);
let body = bcx.build.GEP(vec_val, ~[C_int(0), C_int(abi::vec_elt_data)]); let body = bcx.build.GEP(vec_val, ~[C_int(0), C_int(abi::vec_elt_data)]);
let pseudo_tup_ty = 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::init_elt[ty::t](unit_ty,
std::ivec::len(args))); std::ivec::len(args)));
let i: int = 0; 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 // Synthesize a tuple type for the fields so that GEP_tup_like() can work
// its magic. // 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 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 llobj_box_ty: TypeRef = T_obj_ptr(*bcx_ccx(bcx), n_typarams);
let box_cell = 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 bcx = new_top_block_ctxt(fcx);
let lltop = bcx.llbb; let lltop = bcx.llbb;
let arg_t = arg_tys_of_fn(cx.ccx, ctor_id).(0).ty; 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; let arg;
alt fcx.llargs.find(dtor.decl.inputs.(0).id) { alt fcx.llargs.find(dtor.decl.inputs.(0).id) {
some(x) { arg = load_if_immediate(bcx, x, arg_t); } some(x) { arg = load_if_immediate(bcx, x, arg_t); }

View file

@ -122,7 +122,7 @@ fn trans_spawn(cx: &@block_ctxt, dom: &ast::spawn_dom, name: &option::t[str],
} }
// Make the tuple. // 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. // Allocate and fill the tuple.
let llargs = alloc_ty(bcx, args_ty); let llargs = alloc_ty(bcx, args_ty);

View file

@ -152,7 +152,7 @@ fn trans_obj(cx: @local_ctxt, sp: &span, ob: &ast::_obj,
~[0, abi::obj_body_elt_typarams]); ~[0, abi::obj_body_elt_typarams]);
bcx = body_typarams.bcx; bcx = body_typarams.bcx;
// TODO: can we just get typarams_ty out of body_ty instead? // 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; let i: int = 0;
for tp: ast::ty_param in ty_params { for tp: ast::ty_param in ty_params {
let typaram = bcx.fcx.lltydescs.(i); let typaram = bcx.fcx.lltydescs.(i);
@ -174,7 +174,7 @@ fn trans_obj(cx: @local_ctxt, sp: &span, ob: &ast::_obj,
some(arg1) { some(arg1) {
let arg = load_if_immediate(bcx, arg1, arg_tys.(i).ty); let arg = load_if_immediate(bcx, arg1, arg_tys.(i).ty);
// TODO: can we just get fields_ty out of body_ty instead? // 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 = let field =
GEP_tup_like(bcx, fields_ty, body_fields.val, ~[0, i]); GEP_tup_like(bcx, fields_ty, body_fields.val, ~[0, i]);
bcx = field.bcx; 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. // have additional field exprs in the AST.
load_if_immediate(bcx, additional_field_vals.(i).val, load_if_immediate(bcx, additional_field_vals.(i).val,
additional_field_tys.(i)); 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); additional_field_tys);
let field = let field =
GEP_tup_like(bcx, fields_ty, body_fields.val, ~[0, i]); 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 { maybe_inner_obj_ty: option::t[ty::t]) -> ty::t {
let tydesc_ty: ty::t = ty::mk_type(tcx); let tydesc_ty: ty::t = ty::mk_type(tcx);
let typarams_ty_tup: ty::t = ty::mk_imm_tup(tcx, typarams_ty); let typarams_ty_tup: ty::t = ty::mk_tup(tcx, typarams_ty);
let fields_ty_tup: ty::t = ty::mk_imm_tup(tcx, fields_ty); let fields_ty_tup: ty::t = ty::mk_tup(tcx, fields_ty);
let body_ty: ty::t; let body_ty: ty::t;
alt maybe_inner_obj_ty { alt maybe_inner_obj_ty {
some(inner_obj_ty) { some(inner_obj_ty) {
body_ty = ty::mk_imm_tup(tcx, ~[tydesc_ty, typarams_ty_tup, body_ty = ty::mk_tup(tcx, ~[tydesc_ty, typarams_ty_tup,
fields_ty_tup, inner_obj_ty]); fields_ty_tup, inner_obj_ty]);
} }
none { none {
body_ty = ty::mk_imm_tup(tcx, ~[tydesc_ty, typarams_ty_tup, body_ty = ty::mk_tup(tcx, ~[tydesc_ty, typarams_ty_tup,
fields_ty_tup]); fields_ty_tup]);
} }
} }

View file

@ -35,7 +35,6 @@ import std::map::new_int_hash;
import util::common::new_def_hash; import util::common::new_def_hash;
import util::common::log_expr; import util::common::log_expr;
import util::common::log_fn; import util::common::log_fn;
import util::common::elt_exprs;
import util::common::field_exprs; import util::common::field_exprs;
import util::common::has_nonlocal_exits; import util::common::has_nonlocal_exits;
import util::common::log_stmt; 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); find_pre_post_exprs(fcx, es, e.id);
} }
expr_tup(elts) { 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_move(lhs, rhs) { handle_update(fcx, e, lhs, rhs, oper_move); }
expr_swap(lhs, rhs) { handle_update(fcx, e, lhs, rhs, oper_swap); } expr_swap(lhs, rhs) { handle_update(fcx, e, lhs, rhs, oper_swap); }

View file

@ -23,7 +23,6 @@ import util::common::log_expr;
import util::common::log_block; import util::common::log_block;
import util::common::log_block_err; import util::common::log_block_err;
import util::common::log_fn; import util::common::log_fn;
import util::common::elt_exprs;
import util::common::field_exprs; import util::common::field_exprs;
import util::common::has_nonlocal_exits; import util::common::has_nonlocal_exits;
import util::common::log_stmt; 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, ret find_pre_post_state_exprs(fcx, pres, e.id,
ivec::init_elt(init_assign, ivec::init_elt(init_assign,
ivec::len(elts)), ivec::len(elts)),
elt_exprs(elts), return); elts, return);
} }
expr_move(lhs, rhs) { expr_move(lhs, rhs) {
ret find_pre_post_state_two(fcx, pres, lhs, rhs, e.id, oper_move); ret find_pre_post_state_two(fcx, pres, lhs, rhs, e.id, oper_move);

View file

@ -70,7 +70,6 @@ export mk_float;
export mk_fn; export mk_fn;
export mk_imm_box; export mk_imm_box;
export mk_mut_ptr; export mk_mut_ptr;
export mk_imm_tup;
export mk_imm_vec; export mk_imm_vec;
export mk_int; export mk_int;
export mk_istr; export mk_istr;
@ -282,7 +281,7 @@ tag sty {
ty_native_fn(ast::native_abi, [arg], t); ty_native_fn(ast::native_abi, [arg], t);
ty_obj([method]); ty_obj([method]);
ty_res(def_id, t, [t]); ty_res(def_id, t, [t]);
ty_tup([mt]); ty_tup([t]);
ty_var(int); // type variable ty_var(int); // type variable
ty_param(uint, ast::kind); // fn/tag type param ty_param(uint, ast::kind); // fn/tag type param
@ -306,7 +305,6 @@ tag type_err {
terr_box_mutability; terr_box_mutability;
terr_vec_mutability; terr_vec_mutability;
terr_tuple_size(uint, uint); terr_tuple_size(uint, uint);
terr_tuple_mutability;
terr_record_size(uint, uint); terr_record_size(uint, uint);
terr_record_mutability; terr_record_mutability;
terr_record_fields(ast::ident, ast::ident); terr_record_fields(ast::ident, ast::ident);
@ -491,9 +489,9 @@ fn mk_raw_ty(cx: &ctxt, st: &sty, in_cname: &option::t[str]) -> @raw_t {
derive_flags_mt(cx, has_params, has_vars, f.mt); derive_flags_mt(cx, has_params, has_vars, f.mt);
} }
} }
ty_tup(mts) { ty_tup(ts) {
for m in mts { for tt in ts {
derive_flags_mt(cx, has_params, has_vars, m); derive_flags_t(cx, has_params, has_vars, tt);
} }
} }
ty_fn(_, args, 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)); 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_tup(cx: &ctxt, ts: &[t]) -> t { ret gen_ty(cx, ty_tup(ts)); }
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_fn(cx: &ctxt, proto: &ast::proto, args: &[arg], ty: &t, fn mk_fn(cx: &ctxt, proto: &ast::proto, args: &[arg], ty: &t,
cf: &controlflow, constrs: &[@constr]) -> t { cf: &controlflow, constrs: &[@constr]) -> t {
@ -687,8 +678,8 @@ fn walk_ty(cx: &ctxt, walker: ty_walk, ty: t) {
ty_rec(fields) { ty_rec(fields) {
for fl: field in fields { walk_ty(cx, walker, fl.mt.ty); } for fl: field in fields { walk_ty(cx, walker, fl.mt.ty); }
} }
ty_tup(mts) { ty_tup(ts) {
for tm in mts { walk_ty(cx, walker, tm.ty); } for tt in ts { walk_ty(cx, walker, tt); }
} }
ty_fn(proto, args, ret_ty, _, _) { ty_fn(proto, args, ret_ty, _, _) {
for a: arg in args { walk_ty(cx, walker, a.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 = copy_cname(cx, mk_rec(cx, new_fields), ty);
} }
ty_tup(mts) { ty_tup(ts) {
let new_mts = ~[]; let new_ts = ~[];
for tm in mts { for tt in ts {
let new_subty = fold_ty(cx, fld, tm.ty); new_ts += ~[fold_ty(cx, fld, tt)];
new_mts += ~[{ty: new_subty, mut: tm.mut}];
} }
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) { ty_fn(proto, args, ret_ty, cf, constrs) {
let new_args: [arg] = ~[]; 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 { fn get_element_type(cx: &ctxt, ty: &t, i: uint) -> t {
alt struct(cx, ty) { alt struct(cx, ty) {
ty_rec(flds) { ret flds.(i).mt.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) + cx.sess.bug("get_element_type called on type " + ty_to_str(cx, ty) +
" - expected a \ " - expected a \
@ -1032,7 +1022,7 @@ fn type_has_pointers(cx: &ctxt, ty: &t) -> bool {
} }
ty_tup(elts) { ty_tup(elts) {
for m in 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) { ty_tag(did, tps) {
@ -1225,11 +1215,9 @@ fn type_has_dynamic_size(cx: &ctxt, ty: &t) -> bool {
} }
ret false; ret false;
} }
ty_tup(mts) { ty_tup(ts) {
let i = 0u; for tt in ts {
while i < ivec::len(mts) { if type_has_dynamic_size(cx, tt) { ret true; }
if type_has_dynamic_size(cx, mts.(i).ty) { ret true; }
i += 1u;
} }
ret false; ret false;
} }
@ -1356,7 +1344,7 @@ fn type_owns_heap_mem(cx: &ctxt, ty: &t) -> bool {
} }
ty_tup(elts) { ty_tup(elts) {
for m in 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) { ty_res(_, inner, tps) {
@ -1397,7 +1385,7 @@ fn type_is_pod(cx : &ctxt, ty : &t) -> bool {
ty_tag(did, tps) { ty_tag(did, tps) {
let variants = tag_variants(cx, did); let variants = tag_variants(cx, did);
for variant : variant_info in variants { 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. // Perform any type parameter substitutions.
tup_ty = substitute_type_params(cx, tps, tup_ty); 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) { ty_tup(elts) {
for elt in 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) { ty_res(_, inner, tps) {
@ -1563,9 +1551,9 @@ fn hash_type_structure(st: &sty) -> uint {
for f: field in fields { h += h << 5u + hash_ty(f.mt.ty); } for f: field in fields { h += h << 5u + hash_ty(f.mt.ty); }
ret h; ret h;
} }
ty_tup(mts) { ty_tup(ts) {
let h = 25u; 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; ret h;
} }
@ -1749,14 +1737,14 @@ fn equal_type_structures(a: &sty, b: &sty) -> bool {
_ { ret false; } _ { ret false; }
} }
} }
ty_tup(mts_a) { ty_tup(ts_a) {
alt (b) { alt (b) {
ty_tup(mts_b) { ty_tup(ts_b) {
let len = ivec::len(mts_a); let len = ivec::len(ts_a);
if len != ivec::len(mts_b) { ret false; } if len != ivec::len(ts_b) { ret false; }
let i = 0u; let i = 0u;
while i < len { 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; i += 1u;
} }
ret true; ret true;
@ -2743,17 +2731,11 @@ mod unify {
while i < expected_len { while i < expected_len {
let expected_elem = expected_elems.(i); let expected_elem = expected_elems.(i);
let actual_elem = actual_elems.(i); let actual_elem = actual_elems.(i);
let mut; let result = unify_step(cx, expected_elem,
alt unify_mut(expected_elem.mut, actual_elem.mut) { actual_elem);
none. { ret ures_err(terr_tuple_mutability); }
some(m) { mut = m; }
}
let result = unify_step(cx, expected_elem.ty,
actual_elem.ty);
alt result { alt result {
ures_ok(rty) { ures_ok(rty) {
let mt = {ty: rty, mut: mut}; result_elems += ~[rty];
result_elems += ~[mt];
} }
_ { ret result; } _ { 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 but found one with " + uint::to_str(a_sz, 10u)
+ " elements"; + " elements";
} }
terr_tuple_mutability. {
ret "tuple elements differ in mutability";
}
terr_record_size(e_sz, a_sz) { terr_record_size(e_sz, a_sz) {
ret "expected a record with " + uint::to_str(e_sz, 10u) + ret "expected a record with " + uint::to_str(e_sz, 10u) +
" fields but found one with " + uint::to_str(a_sz, 10u) + " fields but found one with " + uint::to_str(a_sz, 10u) +

View file

@ -340,7 +340,7 @@ fn ast_ty_to_ty(tcx: &ty::ctxt, getter: &ty_getter, ast_ty: &@ast::ty) ->
typ = ty::mk_chan(tcx, ast_ty_to_ty(tcx, getter, t)); typ = ty::mk_chan(tcx, ast_ty_to_ty(tcx, getter, t));
} }
ast::ty_tup(fields) { 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); typ = ty::mk_tup(tcx, flds);
} }
ast::ty_rec(fields) { ast::ty_rec(fields) {
@ -2178,14 +2178,14 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr,
write::ty_only_fixup(fcx, id, typ); write::ty_only_fixup(fcx, id, typ);
} }
ast::expr_tup(elts) { ast::expr_tup(elts) {
let elts_mt = ~[]; let elt_ts = ~[];
ivec::reserve(elts_mt, ivec::len(elts)); ivec::reserve(elt_ts, ivec::len(elts));
for e in elts { for e in elts {
check_expr(fcx, e.expr); check_expr(fcx, e);
let ety = expr_ty(fcx.ccx.tcx, e.expr); let ety = expr_ty(fcx.ccx.tcx, e);
elts_mt += ~[{ty: ety, mut: e.mut}]; 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); write::ty_only_fixup(fcx, id, typ);
} }
ast::expr_rec(fields, base) { ast::expr_rec(fields, base) {

View file

@ -273,8 +273,6 @@ tag decl_ { decl_local([@local]); decl_item(@item); }
type arm = {pats: [@pat], block: blk}; type arm = {pats: [@pat], block: blk};
type elt = {mut: mutability, expr: @expr};
type field_ = {mut: mutability, ident: ident, expr: @expr}; type field_ = {mut: mutability, ident: ident, expr: @expr};
type field = spanned[field_]; type field = spanned[field_];
@ -292,7 +290,7 @@ tag expr_ {
expr_vec([@expr], mutability, seq_kind); expr_vec([@expr], mutability, seq_kind);
expr_rec([field], option::t[@expr]); expr_rec([field], option::t[@expr]);
expr_call(@expr, [@expr]); expr_call(@expr, [@expr]);
expr_tup([elt]); expr_tup([@expr]);
expr_self_method(ident); expr_self_method(ident);
expr_bind(@expr, [option::t[@expr]]); expr_bind(@expr, [option::t[@expr]]);
expr_spawn(spawn_dom, option::t[str], @expr, [@expr]); expr_spawn(spawn_dom, option::t[str], @expr, [@expr]);
@ -448,7 +446,7 @@ tag ty_ {
ty_rec([ty_field]); ty_rec([ty_field]);
ty_fn(proto, [ty_arg], @ty, controlflow, [@constr]); ty_fn(proto, [ty_arg], @ty, controlflow, [@constr]);
ty_obj([ty_method]); ty_obj([ty_method]);
ty_tup([mt]); ty_tup([@ty]);
ty_path(path, node_id); ty_path(path, node_id);
ty_type; ty_type;
ty_constr(@ty, [@ty_constr]); ty_constr(@ty, [@ty_constr]);

View file

@ -339,11 +339,7 @@ fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ {
option::map(fld.fold_expr, maybe_expr)) option::map(fld.fold_expr, maybe_expr))
} }
expr_tup(elts) { expr_tup(elts) {
let elts_ = ~[]; expr_tup(ivec::map(fld.fold_expr, elts))
for elt in elts {
elts_ += ~[{mut: elt.mut, expr: fld.fold_expr(elt.expr)}];
}
expr_tup(elts_)
} }
expr_call(f, args) { expr_call(f, args) {
expr_call(fld.fold_expr(f), fld.map_exprs(fld.fold_expr, args)) expr_call(fld.fold_expr(f), fld.map_exprs(fld.fold_expr, args))

View file

@ -324,7 +324,7 @@ fn print_type(s: &ps, ty: &ast::ty) {
} }
ast::ty_tup(elts) { ast::ty_tup(elts) {
popen(s); popen(s);
commasep(s, inconsistent, elts, print_mt); commasep(s, inconsistent, elts, print_boxed_type);
pclose(s); pclose(s);
} }
ast::ty_fn(proto, inputs, output, cf, constrs) { ast::ty_fn(proto, inputs, output, cf, constrs) {
@ -753,15 +753,8 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
word(s.s, "}"); word(s.s, "}");
} }
ast::expr_tup(exprs) { 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); popen(s);
commasep_cmnt(s, inconsistent, exprs, printElt, get_span); commasep_exprs(s, inconsistent, exprs);
pclose(s); pclose(s);
} }
ast::expr_call(func, args) { ast::expr_call(func, args) {

View file

@ -133,8 +133,8 @@ fn visit_ty[E](t: &@ty, e: &E, v: &vt[E]) {
ty_rec(flds) { ty_rec(flds) {
for f: ty_field in flds { v.visit_ty(f.node.mt.ty, e, v); } for f: ty_field in flds { v.visit_ty(f.node.mt.ty, e, v); }
} }
ty_tup(mts) { ty_tup(ts) {
for mt in mts { v.visit_ty(mt.ty, e, v); } for tt in ts { v.visit_ty(tt, e, v); }
} }
ty_fn(_, args, out, _, constrs) { ty_fn(_, args, out, _, constrs) {
for a: ty_arg in args { v.visit_ty(a.node.ty, e, v); } 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); visit_expr_opt(base, e, v);
} }
expr_tup(elts) { 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) { expr_call(callee, args) {
v.visit_expr(callee, e, v); v.visit_expr(callee, e, v);

View file

@ -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); 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_expr(f: &ast::field) -> @ast::expr { ret f.node.expr; }
fn field_exprs(fields: &[ast::field]) -> [@ast::expr] { fn field_exprs(fields: &[ast::field]) -> [@ast::expr] {

View file

@ -105,7 +105,7 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str {
} }
ty_tup(elems) { ty_tup(elems) {
let strs = ~[]; 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, ",") + ")"; s += "(" + str::connect(strs, ",") + ")";
} }
ty_tag(id, tps) { ty_tag(id, tps) {