Skip to content

Commit 09e591c

Browse files
committed
rustc: Use interior vectors for tag type parameters
1 parent 9c4411a commit 09e591c

File tree

5 files changed

+188
-123
lines changed

5 files changed

+188
-123
lines changed

src/comp/metadata/tydecode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
169169
case ('t') {
170170
assert (next(st) as char == '[');
171171
auto def = parse_def(st, sd);
172-
let vec[ty::t] params = [];
173-
while (peek(st) as char != ']') { params += [parse_ty(st, sd)]; }
172+
let ty::t[] params = ~[];
173+
while (peek(st) as char != ']') { params += ~[parse_ty(st, sd)]; }
174174
st.pos = st.pos + 1u;
175175
ret ty::mk_tag(st.tcx, def, params);
176176
}

src/comp/middle/trans.rs

+65-35
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,11 @@ fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
879879
llty = abs_pair;
880880
}
881881
case (ty::ty_res(_, ?sub, ?tps)) {
882-
auto sub1 = ty::substitute_type_params(cx.tcx, tps, sub);
882+
// FIXME: Remove this vec->ivec conversion.
883+
auto tps_ivec = ~[];
884+
for (ty::t typ in tps) { tps_ivec += ~[typ]; }
885+
886+
auto sub1 = ty::substitute_type_params(cx.tcx, tps_ivec, sub);
883887
ret T_struct([T_i32(), type_of_inner(cx, sp, sub1)]);
884888
}
885889
case (ty::ty_var(_)) {
@@ -1240,7 +1244,12 @@ fn simplify_type(&@crate_ctxt ccx, &ty::t typ) -> ty::t {
12401244
ty::mk_nil(ccx.tcx))]);
12411245
}
12421246
case (ty::ty_res(_, ?sub, ?tps)) {
1243-
auto sub1 = ty::substitute_type_params(ccx.tcx, tps, sub);
1247+
// FIXME: Remove this vec->ivec conversion.
1248+
auto tps_ivec = ~[];
1249+
for (ty::t typ in tps) { tps_ivec += ~[typ]; }
1250+
1251+
auto sub1 = ty::substitute_type_params(ccx.tcx, tps_ivec,
1252+
sub);
12441253
ret ty::mk_imm_tup(ccx.tcx, ~[ty::mk_int(ccx.tcx),
12451254
simplify_type(ccx, sub1)]);
12461255
}
@@ -1259,36 +1268,35 @@ fn static_size_of_tag(&@crate_ctxt cx, &span sp, &ty::t t) -> uint {
12591268
"static_size_of_tag()");
12601269
}
12611270
if (cx.tag_sizes.contains_key(t)) { ret cx.tag_sizes.get(t); }
1262-
auto tid;
1263-
let vec[ty::t] subtys;
12641271
alt (ty::struct(cx.tcx, t)) {
1265-
case (ty::ty_tag(?tid_, ?subtys_)) { tid = tid_; subtys = subtys_; }
1272+
case (ty::ty_tag(?tid, ?subtys)) {
1273+
// Compute max(variant sizes).
1274+
1275+
auto max_size = 0u;
1276+
auto variants = ty::tag_variants(cx.tcx, tid);
1277+
for (ty::variant_info variant in variants) {
1278+
// TODO: Remove this vec->ivec conversion.
1279+
auto args = ~[];
1280+
for (ty::t typ in variant.args) { args += ~[typ]; }
1281+
1282+
auto tup_ty = simplify_type(cx, ty::mk_imm_tup(cx.tcx, args));
1283+
// Perform any type parameter substitutions.
1284+
1285+
tup_ty = ty::substitute_type_params(cx.tcx, subtys, tup_ty);
1286+
// Here we possibly do a recursive call.
1287+
1288+
auto this_size = llsize_of_real(cx, type_of(cx, sp, tup_ty));
1289+
if (max_size < this_size) { max_size = this_size; }
1290+
}
1291+
cx.tag_sizes.insert(t, max_size);
1292+
ret max_size;
1293+
}
12661294
case (_) {
12671295
cx.tcx.sess.span_fatal(sp,
12681296
"non-tag passed to " +
12691297
"static_size_of_tag()");
12701298
}
12711299
}
1272-
// Compute max(variant sizes).
1273-
1274-
auto max_size = 0u;
1275-
auto variants = ty::tag_variants(cx.tcx, tid);
1276-
for (ty::variant_info variant in variants) {
1277-
// TODO: Remove this vec->ivec conversion.
1278-
auto args = ~[];
1279-
for (ty::t typ in variant.args) { args += ~[typ]; }
1280-
1281-
auto tup_ty = simplify_type(cx, ty::mk_imm_tup(cx.tcx, args));
1282-
// Perform any type parameter substitutions.
1283-
1284-
tup_ty = ty::substitute_type_params(cx.tcx, subtys, tup_ty);
1285-
// Here we possibly do a recursive call.
1286-
1287-
auto this_size = llsize_of_real(cx, type_of(cx, sp, tup_ty));
1288-
if (max_size < this_size) { max_size = this_size; }
1289-
}
1290-
cx.tag_sizes.insert(t, max_size);
1291-
ret max_size;
12921300
}
12931301

