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

@ -9,6 +9,8 @@ import middle::ty::*;
import metadata::encoder;
import syntax::print::pp;
import syntax::print::pprust;
import syntax::print::pprust::path_to_str;
import syntax::print::pprust::constr_args_to_str;
import pp::word;
import pp::eof;
import pp::zerobreak;
@ -46,7 +48,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,
&(@constr_def)[] constrs) -> str {
&(@constr)[] constrs) -> str {
auto s;
alt (proto) {
case (ast::proto_iter) { s = "iter"; }
@ -154,21 +156,27 @@ fn ty_to_short_str(&ctxt cx, t typ) -> str {
ret s;
}
fn constr_to_str(&@constr_def c) -> str {
ret ast::path_to_str(c.node.path) +
fn constr_to_str(&@constr c) -> str {
ret path_to_str(c.node.path) +
pprust::constr_args_to_str(pprust::uint_to_str, c.node.args);
}
fn constrs_str(&(@constr_def)[] constrs) -> str {
fn constrs_str(&(@constr)[] constrs) -> str {
auto s = "";
auto colon = true;
for (@constr_def c in constrs) {
for (@constr c in constrs) {
if (colon) { s += " : "; colon = false; } else { s += ", "; }
s += constr_to_str(c);
}
ret s;
}
fn ty_constr_to_str[Q](&@ast::spanned[ast::constr_general_[ast::path,Q]]
c) -> str {
ret path_to_str(c.node.path) +
constr_args_to_str[ast::path](path_to_str, c.node.args);
}
// Local Variables:
// mode: rust
// fill-column: 78;