rustc: Make the various constraint-related types in middle::ty use interior vectors

This commit is contained in:
Patrick Walton 2011-07-01 16:42:16 -07:00
parent 0eb889f9d2
commit b9a2117475
7 changed files with 56 additions and 18 deletions

View File

@ -103,7 +103,7 @@ fn parse_path(@pstate st, str_def sd) -> ast::path {
}
fn parse_constr(@pstate st, str_def sd) -> @ty::constr_def {
let vec[@ast::constr_arg] args = [];
let (@ast::constr_arg)[] args = ~[];
auto sp = rec(lo=0u,hi=0u); // FIXME: use a real span
let ast::path pth = parse_path(st, sd);
let char ignore = next(st) as char;
@ -113,14 +113,15 @@ fn parse_constr(@pstate st, str_def sd) -> @ty::constr_def {
alt (peek(st) as char) {
case ('*') {
st.pos += 1u;
args += [@respan(sp, ast::carg_base)];
args += ~[@respan(sp, ast::carg_base)];
}
case (?c) {
/* how will we disambiguate between
an arg index and a lit argument? */
if (c >= '0' && c <= '9') {
// FIXME
args += [@respan(sp, ast::carg_ident((c as uint) - 48u))];
args += ~[@respan(sp,
ast::carg_ident((c as uint) - 48u))];
ignore = next(st) as char;
}
else {

View File

@ -138,7 +138,7 @@ fn resolve_crate(session sess, &ast_map::map amap, @ast::crate crate) ->
auto e =
@rec(crate_map=new_int_hash[ast::crate_num](),
def_map=new_int_hash[def](),
fn_constrs = new_int_hash[vec[ty::constr_def]](),
fn_constrs = new_int_hash[ty::constr_def[]](),
ast_map=amap,
imports=new_int_hash[import_state](),
mod_map=new_int_hash[@indexed_mod](),
@ -416,8 +416,14 @@ fn resolve_constr(@env e, node_id id, &@ast::constr c, &scopes sc,
if (option::is_some(new_def)) {
alt (option::get(new_def)) {
case (ast::def_fn(?pred_id, ast::pure_fn)) {
// FIXME: Remove this vec->ivec conversion.
let (@ast::constr_arg_general[uint])[] cag_ivec = ~[];
for (@ast::constr_arg_general[uint] cag in c.node.args) {
cag_ivec += ~[cag];
}
let ty::constr_general[uint] c_ =
rec(path=c.node.path, args=c.node.args, id=pred_id);
rec(path=c.node.path, args=cag_ivec, id=pred_id);
let ty::constr_def new_constr = respan(c.span, c_);
add_constr(e, id, new_constr);
}
@ -433,8 +439,8 @@ fn resolve_constr(@env e, node_id id, &@ast::constr c, &scopes sc,
fn add_constr(&@env e, node_id id, &ty::constr_def c) {
e.fn_constrs.insert(id,
alt (e.fn_constrs.find(id)) {
case (none) { [c] }
case (some(?cs)) { cs + [c] }
case (none) { ~[c] }
case (some(?cs)) { cs + ~[c] }
});
}

View File

@ -504,7 +504,7 @@ fn constraints(&fn_ctxt fcx) -> vec[norm_constraint] {
ret rslt;
}
fn match_args(&fn_ctxt fcx, vec[pred_desc] occs, vec[@constr_arg_use] occ) ->
fn match_args(&fn_ctxt fcx, vec[pred_desc] occs, &(@constr_arg_use)[] occ) ->
uint {
log "match_args: looking at " +
constr_args_to_str(std::util::fst[ident, def_id], occ);
@ -513,7 +513,13 @@ fn match_args(&fn_ctxt fcx, vec[pred_desc] occs, vec[@constr_arg_use] occ) ->
fn eq(&tup(ident, def_id) p, &tup(ident, def_id) q) -> bool {
ret p._1 == q._1;
}
if (ty::args_eq(eq, pd.node.args, occ)) { ret pd.node.bit_num; }
// FIXME: Remove this vec->ivec conversion.
let (@constr_arg_use)[] cau_ivec = ~[];
for (@constr_arg_use cau in pd.node.args) {
cau_ivec += ~[cau];
}
if (ty::args_eq(eq, cau_ivec, occ)) { ret pd.node.bit_num; }
}
fcx.ccx.tcx.sess.bug("match_args: no match for occurring args");
}
@ -593,8 +599,14 @@ fn expr_to_constr(ty::ctxt tcx, &@expr e) -> constr {
}
fn pred_desc_to_str(&pred_desc p) -> str {
// FIXME: Remove this vec->ivec conversion.
let (@constr_arg_use)[] cau_ivec = ~[];
for (@constr_arg_use cau in p.node.args) {
cau_ivec += ~[cau];
}
ret "<" + uint::str(p.node.bit_num) + ", " +
constr_args_to_str(std::util::fst[ident, def_id], p.node.args) + ">";
constr_args_to_str(std::util::fst[ident, def_id], cau_ivec) + ">";
}
fn substitute_constr_args(&ty::ctxt cx, &vec[@expr] actuals,

View File

@ -5,6 +5,7 @@ import std::option::*;
import std::vec;
import std::vec::len;
import std::vec::slice;
import aux::constr_arg_use;
import aux::local_node_id_to_def;
import aux::fn_ctxt;
import aux::fn_info;
@ -63,7 +64,14 @@ fn bit_num(&fn_ctxt fcx, &constr_ c) -> uint {
}
case (npred(_, ?args)) {
alt (rslt) {
case (cpred(_, ?descs)) { ret match_args(fcx, *descs, args); }
case (cpred(_, ?descs)) {
// FIXME: Remove this vec->ivec conversion.
let (@constr_arg_use)[] cau_ivec = ~[];
for (@constr_arg_use cau in args) {
cau_ivec += ~[cau];
}
ret match_args(fcx, *descs, cau_ivec);
}
case (_) {
fcx.ccx.tcx.sess.bug("bit_num: asked for pred constraint,"
+ " found an init constraint");

View File

@ -198,7 +198,7 @@ type method =
controlflow cf,
(@constr_def)[] constrs);
type constr_table = hashmap[ast::node_id, vec[constr_def]];
type constr_table = hashmap[ast::node_id, constr_def[]];
type mt = rec(t ty, ast::mutability mut);
@ -281,7 +281,7 @@ tag sty {
type constr_def = spanned[constr_general[uint]];
type constr_general[T] =
rec(ast::path path, vec[@constr_arg_general[T]] args, def_id id);
rec(ast::path path, (@constr_arg_general[T])[] args, def_id id);
// Data structures used in type unification
@ -1438,8 +1438,8 @@ fn arg_eq[T](&fn(&T, &T) -> bool eq, @ast::constr_arg_general[T] a,
}
}
fn args_eq[T](fn(&T, &T) -> bool eq, vec[@ast::constr_arg_general[T]] a,
vec[@ast::constr_arg_general[T]] b) -> bool {
fn args_eq[T](fn(&T, &T) -> bool eq, &(@ast::constr_arg_general[T])[] a,
&(@ast::constr_arg_general[T])[] b) -> bool {
let uint i = 0u;
for (@ast::constr_arg_general[T] arg in a) {
if (!arg_eq(eq, arg, b.(i))) { ret false; }

View File

@ -2355,7 +2355,13 @@ fn ast_constr_to_constr(ty::ctxt tcx, &@ast::constr c)
-> @ty::constr_def {
alt (tcx.def_map.find(c.node.id)) {
case (some(ast::def_fn(?pred_id, ast::pure_fn))) {
ret @respan(c.span, rec(path=c.node.path, args=c.node.args,
// FIXME: Remove this vec->ivec conversion.
let (@ast::constr_arg_general[uint])[] cag_ivec = ~[];
for (@ast::constr_arg_general[uint] cag in c.node.args) {
cag_ivec += ~[cag];
}
ret @respan(c.span, rec(path=c.node.path, args=cag_ivec,
id=pred_id));
}
case (_) {

View File

@ -1421,7 +1421,7 @@ fn next_comment(&ps s) -> option::t[lexer::cmnt] {
fn constr_args_to_str[T](fn(&T) -> str f,
&vec[@ast::constr_arg_general[T]] args) -> str {
&(@ast::constr_arg_general[T])[] args) -> str {
auto comma = false;
auto s = "(";
for (@ast::constr_arg_general[T] a in args) {
@ -1447,8 +1447,13 @@ fn constr_arg_to_str[T](fn(&T) -> str f, &ast::constr_arg_general_[T] c) ->
fn uint_to_str(&uint i) -> str { ret uint::str(i); }
fn ast_constr_to_str(&@ast::constr c) -> str {
// TODO: Remove this vec->ivec conversion.
auto cag_ivec = ~[];
for (@ast::constr_arg_general[uint] cag in c.node.args) {
cag_ivec += ~[cag];
}
ret ast::path_to_str(c.node.path) +
constr_args_to_str(uint_to_str, c.node.args);
constr_args_to_str(uint_to_str, cag_ivec);
}
fn ast_constrs_str(&vec[@ast::constr] constrs) -> str {