12941302
fn dynamic_size_of(&@block_ctxt cx, ty::t t) -> result {
@@ -1516,7 +1524,7 @@ fn GEP_tup_like(&@block_ctxt cx, &ty::t t, ValueRef base, &vec[int] ixs) ->
15161524
// appropriate. @llblobptr is the data part of a tag value; its actual type is
15171525
// meaningless, as it will be cast away.
15181526
fn GEP_tag(@block_ctxt cx, ValueRef llblobptr, &ast::def_id tag_id,
1519-
&ast::def_id variant_id, &vec[ty::t] ty_substs, int ix) -> result {
1527+
&ast::def_id variant_id, &ty::t[] ty_substs, int ix) -> result {
15201528
auto variant =
15211529
ty::tag_variant_with_id(cx.fcx.lcx.ccx.tcx, tag_id, variant_id);
15221530
// Synthesize a tuple type so that GEP_tup_like() can work its magic.
@@ -2138,8 +2146,12 @@ fn make_drop_glue(&@block_ctxt cx, ValueRef v0, &ty::t t) {
21382146

21392147
fn trans_res_drop(@block_ctxt cx, ValueRef rs, &ast::def_id did,
21402148
ty::t inner_t, &vec[ty::t] tps) -> result {
2149+
// FIXME: Remove this vec->ivec conversion.
2150+
auto tps_ivec = ~[];
2151+
for (ty::t tp in tps) { tps_ivec += ~[tp]; }
2152+
21412153
auto ccx = cx.fcx.lcx.ccx;
2142-
auto inner_t_s = ty::substitute_type_params(ccx.tcx, tps, inner_t);
2154+
auto inner_t_s = ty::substitute_type_params(ccx.tcx, tps_ivec, inner_t);
21432155
auto tup_ty = ty::mk_imm_tup(ccx.tcx, ~[ty::mk_int(ccx.tcx), inner_t_s]);
21442156
auto drop_cx = new_sub_block_ctxt(cx, "drop res");
21452157
auto next_cx = new_sub_block_ctxt(cx, "next");
@@ -2645,7 +2657,7 @@ fn iter_structural_ty_full(&@block_ctxt cx, ValueRef av, ValueRef bv,
26452657
}
26462658

26472659
fn iter_variant(@block_ctxt cx, ValueRef a_tup, ValueRef b_tup,
2648-
&ty::variant_info variant, &vec[ty::t] tps,
2660+
&ty::variant_info variant, &ty::t[] tps,
26492661
&ast::def_id tid, &val_pair_and_ty_fn f) -> result {
26502662
if (vec::len[ty::t](variant.args) == 0u) {
26512663
ret rslt(cx, C_nil());
@@ -2707,8 +2719,12 @@ fn iter_structural_ty_full(&@block_ctxt cx, ValueRef av, ValueRef bv,
27072719
}
27082720
}
27092721
case (ty::ty_res(_, ?inner, ?tps)) {
2722+
// FIXME: Remove this vec->ivec conversion.
2723+
auto tps_ivec = ~[];
2724+
for (ty::t tp in tps) { tps_ivec += ~[tp]; }
2725+
27102726
auto inner1 = ty::substitute_type_params(cx.fcx.lcx.ccx.tcx,
2711-
tps, inner);
2727+
tps_ivec, inner);
27122728
r = GEP_tup_like(r.bcx, t, av, [0, 1]);
27132729
auto llfld_a = r.val;
27142730
r = GEP_tup_like(r.bcx, t, bv, [0, 1]);
@@ -4137,8 +4153,12 @@ fn autoderef_lval(&@block_ctxt cx, ValueRef v, &ty::t t, bool is_lval)
41374153
} else { v1 = body; }
41384154
}
41394155
case (ty::ty_res(?did, ?inner, ?tps)) {
4156+
// FIXME: Remove this vec->ivec conversion.
4157+
auto tps_ivec = ~[];
4158+
for (ty::t tp in tps) { tps_ivec += ~[tp]; }
4159+
41404160
if (is_lval) { v1 = cx.build.Load(v1); }
4141-
t1 = ty::substitute_type_params(ccx.tcx, tps, inner);
4161+
t1 = ty::substitute_type_params(ccx.tcx, tps_ivec, inner);
41424162
v1 = cx.build.GEP(v1, [C_int(0), C_int(1)]);
41434163
}
41444164
case (ty::ty_tag(?did, ?tps)) {
@@ -4712,14 +4732,19 @@ fn trans_pat_match(&@block_ctxt cx, &@ast::pat pat, ValueRef llval,
47124732
matched_cx.build.GEP(lltagptr, [C_int(0), C_int(1)]);
47134733
}
47144734
}
4735+
47154736
auto ty_params = ty::node_id_to_type_params
47164737
(cx.fcx.lcx.ccx.tcx, pat.id);
4738+
// FIXME: Remove this vec->ivec conversion.
4739+
auto tps_ivec = ~[];
4740+
for (ty::t tp in ty_params) { tps_ivec += ~[tp]; }
4741+
47174742
if (vec::len(subpats) > 0u) {
47184743
auto i = 0;
47194744
for (@ast::pat subpat in subpats) {
47204745
auto rslt =
47214746
GEP_tag(matched_cx, llblobptr, vdef._0, vdef._1,
4722-
ty_params, i);
4747+
tps_ivec, i);
47234748
auto llsubvalptr = rslt.val;
47244749
matched_cx = rslt.bcx;
47254750
auto llsubval =
@@ -4773,14 +4798,19 @@ fn trans_pat_binding(&@block_ctxt cx, &@ast::pat pat, ValueRef llval,
47734798
(llval, T_opaque_tag_ptr(cx.fcx.lcx.ccx.tn));
47744799
llblobptr = cx.build.GEP(lltagptr, [C_int(0), C_int(1)]);
47754800
}
4801+
47764802
auto ty_param_substs =
47774803
ty::node_id_to_type_params(cx.fcx.lcx.ccx.tcx, pat.id);
4804+
// FIXME: Remove this vec->ivec conversion.
4805+
auto tps_ivec = ~[];
4806+
for (ty::t tp in ty_param_substs) { tps_ivec += ~[tp]; }
4807+
47784808
auto this_cx = cx;
47794809
auto i = 0;
47804810
for (@ast::pat subpat in subpats) {
47814811
auto rslt =
4782-
GEP_tag(this_cx, llblobptr, vdef._0, vdef._1,
4783-
ty_param_substs, i);
4812+
GEP_tag(this_cx, llblobptr, vdef._0, vdef._1, tps_ivec,
4813+
i);
47844814
this_cx = rslt.bcx;
47854815
auto subpat_res =
47864816
trans_pat_binding(this_cx, subpat, rslt.val, true);
@@ -8478,10 +8508,10 @@ fn trans_tag_variant(@local_ctxt cx, ast::node_id tag_id,
84788508
create_llargs_for_fn_args(fcx, ast::proto_fn, none[ty_self_pair],
84798509
ty::ret_ty_of_fn(cx.ccx.tcx, variant.node.id),
84808510
fn_args, ty_params);
8481-
let vec[ty::t] ty_param_substs = [];
8511+
let ty::t[] ty_param_substs = ~[];
84828512
i = 0u;
84838513
for (ast::ty_param tp in ty_params) {
8484-
ty_param_substs += [ty::mk_param(cx.ccx.tcx, i)];
8514+
ty_param_substs += ~[ty::mk_param(cx.ccx.tcx, i)];
84858515
i += 1u;
84868516
}
84878517
auto arg_tys = arg_tys_of_fn(cx.ccx, variant.node.id);

src/comp/middle/ty.rs

+35-20
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ tag sty {
257257
ty_char;
258258
ty_str;
259259
ty_istr;
260-
ty_tag(def_id, vec[t]);
260+
ty_tag(def_id, t[]);
261261
ty_box(mt);
262262
ty_vec(mt);
263263
ty_ivec(mt);
@@ -557,7 +557,7 @@ fn mk_str(&ctxt cx) -> t { ret idx_str; }
557557

558558
fn mk_istr(&ctxt cx) -> t { ret idx_istr; }
559559

560-
fn mk_tag(&ctxt cx, &ast::def_id did, &vec[t] tys) -> t {
560+
fn mk_tag(&ctxt cx, &ast::def_id did, &t[] tys) -> t {
561561
ret gen_ty(cx, ty_tag(did, tys));
562562
}
563563

@@ -753,9 +753,9 @@ fn fold_ty(&ctxt cx, fold_mode fld, t ty_0) -> t {
753753
ty = copy_cname(cx, mk_chan(cx, fold_ty(cx, fld, subty)), ty);
754754
}
755755
case (ty_tag(?tid, ?subtys)) {
756-
let vec[t] new_subtys = [];
756+
let t[] new_subtys = ~[];
757757
for (t subty in subtys) {
758-
new_subtys += [fold_ty(cx, fld, subty)];
758+
new_subtys += ~[fold_ty(cx, fld, subty)];
759759
}
760760
ty = copy_cname(cx, mk_tag(cx, tid, new_subtys), ty);
761761
}
@@ -1052,8 +1052,12 @@ fn type_has_pointers(&ctxt cx, &t ty) -> bool {
10521052
}
10531053
}
10541054
case (ty_res(?did, ?inner, ?tps)) {
1055+
// FIXME: Remove this vec->ivec conversion.
1056+
auto tps_ivec = ~[];
1057+
for (ty::t tp in tps) { tps_ivec += ~[tp]; }
1058+
10551059
result = type_has_pointers
1056-
(cx, substitute_type_params(cx, tps, inner));
1060+
(cx, substitute_type_params(cx, tps_ivec, inner));
10571061
}
10581062
case (_) { result = true; }
10591063
}
@@ -1086,7 +1090,7 @@ fn type_has_dynamic_size(&ctxt cx, &t ty) -> bool {
10861090
case (ty_istr) { ret false; }
10871091
case (ty_tag(_, ?subtys)) {
10881092
auto i = 0u;
1089-
while (i < vec::len[t](subtys)) {
1093+
while (i < ivec::len[t](subtys)) {
10901094
if (type_has_dynamic_size(cx, subtys.(i))) { ret true; }
10911095
i += 1u;
10921096
}
@@ -1240,8 +1244,12 @@ fn type_owns_heap_mem(&ctxt cx, &t ty) -> bool {
12401244
}
12411245
}
12421246
case (ty_res(_, ?inner, ?tps)) {
1247+
// FIXME: Remove this vec->ivec conversion.
1248+
auto tps_ivec = ~[];
1249+
for (ty::t tp in tps) { tps_ivec += ~[tp]; }
1250+
12431251
result = type_owns_heap_mem
1244-
(cx, substitute_type_params(cx, tps, inner));
1252+
(cx, substitute_type_params(cx, tps_ivec, inner));
12451253
}
12461254

12471255
case (ty_ptr(_)) { result = false; }
@@ -1272,7 +1280,11 @@ fn type_autoderef(&ctxt cx, &ty::t t) -> ty::t {
12721280
alt (struct(cx, t1)) {
12731281
case (ty::ty_box(?mt)) { t1 = mt.ty; }
12741282
case (ty::ty_res(_, ?inner, ?tps)) {
1275-
t1 = substitute_type_params(cx, tps, inner);
1283+
// FIXME: Remove this vec->ivec conversion.
1284+
auto tps_ivec = ~[];
1285+
for (ty::t tp in tps) { tps_ivec += ~[tp]; }
1286+
1287+
t1 = substitute_type_params(cx, tps_ivec, inner);
12761288
}
12771289
case (ty::ty_tag(?did, ?tps)) {
12781290
auto variants = tag_variants(cx, did);
@@ -1514,8 +1526,8 @@ fn equal_type_structures(&sty a, &sty b) -> bool {
15141526
alt (b) {
15151527
case (ty_tag(?id_b, ?tys_b)) {
15161528
if (!equal_def(id_a, id_b)) { ret false; }
1517-
auto len = vec::len[t](tys_a);
1518-
if (len != vec::len[t](tys_b)) { ret false; }
1529+
auto len = ivec::len[t](tys_a);
1530+
if (len != ivec::len[t](tys_b)) { ret false; }
15191531
auto i = 0u;
15201532
while (i < len) {
15211533
if (!eq_ty(tys_a.(i), tys_b.(i))) { ret false; }
@@ -1755,7 +1767,13 @@ fn ty_param_substs_opt_and_ty_to_monotype(&ctxt cx,
17551767
t {
17561768
alt (tpot._0) {
17571769
case (none) { ret tpot._1; }
1758-
case (some(?tps)) { ret substitute_type_params(cx, tps, tpot._1); }
1770+
case (some(?tps)) {
1771+
// FIXME: Remove this vec->ivec conversion.
1772+
auto tps_ivec = ~[];
1773+
for (ty::t tp in tps) { tps_ivec += ~[tp]; }
1774+
1775+
ret substitute_type_params(cx, tps_ivec, tpot._1);
1776+
}
17591777
}
17601778
}
17611779

@@ -2328,18 +2346,16 @@ mod unify {
23282346
// TODO: factor this cruft out, see the TODO in the
23292347
// ty::ty_tup case
23302348

2331-
let vec[t] result_tps = [];
2349+
let t[] result_tps = ~[];
23322350
auto i = 0u;
2333-
auto expected_len = vec::len[t](expected_tps);
2351+
auto expected_len = ivec::len[t](expected_tps);
23342352
while (i < expected_len) {
23352353
auto expected_tp = expected_tps.(i);
23362354
auto actual_tp = actual_tps.(i);
23372355
auto result =
23382356
unify_step(cx, expected_tp, actual_tp);
23392357
alt (result) {
2340-
case (ures_ok(?rty)) {
2341-
vec::push[t](result_tps, rty);
2342-
}
2358+
case (ures_ok(?rty)) { result_tps += ~[rty]; }
23432359
case (_) { ret result; }
23442360
}
23452361
i += 1u;
@@ -2769,14 +2785,13 @@ fn bind_params_in_type(&span sp, &ctxt cx, fn() -> int next_ty_var, t typ,
27692785

27702786
// Replaces type parameters in the given type using the given list of
27712787
// substitions.
2772-
fn substitute_type_params(&ctxt cx, vec[ty::t] substs, t typ) -> t {
2788+
fn substitute_type_params(&ctxt cx, &ty::t[] substs, t typ) -> t {
27732789
if (!type_contains_params(cx, typ)) { ret typ; }
2774-
fn substituter(ctxt cx, vec[ty::t] substs, uint idx) -> t {
2790+
fn substituter(ctxt cx, @ty::t[] substs, uint idx) -> t {
27752791
// FIXME: bounds check can fail
2776-
27772792
ret substs.(idx);
27782793
}
2779-
ret fold_ty(cx, fm_param(bind substituter(cx, substs, _)), typ);
2794+
ret fold_ty(cx, fm_param(bind substituter(cx, @substs, _)), typ);
27802795
}
27812796

27822797
fn def_has_ty_params(&ast::def def) -> bool {

0 commit comments

Comments
 (0)