rustc: Change constraints in types to use interior vectors

This commit is contained in:
Patrick Walton 2011-07-01 15:50:32 -07:00
parent f391acbd3f
commit 8bee69da25
6 changed files with 47 additions and 42 deletions

View File

@ -65,13 +65,13 @@ fn parse_ty_or_bang(@pstate st, str_def sd) -> ty_or_bang {
}
}
fn parse_constrs(@pstate st, str_def sd) -> vec[@ty::constr_def] {
let vec[@ty::constr_def] rslt = [];
fn parse_constrs(@pstate st, str_def sd) -> (@ty::constr_def)[] {
let (@ty::constr_def)[] rslt = ~[];
alt (peek(st) as char) {
case (':') {
do {
next(st);
vec::push(rslt, parse_constr(st, sd));
rslt += ~[parse_constr(st, sd)];
} while (peek(st) as char == ';')
}
case (_) { }
@ -333,7 +333,7 @@ fn parse_hex(@pstate st) -> uint {
}
fn parse_ty_fn(@pstate st, str_def sd) ->
tup(ty::arg[], ty::t, ast::controlflow, vec[@ty::constr_def]) {
tup(ty::arg[], ty::t, ast::controlflow, (@ty::constr_def)[]) {
assert (next(st) as char == '[');
let ty::arg[] inputs = ~[];
while (peek(st) as char != ']') {

View File

@ -162,7 +162,7 @@ fn enc_sty(&io::writer w, &@ctxt cx, &ty::sty st) {
case (native_abi_cdecl) { w.write_char('c'); }
case (native_abi_llvm) { w.write_char('l'); }
}
enc_ty_fn(w, cx, args, out, return, []);
enc_ty_fn(w, cx, args, out, return, ~[]);
}
case (ty::ty_obj(?methods)) {
w.write_str("O[");
@ -205,7 +205,7 @@ fn enc_proto(&io::writer w, proto proto) {
}
}
fn enc_ty_fn(&io::writer w, &@ctxt cx, &ty::arg[] args, &ty::t out,
&controlflow cf, &vec[@ty::constr_def] constrs) {
&controlflow cf, &(@ty::constr_def)[] constrs) {
w.write_char('[');
for (ty::arg arg in args) {
alt (arg.mode) {

View File

@ -453,10 +453,10 @@ fn controlflow_expr(&crate_ctxt ccx, @expr e) -> controlflow {
}
}
fn constraints_expr(&ty::ctxt cx, @expr e) -> vec[@ty::constr_def] {
fn constraints_expr(&ty::ctxt cx, @expr e) -> (@ty::constr_def)[] {
alt (ty::struct(cx, ty::node_id_to_type(cx, e.id))) {
case (ty::ty_fn(_, _, _, _, ?cs)) { ret cs; }
case (_) { ret []; }
case (_) { ret ~[]; }
}
}

View File

@ -196,7 +196,7 @@ type method =
arg[] inputs,
t output,
controlflow cf,
vec[@constr_def] constrs);
(@constr_def)[] constrs);
type constr_table = hashmap[ast::node_id, vec[constr_def]];
@ -267,9 +267,9 @@ tag sty {
ty_task;
ty_tup(mt[]);
ty_rec(field[]);
ty_fn(ast::proto, arg[], t, controlflow, vec[@constr_def]);
ty_fn(ast::proto, arg[], t, controlflow, (@constr_def)[]);
ty_native_fn(ast::native_abi, arg[], t);
ty_obj(method[]);
ty_obj(vec[method]);
ty_res(def_id, t, t[]);
ty_var(int); // type variable
ty_param(uint); // fn/tag type param
@ -596,7 +596,7 @@ fn mk_imm_tup(&ctxt cx, &t[] tys) -> t {
fn mk_rec(&ctxt cx, &field[] fs) -> t { ret gen_ty(cx, ty_rec(fs)); }
fn mk_fn(&ctxt cx, &ast::proto proto, &arg[] args, &t ty, &controlflow cf,
&vec[@constr_def] constrs) -> t {
&(@constr_def)[] constrs) -> t {
ret gen_ty(cx, ty_fn(proto, args, ty, cf, constrs));
}
@ -1454,8 +1454,8 @@ fn constr_eq(&@constr_def c, &@constr_def d) -> bool {
args_eq(eq_int, c.node.args, d.node.args);
}
fn constrs_eq(&vec[@constr_def] cs, &vec[@constr_def] ds) -> bool {
if (vec::len(cs) != vec::len(ds)) { ret false; }
fn constrs_eq(&(@constr_def)[] cs, &(@constr_def)[] ds) -> bool {
if (ivec::len(cs) != ivec::len(ds)) { ret false; }
auto i = 0u;
for (@constr_def c in cs) {
if (!constr_eq(c, ds.(i))) { ret false; }
@ -2139,8 +2139,8 @@ mod unify {
&t expected, &t actual, &arg[] expected_inputs,
&t expected_output, &arg[] actual_inputs, &t actual_output,
&controlflow expected_cf, &controlflow actual_cf,
&vec[@constr_def] expected_constrs,
&vec[@constr_def] actual_constrs) -> result {
&(@constr_def)[] expected_constrs,
&(@constr_def)[] actual_constrs) -> result {
if (e_proto != a_proto) { ret ures_err(terr_mismatch); }
alt (expected_cf) {
case (ast::return) { }

View File

@ -335,9 +335,10 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
}
auto out_ty = ast_ty_to_ty(tcx, getter, output);
let fn(&@ast::constr) -> @ty::constr_def g =
bind ast_constr_to_constr(tcx, _);
let vec[@ty::constr_def] out_constrs = vec::map(g, constrs);
auto out_constrs = ~[];
for (@ast::constr constr in constrs) {
out_constrs += ~[ast_constr_to_constr(tcx, constr)];
}
typ = ty::mk_fn(tcx, proto, i, out_ty, cf, out_constrs);
}
case (ast::ty_path(?path, ?id)) {
@ -371,10 +372,10 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
}
auto out = ast_ty_to_ty(tcx, getter, m.node.output);
let fn(&@ast::constr) -> @ty::constr_def g =
bind ast_constr_to_constr(tcx, _);
let vec[@ty::constr_def] out_constrs =
vec::map(g, m.node.constrs);
auto out_constrs = ~[];
for (@ast::constr constr in m.node.constrs) {
out_constrs += ~[ast_constr_to_constr(tcx, constr)];
}
let ty::method new_m =
rec(proto=m.node.proto,
ident=m.node.ident,
@ -490,9 +491,10 @@ mod collect {
for (ast::arg a in decl.inputs) { input_tys += ~[ty_of_arg(a)]; }
auto output_ty = convert(decl.output);
let fn(&@ast::constr) -> @ty::constr_def g =
bind ast_constr_to_constr(cx.tcx, _);
let vec[@ty::constr_def] out_constrs = vec::map(g, decl.constraints);
auto out_constrs = ~[];
for (@ast::constr constr in decl.constraints) {
out_constrs += ~[ast_constr_to_constr(cx.tcx, constr)];
}
auto t_fn =
ty::mk_fn(cx.tcx, proto, input_tys, output_ty, decl.cf,
out_constrs);
@ -568,10 +570,11 @@ mod collect {
}
auto output = convert(m.node.meth.decl.output);
let fn(&@ast::constr) -> @ty::constr_def g =
bind ast_constr_to_constr(cx.tcx, _);
let vec[@ty::constr_def] out_constrs =
vec::map(g, m.node.meth.decl.constraints);
auto out_constrs = ~[];
for (@ast::constr constr in m.node.meth.decl.constraints) {
out_constrs += ~[ast_constr_to_constr(cx.tcx, constr)];
}
ret rec(proto=m.node.meth.proto, ident=m.node.ident,
inputs=inputs, output=output, cf=m.node.meth.decl.cf,
constrs=out_constrs);
@ -596,7 +599,7 @@ mod collect {
}
auto t_fn = ty::mk_fn(cx.tcx, ast::proto_fn, t_inputs, t_obj._1,
ast::return, []);
ast::return, ~[]);
auto tpt = tup(t_obj._0, t_fn);
cx.tcx.tcache.insert(local_def(ctor_id), tpt);
ret tpt;
@ -707,7 +710,7 @@ mod collect {
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, []);
ast::return, ~[]);
}
auto tpt = tup(ty_param_count, result_ty);
cx.tcx.tcache.insert(local_def(variant.node.id), tpt);
@ -778,7 +781,7 @@ mod collect {
case (none) {/* nothing to do */ }
case (some(?m)) {
auto t = ty::mk_fn(cx.tcx, ast::proto_fn, ~[],
ty::mk_nil(cx.tcx), ast::return, []);
ty::mk_nil(cx.tcx), ast::return, ~[]);
write::ty_only(cx.tcx, m.node.id, t);
}
}
@ -788,9 +791,9 @@ mod collect {
auto t_res = ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty,
mk_ty_params(cx, vec::len(tps)));
auto t_ctor = ty::mk_fn(cx.tcx, ast::proto_fn, ~[t_arg],
t_res, ast::return, []);
t_res, ast::return, ~[]);
auto t_dtor = ty::mk_fn(cx.tcx, ast::proto_fn, ~[t_arg],
ty::mk_nil(cx.tcx), ast::return, []);
ty::mk_nil(cx.tcx), ast::return, ~[]);
write::ty_only(cx.tcx, it.id, t_res);
write::ty_only(cx.tcx, ctor_id, t_ctor);
cx.tcx.tcache.insert(local_def(ctor_id),
@ -2254,10 +2257,12 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
}
auto output = convert(m.node.meth.decl.output);
let fn(&@ast::constr) -> @ty::constr_def g =
bind ast_constr_to_constr(ccx.tcx, _);
let vec[@ty::constr_def] out_constrs =
vec::map(g, m.node.meth.decl.constraints);
auto out_constrs = ~[];
for (@ast::constr constr in m.node.meth.decl.constraints) {
out_constrs += ~[ast_constr_to_constr(ccx.tcx, constr)];
}
ret rec(proto=m.node.meth.proto, ident=m.node.ident,
inputs=inputs, output=output, cf=m.node.meth.decl.cf,
constrs=out_constrs);

View File

@ -47,7 +47,7 @@ fn ty_to_str(&ctxt cx, &t typ) -> str {
}
fn fn_to_str(&ctxt cx, ast::proto proto, option::t[ast::ident] ident,
&arg[] inputs, t output, ast::controlflow cf,
&vec[@constr_def] constrs) -> str {
&(@constr_def)[] constrs) -> str {
auto s;
alt (proto) {
case (ast::proto_iter) { s = "iter"; }
@ -130,7 +130,7 @@ fn ty_to_str(&ctxt cx, &t typ) -> str {
}
case (ty_native_fn(_, ?inputs, ?output)) {
s += fn_to_str(cx, ast::proto_fn, none, inputs, output,
ast::return, []);
ast::return, ~[]);
}
case (ty_obj(?meths)) {
auto f = bind method_to_str(cx, _);
@ -162,7 +162,7 @@ fn constr_to_str(&@constr_def c) -> str {
pprust::constr_args_to_str(pprust::uint_to_str, c.node.args);
}
fn constrs_str(&vec[@constr_def] constrs) -> str {
fn constrs_str(&(@constr_def)[] constrs) -> str {
auto s = "";
auto colon = true;
for (@constr_def c in constrs) {