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

@@ -332,7 +332,7 @@ fn print_type(&ps s, &ast::ty ty) {
space(s.s);
word(s.s, ":");
space(s.s);
word(s.s, ast_constrs_str(cs));
word(s.s, ast_ty_constrs_str(cs));
}
}
end(s);
@@ -1521,10 +1521,10 @@ fn next_comment(&ps s) -> option::t[lexer::cmnt] {
// Removing the aliases from the type of f in the next two functions
// triggers memory corruption, but I haven't isolated the bug yet. FIXME
fn constr_args_to_str[T](&fn(&T) -> str f,
&(@ast::constr_arg_general[T])[] args) -> str {
&(@ast::sp_constr_arg[T])[] args) -> str {
auto comma = false;
auto s = "(";
for (@ast::constr_arg_general[T] a in args) {
for (@ast::sp_constr_arg[T] a in args) {
if (comma) { s += ", "; } else { comma = true; }
s += constr_arg_to_str[T](f, a.node);
}
@@ -1547,10 +1547,11 @@ 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 {
ret ast::path_to_str(c.node.path) +
constr_args_to_str(uint_to_str, c.node.args);
ret path_to_str(c.node.path) +
constr_args_to_str(uint_to_str, c.node.args);
}
// FIXME: fix repeated code
fn ast_constrs_str(&(@ast::constr)[] constrs) -> str {
auto s = "";
auto colon = true;
@@ -1568,6 +1569,22 @@ fn proto_to_str(&ast::proto p) -> str {
};
}
fn ty_constr_to_str(&@ast::ty_constr c) -> str {
ret path_to_str(c.node.path) +
constr_args_to_str[ast::path](path_to_str, c.node.args);
}
fn ast_ty_constrs_str(&(@ast::ty_constr)[] constrs) -> str {
auto s = "";
auto colon = true;
for (@ast::ty_constr c in constrs) {
if (colon) { s += " : "; colon = false; } else { s += ", "; }
s += ty_constr_to_str(c);
}
ret s;
}
//
// Local Variables:
// mode: rust