rustc: Use interior vectors for tuple types
This commit is contained in:
parent
be50cdd24a
commit
b841152a40
@ -191,8 +191,8 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
|
||||
case ('C') { ret ty::mk_chan(st.tcx, parse_ty(st, sd)); }
|
||||
case ('T') {
|
||||
assert (next(st) as char == '[');
|
||||
let vec[ty::mt] params = [];
|
||||
while (peek(st) as char != ']') { params += [parse_mt(st, sd)]; }
|
||||
let ty::mt[] params = ~[];
|
||||
while (peek(st) as char != ']') { params += ~[parse_mt(st, sd)]; }
|
||||
st.pos = st.pos + 1u;
|
||||
ret ty::mk_tup(st.tcx, params);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
import std::int;
|
||||
import std::ivec;
|
||||
import std::str;
|
||||
import std::uint;
|
||||
import std::vec;
|
||||
@ -263,7 +264,7 @@ tag sty {
|
||||
ty_port(t);
|
||||
ty_chan(t);
|
||||
ty_task;
|
||||
ty_tup(vec[mt]);
|
||||
ty_tup(mt[]);
|
||||
ty_rec(vec[field]);
|
||||
ty_fn(ast::proto, vec[arg], t, controlflow, vec[@constr_def]);
|
||||
ty_native_fn(ast::native_abi, vec[arg], t);
|
||||
@ -584,13 +585,13 @@ fn mk_chan(&ctxt cx, &t ty) -> t { ret gen_ty(cx, ty_chan(ty)); }
|
||||
|
||||
fn mk_task(&ctxt cx) -> t { ret gen_ty(cx, ty_task); }
|
||||
|
||||
fn mk_tup(&ctxt cx, &vec[mt] tms) -> t { ret gen_ty(cx, ty_tup(tms)); }
|
||||
fn mk_tup(&ctxt cx, &mt[] tms) -> t { ret gen_ty(cx, ty_tup(tms)); }
|
||||
|
||||
fn mk_imm_tup(&ctxt cx, &vec[t] tys) -> t {
|
||||
// TODO: map
|
||||
|
||||
let vec[ty::mt] mts = [];
|
||||
for (t typ in tys) { mts += [rec(ty=typ, mut=ast::imm)]; }
|
||||
let ty::mt[] mts = ~[];
|
||||
for (t typ in tys) { mts += ~[rec(ty=typ, mut=ast::imm)]; }
|
||||
ret mk_tup(cx, mts);
|
||||
}
|
||||
|
||||
@ -775,10 +776,10 @@ fn fold_ty(&ctxt cx, fold_mode fld, t ty_0) -> t {
|
||||
ty = copy_cname(cx, mk_tag(cx, tid, new_subtys), ty);
|
||||
}
|
||||
case (ty_tup(?mts)) {
|
||||
let vec[mt] new_mts = [];
|
||||
let mt[] new_mts = ~[];
|
||||
for (mt tm in mts) {
|
||||
auto new_subty = fold_ty(cx, fld, tm.ty);
|
||||
new_mts += [rec(ty=new_subty, mut=tm.mut)];
|
||||
new_mts += ~[rec(ty=new_subty, mut=tm.mut)];
|
||||
}
|
||||
ty = copy_cname(cx, mk_tup(cx, new_mts), ty);
|
||||
}
|
||||
@ -1111,7 +1112,7 @@ fn type_has_dynamic_size(&ctxt cx, &t ty) -> bool {
|
||||
case (ty_task) { ret false; }
|
||||
case (ty_tup(?mts)) {
|
||||
auto i = 0u;
|
||||
while (i < vec::len[mt](mts)) {
|
||||
while (i < ivec::len[mt](mts)) {
|
||||
if (type_has_dynamic_size(cx, mts.(i).ty)) { ret true; }
|
||||
i += 1u;
|
||||
}
|
||||
@ -1551,8 +1552,8 @@ fn equal_type_structures(&sty a, &sty b) -> bool {
|
||||
case (ty_tup(?mts_a)) {
|
||||
alt (b) {
|
||||
case (ty_tup(?mts_b)) {
|
||||
auto len = vec::len[mt](mts_a);
|
||||
if (len != vec::len[mt](mts_b)) { ret false; }
|
||||
auto len = ivec::len[mt](mts_a);
|
||||
if (len != ivec::len[mt](mts_b)) { ret false; }
|
||||
auto i = 0u;
|
||||
while (i < len) {
|
||||
if (!equal_mt(mts_a.(i), mts_b.(i))) { ret false; }
|
||||
@ -2477,8 +2478,8 @@ mod unify {
|
||||
case (ty::ty_tup(?expected_elems)) {
|
||||
alt (struct(cx.tcx, actual)) {
|
||||
case (ty::ty_tup(?actual_elems)) {
|
||||
auto expected_len = vec::len[ty::mt](expected_elems);
|
||||
auto actual_len = vec::len[ty::mt](actual_elems);
|
||||
auto expected_len = ivec::len[ty::mt](expected_elems);
|
||||
auto actual_len = ivec::len[ty::mt](actual_elems);
|
||||
if (expected_len != actual_len) {
|
||||
auto err =
|
||||
terr_tuple_size(expected_len, actual_len);
|
||||
@ -2487,7 +2488,7 @@ mod unify {
|
||||
// TODO: implement an iterator that can iterate over
|
||||
// two arrays simultaneously.
|
||||
|
||||
let vec[ty::mt] result_elems = [];
|
||||
let ty::mt[] result_elems = ~[];
|
||||
auto i = 0u;
|
||||
while (i < expected_len) {
|
||||
auto expected_elem = expected_elems.(i);
|
||||
@ -2507,7 +2508,7 @@ mod unify {
|
||||
alt (result) {
|
||||
case (ures_ok(?rty)) {
|
||||
auto mt = rec(ty=rty, mut=mut);
|
||||
result_elems += [mt];
|
||||
result_elems += ~[mt];
|
||||
}
|
||||
case (_) { ret result; }
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import middle::ty::unify::fixup_result;
|
||||
import middle::ty::unify::fix_ok;
|
||||
import middle::ty::unify::fix_err;
|
||||
import std::int;
|
||||
import std::ivec;
|
||||
import std::str;
|
||||
import std::ufind;
|
||||
import std::uint;
|
||||
@ -293,9 +294,10 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
|
||||
typ = ty::mk_chan(tcx, ast_ty_to_ty(tcx, getter, t));
|
||||
}
|
||||
case (ast::ty_tup(?fields)) {
|
||||
let vec[ty::mt] flds = [];
|
||||
let ty::mt[] flds = ~[];
|
||||
ivec::reserve(flds, vec::len(fields));
|
||||
for (ast::mt field in fields) {
|
||||
vec::push[ty::mt](flds, ast_mt_to_mt(tcx, getter, field));
|
||||
flds += ~[ast_mt_to_mt(tcx, getter, field)];
|
||||
}
|
||||
typ = ty::mk_tup(tcx, flds);
|
||||
}
|
||||
@ -1937,11 +1939,12 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
||||
write::ty_only_fixup(fcx, id, typ);
|
||||
}
|
||||
case (ast::expr_tup(?elts)) {
|
||||
let vec[ty::mt] elts_mt = [];
|
||||
let ty::mt[] elts_mt = ~[];
|
||||
ivec::reserve(elts_mt, vec::len(elts));
|
||||
for (ast::elt e in elts) {
|
||||
check_expr(fcx, e.expr);
|
||||
auto ety = expr_ty(fcx.ccx.tcx, e.expr);
|
||||
elts_mt += [rec(ty=ety, mut=e.mut)];
|
||||
elts_mt += ~[rec(ty=ety, mut=e.mut)];
|
||||
}
|
||||
auto typ = ty::mk_tup(fcx.ccx.tcx, elts_mt);
|
||||
write::ty_only_fixup(fcx, id, typ);
|
||||
@ -2004,7 +2007,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
||||
case (ty::ty_tup(?args)) {
|
||||
let uint ix =
|
||||
ty::field_num(fcx.ccx.tcx.sess, expr.span, field);
|
||||
if (ix >= vec::len[ty::mt](args)) {
|
||||
if (ix >= ivec::len[ty::mt](args)) {
|
||||
fcx.ccx.tcx.sess.span_fatal(expr.span,
|
||||
"bad index on tuple");
|
||||
}
|
||||
|
@ -107,8 +107,8 @@ fn ty_to_str(&ctxt cx, &t typ) -> str {
|
||||
case (ty_type) { s += "type"; }
|
||||
case (ty_task) { s += "task"; }
|
||||
case (ty_tup(?elems)) {
|
||||
auto f = bind mt_to_str(cx, _);
|
||||
auto strs = vec::map[mt, str](f, elems);
|
||||
let vec[str] strs = [];
|
||||
for (mt tm in elems) { strs += [mt_to_str(cx, tm)]; }
|
||||
s += "tup(" + str::connect(strs, ",") + ")";
|
||||
}
|
||||
case (ty_rec(?elems)) {
|
||||
|
@ -36,4 +36,4 @@ mod interner {
|
||||
}
|
||||
}
|
||||
fn get[T](&interner[T] itr, uint idx) -> T { ret itr.vect.(idx); }
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user