Beginnings of support for constrained types

Programs with constrained types now parse and typecheck, but
typestate doesn't check them specially, so the one relevant test
case so far is XFAILed.

Also rewrote all of the constraint-related data structures in the
process (again), for some reason. I got rid of a superfluous
data structure in the context that was mapping front-end constraints
to resolved constraints, instead handling constraints in the same
way in which everything else gets resolved.
This commit is contained in:
Tim Chevalier 2011-07-19 17:52:34 -07:00
parent da2a7e5bd2
commit bd4aeef78b
20 changed files with 606 additions and 366 deletions

View file

@ -444,7 +444,7 @@ tag ty_ {
ty_obj(ty_method[]);
ty_path(path, node_id);
ty_type;
ty_constr(@ty, (@constr)[]);
ty_constr(@ty, (@ty_constr)[]);
ty_mac(mac);
}
@ -459,16 +459,26 @@ declarations, and ident for uses.
*/
tag constr_arg_general_[T] { carg_base; carg_ident(T); carg_lit(@lit); }
type constr_arg = constr_arg_general[uint];
type fn_constr_arg = constr_arg_general_[uint];
type sp_constr_arg[T] = spanned[constr_arg_general_[T]];
type ty_constr_arg = sp_constr_arg[path];
type constr_arg = spanned[fn_constr_arg];
type constr_arg_general[T] = spanned[constr_arg_general_[T]];
// Constrained types' args are parameterized by paths, since
// we refer to paths directly and not by indices.
// The implicit root of such path, in the constraint-list for a
// constrained type, is * (referring to the base record)
type constr_ = rec(path path,
(@constr_arg_general[uint])[] args,
node_id id);
type constr = spanned[constr_];
type constr_general_[ARG, ID] = rec(path path,
(@(spanned[constr_arg_general_[ARG]]))[] args, ID id);
// In the front end, constraints have a node ID attached.
// Typeck turns this to a def_id, using the output of resolve.
type constr_general[ARG] = spanned[constr_general_[ARG, node_id]];
type constr_ = constr_general_[uint, node_id];
type constr = spanned[constr_general_[uint, node_id]];
type ty_constr_ = ast::constr_general_[ast::path, ast::node_id];
type ty_constr = spanned[ty_constr_];
/* The parser generates ast::constrs; resolve generates
a mapping from each function to a list of ty::constr_defs,
@ -671,19 +681,6 @@ fn ternary_to_if(&@expr e) -> @ast::expr {
}
}
// Path stringification
fn path_to_str(&ast::path pth) -> str {
auto result = str::connect_ivec(pth.node.idents, "::");
if (ivec::len[@ast::ty](pth.node.types) > 0u) {
fn f(&@ast::ty t) -> str { ret print::pprust::ty_to_str(*t); }
result += "[";
result += str::connect_ivec(ivec::map(f, pth.node.types), ",");
result += "]";
}
ret result;
}
//
// Local Variables:
// mode: rust