Skip to content

Commit 6720ea7

Browse files
committed
rustc: Change methods in ty::t to use interior vectors
1 parent 172c563 commit 6720ea7

File tree

4 files changed

+48
-43
lines changed

4 files changed

+48
-43
lines changed

src/comp/metadata/tydecode.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
230230
}
231231
case ('O') {
232232
assert (next(st) as char == '[');
233-
let vec[ty::method] methods = [];
233+
let ty::method[] methods = ~[];
234234
while (peek(st) as char != ']') {
235235
auto proto;
236236
alt (next(st) as char) {
@@ -243,12 +243,12 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
243243
}
244244
auto func = parse_ty_fn(st, sd);
245245
methods +=
246-
[rec(proto=proto,
247-
ident=name,
248-
inputs=func._0,
249-
output=func._1,
250-
cf=func._2,
251-
constrs=func._3)];
246+
~[rec(proto=proto,
247+
ident=name,
248+
inputs=func._0,
249+
output=func._1,
250+
cf=func._2,
251+
constrs=func._3)];
252252
}
253253
st.pos += 1u;
254254
ret ty::mk_obj(st.tcx, methods);

src/comp/middle/ty.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ tag sty {
268268
ty_rec(field[]);
269269
ty_fn(ast::proto, arg[], t, controlflow, vec[@constr_def]);
270270
ty_native_fn(ast::native_abi, arg[], t);
271-
ty_obj(vec[method]);
271+
ty_obj(method[]);
272272
ty_res(def_id, t, vec[t]);
273273
ty_var(int); // type variable
274274
ty_param(uint); // fn/tag type param
@@ -603,7 +603,7 @@ fn mk_native_fn(&ctxt cx, &ast::native_abi abi, &arg[] args, &t ty) -> t {
603603
ret gen_ty(cx, ty_native_fn(abi, args, ty));
604604
}
605605

606-
fn mk_obj(&ctxt cx, &vec[method] meths) -> t {
606+
fn mk_obj(&ctxt cx, &method[] meths) -> t {
607607
ret gen_ty(cx, ty_obj(meths));
608608
}
609609

@@ -811,20 +811,20 @@ fn fold_ty(&ctxt cx, fold_mode fld, t ty_0) -> t {
811811
fold_ty(cx, fld, ret_ty)), ty);
812812
}
813813
case (ty_obj(?methods)) {
814-
let vec[method] new_methods = [];
814+
let method[] new_methods = ~[];
815815
for (method m in methods) {
816816
let arg[] new_args = ~[];
817817
for (arg a in m.inputs) {
818818
new_args += ~[rec(mode=a.mode,
819819
ty=fold_ty(cx, fld, a.ty))];
820820
}
821821
new_methods +=
822-
[rec(proto=m.proto,
823-
ident=m.ident,
824-
inputs=new_args,
825-
output=fold_ty(cx, fld, m.output),
826-
cf=m.cf,
827-
constrs=m.constrs)];
822+
~[rec(proto=m.proto,
823+
ident=m.ident,
824+
inputs=new_args,
825+
output=fold_ty(cx, fld, m.output),
826+
cf=m.cf,
827+
constrs=m.constrs)];
828828
}
829829
ty = copy_cname(cx, mk_obj(cx, new_methods), ty);
830830
}
@@ -1634,8 +1634,8 @@ fn equal_type_structures(&sty a, &sty b) -> bool {
16341634
case (ty_obj(?methods_a)) {
16351635
alt (b) {
16361636
case (ty_obj(?methods_b)) {
1637-
auto len = vec::len[method](methods_a);
1638-
if (len != vec::len[method](methods_b)) { ret false; }
1637+
auto len = ivec::len[method](methods_a);
1638+
if (len != ivec::len[method](methods_b)) { ret false; }
16391639
auto i = 0u;
16401640
while (i < len) {
16411641
auto m_a = methods_a.(i);
@@ -1947,17 +1947,17 @@ fn field_idx(&session::session sess, &span sp, &ast::ident id,
19471947
}
19481948

19491949
fn method_idx(&session::session sess, &span sp, &ast::ident id,
1950-
&vec[method] meths) -> uint {
1950+
&method[] meths) -> uint {
19511951
let uint i = 0u;
19521952
for (method m in meths) { if (str::eq(m.ident, id)) { ret i; } i += 1u; }
19531953
sess.span_fatal(sp, "unknown method '" + id + "' of obj");
19541954
}
19551955

1956-
fn sort_methods(&vec[method] meths) -> vec[method] {
1956+
fn sort_methods(&method[] meths) -> method[] {
19571957
fn method_lteq(&method a, &method b) -> bool {
19581958
ret str::lteq(a.ident, b.ident);
19591959
}
1960-
ret std::sort::merge_sort[method](bind method_lteq(_, _), meths);
1960+
ret std::sort::ivector::merge_sort[method](bind method_lteq(_, _), meths);
19611961
}
19621962

19631963
fn is_lval(&@ast::expr expr) -> bool {
@@ -2197,12 +2197,12 @@ mod unify {
21972197
}
21982198
}
21992199
fn unify_obj(&@ctxt cx, &t expected, &t actual,
2200-
&vec[method] expected_meths, &vec[method] actual_meths) ->
2200+
&method[] expected_meths, &method[] actual_meths) ->
22012201
result {
2202-
let vec[method] result_meths = [];
2202+
let method[] result_meths = ~[];
22032203
let uint i = 0u;
2204-
let uint expected_len = vec::len[method](expected_meths);
2205-
let uint actual_len = vec::len[method](actual_meths);
2204+
let uint expected_len = ivec::len[method](expected_meths);
2205+
let uint actual_len = ivec::len[method](actual_meths);
22062206
if (expected_len != actual_len) { ret ures_err(terr_meth_count); }
22072207
while (i < expected_len) {
22082208
auto e_meth = expected_meths.(i);
@@ -2220,10 +2220,10 @@ mod unify {
22202220
alt (struct(cx.tcx, tfn)) {
22212221
case (ty_fn(?proto, ?ins, ?out, ?cf, ?constrs)) {
22222222
result_meths +=
2223-
[rec(inputs=ins,
2224-
output=out,
2225-
cf=cf,
2226-
constrs=constrs with e_meth)];
2223+
~[rec(inputs=ins,
2224+
output=out,
2225+
cf=cf,
2226+
constrs=constrs with e_meth)];
22272227
}
22282228
}
22292229
}

src/comp/middle/typeck.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
336336
cname = some(path_to_str(path));
337337
}
338338
case (ast::ty_obj(?meths)) {
339-
let vec[ty::method] tmeths = [];
339+
let ty::method[] tmeths = ~[];
340340
for (ast::ty_method m in meths) {
341341
auto ins = ~[];
342342
for (ast::ty_arg ta in m.node.inputs) {
@@ -355,7 +355,7 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
355355
output=out,
356356
cf=m.node.cf,
357357
constrs=out_constrs);
358-
vec::push[ty::method](tmeths, new_m);
358+
tmeths += ~[new_m];
359359
}
360360
typ = ty::mk_obj(tcx, ty::sort_methods(tmeths));
361361
}
@@ -681,9 +681,12 @@ mod collect {
681681
write::ty_only(cx.tcx, variant.node.id, result_ty);
682682
}
683683
}
684-
fn get_obj_method_types(&@ctxt cx, &ast::_obj object) -> vec[ty::method] {
685-
ret vec::map[@ast::method,
686-
method](bind ty_of_method(cx, _), object.methods);
684+
fn get_obj_method_types(&@ctxt cx, &ast::_obj object) -> ty::method[] {
685+
auto meths = ~[];
686+
for (@ast::method am in object.methods) {
687+
meths += ~[ty_of_method(cx, am)];
688+
}
689+
ret meths;
687690
}
688691
fn convert(@ctxt cx, @mutable option::t[ast::native_abi] abi,
689692
&@ast::item it) {
@@ -2069,7 +2072,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
20692072
let uint ix =
20702073
ty::method_idx(fcx.ccx.tcx.sess, expr.span, field,
20712074
methods);
2072-
if (ix >= vec::len[ty::method](methods)) {
2075+
if (ix >= ivec::len[ty::method](methods)) {
20732076
fcx.ccx.tcx.sess.span_fatal(expr.span,
20742077
"bad index on obj");
20752078
}
@@ -2213,11 +2216,13 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
22132216
constrs=out_constrs);
22142217
}
22152218
fn get_anon_obj_method_types(@crate_ctxt ccx,
2216-
&ast::anon_obj anon_obj) ->
2217-
vec[ty::method] {
2218-
ret vec::map[@ast::method,
2219-
method](bind ty_of_method(ccx, _),
2220-
anon_obj.methods);
2219+
&ast::anon_obj anon_obj)
2220+
-> ty::method[] {
2221+
auto meths = ~[];
2222+
for (@ast::method am in anon_obj.methods) {
2223+
meths += ~[ty_of_method(ccx, am)];
2224+
}
2225+
ret meths;
22212226
}
22222227
auto method_types = get_anon_obj_method_types(fcx.ccx, anon_obj);
22232228
auto ot = ty::mk_obj(fcx.ccx.tcx, ty::sort_methods(method_types));

src/comp/pretty/ppaux.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ fn ty_to_str(&ctxt cx, &t typ) -> str {
135135
ast::return, []);
136136
}
137137
case (ty_obj(?meths)) {
138-
auto f = bind method_to_str(cx, _);
139-
auto m = vec::map[method, str](f, meths);
140-
s += "obj {\n\t" + str::connect(m, "\n\t") + "\n}";
138+
auto strs = [];
139+
for (method m in meths) { strs += [method_to_str(cx, m)]; }
140+
s += "obj {\n\t" + str::connect(strs, "\n\t") + "\n}";
141141
}
142142
case (ty_res(?id, _, _)) {
143143
s += "<resource#" + istr(id._0) + ":" + istr(id._1) + ">";

0 commit comments

Comments
 (0)