rustc: Switch tag type parameters to interior vectors

This commit is contained in:
Patrick Walton 2011-07-01 13:01:00 -07:00
parent ede35f4c43
commit 13d920c10d
4 changed files with 19 additions and 31 deletions

View file

@ -253,8 +253,8 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
assert (next(st) as char == '[');
auto def = parse_def(st, sd);
auto inner = parse_ty(st, sd);
let vec[ty::t] params = [];
while (peek(st) as char != ']') { params += [parse_ty(st, sd)]; }
let ty::t[] params = ~[];
while (peek(st) as char != ']') { params += ~[parse_ty(st, sd)]; }
st.pos = st.pos + 1u;
ret ty::mk_res(st.tcx, def, inner, params);
}

View file

@ -2145,13 +2145,9 @@ fn make_drop_glue(&@block_ctxt cx, ValueRef v0, &ty::t t) {
}
fn trans_res_drop(@block_ctxt cx, ValueRef rs, &ast::def_id did,
ty::t inner_t, &vec[ty::t] tps) -> result {
// FIXME: Remove this vec->ivec conversion.
auto tps_ivec = ~[];
for (ty::t tp in tps) { tps_ivec += ~[tp]; }
ty::t inner_t, &ty::t[] tps) -> result {
auto ccx = cx.fcx.lcx.ccx;
auto inner_t_s = ty::substitute_type_params(ccx.tcx, tps_ivec, inner_t);
auto inner_t_s = ty::substitute_type_params(ccx.tcx, tps, inner_t);
auto tup_ty = ty::mk_imm_tup(ccx.tcx, ~[ty::mk_int(ccx.tcx), inner_t_s]);
auto drop_cx = new_sub_block_ctxt(cx, "drop res");
auto next_cx = new_sub_block_ctxt(cx, "next");

View file

@ -269,8 +269,8 @@ tag sty {
ty_rec(field[]);
ty_fn(ast::proto, arg[], t, controlflow, vec[@constr_def]);
ty_native_fn(ast::native_abi, arg[], t);
ty_obj(vec[method]);
ty_res(def_id, t, vec[t]);
ty_obj(method[]);
ty_res(def_id, t, t[]);
ty_var(int); // type variable
ty_param(uint); // fn/tag type param
ty_type;
@ -608,7 +608,7 @@ fn mk_obj(&ctxt cx, &vec[method] meths) -> t {
ret gen_ty(cx, ty_obj(meths));
}
fn mk_res(&ctxt cx, &ast::def_id did, &t inner, &vec[t] tps) -> t {
fn mk_res(&ctxt cx, &ast::def_id did, &t inner, &t[] tps) -> t {
ret gen_ty(cx, ty_res(did, inner, tps));
}
@ -817,8 +817,8 @@ fn fold_ty(&ctxt cx, fold_mode fld, t ty_0) -> t {
ty = copy_cname(cx, mk_obj(cx, new_methods), ty);
}
case (ty_res(?did, ?subty, ?tps)) {
auto new_tps = [];
for (t tp in tps) { new_tps += [fold_ty(cx, fld, tp)]; }
auto new_tps = ~[];
for (t tp in tps) { new_tps += ~[fold_ty(cx, fld, tp)]; }
ty = copy_cname(cx, mk_res(cx, did, fold_ty(cx, fld, subty),
new_tps), ty);
}
@ -2475,13 +2475,13 @@ mod unify {
alt (result) {
case (ures_ok(?res_inner)) {
auto i = 0u;
auto res_tps = [];
auto res_tps = ~[];
for (t ex_tp in ex_tps) {
auto result =
unify_step(cx, ex_tp, act_tps.(i));
alt (result) {
case (ures_ok(?rty)) {
vec::push(res_tps, rty);
res_tps += ~[rty];
}
case (_) { ret result; }
}

View file

@ -474,11 +474,11 @@ mod write {
mod collect {
type ctxt = rec(ty::ctxt tcx);
fn mk_ty_params(&@ctxt cx, uint n) -> vec[ty::t] {
auto tps = [];
fn mk_ty_params(&@ctxt cx, uint n) -> ty::t[] {
auto tps = ~[];
auto i = 0u;
while (i < n) {
tps += [ty::mk_param(cx.tcx, i)];
tps += ~[ty::mk_param(cx.tcx, i)];
i += 1u;
}
ret tps;
@ -650,12 +650,8 @@ mod collect {
auto ty_param_count = vec::len[ast::ty_param](tps);
let vec[ty::t] subtys = mk_ty_params(cx, ty_param_count);
// FIXME: Remove this vec->ivec conversion.
auto tps_ivec = ~[];
for (ty::t tp in subtys) { tps_ivec += ~[tp]; }
auto t = ty::mk_tag(cx.tcx, local_def(it.id), tps_ivec);
let ty::t[] subtys = mk_ty_params(cx, ty_param_count);
auto t = ty::mk_tag(cx.tcx, local_def(it.id), subtys);
auto tpt = tup(ty_param_count, t);
cx.tcx.tcache.insert(local_def(it.id), tpt);
ret tpt;
@ -692,18 +688,14 @@ mod collect {
// Create a set of parameter types shared among all the variants.
auto ty_param_count = vec::len[ast::ty_param](ty_params);
let vec[ty::t] ty_param_tys = mk_ty_params(cx, ty_param_count);
let ty::t[] ty_param_tys = mk_ty_params(cx, ty_param_count);
for (ast::variant variant in variants) {
// Nullary tag constructors get turned into constants; n-ary tag
// constructors get turned into functions.
// FIXME: Remove this vec->ivec conversion.
auto tps_ivec = ~[];
for (ty::t tp in ty_param_tys) { tps_ivec += ~[tp]; }
auto result_ty;
if (vec::len[ast::variant_arg](variant.node.args) == 0u) {
result_ty = ty::mk_tag(cx.tcx, tag_id, tps_ivec);
result_ty = ty::mk_tag(cx.tcx, tag_id, ty_param_tys);
} else {
// As above, tell ast_ty_to_ty() that trans_ty_item_to_ty()
// should be called to resolve named types.
@ -714,7 +706,7 @@ mod collect {
auto arg_ty = ast_ty_to_ty(cx.tcx, f, va.ty);
args += ~[rec(mode=ty::mo_alias(false), ty=arg_ty)];
}
auto tag_t = ty::mk_tag(cx.tcx, tag_id, tps_ivec);
auto tag_t = ty::mk_tag(cx.tcx, tag_id, ty_param_tys);
// FIXME: this will be different for constrained types
result_ty = ty::mk_fn(cx.tcx, ast::proto_fn, args, tag_t,
ast::return, []);