Skip to content

Commit cb2018c

Browse files
committed
rustc: Change constraints in types to use interior vectors
1 parent 13d920c commit cb2018c

File tree

6 files changed

+47
-42
lines changed

6 files changed

+47
-42
lines changed

src/comp/metadata/tydecode.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ fn parse_ty_or_bang(@pstate st, str_def sd) -> ty_or_bang {
6565
}
6666
}
6767

68-
fn parse_constrs(@pstate st, str_def sd) -> vec[@ty::constr_def] {
69-
let vec[@ty::constr_def] rslt = [];
68+
fn parse_constrs(@pstate st, str_def sd) -> (@ty::constr_def)[] {
69+
let (@ty::constr_def)[] rslt = ~[];
7070
alt (peek(st) as char) {
7171
case (':') {
7272
do {
7373
next(st);
74-
vec::push(rslt, parse_constr(st, sd));
74+
rslt += ~[parse_constr(st, sd)];
7575
} while (peek(st) as char == ';')
7676
}
7777
case (_) { }
@@ -333,7 +333,7 @@ fn parse_hex(@pstate st) -> uint {
333333
}
334334

335335
fn parse_ty_fn(@pstate st, str_def sd) ->
336-
tup(ty::arg[], ty::t, ast::controlflow, vec[@ty::constr_def]) {
336+
tup(ty::arg[], ty::t, ast::controlflow, (@ty::constr_def)[]) {
337337
assert (next(st) as char == '[');
338338
let ty::arg[] inputs = ~[];
339339
while (peek(st) as char != ']') {

src/comp/metadata/tyencode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ fn enc_sty(&io::writer w, &@ctxt cx, &ty::sty st) {
162162
case (native_abi_cdecl) { w.write_char('c'); }
163163
case (native_abi_llvm) { w.write_char('l'); }
164164
}
165-
enc_ty_fn(w, cx, args, out, return, []);
165+
enc_ty_fn(w, cx, args, out, return, ~[]);
166166
}
167167
case (ty::ty_obj(?methods)) {
168168
w.write_str("O[");
@@ -205,7 +205,7 @@ fn enc_proto(&io::writer w, proto proto) {
205205
}
206206
}
207207
fn enc_ty_fn(&io::writer w, &@ctxt cx, &ty::arg[] args, &ty::t out,
208-
&controlflow cf, &vec[@ty::constr_def] constrs) {
208+
&controlflow cf, &(@ty::constr_def)[] constrs) {
209209
w.write_char('[');
210210
for (ty::arg arg in args) {
211211
alt (arg.mode) {

src/comp/middle/tstate/auxiliary.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,10 @@ fn controlflow_expr(&crate_ctxt ccx, @expr e) -> controlflow {
453453
}
454454
}
455455

456-
fn constraints_expr(&ty::ctxt cx, @expr e) -> vec[@ty::constr_def] {
456+
fn constraints_expr(&ty::ctxt cx, @expr e) -> (@ty::constr_def)[] {
457457
alt (ty::struct(cx, ty::node_id_to_type(cx, e.id))) {
458458
case (ty::ty_fn(_, _, _, _, ?cs)) { ret cs; }
459-
case (_) { ret []; }
459+
case (_) { ret ~[]; }
460460
}
461461
}
462462

src/comp/middle/ty.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ type method =
196196
arg[] inputs,
197197
t output,
198198
controlflow cf,
199-
vec[@constr_def] constrs);
199+
(@constr_def)[] constrs);
200200

201201
type constr_table = hashmap[ast::node_id, vec[constr_def]];
202202

@@ -267,9 +267,9 @@ tag sty {
267267
ty_task;
268268
ty_tup(mt[]);
269269
ty_rec(field[]);
270-
ty_fn(ast::proto, arg[], t, controlflow, vec[@constr_def]);
270+
ty_fn(ast::proto, arg[], t, controlflow, (@constr_def)[]);
271271
ty_native_fn(ast::native_abi, arg[], t);
272-
ty_obj(method[]);
272+
ty_obj(vec[method]);
273273
ty_res(def_id, t, t[]);
274274
ty_var(int); // type variable
275275
ty_param(uint); // fn/tag type param
@@ -596,7 +596,7 @@ fn mk_imm_tup(&ctxt cx, &t[] tys) -> t {
596596
fn mk_rec(&ctxt cx, &field[] fs) -> t { ret gen_ty(cx, ty_rec(fs)); }
597597

598598
fn mk_fn(&ctxt cx, &ast::proto proto, &arg[] args, &t ty, &controlflow cf,
599-
&vec[@constr_def] constrs) -> t {
599+
&(@constr_def)[] constrs) -> t {
600600
ret gen_ty(cx, ty_fn(proto, args, ty, cf, constrs));
601601
}
602602

@@ -1454,8 +1454,8 @@ fn constr_eq(&@constr_def c, &@constr_def d) -> bool {
14541454
args_eq(eq_int, c.node.args, d.node.args);
14551455
}
14561456

1457-
fn constrs_eq(&vec[@constr_def] cs, &vec[@constr_def] ds) -> bool {
1458-
if (vec::len(cs) != vec::len(ds)) { ret false; }
1457+
fn constrs_eq(&(@constr_def)[] cs, &(@constr_def)[] ds) -> bool {
1458+
if (ivec::len(cs) != ivec::len(ds)) { ret false; }
14591459
auto i = 0u;
14601460
for (@constr_def c in cs) {
14611461
if (!constr_eq(c, ds.(i))) { ret false; }
@@ -2139,8 +2139,8 @@ mod unify {
21392139
&t expected, &t actual, &arg[] expected_inputs,
21402140
&t expected_output, &arg[] actual_inputs, &t actual_output,
21412141
&controlflow expected_cf, &controlflow actual_cf,
2142-
&vec[@constr_def] expected_constrs,
2143-
&vec[@constr_def] actual_constrs) -> result {
2142+
&(@constr_def)[] expected_constrs,
2143+
&(@constr_def)[] actual_constrs) -> result {
21442144
if (e_proto != a_proto) { ret ures_err(terr_mismatch); }
21452145
alt (expected_cf) {
21462146
case (ast::return) { }

src/comp/middle/typeck.rs

+28-23
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,10 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
337337
}
338338
auto out_ty = ast_ty_to_ty(tcx, getter, output);
339339

340-
let fn(&@ast::constr) -> @ty::constr_def g =
341-
bind ast_constr_to_constr(tcx, _);
342-
let vec[@ty::constr_def] out_constrs = vec::map(g, constrs);
340+
auto out_constrs = ~[];
341+
for (@ast::constr constr in constrs) {
342+
out_constrs += ~[ast_constr_to_constr(tcx, constr)];
343+
}
343344
typ = ty::mk_fn(tcx, proto, i, out_ty, cf, out_constrs);
344345
}
345346
case (ast::ty_path(?path, ?id)) {
@@ -373,10 +374,10 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
373374
}
374375
auto out = ast_ty_to_ty(tcx, getter, m.node.output);
375376

376-
let fn(&@ast::constr) -> @ty::constr_def g =
377-
bind ast_constr_to_constr(tcx, _);
378-
let vec[@ty::constr_def] out_constrs =
379-
vec::map(g, m.node.constrs);
377+
auto out_constrs = ~[];
378+
for (@ast::constr constr in m.node.constrs) {
379+
out_constrs += ~[ast_constr_to_constr(tcx, constr)];
380+
}
380381
let ty::method new_m =
381382
rec(proto=m.node.proto,
382383
ident=m.node.ident,
@@ -492,9 +493,10 @@ mod collect {
492493
for (ast::arg a in decl.inputs) { input_tys += ~[ty_of_arg(a)]; }
493494
auto output_ty = convert(decl.output);
494495

495-
let fn(&@ast::constr) -> @ty::constr_def g =
496-
bind ast_constr_to_constr(cx.tcx, _);
497-
let vec[@ty::constr_def] out_constrs = vec::map(g, decl.constraints);
496+
auto out_constrs = ~[];
497+
for (@ast::constr constr in decl.constraints) {
498+
out_constrs += ~[ast_constr_to_constr(cx.tcx, constr)];
499+
}
498500
auto t_fn =
499501
ty::mk_fn(cx.tcx, proto, input_tys, output_ty, decl.cf,
500502
out_constrs);
@@ -570,10 +572,11 @@ mod collect {
570572
}
571573

572574
auto output = convert(m.node.meth.decl.output);
573-
let fn(&@ast::constr) -> @ty::constr_def g =
574-
bind ast_constr_to_constr(cx.tcx, _);
575-
let vec[@ty::constr_def] out_constrs =
576-
vec::map(g, m.node.meth.decl.constraints);
575+
576+
auto out_constrs = ~[];
577+
for (@ast::constr constr in m.node.meth.decl.constraints) {
578+
out_constrs += ~[ast_constr_to_constr(cx.tcx, constr)];
579+
}
577580
ret rec(proto=m.node.meth.proto, ident=m.node.ident,
578581
inputs=inputs, output=output, cf=m.node.meth.decl.cf,
579582
constrs=out_constrs);
@@ -598,7 +601,7 @@ mod collect {
598601
}
599602

600603
auto t_fn = ty::mk_fn(cx.tcx, ast::proto_fn, t_inputs, t_obj._1,
601-
ast::return, []);
604+
ast::return, ~[]);
602605
auto tpt = tup(t_obj._0, t_fn);
603606
cx.tcx.tcache.insert(local_def(ctor_id), tpt);
604607
ret tpt;
@@ -709,7 +712,7 @@ mod collect {
709712
auto tag_t = ty::mk_tag(cx.tcx, tag_id, ty_param_tys);
710713
// FIXME: this will be different for constrained types
711714
result_ty = ty::mk_fn(cx.tcx, ast::proto_fn, args, tag_t,
712-
ast::return, []);
715+
ast::return, ~[]);
713716
}
714717
auto tpt = tup(ty_param_count, result_ty);
715718
cx.tcx.tcache.insert(local_def(variant.node.id), tpt);
@@ -780,7 +783,7 @@ mod collect {
780783
case (none) {/* nothing to do */ }
781784
case (some(?m)) {
782785
auto t = ty::mk_fn(cx.tcx, ast::proto_fn, ~[],
783-
ty::mk_nil(cx.tcx), ast::return, []);
786+
ty::mk_nil(cx.tcx), ast::return, ~[]);
784787
write::ty_only(cx.tcx, m.node.id, t);
785788
}
786789
}
@@ -790,9 +793,9 @@ mod collect {
790793
auto t_res = ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty,
791794
mk_ty_params(cx, vec::len(tps)));
792795
auto t_ctor = ty::mk_fn(cx.tcx, ast::proto_fn, ~[t_arg],
793-
t_res, ast::return, []);
796+
t_res, ast::return, ~[]);
794797
auto t_dtor = ty::mk_fn(cx.tcx, ast::proto_fn, ~[t_arg],
795-
ty::mk_nil(cx.tcx), ast::return, []);
798+
ty::mk_nil(cx.tcx), ast::return, ~[]);
796799
write::ty_only(cx.tcx, it.id, t_res);
797800
write::ty_only(cx.tcx, ctor_id, t_ctor);
798801
cx.tcx.tcache.insert(local_def(ctor_id),
@@ -2285,10 +2288,12 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
22852288
}
22862289

22872290
auto output = convert(m.node.meth.decl.output);
2288-
let fn(&@ast::constr) -> @ty::constr_def g =
2289-
bind ast_constr_to_constr(ccx.tcx, _);
2290-
let vec[@ty::constr_def] out_constrs =
2291-
vec::map(g, m.node.meth.decl.constraints);
2291+
2292+
auto out_constrs = ~[];
2293+
for (@ast::constr constr in m.node.meth.decl.constraints) {
2294+
out_constrs += ~[ast_constr_to_constr(ccx.tcx, constr)];
2295+
}
2296+
22922297
ret rec(proto=m.node.meth.proto, ident=m.node.ident,
22932298
inputs=inputs, output=output, cf=m.node.meth.decl.cf,
22942299
constrs=out_constrs);

src/comp/util/ppaux.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn ty_to_str(&ctxt cx, &t typ) -> str {
4747
}
4848
fn fn_to_str(&ctxt cx, ast::proto proto, option::t[ast::ident] ident,
4949
&arg[] inputs, t output, ast::controlflow cf,
50-
&vec[@constr_def] constrs) -> str {
50+
&(@constr_def)[] constrs) -> str {
5151
auto s;
5252
alt (proto) {
5353
case (ast::proto_iter) { s = "iter"; }
@@ -130,7 +130,7 @@ fn ty_to_str(&ctxt cx, &t typ) -> str {
130130
}
131131
case (ty_native_fn(_, ?inputs, ?output)) {
132132
s += fn_to_str(cx, ast::proto_fn, none, inputs, output,
133-
ast::return, []);
133+
ast::return, ~[]);
134134
}
135135
case (ty_obj(?meths)) {
136136
auto f = bind method_to_str(cx, _);
@@ -162,7 +162,7 @@ fn constr_to_str(&@constr_def c) -> str {
162162
pprust::constr_args_to_str(pprust::uint_to_str, c.node.args);
163163
}
164164

165-
fn constrs_str(&vec[@constr_def] constrs) -> str {
165+
fn constrs_str(&(@constr_def)[] constrs) -> str {
166166
auto s = "";
167167
auto colon = true;
168168
for (@constr_def c in constrs) {

0 commit comments

Comments
 (0)