Use different syntax for checks that matter to typestate

This giant commit changes the syntax of Rust to use "assert" for
"check" expressions that didn't mean anything to the typestate
system, and continue using "check" for checks that are used as
part of typestate checking.

Most of the changes are just replacing "check" with "assert" in test
cases and rustc.
This commit is contained in:
Tim Chevalier 2011-05-02 11:23:07 -07:00 committed by Graydon Hoare
parent 870435caf5
commit aa25f22f19
182 changed files with 1256 additions and 1239 deletions

View File

@ -199,6 +199,14 @@ and parse_stmts_including_none (ps:pstate) : Ast.stmt array =
bump ps; bump ps;
expect ps SEMI; expect ps SEMI;
[| span ps apos (lexpos ps) Ast.STMT_cont |] [| span ps apos (lexpos ps) Ast.STMT_cont |]
| ASSERT ->
bump ps;
let (stmts, expr) =
ctxt "stmts: check value" parse_expr ps
in
expect ps SEMI;
spans ps stmts apos (Ast.STMT_check_expr expr)
(* leaving check as it is; adding assert as a synonym for the "old" check *)
| CHECK -> | CHECK ->
bump ps; bump ps;
begin begin

View File

@ -92,6 +92,7 @@
("type", TYPE); ("type", TYPE);
("check", CHECK); ("check", CHECK);
("assert", ASSERT);
("claim", CLAIM); ("claim", CLAIM);
("prove", PROVE); ("prove", PROVE);

View File

@ -77,6 +77,7 @@ type token =
(* Type and type-state keywords *) (* Type and type-state keywords *)
| TYPE | TYPE
| CHECK | CHECK
| ASSERT
| CLAIM | CLAIM
| PROVE | PROVE
@ -237,6 +238,7 @@ let rec string_of_tok t =
(* Type and type-state keywords *) (* Type and type-state keywords *)
| TYPE -> "type" | TYPE -> "type"
| CHECK -> "check" | CHECK -> "check"
| ASSERT -> "assert"
| CLAIM -> "claim" | CLAIM -> "claim"
| PROVE -> "prove" | PROVE -> "prove"

View File

@ -283,7 +283,10 @@ tag expr_ {
expr_put(option.t[@expr], ann); expr_put(option.t[@expr], ann);
expr_be(@expr, ann); expr_be(@expr, ann);
expr_log(int, @expr, ann); expr_log(int, @expr, ann);
expr_check_expr(@expr, ann); /* just an assert, no significance to typestate */
expr_assert(@expr, ann);
/* preds that typestate is aware of */
expr_check(@expr, ann);
expr_port(ann); expr_port(ann);
expr_chan(@expr, ann); expr_chan(@expr, ann);
} }

View File

@ -93,7 +93,7 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
case ('c') { ret ty.mk_char(st.tcx); } case ('c') { ret ty.mk_char(st.tcx); }
case ('s') { ret ty.mk_str(st.tcx); } case ('s') { ret ty.mk_str(st.tcx); }
case ('t') { case ('t') {
check(next(st) as char == '['); assert (next(st) as char == '[');
auto def = parse_def(st, sd); auto def = parse_def(st, sd);
let vec[ty.t] params = vec(); let vec[ty.t] params = vec();
while (peek(st) as char != ']') { while (peek(st) as char != ']') {
@ -108,7 +108,7 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
case ('P') { ret ty.mk_port(st.tcx, parse_ty(st, sd)); } case ('P') { ret ty.mk_port(st.tcx, parse_ty(st, sd)); }
case ('C') { ret ty.mk_chan(st.tcx, parse_ty(st, sd)); } case ('C') { ret ty.mk_chan(st.tcx, parse_ty(st, sd)); }
case ('T') { case ('T') {
check(next(st) as char == '['); assert (next(st) as char == '[');
let vec[ty.mt] params = vec(); let vec[ty.mt] params = vec();
while (peek(st) as char != ']') { while (peek(st) as char != ']') {
params += vec(parse_mt(st, sd)); params += vec(parse_mt(st, sd));
@ -117,7 +117,7 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
ret ty.mk_tup(st.tcx, params); ret ty.mk_tup(st.tcx, params);
} }
case ('R') { case ('R') {
check(next(st) as char == '['); assert (next(st) as char == '[');
let vec[ty.field] fields = vec(); let vec[ty.field] fields = vec();
while (peek(st) as char != ']') { while (peek(st) as char != ']') {
auto name = ""; auto name = "";
@ -149,7 +149,7 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
ret ty.mk_native_fn(st.tcx,abi,func._0,func._1); ret ty.mk_native_fn(st.tcx,abi,func._0,func._1);
} }
case ('O') { case ('O') {
check(next(st) as char == '['); assert (next(st) as char == '[');
let vec[ty.method] methods = vec(); let vec[ty.method] methods = vec();
while (peek(st) as char != ']') { while (peek(st) as char != ']') {
auto proto; auto proto;
@ -175,9 +175,9 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
case ('Y') { ret ty.mk_type(st.tcx); } case ('Y') { ret ty.mk_type(st.tcx); }
case ('#') { case ('#') {
auto pos = parse_hex(st); auto pos = parse_hex(st);
check (next(st) as char == ':'); assert (next(st) as char == ':');
auto len = parse_hex(st); auto len = parse_hex(st);
check (next(st) as char == '#'); assert (next(st) as char == '#');
alt (st.tcx.rcache.find(tup(st.crate,pos,len))) { alt (st.tcx.rcache.find(tup(st.crate,pos,len))) {
case (some[ty.t](?tt)) { ret tt; } case (some[ty.t](?tt)) { ret tt; }
case (none[ty.t]) { case (none[ty.t]) {
@ -245,7 +245,7 @@ fn parse_hex(@pstate st) -> uint {
} }
fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty.arg], ty.t) { fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty.arg], ty.t) {
check(next(st) as char == '['); assert (next(st) as char == '[');
let vec[ty.arg] inputs = vec(); let vec[ty.arg] inputs = vec();
while (peek(st) as char != ']') { while (peek(st) as char != ']') {
auto mode = ast.val; auto mode = ast.val;

View File

@ -127,6 +127,7 @@ fn keyword_table() -> std.map.hashmap[str, token.token] {
keywords.insert("type", token.TYPE); keywords.insert("type", token.TYPE);
keywords.insert("check", token.CHECK); keywords.insert("check", token.CHECK);
keywords.insert("assert", token.ASSERT);
keywords.insert("claim", token.CLAIM); keywords.insert("claim", token.CLAIM);
keywords.insert("prove", token.PROVE); keywords.insert("prove", token.PROVE);
@ -528,7 +529,7 @@ fn scan_numeric_escape(reader rdr) -> char {
auto n_hex_digits = 0; auto n_hex_digits = 0;
check (rdr.curr() == '\\'); assert (rdr.curr() == '\\');
alt (rdr.next()) { alt (rdr.next()) {
case ('x') { n_hex_digits = 2; } case ('x') { n_hex_digits = 2; }

View File

@ -621,7 +621,7 @@ fn parse_path(parser p, greed g) -> ast.path {
if (p.peek() == token.DOT) { if (p.peek() == token.DOT) {
if (g == GREEDY) { if (g == GREEDY) {
p.bump(); p.bump();
check (is_ident(p.peek())); assert (is_ident(p.peek()));
} else { } else {
more = false; more = false;
} }
@ -816,18 +816,21 @@ fn parse_bottom_expr(parser p) -> @ast.expr {
ex = ast.expr_log(0, e, ast.ann_none); ex = ast.expr_log(0, e, ast.ann_none);
} }
case (token.CHECK) { case (token.ASSERT) {
p.bump(); p.bump();
alt (p.peek()) {
case (token.LPAREN) {
auto e = parse_expr(p); auto e = parse_expr(p);
auto hi = e.span.hi; auto hi = e.span.hi;
ex = ast.expr_check_expr(e, ast.ann_none); ex = ast.expr_assert(e, ast.ann_none);
}
case (_) {
p.get_session().unimpl("constraint-check stmt");
}
} }
case (token.CHECK) {
p.bump();
/* Should be a predicate (pure boolean function) applied to
arguments that are all either slot variables or literals.
but the typechecker enforces that. */
auto e = parse_expr(p);
auto hi = e.span.hi;
ex = ast.expr_check(e, ast.ann_none);
} }
case (token.RET) { case (token.RET) {
@ -937,7 +940,7 @@ fn expand_syntax_ext(parser p, ast.span sp,
&ast.path path, vec[@ast.expr] args, &ast.path path, vec[@ast.expr] args,
option.t[str] body) -> ast.expr_ { option.t[str] body) -> ast.expr_ {
check (_vec.len[ast.ident](path.node.idents) > 0u); assert (_vec.len[ast.ident](path.node.idents) > 0u);
auto extname = path.node.idents.(0); auto extname = path.node.idents.(0);
if (_str.eq(extname, "fmt")) { if (_str.eq(extname, "fmt")) {
auto expanded = extfmt.expand_syntax_ext(args, body); auto expanded = extfmt.expand_syntax_ext(args, body);
@ -1673,7 +1676,8 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
case (ast.expr_put(_,_)) { ret true; } case (ast.expr_put(_,_)) { ret true; }
case (ast.expr_be(_,_)) { ret true; } case (ast.expr_be(_,_)) { ret true; }
case (ast.expr_log(_,_,_)) { ret true; } case (ast.expr_log(_,_,_)) { ret true; }
case (ast.expr_check_expr(_,_)) { ret true; } case (ast.expr_check(_,_)) { ret true; }
case (ast.expr_assert(_,_)) { ret true; }
} }
} }
// We should not be calling this on a cdir. // We should not be calling this on a cdir.
@ -2157,24 +2161,24 @@ fn parse_item(parser p) -> @ast.item {
alt (p.peek()) { alt (p.peek()) {
case (token.CONST) { case (token.CONST) {
check (lyr == ast.layer_value); assert (lyr == ast.layer_value);
ret parse_item_const(p); ret parse_item_const(p);
} }
case (token.FN) { case (token.FN) {
check (lyr == ast.layer_value); assert (lyr == ast.layer_value);
ret parse_item_fn_or_iter(p); ret parse_item_fn_or_iter(p);
} }
case (token.ITER) { case (token.ITER) {
check (lyr == ast.layer_value); assert (lyr == ast.layer_value);
ret parse_item_fn_or_iter(p); ret parse_item_fn_or_iter(p);
} }
case (token.MOD) { case (token.MOD) {
check (lyr == ast.layer_value); assert (lyr == ast.layer_value);
ret parse_item_mod(p); ret parse_item_mod(p);
} }
case (token.NATIVE) { case (token.NATIVE) {
check (lyr == ast.layer_value); assert (lyr == ast.layer_value);
ret parse_item_native_mod(p); ret parse_item_native_mod(p);
} }
case (token.TYPE) { case (token.TYPE) {

View File

@ -89,6 +89,7 @@ tag token {
/* Type and type-state keywords */ /* Type and type-state keywords */
TYPE; TYPE;
ASSERT;
CHECK; CHECK;
CLAIM; CLAIM;
PROVE; PROVE;
@ -258,6 +259,7 @@ fn to_str(token t) -> str {
/* Type and type-state keywords */ /* Type and type-state keywords */
case (TYPE) { ret "type"; } case (TYPE) { ret "type"; }
case (ASSERT) { ret "assert"; }
case (CHECK) { ret "check"; } case (CHECK) { ret "check"; }
case (CLAIM) { ret "claim"; } case (CLAIM) { ret "claim"; }
case (PROVE) { ret "prove"; } case (PROVE) { ret "prove"; }

View File

@ -861,19 +861,19 @@ obj builder(BuilderRef B, @mutable bool terminated) {
/* Terminators */ /* Terminators */
fn RetVoid() -> ValueRef { fn RetVoid() -> ValueRef {
check (!*terminated); assert (!*terminated);
*terminated = true; *terminated = true;
ret llvm.LLVMBuildRetVoid(B); ret llvm.LLVMBuildRetVoid(B);
} }
fn Ret(ValueRef V) -> ValueRef { fn Ret(ValueRef V) -> ValueRef {
check (!*terminated); assert (!*terminated);
*terminated = true; *terminated = true;
ret llvm.LLVMBuildRet(B, V); ret llvm.LLVMBuildRet(B, V);
} }
fn AggregateRet(vec[ValueRef] RetVals) -> ValueRef { fn AggregateRet(vec[ValueRef] RetVals) -> ValueRef {
check (!*terminated); assert (!*terminated);
*terminated = true; *terminated = true;
ret llvm.LLVMBuildAggregateRet(B, ret llvm.LLVMBuildAggregateRet(B,
_vec.buf[ValueRef](RetVals), _vec.buf[ValueRef](RetVals),
@ -881,26 +881,26 @@ obj builder(BuilderRef B, @mutable bool terminated) {
} }
fn Br(BasicBlockRef Dest) -> ValueRef { fn Br(BasicBlockRef Dest) -> ValueRef {
check (!*terminated); assert (!*terminated);
*terminated = true; *terminated = true;
ret llvm.LLVMBuildBr(B, Dest); ret llvm.LLVMBuildBr(B, Dest);
} }
fn CondBr(ValueRef If, BasicBlockRef Then, fn CondBr(ValueRef If, BasicBlockRef Then,
BasicBlockRef Else) -> ValueRef { BasicBlockRef Else) -> ValueRef {
check (!*terminated); assert (!*terminated);
*terminated = true; *terminated = true;
ret llvm.LLVMBuildCondBr(B, If, Then, Else); ret llvm.LLVMBuildCondBr(B, If, Then, Else);
} }
fn Switch(ValueRef V, BasicBlockRef Else, uint NumCases) -> ValueRef { fn Switch(ValueRef V, BasicBlockRef Else, uint NumCases) -> ValueRef {
check (!*terminated); assert (!*terminated);
*terminated = true; *terminated = true;
ret llvm.LLVMBuildSwitch(B, V, Else, NumCases); ret llvm.LLVMBuildSwitch(B, V, Else, NumCases);
} }
fn IndirectBr(ValueRef Addr, uint NumDests) -> ValueRef { fn IndirectBr(ValueRef Addr, uint NumDests) -> ValueRef {
check (!*terminated); assert (!*terminated);
*terminated = true; *terminated = true;
ret llvm.LLVMBuildIndirectBr(B, Addr, NumDests); ret llvm.LLVMBuildIndirectBr(B, Addr, NumDests);
} }
@ -909,7 +909,7 @@ obj builder(BuilderRef B, @mutable bool terminated) {
vec[ValueRef] Args, vec[ValueRef] Args,
BasicBlockRef Then, BasicBlockRef Then,
BasicBlockRef Catch) -> ValueRef { BasicBlockRef Catch) -> ValueRef {
check (!*terminated); assert (!*terminated);
*terminated = true; *terminated = true;
ret llvm.LLVMBuildInvoke(B, Fn, ret llvm.LLVMBuildInvoke(B, Fn,
_vec.buf[ValueRef](Args), _vec.buf[ValueRef](Args),
@ -919,209 +919,209 @@ obj builder(BuilderRef B, @mutable bool terminated) {
} }
fn Unwind() -> ValueRef { fn Unwind() -> ValueRef {
check (!*terminated); assert (!*terminated);
*terminated = true; *terminated = true;
ret llvm.LLVMBuildUnwind(B); ret llvm.LLVMBuildUnwind(B);
} }
fn Unreachable() -> ValueRef { fn Unreachable() -> ValueRef {
check (!*terminated); assert (!*terminated);
*terminated = true; *terminated = true;
ret llvm.LLVMBuildUnreachable(B); ret llvm.LLVMBuildUnreachable(B);
} }
/* Arithmetic */ /* Arithmetic */
fn Add(ValueRef LHS, ValueRef RHS) -> ValueRef { fn Add(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildAdd(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildAdd(B, LHS, RHS, _str.buf(""));
} }
fn NSWAdd(ValueRef LHS, ValueRef RHS) -> ValueRef { fn NSWAdd(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildNSWAdd(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildNSWAdd(B, LHS, RHS, _str.buf(""));
} }
fn NUWAdd(ValueRef LHS, ValueRef RHS) -> ValueRef { fn NUWAdd(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildNUWAdd(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildNUWAdd(B, LHS, RHS, _str.buf(""));
} }
fn FAdd(ValueRef LHS, ValueRef RHS) -> ValueRef { fn FAdd(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildFAdd(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildFAdd(B, LHS, RHS, _str.buf(""));
} }
fn Sub(ValueRef LHS, ValueRef RHS) -> ValueRef { fn Sub(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildSub(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildSub(B, LHS, RHS, _str.buf(""));
} }
fn NSWSub(ValueRef LHS, ValueRef RHS) -> ValueRef { fn NSWSub(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildNSWSub(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildNSWSub(B, LHS, RHS, _str.buf(""));
} }
fn NUWSub(ValueRef LHS, ValueRef RHS) -> ValueRef { fn NUWSub(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildNUWSub(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildNUWSub(B, LHS, RHS, _str.buf(""));
} }
fn FSub(ValueRef LHS, ValueRef RHS) -> ValueRef { fn FSub(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildFSub(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildFSub(B, LHS, RHS, _str.buf(""));
} }
fn Mul(ValueRef LHS, ValueRef RHS) -> ValueRef { fn Mul(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildMul(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildMul(B, LHS, RHS, _str.buf(""));
} }
fn NSWMul(ValueRef LHS, ValueRef RHS) -> ValueRef { fn NSWMul(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildNSWMul(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildNSWMul(B, LHS, RHS, _str.buf(""));
} }
fn NUWMul(ValueRef LHS, ValueRef RHS) -> ValueRef { fn NUWMul(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildNUWMul(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildNUWMul(B, LHS, RHS, _str.buf(""));
} }
fn FMul(ValueRef LHS, ValueRef RHS) -> ValueRef { fn FMul(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildFMul(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildFMul(B, LHS, RHS, _str.buf(""));
} }
fn UDiv(ValueRef LHS, ValueRef RHS) -> ValueRef { fn UDiv(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildUDiv(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildUDiv(B, LHS, RHS, _str.buf(""));
} }
fn SDiv(ValueRef LHS, ValueRef RHS) -> ValueRef { fn SDiv(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildSDiv(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildSDiv(B, LHS, RHS, _str.buf(""));
} }
fn ExactSDiv(ValueRef LHS, ValueRef RHS) -> ValueRef { fn ExactSDiv(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildExactSDiv(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildExactSDiv(B, LHS, RHS, _str.buf(""));
} }
fn FDiv(ValueRef LHS, ValueRef RHS) -> ValueRef { fn FDiv(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildFDiv(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildFDiv(B, LHS, RHS, _str.buf(""));
} }
fn URem(ValueRef LHS, ValueRef RHS) -> ValueRef { fn URem(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildURem(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildURem(B, LHS, RHS, _str.buf(""));
} }
fn SRem(ValueRef LHS, ValueRef RHS) -> ValueRef { fn SRem(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildSRem(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildSRem(B, LHS, RHS, _str.buf(""));
} }
fn FRem(ValueRef LHS, ValueRef RHS) -> ValueRef { fn FRem(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildFRem(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildFRem(B, LHS, RHS, _str.buf(""));
} }
fn Shl(ValueRef LHS, ValueRef RHS) -> ValueRef { fn Shl(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildShl(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildShl(B, LHS, RHS, _str.buf(""));
} }
fn LShr(ValueRef LHS, ValueRef RHS) -> ValueRef { fn LShr(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildLShr(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildLShr(B, LHS, RHS, _str.buf(""));
} }
fn AShr(ValueRef LHS, ValueRef RHS) -> ValueRef { fn AShr(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildAShr(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildAShr(B, LHS, RHS, _str.buf(""));
} }
fn And(ValueRef LHS, ValueRef RHS) -> ValueRef { fn And(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildAnd(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildAnd(B, LHS, RHS, _str.buf(""));
} }
fn Or(ValueRef LHS, ValueRef RHS) -> ValueRef { fn Or(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildOr(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildOr(B, LHS, RHS, _str.buf(""));
} }
fn Xor(ValueRef LHS, ValueRef RHS) -> ValueRef { fn Xor(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildXor(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildXor(B, LHS, RHS, _str.buf(""));
} }
fn BinOp(Opcode Op, ValueRef LHS, ValueRef RHS) -> ValueRef { fn BinOp(Opcode Op, ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildBinOp(B, Op, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildBinOp(B, Op, LHS, RHS, _str.buf(""));
} }
fn Neg(ValueRef V) -> ValueRef { fn Neg(ValueRef V) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildNeg(B, V, _str.buf("")); ret llvm.LLVMBuildNeg(B, V, _str.buf(""));
} }
fn NSWNeg(ValueRef V) -> ValueRef { fn NSWNeg(ValueRef V) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildNSWNeg(B, V, _str.buf("")); ret llvm.LLVMBuildNSWNeg(B, V, _str.buf(""));
} }
fn NUWNeg(ValueRef V) -> ValueRef { fn NUWNeg(ValueRef V) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildNUWNeg(B, V, _str.buf("")); ret llvm.LLVMBuildNUWNeg(B, V, _str.buf(""));
} }
fn FNeg(ValueRef V) -> ValueRef { fn FNeg(ValueRef V) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildFNeg(B, V, _str.buf("")); ret llvm.LLVMBuildFNeg(B, V, _str.buf(""));
} }
fn Not(ValueRef V) -> ValueRef { fn Not(ValueRef V) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildNot(B, V, _str.buf("")); ret llvm.LLVMBuildNot(B, V, _str.buf(""));
} }
/* Memory */ /* Memory */
fn Malloc(TypeRef Ty) -> ValueRef { fn Malloc(TypeRef Ty) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildMalloc(B, Ty, _str.buf("")); ret llvm.LLVMBuildMalloc(B, Ty, _str.buf(""));
} }
fn ArrayMalloc(TypeRef Ty, ValueRef Val) -> ValueRef { fn ArrayMalloc(TypeRef Ty, ValueRef Val) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildArrayMalloc(B, Ty, Val, _str.buf("")); ret llvm.LLVMBuildArrayMalloc(B, Ty, Val, _str.buf(""));
} }
fn Alloca(TypeRef Ty) -> ValueRef { fn Alloca(TypeRef Ty) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildAlloca(B, Ty, _str.buf("")); ret llvm.LLVMBuildAlloca(B, Ty, _str.buf(""));
} }
fn ArrayAlloca(TypeRef Ty, ValueRef Val) -> ValueRef { fn ArrayAlloca(TypeRef Ty, ValueRef Val) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildArrayAlloca(B, Ty, Val, _str.buf("")); ret llvm.LLVMBuildArrayAlloca(B, Ty, Val, _str.buf(""));
} }
fn Free(ValueRef PointerVal) -> ValueRef { fn Free(ValueRef PointerVal) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildFree(B, PointerVal); ret llvm.LLVMBuildFree(B, PointerVal);
} }
fn Load(ValueRef PointerVal) -> ValueRef { fn Load(ValueRef PointerVal) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildLoad(B, PointerVal, _str.buf("")); ret llvm.LLVMBuildLoad(B, PointerVal, _str.buf(""));
} }
fn Store(ValueRef Val, ValueRef Ptr) -> ValueRef { fn Store(ValueRef Val, ValueRef Ptr) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildStore(B, Val, Ptr); ret llvm.LLVMBuildStore(B, Val, Ptr);
} }
fn GEP(ValueRef Pointer, vec[ValueRef] Indices) -> ValueRef { fn GEP(ValueRef Pointer, vec[ValueRef] Indices) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildGEP(B, Pointer, ret llvm.LLVMBuildGEP(B, Pointer,
_vec.buf[ValueRef](Indices), _vec.buf[ValueRef](Indices),
_vec.len[ValueRef](Indices), _vec.len[ValueRef](Indices),
@ -1129,7 +1129,7 @@ obj builder(BuilderRef B, @mutable bool terminated) {
} }
fn InBoundsGEP(ValueRef Pointer, vec[ValueRef] Indices) -> ValueRef { fn InBoundsGEP(ValueRef Pointer, vec[ValueRef] Indices) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildInBoundsGEP(B, Pointer, ret llvm.LLVMBuildInBoundsGEP(B, Pointer,
_vec.buf[ValueRef](Indices), _vec.buf[ValueRef](Indices),
_vec.len[ValueRef](Indices), _vec.len[ValueRef](Indices),
@ -1137,125 +1137,125 @@ obj builder(BuilderRef B, @mutable bool terminated) {
} }
fn StructGEP(ValueRef Pointer, uint Idx) -> ValueRef { fn StructGEP(ValueRef Pointer, uint Idx) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildStructGEP(B, Pointer, Idx, _str.buf("")); ret llvm.LLVMBuildStructGEP(B, Pointer, Idx, _str.buf(""));
} }
fn GlobalString(sbuf Str) -> ValueRef { fn GlobalString(sbuf Str) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildGlobalString(B, Str, _str.buf("")); ret llvm.LLVMBuildGlobalString(B, Str, _str.buf(""));
} }
fn GlobalStringPtr(sbuf Str) -> ValueRef { fn GlobalStringPtr(sbuf Str) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildGlobalStringPtr(B, Str, _str.buf("")); ret llvm.LLVMBuildGlobalStringPtr(B, Str, _str.buf(""));
} }
/* Casts */ /* Casts */
fn Trunc(ValueRef Val, TypeRef DestTy) -> ValueRef { fn Trunc(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildTrunc(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildTrunc(B, Val, DestTy, _str.buf(""));
} }
fn ZExt(ValueRef Val, TypeRef DestTy) -> ValueRef { fn ZExt(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildZExt(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildZExt(B, Val, DestTy, _str.buf(""));
} }
fn SExt(ValueRef Val, TypeRef DestTy) -> ValueRef { fn SExt(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildSExt(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildSExt(B, Val, DestTy, _str.buf(""));
} }
fn FPToUI(ValueRef Val, TypeRef DestTy) -> ValueRef { fn FPToUI(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildFPToUI(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildFPToUI(B, Val, DestTy, _str.buf(""));
} }
fn FPToSI(ValueRef Val, TypeRef DestTy) -> ValueRef { fn FPToSI(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildFPToSI(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildFPToSI(B, Val, DestTy, _str.buf(""));
} }
fn UIToFP(ValueRef Val, TypeRef DestTy) -> ValueRef { fn UIToFP(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildUIToFP(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildUIToFP(B, Val, DestTy, _str.buf(""));
} }
fn SIToFP(ValueRef Val, TypeRef DestTy) -> ValueRef { fn SIToFP(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildSIToFP(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildSIToFP(B, Val, DestTy, _str.buf(""));
} }
fn FPTrunc(ValueRef Val, TypeRef DestTy) -> ValueRef { fn FPTrunc(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildFPTrunc(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildFPTrunc(B, Val, DestTy, _str.buf(""));
} }
fn FPExt(ValueRef Val, TypeRef DestTy) -> ValueRef { fn FPExt(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildFPExt(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildFPExt(B, Val, DestTy, _str.buf(""));
} }
fn PtrToInt(ValueRef Val, TypeRef DestTy) -> ValueRef { fn PtrToInt(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildPtrToInt(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildPtrToInt(B, Val, DestTy, _str.buf(""));
} }
fn IntToPtr(ValueRef Val, TypeRef DestTy) -> ValueRef { fn IntToPtr(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildIntToPtr(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildIntToPtr(B, Val, DestTy, _str.buf(""));
} }
fn BitCast(ValueRef Val, TypeRef DestTy) -> ValueRef { fn BitCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildBitCast(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildBitCast(B, Val, DestTy, _str.buf(""));
} }
fn ZExtOrBitCast(ValueRef Val, TypeRef DestTy) -> ValueRef { fn ZExtOrBitCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildZExtOrBitCast(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildZExtOrBitCast(B, Val, DestTy, _str.buf(""));
} }
fn SExtOrBitCast(ValueRef Val, TypeRef DestTy) -> ValueRef { fn SExtOrBitCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildSExtOrBitCast(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildSExtOrBitCast(B, Val, DestTy, _str.buf(""));
} }
fn TruncOrBitCast(ValueRef Val, TypeRef DestTy) -> ValueRef { fn TruncOrBitCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildTruncOrBitCast(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildTruncOrBitCast(B, Val, DestTy, _str.buf(""));
} }
fn Cast(Opcode Op, ValueRef Val, TypeRef DestTy, sbuf Name) -> ValueRef { fn Cast(Opcode Op, ValueRef Val, TypeRef DestTy, sbuf Name) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildCast(B, Op, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildCast(B, Op, Val, DestTy, _str.buf(""));
} }
fn PointerCast(ValueRef Val, TypeRef DestTy) -> ValueRef { fn PointerCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildPointerCast(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildPointerCast(B, Val, DestTy, _str.buf(""));
} }
fn IntCast(ValueRef Val, TypeRef DestTy) -> ValueRef { fn IntCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildIntCast(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildIntCast(B, Val, DestTy, _str.buf(""));
} }
fn FPCast(ValueRef Val, TypeRef DestTy) -> ValueRef { fn FPCast(ValueRef Val, TypeRef DestTy) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildFPCast(B, Val, DestTy, _str.buf("")); ret llvm.LLVMBuildFPCast(B, Val, DestTy, _str.buf(""));
} }
/* Comparisons */ /* Comparisons */
fn ICmp(uint Op, ValueRef LHS, ValueRef RHS) -> ValueRef { fn ICmp(uint Op, ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildICmp(B, Op, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildICmp(B, Op, LHS, RHS, _str.buf(""));
} }
fn FCmp(uint Op, ValueRef LHS, ValueRef RHS) -> ValueRef { fn FCmp(uint Op, ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildFCmp(B, Op, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildFCmp(B, Op, LHS, RHS, _str.buf(""));
} }
@ -1263,9 +1263,9 @@ obj builder(BuilderRef B, @mutable bool terminated) {
/* Miscellaneous instructions */ /* Miscellaneous instructions */
fn Phi(TypeRef Ty, vec[ValueRef] vals, fn Phi(TypeRef Ty, vec[ValueRef] vals,
vec[BasicBlockRef] bbs) -> ValueRef { vec[BasicBlockRef] bbs) -> ValueRef {
check (!*terminated); assert (!*terminated);
auto phi = llvm.LLVMBuildPhi(B, Ty, _str.buf("")); auto phi = llvm.LLVMBuildPhi(B, Ty, _str.buf(""));
check (_vec.len[ValueRef](vals) == _vec.len[BasicBlockRef](bbs)); assert (_vec.len[ValueRef](vals) == _vec.len[BasicBlockRef](bbs));
llvm.LLVMAddIncoming(phi, llvm.LLVMAddIncoming(phi,
_vec.buf[ValueRef](vals), _vec.buf[ValueRef](vals),
_vec.buf[BasicBlockRef](bbs), _vec.buf[BasicBlockRef](bbs),
@ -1276,7 +1276,7 @@ obj builder(BuilderRef B, @mutable bool terminated) {
fn AddIncomingToPhi(ValueRef phi, fn AddIncomingToPhi(ValueRef phi,
vec[ValueRef] vals, vec[ValueRef] vals,
vec[BasicBlockRef] bbs) { vec[BasicBlockRef] bbs) {
check (_vec.len[ValueRef](vals) == _vec.len[BasicBlockRef](bbs)); assert (_vec.len[ValueRef](vals) == _vec.len[BasicBlockRef](bbs));
llvm.LLVMAddIncoming(phi, llvm.LLVMAddIncoming(phi,
_vec.buf[ValueRef](vals), _vec.buf[ValueRef](vals),
_vec.buf[BasicBlockRef](bbs), _vec.buf[BasicBlockRef](bbs),
@ -1284,7 +1284,7 @@ obj builder(BuilderRef B, @mutable bool terminated) {
} }
fn Call(ValueRef Fn, vec[ValueRef] Args) -> ValueRef { fn Call(ValueRef Fn, vec[ValueRef] Args) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildCall(B, Fn, ret llvm.LLVMBuildCall(B, Fn,
_vec.buf[ValueRef](Args), _vec.buf[ValueRef](Args),
_vec.len[ValueRef](Args), _vec.len[ValueRef](Args),
@ -1292,7 +1292,7 @@ obj builder(BuilderRef B, @mutable bool terminated) {
} }
fn FastCall(ValueRef Fn, vec[ValueRef] Args) -> ValueRef { fn FastCall(ValueRef Fn, vec[ValueRef] Args) -> ValueRef {
check (!*terminated); assert (!*terminated);
auto v = llvm.LLVMBuildCall(B, Fn, auto v = llvm.LLVMBuildCall(B, Fn,
_vec.buf[ValueRef](Args), _vec.buf[ValueRef](Args),
_vec.len[ValueRef](Args), _vec.len[ValueRef](Args),
@ -1302,65 +1302,65 @@ obj builder(BuilderRef B, @mutable bool terminated) {
} }
fn Select(ValueRef If, ValueRef Then, ValueRef Else) -> ValueRef { fn Select(ValueRef If, ValueRef Then, ValueRef Else) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildSelect(B, If, Then, Else, _str.buf("")); ret llvm.LLVMBuildSelect(B, If, Then, Else, _str.buf(""));
} }
fn VAArg(ValueRef List, TypeRef Ty) -> ValueRef { fn VAArg(ValueRef List, TypeRef Ty) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildVAArg(B, List, Ty, _str.buf("")); ret llvm.LLVMBuildVAArg(B, List, Ty, _str.buf(""));
} }
fn ExtractElement(ValueRef VecVal, ValueRef Index) -> ValueRef { fn ExtractElement(ValueRef VecVal, ValueRef Index) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildExtractElement(B, VecVal, Index, _str.buf("")); ret llvm.LLVMBuildExtractElement(B, VecVal, Index, _str.buf(""));
} }
fn InsertElement(ValueRef VecVal, ValueRef EltVal, fn InsertElement(ValueRef VecVal, ValueRef EltVal,
ValueRef Index) -> ValueRef { ValueRef Index) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildInsertElement(B, VecVal, EltVal, Index, ret llvm.LLVMBuildInsertElement(B, VecVal, EltVal, Index,
_str.buf("")); _str.buf(""));
} }
fn ShuffleVector(ValueRef V1, ValueRef V2, ValueRef Mask) -> ValueRef { fn ShuffleVector(ValueRef V1, ValueRef V2, ValueRef Mask) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildShuffleVector(B, V1, V2, Mask, _str.buf("")); ret llvm.LLVMBuildShuffleVector(B, V1, V2, Mask, _str.buf(""));
} }
fn ExtractValue(ValueRef AggVal, uint Index) -> ValueRef { fn ExtractValue(ValueRef AggVal, uint Index) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildExtractValue(B, AggVal, Index, _str.buf("")); ret llvm.LLVMBuildExtractValue(B, AggVal, Index, _str.buf(""));
} }
fn InsertValue(ValueRef AggVal, ValueRef EltVal, fn InsertValue(ValueRef AggVal, ValueRef EltVal,
uint Index) -> ValueRef { uint Index) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildInsertValue(B, AggVal, EltVal, Index, _str.buf("")); ret llvm.LLVMBuildInsertValue(B, AggVal, EltVal, Index, _str.buf(""));
} }
fn IsNull(ValueRef Val) -> ValueRef { fn IsNull(ValueRef Val) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildIsNull(B, Val, _str.buf("")); ret llvm.LLVMBuildIsNull(B, Val, _str.buf(""));
} }
fn IsNotNull(ValueRef Val) -> ValueRef { fn IsNotNull(ValueRef Val) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildIsNotNull(B, Val, _str.buf("")); ret llvm.LLVMBuildIsNotNull(B, Val, _str.buf(""));
} }
fn PtrDiff(ValueRef LHS, ValueRef RHS) -> ValueRef { fn PtrDiff(ValueRef LHS, ValueRef RHS) -> ValueRef {
check (!*terminated); assert (!*terminated);
ret llvm.LLVMBuildPtrDiff(B, LHS, RHS, _str.buf("")); ret llvm.LLVMBuildPtrDiff(B, LHS, RHS, _str.buf(""));
} }
fn Trap() -> ValueRef { fn Trap() -> ValueRef {
check (!*terminated); assert (!*terminated);
let BasicBlockRef BB = llvm.LLVMGetInsertBlock(B); let BasicBlockRef BB = llvm.LLVMGetInsertBlock(B);
let ValueRef FN = llvm.LLVMGetBasicBlockParent(BB); let ValueRef FN = llvm.LLVMGetBasicBlockParent(BB);
let ModuleRef M = llvm.LLVMGetGlobalParent(FN); let ModuleRef M = llvm.LLVMGetGlobalParent(FN);
let ValueRef T = llvm.LLVMGetNamedFunction(M, _str.buf("llvm.trap")); let ValueRef T = llvm.LLVMGetNamedFunction(M, _str.buf("llvm.trap"));
check (T as int != 0); assert (T as int != 0);
let vec[ValueRef] Args = vec(); let vec[ValueRef] Args = vec();
ret llvm.LLVMBuildCall(B, T, ret llvm.LLVMBuildCall(B, T,
_vec.buf[ValueRef](Args), _vec.buf[ValueRef](Args),
@ -1391,8 +1391,8 @@ state obj type_names(std.map.hashmap[TypeRef, str] type_names,
std.map.hashmap[str, TypeRef] named_types) { std.map.hashmap[str, TypeRef] named_types) {
fn associate(str s, TypeRef t) { fn associate(str s, TypeRef t) {
check (!named_types.contains_key(s)); assert (!named_types.contains_key(s));
check (!type_names.contains_key(t)); assert (!type_names.contains_key(t));
type_names.insert(t, s); type_names.insert(t, s);
named_types.insert(s, t); named_types.insert(s, t);
} }

View File

@ -196,7 +196,10 @@ type ast_fold[ENV] =
@expr e, ann a) -> @expr) fold_expr_log, @expr e, ann a) -> @expr) fold_expr_log,
(fn(&ENV e, &span sp, (fn(&ENV e, &span sp,
@expr e, ann a) -> @expr) fold_expr_check_expr, @expr e, ann a) -> @expr) fold_expr_check,
(fn(&ENV e, &span sp,
@expr e, ann a) -> @expr) fold_expr_assert,
(fn(&ENV e, &span sp, (fn(&ENV e, &span sp,
ann a) -> @expr) fold_expr_port, ann a) -> @expr) fold_expr_port,
@ -796,10 +799,16 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr {
ret fld.fold_expr_log(env_, e.span, l, ee, t2); ret fld.fold_expr_log(env_, e.span, l, ee, t2);
} }
case (ast.expr_check_expr(?x, ?t)) { case (ast.expr_check(?x, ?t)) {
auto ee = fold_expr(env_, fld, x); auto ee = fold_expr(env_, fld, x);
auto t2 = fld.fold_ann(env_, t); auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_check_expr(env_, e.span, ee, t2); ret fld.fold_expr_check(env_, e.span, ee, t2);
}
case (ast.expr_assert(?x, ?t)) {
auto ee = fold_expr(env_, fld, x);
auto t2 = fld.fold_ann(env_, t);
ret fld.fold_expr_assert(env_, e.span, ee, t2);
} }
case (ast.expr_port(?t)) { case (ast.expr_port(?t)) {
@ -1380,9 +1389,14 @@ fn identity_fold_expr_log[ENV](&ENV e, &span sp, int lvl, @expr x,
ret @respan(sp, ast.expr_log(lvl, x, a)); ret @respan(sp, ast.expr_log(lvl, x, a));
} }
fn identity_fold_expr_check_expr[ENV](&ENV e, &span sp, @expr x, ann a) fn identity_fold_expr_check[ENV](&ENV e, &span sp, @expr x, ann a)
-> @expr { -> @expr {
ret @respan(sp, ast.expr_check_expr(x, a)); ret @respan(sp, ast.expr_check(x, a));
}
fn identity_fold_expr_assert[ENV](&ENV e, &span sp, @expr x, ann a)
-> @expr {
ret @respan(sp, ast.expr_check(x, a));
} }
fn identity_fold_expr_port[ENV](&ENV e, &span sp, ann a) -> @expr { fn identity_fold_expr_port[ENV](&ENV e, &span sp, ann a) -> @expr {
@ -1676,8 +1690,11 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
fold_expr_put = bind identity_fold_expr_put[ENV](_,_,_,_), fold_expr_put = bind identity_fold_expr_put[ENV](_,_,_,_),
fold_expr_be = bind identity_fold_expr_be[ENV](_,_,_,_), fold_expr_be = bind identity_fold_expr_be[ENV](_,_,_,_),
fold_expr_log = bind identity_fold_expr_log[ENV](_,_,_,_,_), fold_expr_log = bind identity_fold_expr_log[ENV](_,_,_,_,_),
fold_expr_check_expr fold_expr_check
= bind identity_fold_expr_check_expr[ENV](_,_,_,_), = bind identity_fold_expr_check[ENV](_,_,_,_),
fold_expr_assert
= bind identity_fold_expr_assert[ENV](_,_,_,_),
fold_expr_port = bind identity_fold_expr_port[ENV](_,_,_), fold_expr_port = bind identity_fold_expr_port[ENV](_,_,_),
fold_expr_chan = bind identity_fold_expr_chan[ENV](_,_,_,_), fold_expr_chan = bind identity_fold_expr_chan[ENV](_,_,_,_),

View File

@ -63,7 +63,7 @@ mod Encode {
); );
fn ty_str(@ctxt cx, ty.t t) -> str { fn ty_str(@ctxt cx, ty.t t) -> str {
check (! cx.use_abbrevs); assert (! cx.use_abbrevs);
auto sw = io.string_writer(); auto sw = io.string_writer();
enc_ty(sw.get_writer(), cx, t); enc_ty(sw.get_writer(), cx, t);
ret sw.get_str(); ret sw.get_str();

View File

@ -662,7 +662,7 @@ fn fold_pat_tag(&env e, &span sp, ast.path p, vec[@ast.pat] args,
fn fold_expr_path(&env e, &span sp, &ast.path p, &option.t[def] d, fn fold_expr_path(&env e, &span sp, &ast.path p, &option.t[def] d,
ann a) -> @ast.expr { ann a) -> @ast.expr {
auto n_idents = _vec.len[ast.ident](p.node.idents); auto n_idents = _vec.len[ast.ident](p.node.idents);
check (n_idents != 0u); assert (n_idents != 0u);
auto index = new_def_hash[def_wrap](); auto index = new_def_hash[def_wrap]();
auto d = find_final_def(e, index, sp, p.node.idents, ns_value, auto d = find_final_def(e, index, sp, p.node.idents, ns_value,

View File

@ -592,7 +592,7 @@ fn type_of_explicit_args(@crate_ctxt cx, vec[ty.arg] inputs) -> vec[TypeRef] {
let vec[TypeRef] atys = vec(); let vec[TypeRef] atys = vec();
for (ty.arg arg in inputs) { for (ty.arg arg in inputs) {
if (ty.type_has_dynamic_size(cx.tcx, arg.ty)) { if (ty.type_has_dynamic_size(cx.tcx, arg.ty)) {
check (arg.mode == ast.alias); assert (arg.mode == ast.alias);
atys += vec(T_typaram_ptr(cx.tn)); atys += vec(T_typaram_ptr(cx.tn));
} else { } else {
let TypeRef t; let TypeRef t;
@ -638,7 +638,7 @@ fn type_of_fn_full(@crate_ctxt cx,
// Arg 2: Env (closure-bindings / self-obj) // Arg 2: Env (closure-bindings / self-obj)
alt (obj_self) { alt (obj_self) {
case (some[TypeRef](?t)) { case (some[TypeRef](?t)) {
check (t as int != 0); assert (t as int != 0);
atys += vec(t); atys += vec(t);
} }
case (_) { case (_) {
@ -806,7 +806,7 @@ fn type_of_inner(@crate_ctxt cx, ty.t t) -> TypeRef {
case (ty.ty_type) { llty = T_ptr(T_tydesc(cx.tn)); } case (ty.ty_type) { llty = T_ptr(T_tydesc(cx.tn)); }
} }
check (llty as int != 0); assert (llty as int != 0);
llvm.LLVMAddTypeName(cx.llmod, llvm.LLVMAddTypeName(cx.llmod,
_str.buf(ty.ty_to_short_str(cx.tcx, _str.buf(ty.ty_to_short_str(cx.tcx,
cx.type_abbrevs, t)), cx.type_abbrevs, t)),
@ -1361,7 +1361,7 @@ fn dynamic_align_of(@block_ctxt cx, ty.t t) -> result {
fn GEP_tup_like(@block_ctxt cx, ty.t t, fn GEP_tup_like(@block_ctxt cx, ty.t t,
ValueRef base, vec[int] ixs) -> result { ValueRef base, vec[int] ixs) -> result {
check (ty.type_is_tup_like(cx.fcx.lcx.ccx.tcx, t)); assert (ty.type_is_tup_like(cx.fcx.lcx.ccx.tcx, t));
// It might be a static-known type. Handle this. // It might be a static-known type. Handle this.
@ -1399,17 +1399,17 @@ fn GEP_tup_like(@block_ctxt cx, ty.t t,
// and the latter would only be meaningful if we supported non-0 // and the latter would only be meaningful if we supported non-0
// values for the 0th index (we don't). // values for the 0th index (we don't).
check (len > 1u); assert (len > 1u);
if (n == 0u) { if (n == 0u) {
// Since we're starting from a value that's a pointer to a // Since we're starting from a value that's a pointer to a
// *single* structure, the first index (in GEP-ese) should just be // *single* structure, the first index (in GEP-ese) should just be
// 0, to yield the pointee. // 0, to yield the pointee.
check (ixs.(n) == 0); assert (ixs.(n) == 0);
ret split_type(ccx, t, ixs, n+1u); ret split_type(ccx, t, ixs, n+1u);
} }
check (n < len); assert (n < len);
let int ix = ixs.(n); let int ix = ixs.(n);
let vec[ty.t] prefix = vec(); let vec[ty.t] prefix = vec();
@ -1603,8 +1603,8 @@ fn get_tydesc(&@block_ctxt cx, ty.t t, bool escapes) -> result {
let uint n_params = ty.count_ty_params(cx.fcx.lcx.ccx.tcx, t); let uint n_params = ty.count_ty_params(cx.fcx.lcx.ccx.tcx, t);
auto tys = linearize_ty_params(cx, t); auto tys = linearize_ty_params(cx, t);
check (n_params == _vec.len[uint](tys._0)); assert (n_params == _vec.len[uint](tys._0));
check (n_params == _vec.len[ValueRef](tys._1)); assert (n_params == _vec.len[ValueRef](tys._1));
auto root = get_static_tydesc(cx, t, tys._0).tydesc; auto root = get_static_tydesc(cx, t, tys._0).tydesc;
@ -2327,7 +2327,7 @@ fn tag_variants(@crate_ctxt cx, ast.def_id id) -> vec[variant_info] {
ret creader.get_tag_variants(cx.sess, cx.tcx, id); ret creader.get_tag_variants(cx.sess, cx.tcx, id);
} }
check (cx.items.contains_key(id)); assert (cx.items.contains_key(id));
alt (cx.items.get(id).node) { alt (cx.items.get(id).node) {
case (ast.item_tag(_, ?variants, _, _, _)) { case (ast.item_tag(_, ?variants, _, _, _)) {
let vec[variant_info] result = vec(); let vec[variant_info] result = vec();
@ -3346,7 +3346,7 @@ fn join_results(@block_ctxt parent_cx,
// No incoming edges are live, so we're in dead-code-land. // No incoming edges are live, so we're in dead-code-land.
// Arbitrarily pick the first dead edge, since the caller // Arbitrarily pick the first dead edge, since the caller
// is just going to propagate it outward. // is just going to propagate it outward.
check (_vec.len[result](ins) >= 1u); assert (_vec.len[result](ins) >= 1u);
ret ins.(0); ret ins.(0);
} }
@ -3974,7 +3974,7 @@ fn lval_generic_fn(@block_ctxt cx,
auto lv; auto lv;
if (cx.fcx.lcx.ccx.sess.get_targ_crate_num() == fn_id._0) { if (cx.fcx.lcx.ccx.sess.get_targ_crate_num() == fn_id._0) {
// Internal reference. // Internal reference.
check (cx.fcx.lcx.ccx.fn_pairs.contains_key(fn_id)); assert (cx.fcx.lcx.ccx.fn_pairs.contains_key(fn_id));
lv = lval_val(cx, cx.fcx.lcx.ccx.fn_pairs.get(fn_id)); lv = lval_val(cx, cx.fcx.lcx.ccx.fn_pairs.get(fn_id));
} else { } else {
// External reference. // External reference.
@ -4017,7 +4017,7 @@ fn lookup_discriminant(@local_ctxt lcx, ast.def_id tid, ast.def_id vid)
alt (lcx.ccx.discrims.find(vid)) { alt (lcx.ccx.discrims.find(vid)) {
case (none[ValueRef]) { case (none[ValueRef]) {
// It's an external discriminant that we haven't seen yet. // It's an external discriminant that we haven't seen yet.
check (lcx.ccx.sess.get_targ_crate_num() != vid._0); assert (lcx.ccx.sess.get_targ_crate_num() != vid._0);
auto sym = creader.get_symbol(lcx.ccx.sess, vid); auto sym = creader.get_symbol(lcx.ccx.sess, vid);
auto gvar = llvm.LLVMAddGlobal(lcx.ccx.llmod, T_int(), auto gvar = llvm.LLVMAddGlobal(lcx.ccx.llmod, T_int(),
_str.buf(sym)); _str.buf(sym));
@ -4039,7 +4039,7 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
case (ast.def_arg(?did)) { case (ast.def_arg(?did)) {
alt (cx.fcx.llargs.find(did)) { alt (cx.fcx.llargs.find(did)) {
case (none[ValueRef]) { case (none[ValueRef]) {
check (cx.fcx.llupvars.contains_key(did)); assert (cx.fcx.llupvars.contains_key(did));
ret lval_mem(cx, cx.fcx.llupvars.get(did)); ret lval_mem(cx, cx.fcx.llupvars.get(did));
} }
case (some[ValueRef](?llval)) { case (some[ValueRef](?llval)) {
@ -4050,7 +4050,7 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
case (ast.def_local(?did)) { case (ast.def_local(?did)) {
alt (cx.fcx.lllocals.find(did)) { alt (cx.fcx.lllocals.find(did)) {
case (none[ValueRef]) { case (none[ValueRef]) {
check (cx.fcx.llupvars.contains_key(did)); assert (cx.fcx.llupvars.contains_key(did));
ret lval_mem(cx, cx.fcx.llupvars.get(did)); ret lval_mem(cx, cx.fcx.llupvars.get(did));
} }
case (some[ValueRef](?llval)) { case (some[ValueRef](?llval)) {
@ -4059,11 +4059,11 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
} }
} }
case (ast.def_binding(?did)) { case (ast.def_binding(?did)) {
check (cx.fcx.lllocals.contains_key(did)); assert (cx.fcx.lllocals.contains_key(did));
ret lval_mem(cx, cx.fcx.lllocals.get(did)); ret lval_mem(cx, cx.fcx.lllocals.get(did));
} }
case (ast.def_obj_field(?did)) { case (ast.def_obj_field(?did)) {
check (cx.fcx.llobjfields.contains_key(did)); assert (cx.fcx.llobjfields.contains_key(did));
ret lval_mem(cx, cx.fcx.llobjfields.get(did)); ret lval_mem(cx, cx.fcx.llobjfields.get(did));
} }
case (ast.def_fn(?did)) { case (ast.def_fn(?did)) {
@ -4115,7 +4115,7 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
} }
case (ast.def_const(?did)) { case (ast.def_const(?did)) {
// TODO: externals // TODO: externals
check (cx.fcx.lcx.ccx.consts.contains_key(did)); assert (cx.fcx.lcx.ccx.consts.contains_key(did));
ret lval_mem(cx, cx.fcx.lcx.ccx.consts.get(did)); ret lval_mem(cx, cx.fcx.lcx.ccx.consts.get(did));
} }
case (ast.def_native_fn(?did)) { case (ast.def_native_fn(?did)) {
@ -4254,7 +4254,7 @@ fn trans_lval(@block_ctxt cx, @ast.expr e) -> lval_result {
ret trans_index(cx, e.span, base, idx, ann); ret trans_index(cx, e.span, base, idx, ann);
} }
case (ast.expr_unary(?unop, ?base, ?ann)) { case (ast.expr_unary(?unop, ?base, ?ann)) {
check (unop == ast.deref); assert (unop == ast.deref);
auto sub = trans_expr(cx, base); auto sub = trans_expr(cx, base);
auto val = sub.bcx.build.GEP(sub.val, auto val = sub.bcx.build.GEP(sub.val,
@ -4418,7 +4418,7 @@ fn trans_bind_thunk(@local_ctxt cx,
} }
} else if (ty.type_contains_params(cx.ccx.tcx, } else if (ty.type_contains_params(cx.ccx.tcx,
out_arg.ty)) { out_arg.ty)) {
check (out_arg.mode == ast.alias); assert (out_arg.mode == ast.alias);
val = bcx.build.PointerCast(val, llout_arg_ty); val = bcx.build.PointerCast(val, llout_arg_ty);
} }
@ -4431,7 +4431,7 @@ fn trans_bind_thunk(@local_ctxt cx,
let ValueRef passed_arg = llvm.LLVMGetParam(llthunk, a); let ValueRef passed_arg = llvm.LLVMGetParam(llthunk, a);
if (ty.type_contains_params(cx.ccx.tcx, out_arg.ty)) { if (ty.type_contains_params(cx.ccx.tcx, out_arg.ty)) {
check (out_arg.mode == ast.alias); assert (out_arg.mode == ast.alias);
passed_arg = bcx.build.PointerCast(passed_arg, passed_arg = bcx.build.PointerCast(passed_arg,
llout_arg_ty); llout_arg_ty);
} }
@ -5121,7 +5121,7 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
case (ast.expr_assign(?dst, ?src, ?ann)) { case (ast.expr_assign(?dst, ?src, ?ann)) {
auto lhs_res = trans_lval(cx, dst); auto lhs_res = trans_lval(cx, dst);
check (lhs_res.is_mem); assert (lhs_res.is_mem);
auto rhs_res = trans_expr(lhs_res.res.bcx, src); auto rhs_res = trans_expr(lhs_res.res.bcx, src);
auto t = node_ann_type(cx.fcx.lcx.ccx, ann); auto t = node_ann_type(cx.fcx.lcx.ccx, ann);
// FIXME: calculate copy init-ness in typestate. // FIXME: calculate copy init-ness in typestate.
@ -5132,7 +5132,7 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
case (ast.expr_assign_op(?op, ?dst, ?src, ?ann)) { case (ast.expr_assign_op(?op, ?dst, ?src, ?ann)) {
auto t = node_ann_type(cx.fcx.lcx.ccx, ann); auto t = node_ann_type(cx.fcx.lcx.ccx, ann);
auto lhs_res = trans_lval(cx, dst); auto lhs_res = trans_lval(cx, dst);
check (lhs_res.is_mem); assert (lhs_res.is_mem);
auto rhs_res = trans_expr(lhs_res.res.bcx, src); auto rhs_res = trans_expr(lhs_res.res.bcx, src);
if (ty.type_is_sequence(cx.fcx.lcx.ccx.tcx, t)) { if (ty.type_is_sequence(cx.fcx.lcx.ccx.tcx, t)) {
alt (op) { alt (op) {
@ -5189,7 +5189,11 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
ret trans_log(lvl, cx, a); ret trans_log(lvl, cx, a);
} }
case (ast.expr_check_expr(?a, _)) { case (ast.expr_assert(?a, _)) {
ret trans_check_expr(cx, a);
}
case (ast.expr_check(?a, _)) {
ret trans_check_expr(cx, a); ret trans_check_expr(cx, a);
} }
@ -5510,7 +5514,7 @@ fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
fn trans_be(@block_ctxt cx, @ast.expr e) -> result { fn trans_be(@block_ctxt cx, @ast.expr e) -> result {
// FIXME: This should be a typestate precondition // FIXME: This should be a typestate precondition
check (ast.is_call_expr(e)); assert (ast.is_call_expr(e));
// FIXME: Turn this into a real tail call once // FIXME: Turn this into a real tail call once
// calling convention issues are settled // calling convention issues are settled
ret trans_ret(cx, some(e)); ret trans_ret(cx, some(e));
@ -5606,7 +5610,7 @@ fn trans_recv(@block_ctxt cx, @ast.expr lhs, @ast.expr rhs,
auto bcx = cx; auto bcx = cx;
auto data = trans_lval(bcx, lhs); auto data = trans_lval(bcx, lhs);
check (data.is_mem); assert (data.is_mem);
bcx = data.res.bcx; bcx = data.res.bcx;
auto unit_ty = node_ann_type(bcx.fcx.lcx.ccx, ann); auto unit_ty = node_ann_type(bcx.fcx.lcx.ccx, ann);
@ -5638,7 +5642,7 @@ fn recv_val(@block_ctxt cx, ValueRef lhs, @ast.expr rhs,
fn init_local(@block_ctxt cx, @ast.local local) -> result { fn init_local(@block_ctxt cx, @ast.local local) -> result {
// Make a note to drop this slot on the way out. // Make a note to drop this slot on the way out.
check (cx.fcx.lllocals.contains_key(local.id)); assert (cx.fcx.lllocals.contains_key(local.id));
auto llptr = cx.fcx.lllocals.get(local.id); auto llptr = cx.fcx.lllocals.get(local.id);
auto ty = node_ann_type(cx.fcx.lcx.ccx, local.ann); auto ty = node_ann_type(cx.fcx.lcx.ccx, local.ann);
auto bcx = cx; auto bcx = cx;
@ -5754,7 +5758,7 @@ fn trans_block_cleanups(@block_ctxt cx,
auto bcx = cx; auto bcx = cx;
if (cleanup_cx.kind == NON_SCOPE_BLOCK) { if (cleanup_cx.kind == NON_SCOPE_BLOCK) {
check (_vec.len[cleanup](cleanup_cx.cleanups) == 0u); assert (_vec.len[cleanup](cleanup_cx.cleanups) == 0u);
} }
auto i = _vec.len[cleanup](cleanup_cx.cleanups); auto i = _vec.len[cleanup](cleanup_cx.cleanups);
@ -5975,7 +5979,7 @@ fn create_llargs_for_fn_args(&@fn_ctxt cx,
auto i = 0u; auto i = 0u;
for (ast.ty_param tp in ty_params) { for (ast.ty_param tp in ty_params) {
auto llarg = llvm.LLVMGetParam(cx.llfn, arg_n); auto llarg = llvm.LLVMGetParam(cx.llfn, arg_n);
check (llarg as int != 0); assert (llarg as int != 0);
cx.lltydescs += vec(llarg); cx.lltydescs += vec(llarg);
arg_n += 1u; arg_n += 1u;
i += 1u; i += 1u;
@ -5985,14 +5989,14 @@ fn create_llargs_for_fn_args(&@fn_ctxt cx,
if (proto == ast.proto_iter) { if (proto == ast.proto_iter) {
auto llarg = llvm.LLVMGetParam(cx.llfn, arg_n); auto llarg = llvm.LLVMGetParam(cx.llfn, arg_n);
check (llarg as int != 0); assert (llarg as int != 0);
cx.lliterbody = some[ValueRef](llarg); cx.lliterbody = some[ValueRef](llarg);
arg_n += 1u; arg_n += 1u;
} }
for (ast.arg arg in args) { for (ast.arg arg in args) {
auto llarg = llvm.LLVMGetParam(cx.llfn, arg_n); auto llarg = llvm.LLVMGetParam(cx.llfn, arg_n);
check (llarg as int != 0); assert (llarg as int != 0);
cx.llargs.insert(arg.id, llarg); cx.llargs.insert(arg.id, llarg);
arg_n += 1u; arg_n += 1u;
} }
@ -6430,7 +6434,7 @@ fn trans_tag_variant(@local_ctxt cx, ast.def_id tag_id,
id=varg.id)); id=varg.id));
} }
check (cx.ccx.item_ids.contains_key(variant.node.id)); assert (cx.ccx.item_ids.contains_key(variant.node.id));
let ValueRef llfndecl = cx.ccx.item_ids.get(variant.node.id); let ValueRef llfndecl = cx.ccx.item_ids.get(variant.node.id);
auto fcx = new_fn_ctxt(cx, llfndecl); auto fcx = new_fn_ctxt(cx, llfndecl);
@ -6697,7 +6701,7 @@ fn decl_native_fn_and_pair(@crate_ctxt ccx,
for each (uint i in _uint.range(0u, num_ty_param)) { for each (uint i in _uint.range(0u, num_ty_param)) {
auto llarg = llvm.LLVMGetParam(fcx.llfn, arg_n); auto llarg = llvm.LLVMGetParam(fcx.llfn, arg_n);
fcx.lltydescs += vec(llarg); fcx.lltydescs += vec(llarg);
check (llarg as int != 0); assert (llarg as int != 0);
call_args += vec(vp2i(bcx, llarg)); call_args += vec(vp2i(bcx, llarg));
arg_n += 1u; arg_n += 1u;
} }
@ -6763,7 +6767,7 @@ fn decl_native_fn_and_pair(@crate_ctxt ccx,
for (ty.arg arg in args) { for (ty.arg arg in args) {
auto llarg = llvm.LLVMGetParam(fcx.llfn, arg_n); auto llarg = llvm.LLVMGetParam(fcx.llfn, arg_n);
check (llarg as int != 0); assert (llarg as int != 0);
push_arg(bcx, call_args, llarg, arg.ty, arg.mode); push_arg(bcx, call_args, llarg, arg.ty, arg.mode);
if (arg.mode == ast.val) { if (arg.mode == ast.val) {
drop_args += vec(tup(llarg, arg.ty)); drop_args += vec(tup(llarg, arg.ty));

View File

@ -895,7 +895,7 @@ fn type_is_tup_like(ctxt cx, t ty) -> bool {
} }
fn get_element_type(ctxt cx, t ty, uint i) -> t { fn get_element_type(ctxt cx, t ty, uint i) -> t {
check (type_is_tup_like(cx, ty)); assert (type_is_tup_like(cx, ty));
alt (struct(cx, ty)) { alt (struct(cx, ty)) {
case (ty_tup(?mts)) { case (ty_tup(?mts)) {
ret mts.(i).ty; ret mts.(i).ty;
@ -1785,50 +1785,117 @@ fn pat_ty(ctxt cx, @ast.pat pat) -> t {
fail; // not reached fail; // not reached
} }
fn expr_ann(@ast.expr expr) -> option.t[ast.ann] { fn expr_ann(&@ast.expr e) -> ast.ann {
alt (expr.node) { alt(e.node) {
case (ast.expr_vec(_, _, ?ann)) { ret some[ast.ann](ann); } case (ast.expr_vec(_,_,?a)) {
case (ast.expr_tup(_, ?ann)) { ret some[ast.ann](ann); } ret a;
case (ast.expr_rec(_, _, ?ann)) { ret some[ast.ann](ann); } }
case (ast.expr_bind(_, _, ?ann)) { ret some[ast.ann](ann); } case (ast.expr_tup(_,?a)) {
case (ast.expr_call(_, _, ?ann)) { ret some[ast.ann](ann); } ret a;
case (ast.expr_self_method(_, ?ann)) { ret some[ast.ann](ann); } }
case (ast.expr_spawn(_, _, _, _, ?ann)) case (ast.expr_rec(_,_,?a)) {
{ ret some[ast.ann](ann); } ret a;
case (ast.expr_binary(_, _, _, ?ann)) { ret some[ast.ann](ann); } }
case (ast.expr_unary(_, _, ?ann)) { ret some[ast.ann](ann); } case (ast.expr_call(_,_,?a)) {
case (ast.expr_lit(_, ?ann)) { ret some[ast.ann](ann); } ret a;
case (ast.expr_cast(_, _, ?ann)) { ret some[ast.ann](ann); } }
case (ast.expr_if(_, _, _, ?ann)) { ret some[ast.ann](ann); } case (ast.expr_bind(_,_,?a)) {
case (ast.expr_for(_, _, _, ?ann)) { ret some[ast.ann](ann); } ret a;
case (ast.expr_for_each(_, _, _, ?ann)) }
{ ret some[ast.ann](ann); } case (ast.expr_binary(_,_,_,?a)) {
case (ast.expr_while(_, _, ?ann)) { ret some[ast.ann](ann); } ret a;
case (ast.expr_do_while(_, _, ?ann)) { ret some[ast.ann](ann); } }
case (ast.expr_alt(_, _, ?ann)) { ret some[ast.ann](ann); } case (ast.expr_unary(_,_,?a)) {
case (ast.expr_block(_, ?ann)) { ret some[ast.ann](ann); } ret a;
case (ast.expr_assign(_, _, ?ann)) { ret some[ast.ann](ann); } }
case (ast.expr_assign_op(_, _, _, ?ann)) case (ast.expr_lit(_,?a)) {
{ ret some[ast.ann](ann); } ret a;
case (ast.expr_field(_, _, ?ann)) { ret some[ast.ann](ann); } }
case (ast.expr_index(_, _, ?ann)) { ret some[ast.ann](ann); } case (ast.expr_cast(_,_,?a)) {
case (ast.expr_path(_, _, ?ann)) { ret some[ast.ann](ann); } ret a;
case (ast.expr_ext(_, _, _, _, ?ann)) { ret some[ast.ann](ann); } }
case (ast.expr_port(?ann)) { ret some[ast.ann](ann); } case (ast.expr_if(_,_,_,?a)) {
case (ast.expr_chan(_, ?ann)) { ret some[ast.ann](ann); } ret a;
case (ast.expr_send(_, _, ?ann)) { ret some[ast.ann](ann); } }
case (ast.expr_recv(_, _, ?ann)) { ret some[ast.ann](ann); } case (ast.expr_while(_,_,?a)) {
ret a;
case (ast.expr_fail(_)) { ret none[ast.ann]; } }
case (ast.expr_break(_)) { ret none[ast.ann]; } case (ast.expr_for(_,_,_,?a)) {
case (ast.expr_cont(_)) { ret none[ast.ann]; } ret a;
case (ast.expr_log(_,_,_)) { ret none[ast.ann]; } }
case (ast.expr_check_expr(_,_)) { ret none[ast.ann]; } case (ast.expr_for_each(_,_,_,?a)) {
case (ast.expr_ret(_,_)) { ret none[ast.ann]; } ret a;
case (ast.expr_put(_,_)) { ret none[ast.ann]; } }
case (ast.expr_be(_,_)) { ret none[ast.ann]; } case (ast.expr_do_while(_,_,?a)) {
ret a;
}
case (ast.expr_alt(_,_,?a)) {
ret a;
}
case (ast.expr_block(_,?a)) {
ret a;
}
case (ast.expr_assign(_,_,?a)) {
ret a;
}
case (ast.expr_assign_op(_,_,_,?a)) {
ret a;
}
case (ast.expr_send(_,_,?a)) {
ret a;
}
case (ast.expr_recv(_,_,?a)) {
ret a;
}
case (ast.expr_field(_,_,?a)) {
ret a;
}
case (ast.expr_index(_,_,?a)) {
ret a;
}
case (ast.expr_path(_,_,?a)) {
ret a;
}
case (ast.expr_ext(_,_,_,_,?a)) {
ret a;
}
case (ast.expr_fail(?a)) {
ret a;
}
case (ast.expr_ret(_,?a)) {
ret a;
}
case (ast.expr_put(_,?a)) {
ret a;
}
case (ast.expr_be(_,?a)) {
ret a;
}
case (ast.expr_log(_,_,?a)) {
ret a;
}
case (ast.expr_assert(_,?a)) {
ret a;
}
case (ast.expr_check(_,?a)) {
ret a;
}
case (ast.expr_port(?a)) {
ret a;
}
case (ast.expr_chan(_,?a)) {
ret a;
}
case (ast.expr_break(?a)) {
ret a;
}
case (ast.expr_cont(?a)) {
ret a;
}
case (ast.expr_self_method(_, ?a)) {
ret a;
}
} }
fail;
} }
// Returns the type of an expression as a monotype. // Returns the type of an expression as a monotype.
@ -1838,37 +1905,23 @@ fn expr_ann(@ast.expr expr) -> option.t[ast.ann] {
// instead of "fn(&T) -> T with T = int". If this isn't what you want, see // instead of "fn(&T) -> T with T = int". If this isn't what you want, see
// expr_ty_params_and_ty() below. // expr_ty_params_and_ty() below.
fn expr_ty(ctxt cx, @ast.expr expr) -> t { fn expr_ty(ctxt cx, @ast.expr expr) -> t {
alt (expr_ann(expr)) { { ret ann_to_monotype(cx, expr_ann(expr)); }
case (none[ast.ann]) { ret mk_nil(cx); }
case (some[ast.ann](?a)) { ret ann_to_monotype(cx, a); }
}
} }
fn expr_ty_params_and_ty(ctxt cx, @ast.expr expr) -> tup(vec[t], t) { fn expr_ty_params_and_ty(ctxt cx, @ast.expr expr) -> tup(vec[t], t) {
alt (expr_ann(expr)) { auto a = expr_ann(expr);
case (none[ast.ann]) {
let vec[t] tps = vec();
ret tup(tps, mk_nil(cx));
}
case (some[ast.ann](?a)) {
ret tup(ann_to_type_params(a), ann_to_type(a)); ret tup(ann_to_type_params(a), ann_to_type(a));
}
}
} }
fn expr_has_ty_params(@ast.expr expr) -> bool { fn expr_has_ty_params(@ast.expr expr) -> bool {
// FIXME: Rewrite using complex patterns when they're trustworthy. // FIXME: Rewrite using complex patterns when they're trustworthy.
alt (expr_ann(expr)) { alt (expr_ann(expr)) {
case (none[ast.ann]) { fail; }
case (some[ast.ann](?a)) {
alt (a) {
case (ast.ann_none) { fail; } case (ast.ann_none) { fail; }
case (ast.ann_type(_, ?tps_opt, _)) { case (ast.ann_type(_, ?tps_opt, _)) {
ret !option.is_none[vec[t]](tps_opt); ret !option.is_none[vec[t]](tps_opt);
} }
} }
}
}
} }
// FIXME: At the moment this works only for call, bind, and path expressions. // FIXME: At the moment this works only for call, bind, and path expressions.
@ -2233,7 +2286,7 @@ mod Unify {
if (actual_n < vlen) { if (actual_n < vlen) {
cx.types.(actual_n) += vec(expected); cx.types.(actual_n) += vec(expected);
} else { } else {
check (actual_n == vlen); assert (actual_n == vlen);
cx.types += vec(mutable vec(expected)); cx.types += vec(mutable vec(expected));
} }
} }
@ -2601,7 +2654,7 @@ mod Unify {
if (expected_n < vlen) { if (expected_n < vlen) {
cx.types.(expected_n) += vec(actual); cx.types.(expected_n) += vec(actual);
} else { } else {
check (expected_n == vlen); assert (expected_n == vlen);
cx.types += vec(mutable vec(actual)); cx.types += vec(mutable vec(actual));
} }
ret ures_ok(expected); ret ures_ok(expected);

View File

@ -110,7 +110,7 @@ fn ty_param_count_and_ty_for_def(@fn_ctxt fcx, &ast.span sp, &ast.def defn)
-> ty_param_count_and_ty { -> ty_param_count_and_ty {
alt (defn) { alt (defn) {
case (ast.def_arg(?id)) { case (ast.def_arg(?id)) {
// check (fcx.locals.contains_key(id)); // assert (fcx.locals.contains_key(id));
ret tup(0u, fcx.locals.get(id)); ret tup(0u, fcx.locals.get(id));
} }
case (ast.def_local(?id)) { case (ast.def_local(?id)) {
@ -122,7 +122,7 @@ fn ty_param_count_and_ty_for_def(@fn_ctxt fcx, &ast.span sp, &ast.def defn)
ret tup(0u, t); ret tup(0u, t);
} }
case (ast.def_obj_field(?id)) { case (ast.def_obj_field(?id)) {
// check (fcx.locals.contains_key(id)); // assert (fcx.locals.contains_key(id));
ret tup(0u, fcx.locals.get(id)); ret tup(0u, fcx.locals.get(id));
} }
case (ast.def_fn(?id)) { case (ast.def_fn(?id)) {
@ -142,7 +142,7 @@ fn ty_param_count_and_ty_for_def(@fn_ctxt fcx, &ast.span sp, &ast.def defn)
fcx.ccx.type_cache, vid); fcx.ccx.type_cache, vid);
} }
case (ast.def_binding(?id)) { case (ast.def_binding(?id)) {
// check (fcx.locals.contains_key(id)); // assert (fcx.locals.contains_key(id));
ret tup(0u, fcx.locals.get(id)); ret tup(0u, fcx.locals.get(id));
} }
case (ast.def_obj(?id)) { case (ast.def_obj(?id)) {
@ -298,7 +298,7 @@ fn ast_ty_to_ty(ty.ctxt tcx, ty_getter getter, &@ast.ty ast_ty) -> ty.t {
} }
case (ast.ty_path(?path, ?def)) { case (ast.ty_path(?path, ?def)) {
check (def != none[ast.def]); assert (def != none[ast.def]);
alt (option.get[ast.def](def)) { alt (option.get[ast.def](def)) {
case (ast.def_ty(?id)) { case (ast.def_ty(?id)) {
typ = instantiate(tcx, getter, id, path.node.types); typ = instantiate(tcx, getter, id, path.node.types);
@ -411,7 +411,7 @@ mod Collect {
ret creader.get_type(cx.sess, cx.tcx, id); ret creader.get_type(cx.sess, cx.tcx, id);
} }
// check (cx.id_to_ty_item.contains_key(id)); // assert (cx.id_to_ty_item.contains_key(id));
auto it = cx.id_to_ty_item.get(id); auto it = cx.id_to_ty_item.get(id);
auto tpt; auto tpt;
@ -672,7 +672,7 @@ mod Collect {
fn fold_item_const(&@env e, &span sp, ast.ident i, fn fold_item_const(&@env e, &span sp, ast.ident i,
@ast.ty t, @ast.expr ex, @ast.ty t, @ast.expr ex,
ast.def_id id, ast.ann a) -> @ast.item { ast.def_id id, ast.ann a) -> @ast.item {
// check (e.cx.type_cache.contains_key(id)); // assert (e.cx.type_cache.contains_key(id));
auto typ = e.cx.type_cache.get(id)._1; auto typ = e.cx.type_cache.get(id)._1;
auto item = ast.item_const(i, t, ex, id, triv_ann(typ)); auto item = ast.item_const(i, t, ex, id, triv_ann(typ));
ret @fold.respan[ast.item_](sp, item); ret @fold.respan[ast.item_](sp, item);
@ -681,7 +681,7 @@ mod Collect {
fn fold_item_fn(&@env e, &span sp, ast.ident i, fn fold_item_fn(&@env e, &span sp, ast.ident i,
&ast._fn f, vec[ast.ty_param] ty_params, &ast._fn f, vec[ast.ty_param] ty_params,
ast.def_id id, ast.ann a) -> @ast.item { ast.def_id id, ast.ann a) -> @ast.item {
// check (e.cx.type_cache.contains_key(id)); // assert (e.cx.type_cache.contains_key(id));
auto typ = e.cx.type_cache.get(id)._1; auto typ = e.cx.type_cache.get(id)._1;
auto item = ast.item_fn(i, f, ty_params, id, triv_ann(typ)); auto item = ast.item_fn(i, f, ty_params, id, triv_ann(typ));
ret @fold.respan[ast.item_](sp, item); ret @fold.respan[ast.item_](sp, item);
@ -690,7 +690,7 @@ mod Collect {
fn fold_native_item_fn(&@env e, &span sp, ast.ident i, option.t[str] ln, fn fold_native_item_fn(&@env e, &span sp, ast.ident i, option.t[str] ln,
&ast.fn_decl d, vec[ast.ty_param] ty_params, &ast.fn_decl d, vec[ast.ty_param] ty_params,
ast.def_id id, ast.ann a) -> @ast.native_item { ast.def_id id, ast.ann a) -> @ast.native_item {
// check (e.cx.type_cache.contains_key(id)); // assert (e.cx.type_cache.contains_key(id));
auto typ = e.cx.type_cache.get(id)._1; auto typ = e.cx.type_cache.get(id)._1;
auto item = ast.native_item_fn(i, ln, d, ty_params, id, auto item = ast.native_item_fn(i, ln, d, ty_params, id,
triv_ann(typ)); triv_ann(typ));
@ -721,7 +721,7 @@ mod Collect {
fn fold_item_obj(&@env e, &span sp, ast.ident i, fn fold_item_obj(&@env e, &span sp, ast.ident i,
&ast._obj ob, vec[ast.ty_param] ty_params, &ast._obj ob, vec[ast.ty_param] ty_params,
ast.obj_def_ids odid, ast.ann a) -> @ast.item { ast.obj_def_ids odid, ast.ann a) -> @ast.item {
// check (e.cx.type_cache.contains_key(odid.ctor)); // assert (e.cx.type_cache.contains_key(odid.ctor));
auto t = e.cx.type_cache.get(odid.ctor)._1; auto t = e.cx.type_cache.get(odid.ctor)._1;
let vec[method] meth_tys = get_ctor_obj_methods(e, t); let vec[method] meth_tys = get_ctor_obj_methods(e, t);
let vec[@ast.method] methods = vec(); let vec[@ast.method] methods = vec();
@ -777,7 +777,7 @@ mod Collect {
fn fold_item_ty(&@env e, &span sp, ast.ident i, fn fold_item_ty(&@env e, &span sp, ast.ident i,
@ast.ty t, vec[ast.ty_param] ty_params, @ast.ty t, vec[ast.ty_param] ty_params,
ast.def_id id, ast.ann a) -> @ast.item { ast.def_id id, ast.ann a) -> @ast.item {
// check (e.cx.type_cache.contains_key(id)); // assert (e.cx.type_cache.contains_key(id));
auto typ = e.cx.type_cache.get(id)._1; auto typ = e.cx.type_cache.get(id)._1;
auto item = ast.item_ty(i, t, ty_params, id, triv_ann(typ)); auto item = ast.item_ty(i, t, ty_params, id, triv_ann(typ));
ret @fold.respan[ast.item_](sp, item); ret @fold.respan[ast.item_](sp, item);
@ -1214,7 +1214,7 @@ mod Pushdown {
case (none[@ast.expr]) { case (none[@ast.expr]) {
auto i = 0u; auto i = 0u;
for (ast.field field_0 in fields_0) { for (ast.field field_0 in fields_0) {
check (_str.eq(field_0.ident, assert (_str.eq(field_0.ident,
field_mts.(i).ident)); field_mts.(i).ident));
auto e_1 = auto e_1 =
pushdown_expr(fcx, pushdown_expr(fcx,
@ -1409,7 +1409,8 @@ mod Pushdown {
case (ast.expr_ret(_,_)) { e_1 = e.node; } case (ast.expr_ret(_,_)) { e_1 = e.node; }
case (ast.expr_put(_,_)) { e_1 = e.node; } case (ast.expr_put(_,_)) { e_1 = e.node; }
case (ast.expr_be(_,_)) { e_1 = e.node; } case (ast.expr_be(_,_)) { e_1 = e.node; }
case (ast.expr_check_expr(_,_)) { e_1 = e.node; } case (ast.expr_check(_,_)) { e_1 = e.node; }
case (ast.expr_assert(_,_)) { e_1 = e.node; }
case (ast.expr_port(?ann)) { case (ast.expr_port(?ann)) {
auto t = Demand.simple(fcx, e.span, expected, auto t = Demand.simple(fcx, e.span, expected,
@ -1839,7 +1840,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
case (ast.expr_path(?pth, ?defopt, _)) { case (ast.expr_path(?pth, ?defopt, _)) {
auto t = ty.mk_nil(fcx.ccx.tcx); auto t = ty.mk_nil(fcx.ccx.tcx);
check (defopt != none[ast.def]); assert (defopt != none[ast.def]);
auto defn = option.get[ast.def](defopt); auto defn = option.get[ast.def](defopt);
auto tpt = ty_param_count_and_ty_for_def(fcx, expr.span, defn); auto tpt = ty_param_count_and_ty_for_def(fcx, expr.span, defn);
@ -1939,7 +1940,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
case (ast.expr_be(?e, _)) { case (ast.expr_be(?e, _)) {
/* FIXME: prove instead of check */ /* FIXME: prove instead of check */
check (ast.is_call_expr(e)); assert (ast.is_call_expr(e));
auto expr_0 = check_expr(fcx, e); auto expr_0 = check_expr(fcx, e);
auto expr_1 = Pushdown.pushdown_expr(fcx, fcx.ret_ty, expr_0); auto expr_1 = Pushdown.pushdown_expr(fcx, fcx.ret_ty, expr_0);
ret @fold.respan[ast.expr_](expr.span, ret @fold.respan[ast.expr_](expr.span,
@ -1953,12 +1954,25 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
plain_ann(fcx.ccx.tcx))); plain_ann(fcx.ccx.tcx)));
} }
case (ast.expr_check_expr(?e, _)) { case (ast.expr_check(?e, _)) {
/* FIXME */
/* presumably, here is where we should check that e is
actually a call to a predicate, where all the arguments
are literals or slot variables? */
auto expr_t = check_expr(fcx, e); auto expr_t = check_expr(fcx, e);
Demand.simple(fcx, expr.span, ty.mk_bool(fcx.ccx.tcx), Demand.simple(fcx, expr.span, ty.mk_bool(fcx.ccx.tcx),
expr_ty(fcx.ccx.tcx, expr_t)); expr_ty(fcx.ccx.tcx, expr_t));
ret @fold.respan[ast.expr_] ret @fold.respan[ast.expr_]
(expr.span, ast.expr_check_expr(expr_t, (expr.span, ast.expr_check(expr_t,
plain_ann(fcx.ccx.tcx)));
}
case (ast.expr_assert(?e, _)) {
auto expr_t = check_expr(fcx, e);
Demand.simple(fcx, expr.span, ty.mk_bool(fcx.ccx.tcx),
expr_ty(fcx.ccx.tcx, expr_t));
ret @fold.respan[ast.expr_]
(expr.span, ast.expr_assert(expr_t,
plain_ann(fcx.ccx.tcx))); plain_ann(fcx.ccx.tcx)));
} }

View File

@ -55,7 +55,8 @@ import front.ast.expr_put;
import front.ast.expr_port; import front.ast.expr_port;
import front.ast.expr_chan; import front.ast.expr_chan;
import front.ast.expr_be; import front.ast.expr_be;
import front.ast.expr_check_expr; import front.ast.expr_check;
import front.ast.expr_assert;
import front.ast.expr_cast; import front.ast.expr_cast;
import front.ast.expr_for; import front.ast.expr_for;
import front.ast.expr_for_each; import front.ast.expr_for_each;
@ -147,8 +148,7 @@ import util.typestate_ann.clone;
import middle.ty; import middle.ty;
import middle.ty.ann_to_type; import middle.ty.ann_to_type;
import middle.ty.arg; import middle.ty.arg;
import middle.ty.block_ty; import middle.ty.expr_ann;
import middle.ty.expr_ty;
import middle.ty.ty_to_str; import middle.ty.ty_to_str;
import pretty.pprust.print_block; import pretty.pprust.print_block;
@ -293,11 +293,11 @@ type fn_info = std.map.hashmap[def_id, var_info];
type fn_info_map = std.map.hashmap[def_id, fn_info]; type fn_info_map = std.map.hashmap[def_id, fn_info];
fn bit_num(def_id v, fn_info m) -> uint { fn bit_num(def_id v, fn_info m) -> uint {
check (m.contains_key(v)); assert (m.contains_key(v));
ret m.get(v)._0; ret m.get(v)._0;
} }
fn get_fn_info(fn_info_map fm, def_id did) -> fn_info { fn get_fn_info(fn_info_map fm, def_id did) -> fn_info {
check (fm.contains_key(did)); assert (fm.contains_key(did));
ret fm.get(did); ret fm.get(did);
} }
@ -389,116 +389,6 @@ fn mk_f_to_fn_info(@ast.crate c) -> fn_info_map {
ret res; ret res;
} }
/**** Helpers ****/ /**** Helpers ****/
fn expr_ann(&expr e) -> ann {
alt(e.node) {
case (ast.expr_vec(_,_,?a)) {
ret a;
}
case (ast.expr_tup(_,?a)) {
ret a;
}
case (ast.expr_rec(_,_,?a)) {
ret a;
}
case (ast.expr_call(_,_,?a)) {
ret a;
}
case (ast.expr_bind(_,_,?a)) {
ret a;
}
case (ast.expr_binary(_,_,_,?a)) {
ret a;
}
case (ast.expr_unary(_,_,?a)) {
ret a;
}
case (ast.expr_lit(_,?a)) {
ret a;
}
case (ast.expr_cast(_,_,?a)) {
ret a;
}
case (ast.expr_if(_,_,_,?a)) {
ret a;
}
case (ast.expr_while(_,_,?a)) {
ret a;
}
case (ast.expr_for(_,_,_,?a)) {
ret a;
}
case (ast.expr_for_each(_,_,_,?a)) {
ret a;
}
case (ast.expr_do_while(_,_,?a)) {
ret a;
}
case (ast.expr_alt(_,_,?a)) {
ret a;
}
case (ast.expr_block(_,?a)) {
ret a;
}
case (ast.expr_assign(_,_,?a)) {
ret a;
}
case (ast.expr_assign_op(_,_,_,?a)) {
ret a;
}
case (ast.expr_send(_,_,?a)) {
ret a;
}
case (ast.expr_recv(_,_,?a)) {
ret a;
}
case (ast.expr_field(_,_,?a)) {
ret a;
}
case (ast.expr_index(_,_,?a)) {
ret a;
}
case (ast.expr_path(_,_,?a)) {
ret a;
}
case (ast.expr_ext(_,_,_,_,?a)) {
ret a;
}
case (ast.expr_fail(?a)) {
ret a;
}
case (ast.expr_ret(_,?a)) {
ret a;
}
case (ast.expr_put(_,?a)) {
ret a;
}
case (ast.expr_be(_,?a)) {
ret a;
}
case (ast.expr_log(_,_,?a)) {
ret a;
}
case (ast.expr_check_expr(_,?a)) {
ret a;
}
case (ast.expr_port(?a)) {
ret a;
}
case (ast.expr_chan(_,?a)) {
ret a;
}
case (expr_break(?a)) {
ret a;
}
case (expr_cont(?a)) {
ret a;
}
case (expr_self_method(_, ?a)) {
ret a;
}
}
}
fn ann_to_ts_ann(ann a, uint nv) -> ts_ann { fn ann_to_ts_ann(ann a, uint nv) -> ts_ann {
alt (a) { alt (a) {
case (ann_none) { ret empty_ann(nv); } case (ann_none) { ret empty_ann(nv); }
@ -532,7 +422,7 @@ fn ann_to_ts_ann_fail_more(ann a) -> @ts_ann {
fail; fail;
} }
case (ann_type(_,_,?t)) { case (ann_type(_,_,?t)) {
check (! is_none[@ts_ann](t)); assert (! is_none[@ts_ann](t));
ret get[@ts_ann](t); ret get[@ts_ann](t);
} }
} }
@ -557,7 +447,7 @@ fn stmt_to_ann(&stmt s) -> option.t[@ts_ann] {
} }
/* fails if e has no annotation */ /* fails if e has no annotation */
fn expr_states(&expr e) -> pre_and_post_state { fn expr_states(@expr e) -> pre_and_post_state {
alt (expr_ann(e)) { alt (expr_ann(e)) {
case (ann_none) { case (ann_none) {
log_err "expr_pp: the impossible happened (no annotation)"; log_err "expr_pp: the impossible happened (no annotation)";
@ -578,7 +468,7 @@ fn expr_states(&expr e) -> pre_and_post_state {
} }
/* fails if e has no annotation */ /* fails if e has no annotation */
fn expr_pp(&expr e) -> pre_and_post { fn expr_pp(@expr e) -> pre_and_post {
alt (expr_ann(e)) { alt (expr_ann(e)) {
case (ann_none) { case (ann_none) {
log_err "expr_pp: the impossible happened (no annotation)"; log_err "expr_pp: the impossible happened (no annotation)";
@ -664,19 +554,19 @@ fn stmt_states(&stmt s, uint nv) -> pre_and_post_state {
} }
fn expr_precond(&expr e) -> precond { fn expr_precond(@expr e) -> precond {
ret (expr_pp(e)).precondition; ret (expr_pp(e)).precondition;
} }
fn expr_postcond(&expr e) -> postcond { fn expr_postcond(@expr e) -> postcond {
ret (expr_pp(e)).postcondition; ret (expr_pp(e)).postcondition;
} }
fn expr_prestate(&expr e) -> prestate { fn expr_prestate(@expr e) -> prestate {
ret (expr_states(e)).prestate; ret (expr_states(e)).prestate;
} }
fn expr_poststate(&expr e) -> poststate { fn expr_poststate(@expr e) -> poststate {
ret (expr_states(e)).poststate; ret (expr_states(e)).poststate;
} }
@ -737,7 +627,7 @@ fn seq_preconds(fn_info enclosing, vec[pre_and_post] pps) -> precond {
if (sz >= 1u) { if (sz >= 1u) {
auto first = pps.(0); auto first = pps.(0);
check (pps_len(first) == num_vars); assert (pps_len(first) == num_vars);
let precond rest = seq_preconds(enclosing, let precond rest = seq_preconds(enclosing,
slice[pre_and_post](pps, 1u, sz)); slice[pre_and_post](pps, 1u, sz));
difference(rest, first.postcondition); difference(rest, first.postcondition);
@ -797,7 +687,7 @@ fn intersect_postconds_go(&postcond first, &vec[postcond] rest) -> postcond {
} }
fn intersect_postconds(&vec[postcond] pcs) -> postcond { fn intersect_postconds(&vec[postcond] pcs) -> postcond {
check (len[postcond](pcs) > 0u); assert (len[postcond](pcs) > 0u);
ret intersect_postconds_go(bitv.clone(pcs.(0)), pcs); ret intersect_postconds_go(bitv.clone(pcs.(0)), pcs);
} }
@ -826,7 +716,7 @@ fn find_pre_post_state_native_mod(&native_mod m) -> bool {
fn find_pre_post_obj(&fn_info_map fm, _obj o) -> () { fn find_pre_post_obj(&fn_info_map fm, _obj o) -> () {
fn do_a_method(fn_info_map fm, &@method m) -> () { fn do_a_method(fn_info_map fm, &@method m) -> () {
check(fm.contains_key(m.node.id)); assert (fm.contains_key(m.node.id));
find_pre_post_fn(fm, fm.get(m.node.id), m.node.meth); find_pre_post_fn(fm, fm.get(m.node.id), m.node.meth);
} }
auto f = bind do_a_method(fm,_); auto f = bind do_a_method(fm,_);
@ -836,7 +726,7 @@ fn find_pre_post_obj(&fn_info_map fm, _obj o) -> () {
fn find_pre_post_state_obj(fn_info_map fm, _obj o) -> bool { fn find_pre_post_state_obj(fn_info_map fm, _obj o) -> bool {
fn do_a_method(fn_info_map fm, &@method m) -> bool { fn do_a_method(fn_info_map fm, &@method m) -> bool {
check(fm.contains_key(m.node.id)); assert (fm.contains_key(m.node.id));
ret find_pre_post_state_fn(fm, fm.get(m.node.id), m.node.meth); ret find_pre_post_state_fn(fm, fm.get(m.node.id), m.node.meth);
} }
auto f = bind do_a_method(fm,_); auto f = bind do_a_method(fm,_);
@ -849,10 +739,10 @@ fn find_pre_post_state_obj(fn_info_map fm, _obj o) -> bool {
fn find_pre_post_item(fn_info_map fm, fn_info enclosing, &item i) -> () { fn find_pre_post_item(fn_info_map fm, fn_info enclosing, &item i) -> () {
alt (i.node) { alt (i.node) {
case (ast.item_const(?id, ?t, ?e, ?di, ?a)) { case (ast.item_const(?id, ?t, ?e, ?di, ?a)) {
find_pre_post_expr(fm, enclosing, *e); find_pre_post_expr(fm, enclosing, e);
} }
case (ast.item_fn(?id, ?f, ?ps, ?di, ?a)) { case (ast.item_fn(?id, ?f, ?ps, ?di, ?a)) {
check (fm.contains_key(di)); assert (fm.contains_key(di));
find_pre_post_fn(fm, fm.get(di), f); find_pre_post_fn(fm, fm.get(di), f);
} }
case (ast.item_mod(?id, ?m, ?di)) { case (ast.item_mod(?id, ?m, ?di)) {
@ -883,14 +773,14 @@ fn find_pre_post_exprs(&fn_info_map fm, &fn_info enclosing,
fn do_one(fn_info_map fm, fn_info enclosing, fn do_one(fn_info_map fm, fn_info enclosing,
&@expr e) -> () { &@expr e) -> () {
find_pre_post_expr(fm, enclosing, *e); find_pre_post_expr(fm, enclosing, e);
} }
auto f = bind do_one(fm, enclosing, _); auto f = bind do_one(fm, enclosing, _);
_vec.map[@expr, ()](f, args); _vec.map[@expr, ()](f, args);
fn get_pp(&@expr e) -> pre_and_post { fn get_pp(&@expr e) -> pre_and_post {
ret expr_pp(*e); ret expr_pp(e);
} }
auto g = get_pp; auto g = get_pp;
auto pps = _vec.map[@expr, pre_and_post](g, args); auto pps = _vec.map[@expr, pre_and_post](g, args);
@ -904,31 +794,31 @@ fn find_pre_post_exprs(&fn_info_map fm, &fn_info enclosing,
fn find_pre_post_loop(&fn_info_map fm, &fn_info enclosing, &@decl d, fn find_pre_post_loop(&fn_info_map fm, &fn_info enclosing, &@decl d,
&@expr index, &block body, &ann a) -> () { &@expr index, &block body, &ann a) -> () {
find_pre_post_expr(fm, enclosing, *index); find_pre_post_expr(fm, enclosing, index);
find_pre_post_block(fm, enclosing, body); find_pre_post_block(fm, enclosing, body);
auto loop_precond = declare_var(enclosing, decl_lhs(d), auto loop_precond = declare_var(enclosing, decl_lhs(d),
seq_preconds(enclosing, vec(expr_pp(*index), seq_preconds(enclosing, vec(expr_pp(index),
block_pp(body)))); block_pp(body))));
auto loop_postcond = intersect_postconds auto loop_postcond = intersect_postconds
(vec(expr_postcond(*index), block_postcond(body))); (vec(expr_postcond(index), block_postcond(body)));
set_pre_and_post(a, rec(precondition=loop_precond, set_pre_and_post(a, rec(precondition=loop_precond,
postcondition=loop_postcond)); postcondition=loop_postcond));
} }
/* Fills in annotations as a side effect. Does not rebuild the expr */ /* Fills in annotations as a side effect. Does not rebuild the expr */
fn find_pre_post_expr(&fn_info_map fm, &fn_info enclosing, &expr e) -> () { fn find_pre_post_expr(&fn_info_map fm, &fn_info enclosing, @expr e) -> () {
auto num_local_vars = num_locals(enclosing); auto num_local_vars = num_locals(enclosing);
fn do_rand_(fn_info_map fm, fn_info enclosing, &@expr e) -> () { fn do_rand_(fn_info_map fm, fn_info enclosing, &@expr e) -> () {
find_pre_post_expr(fm, enclosing, *e); find_pre_post_expr(fm, enclosing, e);
} }
fn pp_one(&@expr e) -> pre_and_post { fn pp_one(&@expr e) -> pre_and_post {
ret expr_pp(*e); ret expr_pp(e);
} }
log("find_pre_post_expr (num_locals =" + log("find_pre_post_expr (num_locals =" +
uistr(num_local_vars) + "):"); uistr(num_local_vars) + "):");
log_expr(e); log_expr(*e);
alt (e.node) { alt (e.node) {
case (expr_call(?operator, ?operands, ?a)) { case (expr_call(?operator, ?operands, ?a)) {
@ -974,18 +864,18 @@ fn find_pre_post_expr(&fn_info_map fm, &fn_info enclosing, &expr e) -> () {
set_pre_and_post(a, empty_pre_post(num_local_vars)); set_pre_and_post(a, empty_pre_post(num_local_vars));
} }
case(expr_log(_, ?arg, ?a)) { case(expr_log(_, ?arg, ?a)) {
find_pre_post_expr(fm, enclosing, *arg); find_pre_post_expr(fm, enclosing, arg);
set_pre_and_post(a, expr_pp(*arg)); set_pre_and_post(a, expr_pp(arg));
} }
case (expr_chan(?arg, ?a)) { case (expr_chan(?arg, ?a)) {
find_pre_post_expr(fm, enclosing, *arg); find_pre_post_expr(fm, enclosing, arg);
set_pre_and_post(a, expr_pp(*arg)); set_pre_and_post(a, expr_pp(arg));
} }
case(expr_put(?opt, ?a)) { case(expr_put(?opt, ?a)) {
alt (opt) { alt (opt) {
case (some[@expr](?arg)) { case (some[@expr](?arg)) {
find_pre_post_expr(fm, enclosing, *arg); find_pre_post_expr(fm, enclosing, arg);
set_pre_and_post(a, expr_pp(*arg)); set_pre_and_post(a, expr_pp(arg));
} }
case (none[@expr]) { case (none[@expr]) {
set_pre_and_post(a, empty_pre_post(num_local_vars)); set_pre_and_post(a, empty_pre_post(num_local_vars));
@ -1004,10 +894,10 @@ fn find_pre_post_expr(&fn_info_map fm, &fn_info enclosing, &expr e) -> () {
case (expr_assign(?lhs, ?rhs, ?a)) { case (expr_assign(?lhs, ?rhs, ?a)) {
alt (lhs.node) { alt (lhs.node) {
case (expr_path(?p, some[def](def_local(?d_id)), ?a_lhs)) { case (expr_path(?p, some[def](def_local(?d_id)), ?a_lhs)) {
find_pre_post_expr(fm, enclosing, *rhs); find_pre_post_expr(fm, enclosing, rhs);
set_pre_and_post(a, expr_pp(*rhs)); set_pre_and_post(a, expr_pp(rhs));
log("gen:"); log("gen:");
log_expr(e); log_expr(*e);
gen(enclosing, a, d_id); gen(enclosing, a, d_id);
} }
case (_) { case (_) {
@ -1020,10 +910,10 @@ fn find_pre_post_expr(&fn_info_map fm, &fn_info enclosing, &expr e) -> () {
case (expr_recv(?lhs, ?rhs, ?a)) { case (expr_recv(?lhs, ?rhs, ?a)) {
alt (lhs.node) { alt (lhs.node) {
case (expr_path(?p, some[def](def_local(?d_id)), ?a_lhs)) { case (expr_path(?p, some[def](def_local(?d_id)), ?a_lhs)) {
find_pre_post_expr(fm, enclosing, *rhs); find_pre_post_expr(fm, enclosing, rhs);
set_pre_and_post(a, expr_pp(*rhs)); set_pre_and_post(a, expr_pp(rhs));
log("gen:"); log("gen:");
log_expr(e); log_expr(*e);
gen(enclosing, a, d_id); gen(enclosing, a, d_id);
} }
case (_) { case (_) {
@ -1049,45 +939,45 @@ fn find_pre_post_expr(&fn_info_map fm, &fn_info enclosing, &expr e) -> () {
postcondition=false_postcond(num_local_vars))); postcondition=false_postcond(num_local_vars)));
} }
case (some[@expr](?ret_val)) { case (some[@expr](?ret_val)) {
find_pre_post_expr(fm, enclosing, *ret_val); find_pre_post_expr(fm, enclosing, ret_val);
let pre_and_post pp = let pre_and_post pp =
rec(precondition=expr_precond(*ret_val), rec(precondition=expr_precond(ret_val),
postcondition=false_postcond(num_local_vars)); postcondition=false_postcond(num_local_vars));
set_pre_and_post(a, pp); set_pre_and_post(a, pp);
} }
} }
} }
case (expr_be(?e, ?a)) { case (expr_be(?e, ?a)) {
find_pre_post_expr(fm, enclosing, *e); find_pre_post_expr(fm, enclosing, e);
set_pre_and_post(a, rec(precondition=expr_prestate(*e), set_pre_and_post(a, rec(precondition=expr_prestate(e),
postcondition=false_postcond(num_local_vars))); postcondition=false_postcond(num_local_vars)));
} }
case (expr_if(?antec, ?conseq, ?maybe_alt, ?a)) { case (expr_if(?antec, ?conseq, ?maybe_alt, ?a)) {
find_pre_post_expr(fm, enclosing, *antec); find_pre_post_expr(fm, enclosing, antec);
find_pre_post_block(fm, enclosing, conseq); find_pre_post_block(fm, enclosing, conseq);
alt (maybe_alt) { alt (maybe_alt) {
case (none[@expr]) { case (none[@expr]) {
auto precond_res = seq_preconds(enclosing, auto precond_res = seq_preconds(enclosing,
vec(expr_pp(*antec), vec(expr_pp(antec),
block_pp(conseq))); block_pp(conseq)));
set_pre_and_post(a, rec(precondition=precond_res, set_pre_and_post(a, rec(precondition=precond_res,
postcondition= postcondition=
expr_poststate(*antec))); expr_poststate(antec)));
} }
case (some[@expr](?altern)) { case (some[@expr](?altern)) {
find_pre_post_expr(fm, enclosing, *altern); find_pre_post_expr(fm, enclosing, altern);
auto precond_true_case = auto precond_true_case =
seq_preconds(enclosing, seq_preconds(enclosing,
vec(expr_pp(*antec), block_pp(conseq))); vec(expr_pp(antec), block_pp(conseq)));
auto postcond_true_case = union_postconds auto postcond_true_case = union_postconds
(num_local_vars, (num_local_vars,
vec(expr_postcond(*antec), block_postcond(conseq))); vec(expr_postcond(antec), block_postcond(conseq)));
auto precond_false_case = seq_preconds auto precond_false_case = seq_preconds
(enclosing, (enclosing,
vec(expr_pp(*antec), expr_pp(*altern))); vec(expr_pp(antec), expr_pp(altern)));
auto postcond_false_case = union_postconds auto postcond_false_case = union_postconds
(num_local_vars, (num_local_vars,
vec(expr_postcond(*antec), expr_postcond(*altern))); vec(expr_postcond(antec), expr_postcond(altern)));
auto precond_res = union_postconds auto precond_res = union_postconds
(num_local_vars, (num_local_vars,
vec(precond_true_case, precond_false_case)); vec(precond_true_case, precond_false_case));
@ -1107,31 +997,31 @@ fn find_pre_post_expr(&fn_info_map fm, &fn_info enclosing, &expr e) -> () {
find_pre_post_exprs(fm, enclosing, vec(l, r), a); find_pre_post_exprs(fm, enclosing, vec(l, r), a);
} }
case (expr_unary(_,?operand,?a)) { case (expr_unary(_,?operand,?a)) {
find_pre_post_expr(fm, enclosing, *operand); find_pre_post_expr(fm, enclosing, operand);
set_pre_and_post(a, expr_pp(*operand)); set_pre_and_post(a, expr_pp(operand));
} }
case (expr_cast(?operand, _, ?a)) { case (expr_cast(?operand, _, ?a)) {
find_pre_post_expr(fm, enclosing, *operand); find_pre_post_expr(fm, enclosing, operand);
set_pre_and_post(a, expr_pp(*operand)); set_pre_and_post(a, expr_pp(operand));
} }
case (expr_while(?test, ?body, ?a)) { case (expr_while(?test, ?body, ?a)) {
find_pre_post_expr(fm, enclosing, *test); find_pre_post_expr(fm, enclosing, test);
find_pre_post_block(fm, enclosing, body); find_pre_post_block(fm, enclosing, body);
set_pre_and_post(a, set_pre_and_post(a,
rec(precondition= rec(precondition=
seq_preconds(enclosing, seq_preconds(enclosing,
vec(expr_pp(*test), vec(expr_pp(test),
block_pp(body))), block_pp(body))),
postcondition= postcondition=
intersect_postconds(vec(expr_postcond(*test), intersect_postconds(vec(expr_postcond(test),
block_postcond(body))))); block_postcond(body)))));
} }
case (expr_do_while(?body, ?test, ?a)) { case (expr_do_while(?body, ?test, ?a)) {
find_pre_post_block(fm, enclosing, body); find_pre_post_block(fm, enclosing, body);
find_pre_post_expr(fm, enclosing, *test); find_pre_post_expr(fm, enclosing, test);
auto loop_postcond = union_postconds(num_local_vars, auto loop_postcond = union_postconds(num_local_vars,
vec(block_postcond(body), expr_postcond(*test))); vec(block_postcond(body), expr_postcond(test)));
/* conservative approximination: if the body /* conservative approximination: if the body
could break or cont, the test may never be executed */ could break or cont, the test may never be executed */
if (has_nonlocal_exits(body)) { if (has_nonlocal_exits(body)) {
@ -1141,7 +1031,7 @@ fn find_pre_post_expr(&fn_info_map fm, &fn_info enclosing, &expr e) -> () {
set_pre_and_post(a, set_pre_and_post(a,
rec(precondition=seq_preconds(enclosing, rec(precondition=seq_preconds(enclosing,
vec(block_pp(body), vec(block_pp(body),
expr_pp(*test))), expr_pp(test))),
postcondition=loop_postcond)); postcondition=loop_postcond));
} }
case (expr_for(?d, ?index, ?body, ?a)) { case (expr_for(?d, ?index, ?body, ?a)) {
@ -1154,7 +1044,7 @@ fn find_pre_post_expr(&fn_info_map fm, &fn_info enclosing, &expr e) -> () {
find_pre_post_exprs(fm, enclosing, vec(e, sub), a); find_pre_post_exprs(fm, enclosing, vec(e, sub), a);
} }
case (expr_alt(?e, ?alts, ?a)) { case (expr_alt(?e, ?alts, ?a)) {
find_pre_post_expr(fm, enclosing, *e); find_pre_post_expr(fm, enclosing, e);
fn do_an_alt(fn_info_map fm, fn_info enc, &arm an_alt) fn do_an_alt(fn_info_map fm, fn_info enc, &arm an_alt)
-> pre_and_post { -> pre_and_post {
find_pre_post_block(fm, enc, an_alt.block); find_pre_post_block(fm, enc, an_alt.block);
@ -1170,7 +1060,7 @@ fn find_pre_post_expr(&fn_info_map fm, &fn_info enclosing, &expr e) -> () {
intersect(pp.postcondition, next.postcondition); intersect(pp.postcondition, next.postcondition);
ret pp; ret pp;
} }
auto antec_pp = pp_clone(expr_pp(*e)); auto antec_pp = pp_clone(expr_pp(e));
auto e_pp = rec(precondition=empty_prestate(num_local_vars), auto e_pp = rec(precondition=empty_prestate(num_local_vars),
postcondition=false_postcond(num_local_vars)); postcondition=false_postcond(num_local_vars));
auto g = bind combine_pp(antec_pp, enclosing, _, _); auto g = bind combine_pp(antec_pp, enclosing, _, _);
@ -1181,8 +1071,8 @@ fn find_pre_post_expr(&fn_info_map fm, &fn_info enclosing, &expr e) -> () {
set_pre_and_post(a, alts_overall_pp); set_pre_and_post(a, alts_overall_pp);
} }
case (expr_field(?operator, _, ?a)) { case (expr_field(?operator, _, ?a)) {
find_pre_post_expr(fm, enclosing, *operator); find_pre_post_expr(fm, enclosing, operator);
set_pre_and_post(a, expr_pp(*operator)); set_pre_and_post(a, expr_pp(operator));
} }
case (expr_fail(?a)) { case (expr_fail(?a)) {
set_pre_and_post(a, set_pre_and_post(a,
@ -1191,10 +1081,14 @@ fn find_pre_post_expr(&fn_info_map fm, &fn_info enclosing, &expr e) -> () {
rec(precondition=empty_prestate(num_local_vars), rec(precondition=empty_prestate(num_local_vars),
postcondition=false_postcond(num_local_vars))); postcondition=false_postcond(num_local_vars)));
} }
case (expr_check_expr(?p, ?a)) { case (expr_assert(?p, ?a)) {
find_pre_post_expr(fm, enclosing, p);
set_pre_and_post(a, expr_pp(p));
}
case (expr_check(?p, ?a)) {
/* will need to change when we support arbitrary predicates... */ /* will need to change when we support arbitrary predicates... */
find_pre_post_expr(fm, enclosing, *p); find_pre_post_expr(fm, enclosing, p);
set_pre_and_post(a, expr_pp(*p)); set_pre_and_post(a, expr_pp(p));
} }
case(expr_bind(?operator, ?maybe_args, ?a)) { case(expr_bind(?operator, ?maybe_args, ?a)) {
auto args = _vec.cat_options[@expr](maybe_args); auto args = _vec.cat_options[@expr](maybe_args);
@ -1211,21 +1105,21 @@ fn find_pre_post_expr(&fn_info_map fm, &fn_info enclosing, &expr e) -> () {
set_pre_and_post(a, empty_pre_post(num_local_vars)); set_pre_and_post(a, empty_pre_post(num_local_vars));
} }
case (expr_ext(_, _, _, ?expanded, ?a)) { case (expr_ext(_, _, _, ?expanded, ?a)) {
find_pre_post_expr(fm, enclosing, *expanded); find_pre_post_expr(fm, enclosing, expanded);
set_pre_and_post(a, expr_pp(*expanded)); set_pre_and_post(a, expr_pp(expanded));
} }
} }
} }
fn gen(&fn_info enclosing, &ann a, def_id id) -> bool { fn gen(&fn_info enclosing, &ann a, def_id id) -> bool {
check(enclosing.contains_key(id)); assert (enclosing.contains_key(id));
let uint i = (enclosing.get(id))._0; let uint i = (enclosing.get(id))._0;
ret set_in_postcond(i, (ann_to_ts_ann_fail_more(a)).conditions); ret set_in_postcond(i, (ann_to_ts_ann_fail_more(a)).conditions);
} }
fn declare_var(&fn_info enclosing, def_id id, prestate pre) fn declare_var(&fn_info enclosing, def_id id, prestate pre)
-> prestate { -> prestate {
check(enclosing.contains_key(id)); assert (enclosing.contains_key(id));
let uint i = (enclosing.get(id))._0; let uint i = (enclosing.get(id))._0;
auto res = clone(pre); auto res = clone(pre);
relax_prestate(i, res); relax_prestate(i, res);
@ -1233,7 +1127,7 @@ fn declare_var(&fn_info enclosing, def_id id, prestate pre)
} }
fn gen_poststate(&fn_info enclosing, &ann a, def_id id) -> bool { fn gen_poststate(&fn_info enclosing, &ann a, def_id id) -> bool {
check(enclosing.contains_key(id)); assert (enclosing.contains_key(id));
let uint i = (enclosing.get(id))._0; let uint i = (enclosing.get(id))._0;
ret set_in_poststate(i, (ann_to_ts_ann_fail_more(a)).states); ret set_in_poststate(i, (ann_to_ts_ann_fail_more(a)).states);
@ -1251,8 +1145,8 @@ fn find_pre_post_stmt(fn_info_map fm, &fn_info enclosing, &ast.stmt s)
case(ast.decl_local(?alocal)) { case(ast.decl_local(?alocal)) {
alt(alocal.init) { alt(alocal.init) {
case(some[ast.initializer](?an_init)) { case(some[ast.initializer](?an_init)) {
find_pre_post_expr(fm, enclosing, *an_init.expr); find_pre_post_expr(fm, enclosing, an_init.expr);
auto rhs_pp = expr_pp(*an_init.expr); auto rhs_pp = expr_pp(an_init.expr);
set_pre_and_post(alocal.ann, rhs_pp); set_pre_and_post(alocal.ann, rhs_pp);
/* Inherit ann from initializer, and add var being /* Inherit ann from initializer, and add var being
@ -1281,8 +1175,8 @@ fn find_pre_post_stmt(fn_info_map fm, &fn_info enclosing, &ast.stmt s)
} }
} }
case(stmt_expr(?e,?a)) { case(stmt_expr(?e,?a)) {
find_pre_post_expr(fm, enclosing, *e); find_pre_post_expr(fm, enclosing, e);
set_pre_and_post(a, expr_pp(*e)); set_pre_and_post(a, expr_pp(e));
} }
} }
} }
@ -1318,7 +1212,7 @@ fn find_pre_post_block(&fn_info_map fm, &fn_info enclosing, block b)
_vec.map[@stmt, ()](do_one, b.node.stmts); _vec.map[@stmt, ()](do_one, b.node.stmts);
fn do_inner_(fn_info_map fm, fn_info i, &@expr e) -> () { fn do_inner_(fn_info_map fm, fn_info i, &@expr e) -> () {
find_pre_post_expr(fm, i, *e); find_pre_post_expr(fm, i, e);
} }
auto do_inner = bind do_inner_(fm, enclosing, _); auto do_inner = bind do_inner_(fm, enclosing, _);
option.map[@expr, ()](do_inner, b.node.expr); option.map[@expr, ()](do_inner, b.node.expr);
@ -1331,7 +1225,7 @@ fn find_pre_post_block(&fn_info_map fm, &fn_info enclosing, block b)
auto f = get_pp_stmt; auto f = get_pp_stmt;
pps += _vec.map[@stmt, pre_and_post](f, b.node.stmts); pps += _vec.map[@stmt, pre_and_post](f, b.node.stmts);
fn get_pp_expr(&@expr e) -> pre_and_post { fn get_pp_expr(&@expr e) -> pre_and_post {
ret expr_pp(*e); ret expr_pp(e);
} }
auto g = get_pp_expr; auto g = get_pp_expr;
plus_option[pre_and_post](pps, plus_option[pre_and_post](pps,
@ -1363,7 +1257,7 @@ fn check_item_fn(&fn_info_map fm, &span sp, ident i, &ast._fn f,
log("check_item_fn:"); log("check_item_fn:");
log_fn(f, i, ty_params); log_fn(f, i, ty_params);
check (fm.contains_key(id)); assert (fm.contains_key(id));
find_pre_post_fn(fm, fm.get(id), f); find_pre_post_fn(fm, fm.get(id), f);
ret @respan(sp, ast.item_fn(i, f, ty_params, id, a)); ret @respan(sp, ast.item_fn(i, f, ty_params, id, a));
@ -1377,7 +1271,7 @@ fn find_pre_post_state_item(fn_info_map fm, fn_info enclosing, @item i)
empty_prestate(num_locals(enclosing)), e); empty_prestate(num_locals(enclosing)), e);
} }
case (ast.item_fn(?id, ?f, ?ps, ?di, ?a)) { case (ast.item_fn(?id, ?f, ?ps, ?di, ?a)) {
check (fm.contains_key(di)); assert (fm.contains_key(di));
ret find_pre_post_state_fn(fm, fm.get(di), f); ret find_pre_post_state_fn(fm, fm.get(di), f);
} }
case (ast.item_mod(?id, ?m, ?di)) { case (ast.item_mod(?id, ?m, ?di)) {
@ -1401,7 +1295,7 @@ fn find_pre_post_state_item(fn_info_map fm, fn_info enclosing, @item i)
fn set_prestate_ann(@ann a, prestate pre) -> bool { fn set_prestate_ann(@ann a, prestate pre) -> bool {
alt (*a) { alt (*a) {
case (ann_type(_,_,?ts_a)) { case (ann_type(_,_,?ts_a)) {
check (! is_none[@ts_ann](ts_a)); assert (! is_none[@ts_ann](ts_a));
ret set_prestate(get[@ts_ann](ts_a), pre); ret set_prestate(get[@ts_ann](ts_a), pre);
} }
case (ann_none) { case (ann_none) {
@ -1415,8 +1309,8 @@ fn set_prestate_ann(@ann a, prestate pre) -> bool {
fn extend_prestate_ann(ann a, prestate pre) -> bool { fn extend_prestate_ann(ann a, prestate pre) -> bool {
alt (a) { alt (a) {
case (ann_type(_,_,?ts_a)) { case (ann_type(_,_,?ts_a)) {
check (! is_none[@ts_ann](ts_a)); assert (! is_none[@ts_ann](ts_a));
ret extend_prestate((*get[@ts_ann](ts_a)).states.prestate, pre); ret extend_prestate((get[@ts_ann](ts_a)).states.prestate, pre);
} }
case (ann_none) { case (ann_none) {
log("set_prestate_ann: expected an ann_type here"); log("set_prestate_ann: expected an ann_type here");
@ -1428,8 +1322,8 @@ fn extend_prestate_ann(ann a, prestate pre) -> bool {
fn set_poststate_ann(ann a, poststate post) -> bool { fn set_poststate_ann(ann a, poststate post) -> bool {
alt (a) { alt (a) {
case (ann_type(_,_,?ts_a)) { case (ann_type(_,_,?ts_a)) {
check (! is_none[@ts_ann](ts_a)); assert (! is_none[@ts_ann](ts_a));
ret set_poststate(*get[@ts_ann](ts_a), post); ret set_poststate(get[@ts_ann](ts_a), post);
} }
case (ann_none) { case (ann_none) {
log("set_poststate_ann: expected an ann_type here"); log("set_poststate_ann: expected an ann_type here");
@ -1441,7 +1335,7 @@ fn set_poststate_ann(ann a, poststate post) -> bool {
fn extend_poststate_ann(ann a, poststate post) -> bool { fn extend_poststate_ann(ann a, poststate post) -> bool {
alt (a) { alt (a) {
case (ann_type(_,_,?ts_a)) { case (ann_type(_,_,?ts_a)) {
check (! is_none[@ts_ann](ts_a)); assert (! is_none[@ts_ann](ts_a));
ret extend_poststate((*get[@ts_ann](ts_a)).states.poststate, post); ret extend_poststate((*get[@ts_ann](ts_a)).states.poststate, post);
} }
case (ann_none) { case (ann_none) {
@ -1454,7 +1348,7 @@ fn extend_poststate_ann(ann a, poststate post) -> bool {
fn set_pre_and_post(&ann a, pre_and_post pp) -> () { fn set_pre_and_post(&ann a, pre_and_post pp) -> () {
alt (a) { alt (a) {
case (ann_type(_,_,?ts_a)) { case (ann_type(_,_,?ts_a)) {
check (! is_none[@ts_ann](ts_a)); assert (! is_none[@ts_ann](ts_a));
auto t = *get[@ts_ann](ts_a); auto t = *get[@ts_ann](ts_a);
/* log("set_pre_and_post, old ="); /* log("set_pre_and_post, old =");
log_pp(t.conditions); log_pp(t.conditions);
@ -1478,7 +1372,7 @@ fn seq_states(&fn_info_map fm, &fn_info enclosing,
for (@expr e in exprs) { for (@expr e in exprs) {
changed = find_pre_post_state_expr(fm, enclosing, post, e) || changed; changed = find_pre_post_state_expr(fm, enclosing, post, e) || changed;
post = expr_poststate(*e); post = expr_poststate(e);
} }
ret tup(changed, post); ret tup(changed, post);
@ -1513,8 +1407,8 @@ fn find_pre_post_state_loop(fn_info_map fm, fn_info enclosing,
/* in general, would need the intersection of /* in general, would need the intersection of
(poststate of index, poststate of body) */ (poststate of index, poststate of body) */
changed = find_pre_post_state_block(fm, enclosing, changed = find_pre_post_state_block(fm, enclosing,
expr_poststate(*index), body) || changed; expr_poststate(index), body) || changed;
auto res_p = intersect_postconds(vec(expr_poststate(*index), auto res_p = intersect_postconds(vec(expr_poststate(index),
block_poststate(body))); block_poststate(body)));
changed = extend_poststate_ann(a, res_p) || changed; changed = extend_poststate_ann(a, res_p) || changed;
@ -1522,7 +1416,7 @@ fn find_pre_post_state_loop(fn_info_map fm, fn_info enclosing,
} }
fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing, fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
&prestate pres, &@expr e) -> bool { &prestate pres, @expr e) -> bool {
auto changed = false; auto changed = false;
auto num_local_vars = num_locals(enclosing); auto num_local_vars = num_locals(enclosing);
@ -1540,20 +1434,20 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
|| changed; || changed;
/* rands go left-to-right */ /* rands go left-to-right */
ret(find_pre_post_state_exprs(fm, enclosing, ret(find_pre_post_state_exprs(fm, enclosing,
expr_poststate(*operator), a, operands) expr_poststate(operator), a, operands)
|| changed); || changed);
} }
case (expr_spawn(_, _, ?operator, ?operands, ?a)) { case (expr_spawn(_, _, ?operator, ?operands, ?a)) {
changed = find_pre_post_state_expr(fm, enclosing, pres, operator); changed = find_pre_post_state_expr(fm, enclosing, pres, operator);
ret(find_pre_post_state_exprs(fm, enclosing, ret(find_pre_post_state_exprs(fm, enclosing,
expr_poststate(*operator), a, operands) expr_poststate(operator), a, operands)
|| changed); || changed);
} }
case (expr_bind(?operator, ?maybe_args, ?a)) { case (expr_bind(?operator, ?maybe_args, ?a)) {
changed = find_pre_post_state_expr(fm, enclosing, pres, operator) changed = find_pre_post_state_expr(fm, enclosing, pres, operator)
|| changed; || changed;
ret (find_pre_post_state_exprs(fm, enclosing, ret (find_pre_post_state_exprs(fm, enclosing,
expr_poststate(*operator), a, cat_options[@expr](maybe_args)) expr_poststate(operator), a, cat_options[@expr](maybe_args))
|| changed); || changed);
} }
case (expr_path(_,_,?a)) { case (expr_path(_,_,?a)) {
@ -1563,19 +1457,19 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
/* factor out the "one exp" pattern */ /* factor out the "one exp" pattern */
changed = find_pre_post_state_expr(fm, enclosing, pres, e); changed = find_pre_post_state_expr(fm, enclosing, pres, e);
changed = extend_prestate_ann(a, pres) || changed; changed = extend_prestate_ann(a, pres) || changed;
changed = extend_poststate_ann(a, expr_poststate(*e)) || changed; changed = extend_poststate_ann(a, expr_poststate(e)) || changed;
ret changed; ret changed;
} }
case (expr_chan(?e, ?a)) { case (expr_chan(?e, ?a)) {
changed = find_pre_post_state_expr(fm, enclosing, pres, e); changed = find_pre_post_state_expr(fm, enclosing, pres, e);
changed = extend_prestate_ann(a, pres) || changed; changed = extend_prestate_ann(a, pres) || changed;
changed = extend_poststate_ann(a, expr_poststate(*e)) || changed; changed = extend_poststate_ann(a, expr_poststate(e)) || changed;
ret changed; ret changed;
} }
case (expr_ext(_, _, _, ?expanded, ?a)) { case (expr_ext(_, _, _, ?expanded, ?a)) {
changed = find_pre_post_state_expr(fm, enclosing, pres, expanded); changed = find_pre_post_state_expr(fm, enclosing, pres, expanded);
changed = extend_prestate_ann(a, pres) || changed; changed = extend_prestate_ann(a, pres) || changed;
changed = extend_poststate_ann(a, expr_poststate(*expanded)) changed = extend_poststate_ann(a, expr_poststate(expanded))
|| changed; || changed;
ret changed; ret changed;
} }
@ -1584,7 +1478,7 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
case (some[@expr](?arg)) { case (some[@expr](?arg)) {
changed = find_pre_post_state_expr(fm, enclosing, pres, arg); changed = find_pre_post_state_expr(fm, enclosing, pres, arg);
changed = extend_prestate_ann(a, pres) || changed; changed = extend_prestate_ann(a, pres) || changed;
changed = extend_poststate_ann(a, expr_poststate(*arg)) changed = extend_poststate_ann(a, expr_poststate(arg))
|| changed; || changed;
ret changed; ret changed;
} }
@ -1611,7 +1505,7 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
case (some[@expr](?base)) { case (some[@expr](?base)) {
changed = find_pre_post_state_expr(fm, enclosing, pres, base) changed = find_pre_post_state_expr(fm, enclosing, pres, base)
|| changed; || changed;
changed = extend_poststate_ann(a, expr_poststate(*base)) changed = extend_poststate_ann(a, expr_poststate(base))
|| changed; || changed;
} }
} }
@ -1626,7 +1520,7 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
changed = pure_exp(a_lhs, pres) || changed; changed = pure_exp(a_lhs, pres) || changed;
changed = find_pre_post_state_expr(fm, enclosing, pres, rhs) changed = find_pre_post_state_expr(fm, enclosing, pres, rhs)
|| changed; || changed;
changed = extend_poststate_ann(a, expr_poststate(*rhs)) changed = extend_poststate_ann(a, expr_poststate(rhs))
|| changed; || changed;
changed = gen_poststate(enclosing, a, d_id) || changed; changed = gen_poststate(enclosing, a, d_id) || changed;
} }
@ -1635,8 +1529,8 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
changed = find_pre_post_state_expr(fm, enclosing, pres, lhs) changed = find_pre_post_state_expr(fm, enclosing, pres, lhs)
|| changed; || changed;
changed = find_pre_post_state_expr(fm, enclosing, changed = find_pre_post_state_expr(fm, enclosing,
expr_poststate(*lhs), rhs) || changed; expr_poststate(lhs), rhs) || changed;
changed = extend_poststate_ann(a, expr_poststate(*rhs)) changed = extend_poststate_ann(a, expr_poststate(rhs))
|| changed; || changed;
} }
} }
@ -1651,7 +1545,7 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
changed = pure_exp(a_lhs, pres) || changed; changed = pure_exp(a_lhs, pres) || changed;
changed = find_pre_post_state_expr(fm, enclosing, pres, rhs) changed = find_pre_post_state_expr(fm, enclosing, pres, rhs)
|| changed; || changed;
changed = extend_poststate_ann(a, expr_poststate(*rhs)) changed = extend_poststate_ann(a, expr_poststate(rhs))
|| changed; || changed;
changed = gen_poststate(enclosing, a, d_id) || changed; changed = gen_poststate(enclosing, a, d_id) || changed;
} }
@ -1660,8 +1554,8 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
changed = find_pre_post_state_expr(fm, enclosing, pres, lhs) changed = find_pre_post_state_expr(fm, enclosing, pres, lhs)
|| changed; || changed;
changed = find_pre_post_state_expr(fm, enclosing, changed = find_pre_post_state_expr(fm, enclosing,
expr_poststate(*lhs), rhs) || changed; expr_poststate(lhs), rhs) || changed;
changed = extend_poststate_ann(a, expr_poststate(*rhs)) changed = extend_poststate_ann(a, expr_poststate(rhs))
|| changed; || changed;
} }
} }
@ -1691,17 +1585,17 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
changed = find_pre_post_state_expr(fm, enclosing, pres, antec) changed = find_pre_post_state_expr(fm, enclosing, pres, antec)
|| changed; || changed;
changed = find_pre_post_state_block(fm, enclosing, changed = find_pre_post_state_block(fm, enclosing,
expr_poststate(*antec), conseq) || changed; expr_poststate(antec), conseq) || changed;
alt (maybe_alt) { alt (maybe_alt) {
case (none[@expr]) { case (none[@expr]) {
changed = extend_poststate_ann(a, expr_poststate(*antec)) changed = extend_poststate_ann(a, expr_poststate(antec))
|| changed; || changed;
} }
case (some[@expr](?altern)) { case (some[@expr](?altern)) {
changed = find_pre_post_state_expr(fm, enclosing, changed = find_pre_post_state_expr(fm, enclosing,
expr_poststate(*antec), altern) || changed; expr_poststate(antec), altern) || changed;
auto poststate_res = intersect_postconds auto poststate_res = intersect_postconds
(vec(block_poststate(conseq), expr_poststate(*altern))); (vec(block_poststate(conseq), expr_poststate(altern)));
changed = extend_poststate_ann(a, poststate_res) || changed; changed = extend_poststate_ann(a, poststate_res) || changed;
} }
} }
@ -1710,7 +1604,7 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
log("new prestate:"); log("new prestate:");
log_bitv(enclosing, pres); log_bitv(enclosing, pres);
log("new poststate:"); log("new poststate:");
log_bitv(enclosing, expr_poststate(*e)); log_bitv(enclosing, expr_poststate(e));
ret changed; ret changed;
} }
@ -1720,8 +1614,8 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
changed = find_pre_post_state_expr(fm, enclosing, pres, l) changed = find_pre_post_state_expr(fm, enclosing, pres, l)
|| changed; || changed;
changed = find_pre_post_state_expr(fm, changed = find_pre_post_state_expr(fm,
enclosing, expr_poststate(*l), r) || changed; enclosing, expr_poststate(l), r) || changed;
changed = extend_poststate_ann(a, expr_poststate(*r)) || changed; changed = extend_poststate_ann(a, expr_poststate(r)) || changed;
ret changed; ret changed;
} }
case (expr_send(?l, ?r, ?a)) { case (expr_send(?l, ?r, ?a)) {
@ -1729,8 +1623,8 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
changed = find_pre_post_state_expr(fm, enclosing, pres, l) changed = find_pre_post_state_expr(fm, enclosing, pres, l)
|| changed; || changed;
changed = find_pre_post_state_expr(fm, changed = find_pre_post_state_expr(fm,
enclosing, expr_poststate(*l), r) || changed; enclosing, expr_poststate(l), r) || changed;
changed = extend_poststate_ann(a, expr_poststate(*r)) || changed; changed = extend_poststate_ann(a, expr_poststate(r)) || changed;
ret changed; ret changed;
} }
case (expr_assign_op(?op, ?lhs, ?rhs, ?a)) { case (expr_assign_op(?op, ?lhs, ?rhs, ?a)) {
@ -1739,8 +1633,8 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
changed = find_pre_post_state_expr(fm, enclosing, pres, lhs) changed = find_pre_post_state_expr(fm, enclosing, pres, lhs)
|| changed; || changed;
changed = find_pre_post_state_expr(fm, changed = find_pre_post_state_expr(fm,
enclosing, expr_poststate(*lhs), rhs) || changed; enclosing, expr_poststate(lhs), rhs) || changed;
changed = extend_poststate_ann(a, expr_poststate(*rhs)) || changed; changed = extend_poststate_ann(a, expr_poststate(rhs)) || changed;
ret changed; ret changed;
} }
case (expr_while(?test, ?body, ?a)) { case (expr_while(?test, ?body, ?a)) {
@ -1756,9 +1650,9 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
changed = find_pre_post_state_expr(fm, enclosing, pres, test) changed = find_pre_post_state_expr(fm, enclosing, pres, test)
|| changed; || changed;
changed = find_pre_post_state_block(fm, changed = find_pre_post_state_block(fm,
enclosing, expr_poststate(*test), body) || changed; enclosing, expr_poststate(test), body) || changed;
changed = extend_poststate_ann(a, changed = extend_poststate_ann(a,
intersect_postconds(vec(expr_poststate(*test), intersect_postconds(vec(expr_poststate(test),
block_poststate(body)))) || changed; block_poststate(body)))) || changed;
ret changed; ret changed;
} }
@ -1777,7 +1671,7 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
changed = set_poststate_ann(a, pres) || changed; changed = set_poststate_ann(a, pres) || changed;
} }
else { else {
changed = extend_poststate_ann(a, expr_poststate(*test)) changed = extend_poststate_ann(a, expr_poststate(test))
|| changed; || changed;
} }
@ -1793,14 +1687,14 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
changed = extend_prestate_ann(a, pres) || changed; changed = extend_prestate_ann(a, pres) || changed;
changed = find_pre_post_state_expr(fm, enclosing, pres, e) || changed; changed = find_pre_post_state_expr(fm, enclosing, pres, e) || changed;
changed = find_pre_post_state_expr(fm, enclosing, changed = find_pre_post_state_expr(fm, enclosing,
expr_poststate(*e), sub) || changed; expr_poststate(e), sub) || changed;
changed = extend_poststate_ann(a, expr_poststate(*sub)); changed = extend_poststate_ann(a, expr_poststate(sub));
ret changed; ret changed;
} }
case (expr_alt(?e, ?alts, ?a)) { case (expr_alt(?e, ?alts, ?a)) {
changed = extend_prestate_ann(a, pres) || changed; changed = extend_prestate_ann(a, pres) || changed;
changed = find_pre_post_state_expr(fm, enclosing, pres, e) || changed; changed = find_pre_post_state_expr(fm, enclosing, pres, e) || changed;
auto e_post = expr_poststate(*e); auto e_post = expr_poststate(e);
auto a_post; auto a_post;
if (_vec.len[arm](alts) > 0u) { if (_vec.len[arm](alts) > 0u) {
a_post = false_postcond(num_local_vars); a_post = false_postcond(num_local_vars);
@ -1821,14 +1715,14 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
case (expr_field(?e,_,?a)) { case (expr_field(?e,_,?a)) {
changed = find_pre_post_state_expr(fm, enclosing, pres, e); changed = find_pre_post_state_expr(fm, enclosing, pres, e);
changed = extend_prestate_ann(a, pres) || changed; changed = extend_prestate_ann(a, pres) || changed;
changed = extend_poststate_ann(a, expr_poststate(*e)) || changed; changed = extend_poststate_ann(a, expr_poststate(e)) || changed;
ret changed; ret changed;
} }
case (expr_unary(_,?operand,?a)) { case (expr_unary(_,?operand,?a)) {
changed = find_pre_post_state_expr(fm, enclosing, pres, operand) changed = find_pre_post_state_expr(fm, enclosing, pres, operand)
|| changed; || changed;
changed = extend_prestate_ann(a, pres) || changed; changed = extend_prestate_ann(a, pres) || changed;
changed = extend_poststate_ann(a, expr_poststate(*operand)) changed = extend_poststate_ann(a, expr_poststate(operand))
|| changed; || changed;
ret changed; ret changed;
} }
@ -1836,7 +1730,7 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
changed = find_pre_post_state_expr(fm, enclosing, pres, operand) changed = find_pre_post_state_expr(fm, enclosing, pres, operand)
|| changed; || changed;
changed = extend_prestate_ann(a, pres) || changed; changed = extend_prestate_ann(a, pres) || changed;
changed = extend_poststate_ann(a, expr_poststate(*operand)) changed = extend_poststate_ann(a, expr_poststate(operand))
|| changed; || changed;
ret changed; ret changed;
} }
@ -1845,14 +1739,15 @@ fn find_pre_post_state_expr(&fn_info_map fm, &fn_info enclosing,
/* if execution continues after fail, then everything is true! woo! */ /* if execution continues after fail, then everything is true! woo! */
changed = set_poststate_ann(a, false_postcond(num_local_vars)) changed = set_poststate_ann(a, false_postcond(num_local_vars))
|| changed; || changed;
/* log_err("fail: poststate = ");
log_bitv(enclosing, expr_poststate(*e)); */
ret changed; ret changed;
} }
case (expr_check_expr(?p, ?a)) { case (expr_assert(?p, ?a)) {
ret pure_exp(a, pres);
}
case (expr_check(?p, ?a)) {
changed = extend_prestate_ann(a, pres) || changed; changed = extend_prestate_ann(a, pres) || changed;
changed = find_pre_post_state_expr(fm, enclosing, pres, p) || changed; changed = find_pre_post_state_expr(fm, enclosing, pres, p) || changed;
/* p is pure, so the poststate must be the same as the prestate */ /* FIXME: update the postcondition to reflect that p holds */
changed = extend_poststate_ann(a, pres) || changed; changed = extend_poststate_ann(a, pres) || changed;
ret changed; ret changed;
} }
@ -1875,7 +1770,7 @@ fn find_pre_post_state_stmt(&fn_info_map fm, &fn_info enclosing,
&prestate pres, @stmt s) -> bool { &prestate pres, @stmt s) -> bool {
auto changed = false; auto changed = false;
auto stmt_ann_ = stmt_to_ann(*s); auto stmt_ann_ = stmt_to_ann(*s);
check (!is_none[@ts_ann](stmt_ann_)); assert (!is_none[@ts_ann](stmt_ann_));
auto stmt_ann = *(get[@ts_ann](stmt_ann_)); auto stmt_ann = *(get[@ts_ann](stmt_ann_));
log("*At beginning: stmt = "); log("*At beginning: stmt = ");
log_stmt(*s); log_stmt(*s);
@ -1897,7 +1792,7 @@ fn find_pre_post_state_stmt(&fn_info_map fm, &fn_info enclosing,
changed = find_pre_post_state_expr changed = find_pre_post_state_expr
(fm, enclosing, pres, an_init.expr) || changed; (fm, enclosing, pres, an_init.expr) || changed;
changed = extend_poststate(stmt_ann.states.poststate, changed = extend_poststate(stmt_ann.states.poststate,
expr_poststate(*an_init.expr)) expr_poststate(an_init.expr))
|| changed; || changed;
changed = gen_poststate(enclosing, a, alocal.id) || changed; changed = gen_poststate(enclosing, a, alocal.id) || changed;
log("Summary: stmt = "); log("Summary: stmt = ");
@ -1932,10 +1827,10 @@ fn find_pre_post_state_stmt(&fn_info_map fm, &fn_info enclosing,
} }
case (stmt_expr(?e, _)) { case (stmt_expr(?e, _)) {
changed = find_pre_post_state_expr(fm, enclosing, pres, e) || changed; changed = find_pre_post_state_expr(fm, enclosing, pres, e) || changed;
changed = extend_prestate(stmt_ann.states.prestate, expr_prestate(*e)) changed = extend_prestate(stmt_ann.states.prestate, expr_prestate(e))
|| changed; || changed;
changed = extend_poststate(stmt_ann.states.poststate, changed = extend_poststate(stmt_ann.states.poststate,
expr_poststate(*e)) || changed; expr_poststate(e)) || changed;
/* /*
log("Summary: stmt = "); log("Summary: stmt = ");
log_stmt(*s); log_stmt(*s);
@ -1980,7 +1875,7 @@ fn find_pre_post_state_block(&fn_info_map fm, &fn_info enclosing,
case (none[@expr]) {} case (none[@expr]) {}
case (some[@expr](?e)) { case (some[@expr](?e)) {
changed = find_pre_post_state_expr(fm, enclosing, pres, e) || changed; changed = find_pre_post_state_expr(fm, enclosing, pres, e) || changed;
post = expr_poststate(*e); post = expr_poststate(e);
} }
} }
@ -2038,13 +1933,13 @@ fn fixed_point_states(fn_info_map fm, fn_info f_info,
} }
} }
fn check_states_expr(fn_info enclosing, &expr e) -> () { fn check_states_expr(fn_info enclosing, @expr e) -> () {
let precond prec = expr_precond(e); let precond prec = expr_precond(e);
let prestate pres = expr_prestate(e); let prestate pres = expr_prestate(e);
if (!implies(pres, prec)) { if (!implies(pres, prec)) {
log_err("check_states_expr: Unsatisfied precondition constraint for "); log_err("check_states_expr: Unsatisfied precondition constraint for ");
log_expr_err(e); log_expr_err(*e);
log_err("Precondition: "); log_err("Precondition: ");
log_bitv_err(enclosing, prec); log_bitv_err(enclosing, prec);
log_err("Prestate: "); log_err("Prestate: ");
@ -2093,7 +1988,7 @@ fn check_states_against_conditions(fn_info enclosing, &ast._fn f) -> () {
_vec.map[@stmt, ()](do_one, f.body.node.stmts); _vec.map[@stmt, ()](do_one, f.body.node.stmts);
fn do_inner_(fn_info i, &@expr e) -> () { fn do_inner_(fn_info i, &@expr e) -> () {
check_states_expr(i, *e); check_states_expr(i, e);
} }
auto do_inner = bind do_inner_(enclosing, _); auto do_inner = bind do_inner_(enclosing, _);
option.map[@expr, ()](do_inner, f.body.node.expr); option.map[@expr, ()](do_inner, f.body.node.expr);
@ -2116,7 +2011,7 @@ fn check_item_fn_state(&fn_info_map f_info_map, &span sp, ident i,
ann a) -> @item { ann a) -> @item {
/* Look up the var-to-bit-num map for this function */ /* Look up the var-to-bit-num map for this function */
check(f_info_map.contains_key(id)); assert (f_info_map.contains_key(id));
auto f_info = f_info_map.get(id); auto f_info = f_info_map.get(id);
check_fn_states(f_info_map, f_info, f); check_fn_states(f_info_map, f_info, f);
@ -2126,7 +2021,7 @@ fn check_item_fn_state(&fn_info_map f_info_map, &span sp, ident i,
} }
fn check_method_states(&fn_info_map f_info_map, @method m) -> () { fn check_method_states(&fn_info_map f_info_map, @method m) -> () {
check (f_info_map.contains_key(m.node.id)); assert (f_info_map.contains_key(m.node.id));
auto f_info = f_info_map.get(m.node.id); auto f_info = f_info_map.get(m.node.id);
check_fn_states(f_info_map, f_info, m.node.meth); check_fn_states(f_info_map, f_info, m.node.meth);
} }
@ -2193,7 +2088,7 @@ fn init_block(&fn_info fi, &span sp, &block_ b) -> block {
fn item_fn_anns(&fn_info_map fm, &span sp, ident i, &ast._fn f, fn item_fn_anns(&fn_info_map fm, &span sp, ident i, &ast._fn f,
vec[ast.ty_param] ty_params, def_id id, ann a) -> @item { vec[ast.ty_param] ty_params, def_id id, ann a) -> @item {
check(fm.contains_key(id)); assert (fm.contains_key(id));
auto f_info = fm.get(id); auto f_info = fm.get(id);
log(i + " has " + uistr(num_locals(f_info)) + " local vars"); log(i + " has " + uistr(num_locals(f_info)) + " local vars");
@ -2413,8 +2308,11 @@ fn annotate_expr(&fn_info_map fm, &@expr e) -> @expr {
case (expr_log(?n, ?e, ?a)) { case (expr_log(?n, ?e, ?a)) {
e1 = expr_log(n, annotate_expr(fm, e), a); e1 = expr_log(n, annotate_expr(fm, e), a);
} }
case (expr_check_expr(?e, ?a)) { case (expr_assert(?e, ?a)) {
e1 = expr_check_expr(annotate_expr(fm, e), a); e1 = expr_assert(annotate_expr(fm, e), a);
}
case (expr_check(?e, ?a)) {
e1 = expr_check(annotate_expr(fm, e), a);
} }
case (expr_port(_)) { /* no change */ } case (expr_port(_)) { /* no change */ }
case (expr_chan(?e, ?a)) { case (expr_chan(?e, ?a)) {

View File

@ -392,7 +392,10 @@ fn walk_expr(&ast_visitor v, @ast.expr e) {
case (ast.expr_log(_,?x, _)) { case (ast.expr_log(_,?x, _)) {
walk_expr(v, x); walk_expr(v, x);
} }
case (ast.expr_check_expr(?x, _)) { case (ast.expr_check(?x, _)) {
walk_expr(v, x);
}
case (ast.expr_assert(?x, _)) {
walk_expr(v, x); walk_expr(v, x);
} }
case (ast.expr_port(_)) { } case (ast.expr_port(_)) { }

View File

@ -661,12 +661,18 @@ fn print_expr(ps s, &@ast.expr expr) {
} }
print_expr(s, expr); print_expr(s, expr);
} }
case (ast.expr_check_expr(?expr,_)) { case (ast.expr_check(?expr,_)) {
wrd1(s, "check"); wrd1(s, "check");
popen_h(s); popen_h(s);
print_expr(s, expr); print_expr(s, expr);
pclose(s); pclose(s);
} }
case (ast.expr_assert(?expr,_)) {
wrd1(s, "assert");
popen_h(s);
print_expr(s, expr);
pclose(s);
}
case (ast.expr_ext(?path, ?args, ?body, _, _)) { case (ast.expr_ext(?path, ?args, ?body, _, _)) {
wrd(s.s, "#"); wrd(s.s, "#");
print_path(s, path); print_path(s, path);

View File

@ -85,7 +85,7 @@ fn intersect(&precond p1, &precond p2) -> bool {
fn pps_len(&pre_and_post p) -> uint { fn pps_len(&pre_and_post p) -> uint {
// gratuitous check // gratuitous check
check (p.precondition.nbits == p.postcondition.nbits); assert (p.precondition.nbits == p.postcondition.nbits);
ret p.precondition.nbits; ret p.precondition.nbits;
} }
@ -129,7 +129,7 @@ fn set_prestate(@ts_ann a, &prestate p) -> bool {
// Sets all the bits in a's postcondition to equal the // Sets all the bits in a's postcondition to equal the
// corresponding bit in p's postcondition. // corresponding bit in p's postcondition.
fn set_poststate(&ts_ann a, &poststate p) -> bool { fn set_poststate(@ts_ann a, &poststate p) -> bool {
ret bitv.copy(a.states.poststate, p); ret bitv.copy(a.states.poststate, p);
} }

View File

@ -35,7 +35,7 @@ fn color_supported() -> bool {
} }
fn set_color(io.buf_writer writer, u8 first_char, u8 color) { fn set_color(io.buf_writer writer, u8 first_char, u8 color) {
check (color < 16u8); assert (color < 16u8);
esc(writer); esc(writer);
if (color >= 8u8) { if (color >= 8u8) {

View File

@ -27,7 +27,7 @@ iter range(int lo, int hi) -> int {
fn to_str(int n, uint radix) -> str fn to_str(int n, uint radix) -> str
{ {
check (0u < radix && radix <= 16u); assert (0u < radix && radix <= 16u);
if (n < 0) { if (n < 0) {
ret "-" + _uint.to_str((-n) as uint, radix); ret "-" + _uint.to_str((-n) as uint, radix);
} else { } else {

View File

@ -218,14 +218,14 @@ fn utf8_char_width(u8 b) -> uint {
fn char_range_at(str s, uint i) -> tup(char, uint) { fn char_range_at(str s, uint i) -> tup(char, uint) {
auto b0 = s.(i); auto b0 = s.(i);
auto w = utf8_char_width(b0); auto w = utf8_char_width(b0);
check(w != 0u); assert (w != 0u);
if (w == 1u) {ret tup(b0 as char, i + 1u);} if (w == 1u) {ret tup(b0 as char, i + 1u);}
auto val = 0u; auto val = 0u;
auto end = i + w; auto end = i + w;
i += 1u; i += 1u;
while (i < end) { while (i < end) {
auto byte = s.(i); auto byte = s.(i);
check(byte & 0xc0_u8 == tag_cont_u8); assert (byte & 0xc0_u8 == tag_cont_u8);
val <<= 6u; val <<= 6u;
val += (byte & 0x3f_u8) as uint; val += (byte & 0x3f_u8) as uint;
i += 1u; i += 1u;
@ -247,11 +247,11 @@ fn char_len(str s) -> uint {
auto total = byte_len(s); auto total = byte_len(s);
while (i < total) { while (i < total) {
auto chsize = utf8_char_width(s.(i)); auto chsize = utf8_char_width(s.(i));
check(chsize > 0u); assert (chsize > 0u);
len += 1u; len += 1u;
i += chsize; i += chsize;
} }
check(i == total); assert (i == total);
ret len; ret len;
} }
@ -274,7 +274,7 @@ fn push_char(&mutable str s, char ch) {
fn pop_char(&mutable str s) -> char { fn pop_char(&mutable str s) -> char {
auto end = byte_len(s); auto end = byte_len(s);
while (end > 0u && s.(end - 1u) & 0xc0_u8 == tag_cont_u8) {end -= 1u;} while (end > 0u && s.(end - 1u) & 0xc0_u8 == tag_cont_u8) {end -= 1u;}
check(end > 0u); assert (end > 0u);
auto ch = char_at(s, end - 1u); auto ch = char_at(s, end - 1u);
s = substr(s, 0u, end - 1u); s = substr(s, 0u, end - 1u);
ret ch; ret ch;
@ -404,7 +404,7 @@ fn slice(str s, uint begin, uint end) -> str {
fn shift_byte(&mutable str s) -> u8 { fn shift_byte(&mutable str s) -> u8 {
auto len = byte_len(s); auto len = byte_len(s);
check(len > 0u); assert (len > 0u);
auto b = s.(0); auto b = s.(0);
s = substr(s, 1u, len - 1u); s = substr(s, 1u, len - 1u);
ret b; ret b;
@ -412,7 +412,7 @@ fn shift_byte(&mutable str s) -> u8 {
fn pop_byte(&mutable str s) -> u8 { fn pop_byte(&mutable str s) -> u8 {
auto len = byte_len(s); auto len = byte_len(s);
check(len > 0u); assert (len > 0u);
auto b = s.(len - 1u); auto b = s.(len - 1u);
s = substr(s, 0u, len - 1u); s = substr(s, 0u, len - 1u);
ret b; ret b;

View File

@ -56,7 +56,7 @@ fn to_str(uint num, uint radix) -> str
{ {
auto n = num; auto n = num;
check (0u < radix && radix <= 16u); assert (0u < radix && radix <= 16u);
fn digit(uint n) -> char { fn digit(uint n) -> char {
alt (n) { alt (n) {
case (0u) { ret '0'; } case (0u) { ret '0'; }

View File

@ -131,7 +131,7 @@ fn len_set[T](array[T] v, uint n) {
} }
fn buf_off[T](array[T] v, uint offset) -> vbuf { fn buf_off[T](array[T] v, uint offset) -> vbuf {
check (offset < len[T](v)); assert (offset < len[T](v));
ret rustrt.vec_buf[T](v, offset); ret rustrt.vec_buf[T](v, offset);
} }
@ -149,9 +149,10 @@ fn last[T](array[T] v) -> option.t[T] {
} }
// Returns elements from [start..end) from v. // Returns elements from [start..end) from v.
fn slice[T](array[T] v, uint start, uint end) -> vec[T] { fn slice[T](array[T] v, uint start, uint end) -> vec[T] {
check (start <= end); assert (start <= end);
check (end <= len[T](v)); assert (end <= len[T](v));
auto result = alloc[T](end - start); auto result = alloc[T](end - start);
let uint i = start; let uint i = start;
while (i < end) { while (i < end) {
@ -163,7 +164,7 @@ fn slice[T](array[T] v, uint start, uint end) -> vec[T] {
fn shift[T](&mutable array[T] v) -> T { fn shift[T](&mutable array[T] v) -> T {
auto ln = len[T](v); auto ln = len[T](v);
check(ln > 0u); assert (ln > 0u);
auto e = v.(0); auto e = v.(0);
v = slice[T](v, 1u, ln); v = slice[T](v, 1u, ln);
ret e; ret e;
@ -171,7 +172,7 @@ fn shift[T](&mutable array[T] v) -> T {
fn pop[T](&mutable array[T] v) -> T { fn pop[T](&mutable array[T] v) -> T {
auto ln = len[T](v); auto ln = len[T](v);
check(ln > 0u); assert (ln > 0u);
ln -= 1u; ln -= 1u;
auto e = v.(ln); auto e = v.(ln);
v = slice[T](v, 0u, ln); v = slice[T](v, 0u, ln);

View File

@ -28,8 +28,8 @@ fn create(uint nbits, bool init) -> t {
fn process(&fn(uint, uint) -> uint op, &t v0, &t v1) -> bool { fn process(&fn(uint, uint) -> uint op, &t v0, &t v1) -> bool {
auto len = _vec.len[mutable uint](v1.storage); auto len = _vec.len[mutable uint](v1.storage);
check (_vec.len[mutable uint](v0.storage) == len); assert (_vec.len[mutable uint](v0.storage) == len);
check (v0.nbits == v1.nbits); assert (v0.nbits == v1.nbits);
auto changed = false; auto changed = false;
@ -84,7 +84,7 @@ fn clone(t v) -> t {
} }
fn get(&t v, uint i) -> bool { fn get(&t v, uint i) -> bool {
check (i < v.nbits); assert (i < v.nbits);
auto bits = uint_bits(); auto bits = uint_bits();
@ -129,7 +129,7 @@ fn difference(&t v0, &t v1) -> bool {
} }
fn set(&t v, uint i, bool x) { fn set(&t v, uint i, bool x) {
check (i < v.nbits); assert (i < v.nbits);
auto bits = uint_bits(); auto bits = uint_bits();
@ -196,7 +196,7 @@ fn to_str(&t v) -> str {
// FIXME: can we just use structural equality on to_vec? // FIXME: can we just use structural equality on to_vec?
fn eq_vec(&t v0, &vec[uint] v1) -> bool { fn eq_vec(&t v0, &vec[uint] v1) -> bool {
check (v0.nbits == _vec.len[uint](v1)); assert (v0.nbits == _vec.len[uint](v1));
auto len = v0.nbits; auto len = v0.nbits;
auto i = 0u; auto i = 0u;
while (i < len) { while (i < len) {

View File

@ -28,7 +28,7 @@ fn create[T]() -> t[T] {
* elsewhere. * elsewhere.
*/ */
fn grow[T](uint nelts, uint lo, vec[cell[T]] elts) -> vec[cell[T]] { fn grow[T](uint nelts, uint lo, vec[cell[T]] elts) -> vec[cell[T]] {
check (nelts == _vec.len[cell[T]](elts)); assert (nelts == _vec.len[cell[T]](elts));
fn fill[T](uint i, uint nelts, uint lo, fn fill[T](uint i, uint nelts, uint lo,
vec[cell[T]] old) -> cell[T] { vec[cell[T]] old) -> cell[T] {

View File

@ -99,7 +99,7 @@ fn doc_data(doc d) -> vec[u8] {
fn be_uint_from_bytes(vec[u8] data, uint start, uint size) -> uint { fn be_uint_from_bytes(vec[u8] data, uint start, uint size) -> uint {
auto sz = size; auto sz = size;
check (sz <= 4u); assert (sz <= 4u);
auto val = 0u; auto val = 0u;
auto pos = start; auto pos = start;
while (sz > 0u) { while (sz > 0u) {

View File

@ -10,7 +10,7 @@ type path = str;
fn dirname(path p) -> path { fn dirname(path p) -> path {
auto sep = path_sep(); auto sep = path_sep();
check (_str.byte_len(sep) == 1u); assert (_str.byte_len(sep) == 1u);
let int i = _str.rindex(p, sep.(0)); let int i = _str.rindex(p, sep.(0));
if (i == -1) { if (i == -1) {
ret p; ret p;

View File

@ -72,7 +72,7 @@ state obj FILE_buf_reader(os.libc.FILE f, bool must_close) {
ret os.libc.feof(f) != 0; ret os.libc.feof(f) != 0;
} }
fn seek(int offset, seek_style whence) { fn seek(int offset, seek_style whence) {
check (os.libc.fseek(f, offset, convert_whence(whence)) == 0); assert (os.libc.fseek(f, offset, convert_whence(whence)) == 0);
} }
fn tell() -> uint { fn tell() -> uint {
ret os.libc.ftell(f) as uint; ret os.libc.ftell(f) as uint;
@ -101,14 +101,14 @@ state obj new_reader(buf_reader rdr) {
if (c0 == -1) {ret -1 as char;} // FIXME will this stay valid? if (c0 == -1) {ret -1 as char;} // FIXME will this stay valid?
auto b0 = c0 as u8; auto b0 = c0 as u8;
auto w = _str.utf8_char_width(b0); auto w = _str.utf8_char_width(b0);
check(w > 0u); assert (w > 0u);
if (w == 1u) {ret b0 as char;} if (w == 1u) {ret b0 as char;}
auto val = 0u; auto val = 0u;
while (w > 1u) { while (w > 1u) {
w -= 1u; w -= 1u;
auto next = rdr.read_byte(); auto next = rdr.read_byte();
check(next > -1); assert (next > -1);
check(next & 0xc0 == 0x80); assert (next & 0xc0 == 0x80);
val <<= 6u; val <<= 6u;
val += (next & 0x3f) as uint; val += (next & 0x3f) as uint;
} }
@ -279,7 +279,7 @@ state obj FILE_writer(os.libc.FILE f, bool must_close) {
} }
fn seek(int offset, seek_style whence) { fn seek(int offset, seek_style whence) {
check(os.libc.fseek(f, offset, convert_whence(whence)) == 0); assert (os.libc.fseek(f, offset, convert_whence(whence)) == 0);
} }
fn tell() -> uint { fn tell() -> uint {

View File

@ -66,7 +66,7 @@ fn dylib_filename(str base) -> str {
fn pipe() -> tup(int, int) { fn pipe() -> tup(int, int) {
let vec[mutable int] fds = vec(mutable 0, 0); let vec[mutable int] fds = vec(mutable 0, 0);
check(os.libc.pipe(_vec.buf[mutable int](fds)) == 0); assert (os.libc.pipe(_vec.buf[mutable int](fds)) == 0);
ret tup(fds.(0), fds.(1)); ret tup(fds.(0), fds.(1));
} }
@ -76,7 +76,7 @@ fn fd_FILE(int fd) -> libc.FILE {
fn waitpid(int pid) -> int { fn waitpid(int pid) -> int {
let vec[mutable int] status = vec(mutable 0); let vec[mutable int] status = vec(mutable 0);
check(os.libc.waitpid(pid, _vec.buf[mutable int](status), 0) != -1); assert (os.libc.waitpid(pid, _vec.buf[mutable int](status), 0) != -1);
ret status.(0); ret status.(0);
} }

View File

@ -63,7 +63,7 @@ fn dylib_filename(str base) -> str {
fn pipe() -> tup(int, int) { fn pipe() -> tup(int, int) {
let vec[mutable int] fds = vec(mutable 0, 0); let vec[mutable int] fds = vec(mutable 0, 0);
check(os.libc.pipe(_vec.buf[mutable int](fds)) == 0); assert (os.libc.pipe(_vec.buf[mutable int](fds)) == 0);
ret tup(fds.(0), fds.(1)); ret tup(fds.(0), fds.(1));
} }
@ -73,7 +73,7 @@ fn fd_FILE(int fd) -> libc.FILE {
fn waitpid(int pid) -> int { fn waitpid(int pid) -> int {
let vec[mutable int] status = vec(mutable 0); let vec[mutable int] status = vec(mutable 0);
check(os.libc.waitpid(pid, _vec.buf[mutable int](status), 0) != -1); assert (os.libc.waitpid(pid, _vec.buf[mutable int](status), 0) != -1);
ret status.(0); ret status.(0);
} }

View File

@ -5,7 +5,7 @@ native "rust" mod rustrt {
fn list_dir(str path) -> vec[str] { fn list_dir(str path) -> vec[str] {
// TODO ensure this is always closed // TODO ensure this is always closed
auto dir = os.libc.opendir(_str.buf(path)); auto dir = os.libc.opendir(_str.buf(path));
check (dir as uint != 0u); assert (dir as uint != 0u);
let vec[str] result = vec(); let vec[str] result = vec();
while (true) { while (true) {
auto ent = os.libc.readdir(dir); auto ent = os.libc.readdir(dir);

View File

@ -43,7 +43,7 @@ fn mk_sha1() -> sha1 {
fn add_input(&sha1state st, &vec[u8] msg) { fn add_input(&sha1state st, &vec[u8] msg) {
// FIXME: Should be typestate precondition // FIXME: Should be typestate precondition
check (!st.computed); assert (!st.computed);
for (u8 element in msg) { for (u8 element in msg) {
st.msg_block.(st.msg_block_idx) = element; st.msg_block.(st.msg_block_idx) = element;
@ -67,7 +67,7 @@ fn mk_sha1() -> sha1 {
fn process_msg_block(&sha1state st) { fn process_msg_block(&sha1state st) {
// FIXME: Make precondition // FIXME: Make precondition
check (_vec.len[mutable u32](st.h) == digest_buf_len); assert (_vec.len[mutable u32](st.h) == digest_buf_len);
// Constants // Constants
auto k = vec(0x5A827999u32, auto k = vec(0x5A827999u32,
@ -192,7 +192,7 @@ fn mk_sha1() -> sha1 {
*/ */
fn pad_msg(&sha1state st) { fn pad_msg(&sha1state st) {
// FIXME: Should be a precondition // FIXME: Should be a precondition
check (_vec.len[mutable u8](st.msg_block) == msg_block_len); assert (_vec.len[mutable u8](st.msg_block) == msg_block_len);
/* /*
* Check to see if the current message block is too small to hold * Check to see if the current message block is too small to hold
@ -236,7 +236,7 @@ fn mk_sha1() -> sha1 {
fn reset() { fn reset() {
// FIXME: Should be typestate precondition // FIXME: Should be typestate precondition
check (_vec.len[mutable u32](st.h) == digest_buf_len); assert (_vec.len[mutable u32](st.h) == digest_buf_len);
st.len_low = 0u32; st.len_low = 0u32;
st.len_high = 0u32; st.len_high = 0u32;

View File

@ -53,7 +53,7 @@ fn dylib_filename(str base) -> str {
fn pipe() -> tup(int, int) { fn pipe() -> tup(int, int) {
let vec[mutable int] fds = vec(mutable 0, 0); let vec[mutable int] fds = vec(mutable 0, 0);
check(os.libc._pipe(_vec.buf[mutable int](fds), 1024u, assert (os.libc._pipe(_vec.buf[mutable int](fds), 1024u,
libc_constants.O_BINARY()) == 0); libc_constants.O_BINARY()) == 0);
ret tup(fds.(0), fds.(1)); ret tup(fds.(0), fds.(1));
} }

View File

@ -2,5 +2,5 @@
// error-pattern:1 == 2 // error-pattern:1 == 2
fn main() { fn main() {
check (1 == 2); assert (1 == 2);
} }

View File

@ -4,7 +4,7 @@
// error-pattern:1 == 2 // error-pattern:1 == 2
fn child() { fn child() {
check (1 == 2); assert (1 == 2);
} }
fn main() { fn main() {

View File

@ -6,12 +6,12 @@
fn main() { fn main() {
let str s = "hello"; let str s = "hello";
let int x = 0; let int x = 0;
check (s.(x) == (0x68 as u8)); assert (s.(x) == (0x68 as u8));
// NB: at the moment a string always has a trailing NULL, // NB: at the moment a string always has a trailing NULL,
// so the largest index value on the string above is 5, not // so the largest index value on the string above is 5, not
// 4. Possibly change this. // 4. Possibly change this.
// Bounds-check failure. // Bounds-check failure.
check (s.(x + 6) == (0x0 as u8)); assert (s.(x + 6) == (0x0 as u8));
} }

View File

@ -6,7 +6,7 @@
fn main() { fn main() {
let vec[int] v = vec(10); let vec[int] v = vec(10);
let int x = 0; let int x = 0;
check (v.(x) == 10); assert (v.(x) == 10);
// Bounds-check failure. // Bounds-check failure.
check (v.(x + 2) == 20); assert (v.(x + 2) == 20);
} }

View File

@ -6,7 +6,7 @@
fn main() { fn main() {
let vec[int] v = vec(10, 20); let vec[int] v = vec(10, 20);
let int x = 0; let int x = 0;
check (v.(x) == 10); assert (v.(x) == 10);
// Bounds-check failure. // Bounds-check failure.
check (v.(x-1) == 20); assert (v.(x-1) == 20);
} }

View File

@ -21,12 +21,12 @@ fn foo(str s) {
} }
log _str.refcount(s); log _str.refcount(s);
check (_str.refcount(s) == const_refcount); assert (_str.refcount(s) == const_refcount);
} }
fn main() { fn main() {
let str s = "hi"; // ref up let str s = "hi"; // ref up
foo(s); // ref up then down foo(s); // ref up then down
log _str.refcount(s); log _str.refcount(s);
check (_str.refcount(s) == const_refcount); assert (_str.refcount(s) == const_refcount);
} }

View File

@ -12,6 +12,6 @@ fn altlit(int f) -> int {
} }
fn main() { fn main() {
check (altlit(10) == 20); assert (altlit(10) == 20);
check (altlit(11) == 22); assert (altlit(11) == 22);
} }

View File

@ -32,8 +32,8 @@ fn main() {
let color gray = rgb(127, 127, 127); let color gray = rgb(127, 127, 127);
let color clear = rgba(50, 150, 250, 0); let color clear = rgba(50, 150, 250, 0);
let color red = hsl(0, 255, 255); let color red = hsl(0, 255, 255);
check (process(gray) == 127); assert (process(gray) == 127);
check (process(clear) == 0); assert (process(clear) == 0);
check (process(red) == 255); assert (process(red) == 255);
} }

View File

@ -1,5 +1,5 @@
fn main() -> () { fn main() -> () {
let int a = 10; let int a = 10;
log a; log a;
check (a * (a - 1) == 90); assert (a * (a - 1) == 90);
} }

View File

@ -1,22 +1,22 @@
fn main() -> () { fn main() -> () {
let int i32_a = 10; let int i32_a = 10;
check(i32_a == 10); assert (i32_a == 10);
check(i32_a - 10 == 0); assert (i32_a - 10 == 0);
check(i32_a / 10 == 1); assert (i32_a / 10 == 1);
check(i32_a - 20 == -10); assert (i32_a - 20 == -10);
check(i32_a << 10 == 10240); assert (i32_a << 10 == 10240);
check(i32_a << 16 == 655360); assert (i32_a << 16 == 655360);
check(i32_a * 16 == 160); assert (i32_a * 16 == 160);
check(i32_a * i32_a * i32_a == 1000); assert (i32_a * i32_a * i32_a == 1000);
check(i32_a * i32_a * i32_a * i32_a == 10000); assert (i32_a * i32_a * i32_a * i32_a == 10000);
check(((i32_a * i32_a) / i32_a) * i32_a == 100); assert (((i32_a * i32_a) / i32_a) * i32_a == 100);
check(i32_a * (i32_a - 1) << 2 + i32_a == 368640); assert (i32_a * (i32_a - 1) << 2 + i32_a == 368640);
let int i32_b = 0x10101010; let int i32_b = 0x10101010;
check(i32_b + 1 - 1 == i32_b); assert (i32_b + 1 - 1 == i32_b);
check(i32_b << 1 == i32_b << 1); assert (i32_b << 1 == i32_b << 1);
check(i32_b >> 1 == i32_b >> 1); assert (i32_b >> 1 == i32_b >> 1);
check((i32_b & (i32_b << 1)) == 0); assert ((i32_b & (i32_b << 1)) == 0);
log ((i32_b | (i32_b << 1))); log ((i32_b | (i32_b << 1)));
check((i32_b | (i32_b << 1)) == 0x30303030); assert ((i32_b | (i32_b << 1)) == 0x30303030);
} }

View File

@ -1,5 +1,5 @@
fn main() -> () { fn main() -> () {
let int i32_c = 0x10101010; let int i32_c = 0x10101010;
check (i32_c + i32_c * 2 / 3 * 2 + (i32_c - 7 % 3) == assert (i32_c + i32_c * 2 / 3 * 2 + (i32_c - 7 % 3) ==
i32_c + (((i32_c * 2) / 3) * 2) + (i32_c - (7 % 3))); i32_c + (((i32_c * 2) / 3) * 2) + (i32_c - (7 % 3)));
} }

View File

@ -2,24 +2,24 @@
// Unsigned integer operations // Unsigned integer operations
fn main() { fn main() {
check (0u8 < 255u8); assert (0u8 < 255u8);
check (0u8 <= 255u8); assert (0u8 <= 255u8);
check (255u8 > 0u8); assert (255u8 > 0u8);
check (255u8 >= 0u8); assert (255u8 >= 0u8);
check (250u8 / 10u8 == 25u8); assert (250u8 / 10u8 == 25u8);
check (255u8 % 10u8 == 5u8); assert (255u8 % 10u8 == 5u8);
check (0u16 < 60000u16); assert (0u16 < 60000u16);
check (0u16 <= 60000u16); assert (0u16 <= 60000u16);
check (60000u16 > 0u16); assert (60000u16 > 0u16);
check (60000u16 >= 0u16); assert (60000u16 >= 0u16);
check (60000u16 / 10u16 == 6000u16); assert (60000u16 / 10u16 == 6000u16);
check (60005u16 % 10u16 == 5u16); assert (60005u16 % 10u16 == 5u16);
check (0u32 < 4000000000u32); assert (0u32 < 4000000000u32);
check (0u32 <= 4000000000u32); assert (0u32 <= 4000000000u32);
check (4000000000u32 > 0u32); assert (4000000000u32 > 0u32);
check (4000000000u32 >= 0u32); assert (4000000000u32 >= 0u32);
check (4000000000u32 / 10u32 == 400000000u32); assert (4000000000u32 / 10u32 == 400000000u32);
check (4000000005u32 % 10u32 == 5u32); assert (4000000005u32 % 10u32 == 5u32);
// 64-bit numbers have some flakiness yet. Not tested // 64-bit numbers have some flakiness yet. Not tested
} }

View File

@ -8,11 +8,11 @@ fn main() {
let clam b = rec(x=@10, y=@20); let clam b = rec(x=@10, y=@20);
let int z = a.x + b.y; let int z = a.x + b.y;
log z; log z;
check (z == 21); assert (z == 21);
let fish forty = tup(@40); let fish forty = tup(@40);
let fish two = tup(@2); let fish two = tup(@2);
let int answer = forty._0 + two._0; let int answer = forty._0 + two._0;
log answer; log answer;
check (answer == 42); assert (answer == 42);
} }

View File

@ -4,5 +4,5 @@ fn foo(@int a, @int b) -> int {
fn main() { fn main() {
auto f1 = bind foo(@10, @12); auto f1 = bind foo(@10, @12);
check(f1() == 22); assert (f1() == 22);
} }

View File

@ -7,5 +7,5 @@ fn f(int n) -> int {
fn main() { fn main() {
let fn() -> int g = bind f(10); let fn() -> int g = bind f(10);
let int i = g(); let int i = g();
check(i == 10); assert (i == 10);
} }

View File

@ -11,7 +11,7 @@ fn main() {
auto ctor1 = bind simple(_, 2); auto ctor1 = bind simple(_, 2);
auto obj1 = ctor0(2); auto obj1 = ctor0(2);
auto obj2 = ctor1(1); auto obj2 = ctor1(1);
check (obj0.sum() == 3); assert (obj0.sum() == 3);
check (obj1.sum() == 3); assert (obj1.sum() == 3);
check (obj2.sum() == 3); assert (obj2.sum() == 3);
} }

View File

@ -7,5 +7,5 @@ fn f() -> int {
fn main() { fn main() {
let fn() -> int g = bind f(); let fn() -> int g = bind f();
let int i = g(); let int i = g();
check(i == 42); assert (i == 42);
} }

View File

@ -7,5 +7,5 @@ fn f(int n) -> int {
fn main() { fn main() {
let fn(int) -> int g = bind f(_); let fn(int) -> int g = bind f(_);
let int i = g(42); let int i = g(42);
check(i == 42); assert (i == 42);
} }

View File

@ -8,14 +8,14 @@ fn main() {
a = a ^ b; a = a ^ b;
log a; log a;
log b; log b;
check (b == 1); assert (b == 1);
check (a == 2); assert (a == 2);
check (~(0xf0) & 0xff == 0xf); assert (~(0xf0) & 0xff == 0xf);
check (0xf0 | 0xf == 0xff); assert (0xf0 | 0xf == 0xff);
check (0xf << 4 == 0xf0); assert (0xf << 4 == 0xf0);
check (0xf0 >> 4 == 0xf); assert (0xf0 >> 4 == 0xf);
check (-16 >>> 2 == -4); assert (-16 >>> 2 == -4);
check (0b1010_1010 | 0b0101_0101 == 0xff); assert (0b1010_1010 | 0b0101_0101 == 0xff);
} }

View File

@ -2,14 +2,14 @@
fn main() { fn main() {
if (!false) { if (!false) {
check (true); assert (true);
} else { } else {
check (false); assert (false);
} }
if (!true) { if (!true) {
check (false); assert (false);
} else { } else {
check (true); assert (true);
} }
} }

View File

@ -1,6 +1,6 @@
// xfail-boot // xfail-boot
fn main() { fn main() {
check (@1 < @3); assert (@1 < @3);
check (@@"hello " > @@"hello"); assert (@@"hello " > @@"hello");
check (@@@"hello" != @@@"there"); assert (@@@"hello" != @@@"there");
} }

View File

@ -6,5 +6,5 @@ fn main() {
let int foo = 17; let int foo = 17;
let box[int] bfoo = tup(@foo); let box[int] bfoo = tup(@foo);
log "see what's in our box"; log "see what's in our box";
check (unbox[int](bfoo) == foo); assert (unbox[int](bfoo) == foo);
} }

View File

@ -1,4 +1,4 @@
fn main() { fn main() {
let @int x = @10; let @int x = @10;
check ((*x) == 10); assert ((*x) == 10);
} }

View File

@ -6,35 +6,35 @@ fn main() {
i += 1; i += 1;
if (i == 10) { break; } if (i == 10) { break; }
} }
check(i == 10); assert (i == 10);
do { do {
i += 1; i += 1;
if (i == 20) { break; } if (i == 20) { break; }
} while (i < 30); } while (i < 30);
check(i == 20); assert (i == 20);
for (int x in vec(1, 2, 3, 4, 5, 6)) { for (int x in vec(1, 2, 3, 4, 5, 6)) {
if (x == 3) { break; } if (x == 3) { break; }
check(x <= 3); assert (x <= 3);
} }
i = 0; i = 0;
while (i < 10) { while (i < 10) {
i += 1; i += 1;
if (i % 2 == 0) { cont; } if (i % 2 == 0) { cont; }
check(i % 2 != 0); assert (i % 2 != 0);
} }
i = 0; i = 0;
do { do {
i += 1; i += 1;
if (i % 2 == 0) { cont; } if (i % 2 == 0) { cont; }
check(i % 2 != 0); assert (i % 2 != 0);
} while (i < 10); } while (i < 10);
for (int x in vec(1, 2, 3, 4, 5, 6)) { for (int x in vec(1, 2, 3, 4, 5, 6)) {
if (x % 2 == 0) { cont; } if (x % 2 == 0) { cont; }
check(x % 2 != 0); assert (x % 2 != 0);
} }
} }

View File

@ -3,14 +3,14 @@
fn main() { fn main() {
let int i = 'Q' as int; let int i = 'Q' as int;
check (i == 0x51); assert (i == 0x51);
let u32 u = i as u32; let u32 u = i as u32;
check (u == (0x51 as u32)); assert (u == (0x51 as u32));
check (u == ('Q' as u32)); assert (u == ('Q' as u32));
check ((i as u8) == ('Q' as u8)); assert ((i as u8) == ('Q' as u8));
check (((i as u8) as i8) == (('Q' as u8) as i8)); assert (((i as u8) as i8) == (('Q' as u8) as i8));
check ((0x51 as char) == 'Q'); assert ((0x51 as char) == 'Q');
check (true == (1 as bool)); assert (true == (1 as bool));
check ((0 as u32) == (false as u32)); assert ((0 as u32) == (false as u32));
} }

View File

@ -1,12 +1,12 @@
fn main() { fn main() {
let char c = 'x'; let char c = 'x';
let char d = 'x'; let char d = 'x';
check(c == 'x'); assert (c == 'x');
check('x' == c); assert ('x' == c);
check(c == c); assert (c == c);
check(c == d); assert (c == d);
check(d == c); assert (d == c);
check (d == 'x'); assert (d == 'x');
check('x' == d); assert ('x' == d);
} }

View File

@ -1,8 +1,8 @@
// xfail-boot // xfail-boot
// xfail-stage0 // xfail-stage0
fn f(@rec(int a, int b) x) { fn f(@rec(int a, int b) x) {
check (x.a == 10); assert (x.a == 10);
check (x.b == 12); assert (x.b == 12);
} }
fn main() { fn main() {

View File

@ -8,7 +8,7 @@ fn main() {
y <- p; y <- p;
log "received"; log "received";
log y; log y;
check (y == 10); assert (y == 10);
} }
fn child(chan[int] c) { fn child(chan[int] c) {

View File

@ -6,9 +6,9 @@ fn main() {
ch <| 10; ch <| 10;
let int i <- po; let int i <- po;
check (i == 10); assert (i == 10);
ch <| 11; ch <| 11;
auto j <- po; auto j <- po;
check (j == 11); assert (j == 11);
} }

View File

@ -10,5 +10,5 @@ fn f(int x) -> int {
} }
fn main() { fn main() {
check (f(5000) == 5000); assert (f(5000) == 5000);
} }

View File

@ -3,15 +3,15 @@
fn main() { fn main() {
let int x = 15; let int x = 15;
let int y = 5; let int y = 5;
check(x / 5 == 3); assert (x / 5 == 3);
check(x / 4 == 3); assert (x / 4 == 3);
check(x / 3 == 5); assert (x / 3 == 5);
check(x / y == 3); assert (x / y == 3);
check(15 / y == 3); assert (15 / y == 3);
check(x % 5 == 0); assert (x % 5 == 0);
check(x % 4 == 3); assert (x % 4 == 3);
check(x % 3 == 0); assert (x % 3 == 0);
check(x % y == 0); assert (x % y == 0);
check(15 % y == 0); assert (15 % y == 0);
} }

View File

@ -1,42 +1,42 @@
fn main() { fn main() {
if (1 == 2) { if (1 == 2) {
check(false); assert (false);
} else if (2 == 3) { } else if (2 == 3) {
check(false); assert (false);
} else if (3 == 4) { } else if (3 == 4) {
check(false); assert (false);
} else { } else {
check(true); assert (true);
} }
if (1 == 2) { if (1 == 2) {
check(false); assert (false);
} else if (2 == 2) { } else if (2 == 2) {
check(true); assert (true);
} }
if (1 == 2) { if (1 == 2) {
check(false); assert (false);
} else if (2 == 2) { } else if (2 == 2) {
if (1 == 1) { if (1 == 1) {
check(true); assert (true);
} else { } else {
if (2 == 1) { if (2 == 1) {
check(false); assert (false);
} else { } else {
check(false); assert (false);
} }
} }
} }
if (1 == 2) { if (1 == 2) {
check(false); assert (false);
} else { } else {
if (1 == 2) { if (1 == 2) {
check(false); assert (false);
} else { } else {
check(true); assert (true);
} }
} }
} }

View File

@ -9,7 +9,7 @@ fn test_box() {
@100 @100
} }
}; };
check (*res == 100); assert (*res == 100);
} }
fn test_str() { fn test_str() {
@ -18,7 +18,7 @@ fn test_str() {
"happy" "happy"
} }
}; };
check (res == "happy"); assert (res == "happy");
} }
fn main() { fn main() {

View File

@ -9,7 +9,7 @@ fn test_generic[T](@T expected, &compare[T] eq) {
expected expected
} }
}; };
check (eq(expected, actual)); assert (eq(expected, actual));
} }
fn test_box() { fn test_box() {

View File

@ -9,7 +9,7 @@ fn test_generic[T](&T expected, &compare[T] eq) {
expected expected
} }
}; };
check (eq(expected, actual)); assert (eq(expected, actual));
} }
fn test_vec() { fn test_vec() {

View File

@ -9,7 +9,7 @@ fn test_generic[T](&T expected, &compare[T] eq) {
expected expected
} }
}; };
check (eq(expected, actual)); assert (eq(expected, actual));
} }
fn test_bool() { fn test_bool() {

View File

@ -9,7 +9,7 @@ fn test_rec() {
rec(i = 100) rec(i = 100)
} }
}; };
check (res == rec(i = 100)); assert (res == rec(i = 100));
} }
fn test_tag() { fn test_tag() {
@ -26,7 +26,7 @@ fn test_tag() {
sad sad
} }
}; };
check (res == happy); assert (res == happy);
} }
fn main() { fn main() {

View File

@ -12,7 +12,7 @@ fn test_basic() {
false false
} }
}; };
check (res); assert (res);
res = alt(false) { res = alt(false) {
case (true) { case (true) {
@ -22,7 +22,7 @@ fn test_basic() {
true true
} }
}; };
check (res); assert (res);
} }
fn test_inferrence() { fn test_inferrence() {
@ -34,7 +34,7 @@ fn test_inferrence() {
false false
} }
}; };
check (res); assert (res);
} }
fn test_alt_as_alt_head() { fn test_alt_as_alt_head() {
@ -47,7 +47,7 @@ fn test_alt_as_alt_head() {
true true
} }
}; };
check (res); assert (res);
} }
fn test_alt_as_block_result() { fn test_alt_as_block_result() {
@ -66,7 +66,7 @@ fn test_alt_as_block_result() {
} }
} }
}; };
check (res); assert (res);
} }
fn main() { fn main() {

View File

@ -6,5 +6,5 @@ fn main() {
@100 @100
}; };
check (*x == 100); assert (*x == 100);
} }

View File

@ -6,7 +6,7 @@ fn test_fn() {
ret 10; ret 10;
} }
let t res = { ten }; let t res = { ten };
check (res() == 10); assert (res() == 10);
} }
fn main() { fn main() {

View File

@ -5,7 +5,7 @@ type compare[T] = fn(@T t1, @T t2) -> bool;
fn test_generic[T](@T expected, &compare[T] eq) { fn test_generic[T](@T expected, &compare[T] eq) {
let @T actual = { expected }; let @T actual = { expected };
check (eq(expected, actual)); assert (eq(expected, actual));
} }
fn test_box() { fn test_box() {

View File

@ -5,7 +5,7 @@ type compare[T] = fn(&T t1, &T t2) -> bool;
fn test_generic[T](&T expected, &compare[T] eq) { fn test_generic[T](&T expected, &compare[T] eq) {
let T actual = { expected }; let T actual = { expected };
check (eq(expected, actual)); assert (eq(expected, actual));
} }
fn test_vec() { fn test_vec() {

View File

@ -7,7 +7,7 @@ type compare[T] = fn(&T t1, &T t2) -> bool;
fn test_generic[T](&T expected, &compare[T] eq) { fn test_generic[T](&T expected, &compare[T] eq) {
let T actual = { expected }; let T actual = { expected };
check (eq(expected, actual)); assert (eq(expected, actual));
} }
fn test_bool() { fn test_bool() {

View File

@ -5,12 +5,12 @@
fn test_basic() { fn test_basic() {
let bool res = { true }; let bool res = { true };
check (res); assert (res);
} }
fn test_rec() { fn test_rec() {
auto res = { rec(v1 = 10, v2 = 20) }; auto res = { rec(v1 = 10, v2 = 20) };
check (res.v2 == 20); assert (res.v2 == 20);
} }
fn test_filled_with_stuff() { fn test_filled_with_stuff() {
@ -21,7 +21,7 @@ fn test_filled_with_stuff() {
} }
a a
}; };
check (res == 10); assert (res == 10);
} }
fn main() { fn main() {

View File

@ -5,12 +5,12 @@
fn test_box() { fn test_box() {
auto res = if (true) { @100 } else { @101 }; auto res = if (true) { @100 } else { @101 };
check (*res == 100); assert (*res == 100);
} }
fn test_str() { fn test_str() {
auto res = if (true) { "happy" } else { "sad" }; auto res = if (true) { "happy" } else { "sad" };
check (res == "happy"); assert (res == "happy");
} }
fn main() { fn main() {

View File

@ -5,7 +5,7 @@ type compare[T] = fn(@T t1, @T t2) -> bool;
fn test_generic[T](@T expected, @T not_expected, &compare[T] eq) { fn test_generic[T](@T expected, @T not_expected, &compare[T] eq) {
let @T actual = if (true) { expected } else { not_expected }; let @T actual = if (true) { expected } else { not_expected };
check (eq(expected, actual)); assert (eq(expected, actual));
} }
fn test_box() { fn test_box() {

View File

@ -5,7 +5,7 @@ type compare[T] = fn(&T t1, &T t2) -> bool;
fn test_generic[T](&T expected, &T not_expected, &compare[T] eq) { fn test_generic[T](&T expected, &T not_expected, &compare[T] eq) {
let T actual = if (true) { expected } else { not_expected }; let T actual = if (true) { expected } else { not_expected };
check (eq(expected, actual)); assert (eq(expected, actual));
} }
fn test_vec() { fn test_vec() {

View File

@ -7,7 +7,7 @@ type compare[T] = fn(&T t1, &T t2) -> bool;
fn test_generic[T](&T expected, &T not_expected, &compare[T] eq) { fn test_generic[T](&T expected, &T not_expected, &compare[T] eq) {
let T actual = if (true) { expected } else { not_expected }; let T actual = if (true) { expected } else { not_expected };
check (eq(expected, actual)); assert (eq(expected, actual));
} }
fn test_bool() { fn test_bool() {

View File

@ -5,7 +5,7 @@
fn test_rec() { fn test_rec() {
auto res = if (true) { rec(i = 100) } else { rec(i = 101) }; auto res = if (true) { rec(i = 100) } else { rec(i = 101) };
check (res == rec(i = 100)); assert (res == rec(i = 100));
} }
fn test_tag() { fn test_tag() {
@ -15,7 +15,7 @@ fn test_tag() {
} }
auto res = if (true) { happy } else { sad }; auto res = if (true) { happy } else { sad };
check (res == happy); assert (res == happy);
} }
fn main() { fn main() {

View File

@ -5,12 +5,12 @@
fn test_if() { fn test_if() {
let bool res = if (true) { true } else { false }; let bool res = if (true) { true } else { false };
check (res); assert (res);
} }
fn test_else() { fn test_else() {
let bool res = if (false) { false } else { true }; let bool res = if (false) { false } else { true };
check (res); assert (res);
} }
fn test_elseif1() { fn test_elseif1() {
@ -21,7 +21,7 @@ fn test_elseif1() {
} else { } else {
false false
}; };
check (res); assert (res);
} }
fn test_elseif2() { fn test_elseif2() {
@ -32,7 +32,7 @@ fn test_elseif2() {
} else { } else {
false false
}; };
check (res); assert (res);
} }
fn test_elseif3() { fn test_elseif3() {
@ -43,12 +43,12 @@ fn test_elseif3() {
} else { } else {
true true
}; };
check (res); assert (res);
} }
fn test_inferrence() { fn test_inferrence() {
auto res = if (true) { true } else { false }; auto res = if (true) { true } else { false };
check (res); assert (res);
} }
fn test_if_as_if_condition() { fn test_if_as_if_condition() {
@ -57,14 +57,14 @@ fn test_if_as_if_condition() {
} else { } else {
false false
}; };
check (res1); assert (res1);
auto res2 = if (if (true) { false } else { true }) { auto res2 = if (if (true) { false } else { true }) {
false false
} else { } else {
true true
}; };
check (res2); assert (res2);
} }
fn test_if_as_block_result() { fn test_if_as_block_result() {
@ -77,7 +77,7 @@ fn test_if_as_block_result() {
} else { } else {
false false
}; };
check (res); assert (res);
} }
fn main() { fn main() {

View File

@ -3,16 +3,16 @@
type point = rec(int x, int y, mutable int z); type point = rec(int x, int y, mutable int z);
fn f(@point p) { fn f(@point p) {
check (p.z == 12); assert (p.z == 12);
p.z = 13; p.z = 13;
check (p.z == 13); assert (p.z == 13);
} }
fn main() { fn main() {
let point a = rec(x=10, y=11, mutable z=12); let point a = rec(x=10, y=11, mutable z=12);
let @point b = @a; let @point b = @a;
check (b.z == 12); assert (b.z == 12);
f(b); f(b);
check (a.z == 12); assert (a.z == 12);
check (b.z == 13); assert (b.z == 13);
} }

View File

@ -15,7 +15,7 @@ fn f(int x) -> int {
} }
} }
fn main () { fn main () {
check (f(5) == 120); assert (f(5) == 120);
// log "all done"; // log "all done";
} }

View File

@ -12,13 +12,13 @@ fn main() {
auto j = 3.1e+9; auto j = 3.1e+9;
auto k = 3.2e-10; auto k = 3.2e-10;
check(a == b); assert (a == b);
check(c < b); assert (c < b);
check(c == d); assert (c == d);
check(e < g); assert (e < g);
check(f < h); assert (f < h);
check(g == 1000000.0f32); assert (g == 1000000.0f32);
check(h == i); assert (h == i);
check(j > k); assert (j > k);
check(k < a); assert (k < a);
} }

View File

@ -1,9 +1,9 @@
// xfail-boot // xfail-boot
fn main() { fn main() {
auto f = 4.999999999999; auto f = 4.999999999999;
check (f > 4.90); assert (f > 4.90);
check (f < 5.0); assert (f < 5.0);
auto g = 4.90000000001e-10; auto g = 4.90000000001e-10;
check(g > 5e-11); assert (g > 5e-11);
check(g < 5e-9); assert (g < 5e-9);
} }

View File

@ -28,12 +28,12 @@ fn main() {
} }
} }
check (a.(0) == 0); assert (a.(0) == 0);
check (a.(1) == 1); assert (a.(1) == 1);
check (a.(2) == 10); assert (a.(2) == 10);
check (a.(3) == 11); assert (a.(3) == 11);
check (a.(4) == 100); assert (a.(4) == 100);
check (a.(5) == 101); assert (a.(5) == 101);
check (a.(6) == 110); assert (a.(6) == 110);
check (a.(7) == 111); assert (a.(7) == 111);
} }

View File

@ -16,8 +16,8 @@ fn main() {
} }
} }
check (a.(0) == 0); assert (a.(0) == 0);
check (a.(1) == 1); assert (a.(1) == 1);
check (a.(2) == 10); assert (a.(2) == 10);
check (a.(3) == 11); assert (a.(3) == 11);
} }

View File

@ -14,9 +14,9 @@ fn main() {
for each (tup(int,int) p in pairs()) { for each (tup(int,int) p in pairs()) {
log p._0; log p._0;
log p._1; log p._1;
check (p._0 + 10 == i); assert (p._0 + 10 == i);
i += 1; i += 1;
j = p._1; j = p._1;
} }
check(j == 45); assert (j == 45);
} }

View File

@ -9,7 +9,7 @@ fn main() {
} }
log "sum"; log "sum";
log sum; log sum;
check (sum == 45); assert (sum == 45);
} }
iter first_ten() -> int { iter first_ten() -> int {

View File

@ -13,7 +13,7 @@ fn main() {
let int a = direct(3); // direct let int a = direct(3); // direct
//let int b = ho(direct); // indirect unbound //let int b = ho(direct); // indirect unbound
let int c = ho(bind direct(_)); // indirect bound let int c = ho(bind direct(_)); // indirect bound
//check(a == b); //assert (a == b);
//check(b == c); //assert (b == c);
} }

View File

@ -7,5 +7,5 @@ fn f() -> int {
fn main() { fn main() {
let fn() -> int g = f; let fn() -> int g = f;
let int i = g(); let int i = g();
check(i == 42); assert (i == 42);
} }

View File

@ -8,5 +8,5 @@ fn main() {
auto expected = @100; auto expected = @100;
auto actual = id[@int](expected); auto actual = id[@int](expected);
log *actual; log *actual;
check (*expected == *actual); assert (*expected == *actual);
} }

View File

@ -5,7 +5,7 @@ fn id[T](&T t) -> T {
fn main() { fn main() {
auto t = tup(1,2,3,4,5,6,7); auto t = tup(1,2,3,4,5,6,7);
check (t._5 == 6); assert (t._5 == 6);
auto f0 = bind id[tup(int,int,int,int,int,int,int)](t); auto f0 = bind id[tup(int,int,int,int,int,int,int)](t);
check (f0()._5 == 6); assert (f0()._5 == 6);
} }

View File

@ -4,7 +4,7 @@ fn id[T](&T t) -> T {
fn main() { fn main() {
auto t = tup(1,2,3,4,5,6,7); auto t = tup(1,2,3,4,5,6,7);
check (t._5 == 6); assert (t._5 == 6);
auto f1 = bind id[tup(int,int,int,int,int,int,int)](_); auto f1 = bind id[tup(int,int,int,int,int,int,int)](_);
check (f1(t)._5 == 6); assert (f1(t)._5 == 6);
} }

View File

@ -4,5 +4,5 @@ fn box[T](&tup(T,T,T) x) -> @tup(T,T,T) {
fn main() { fn main() {
let @tup(int,int,int) x = box[int](tup(1,2,3)); let @tup(int,int,int) x = box[int](tup(1,2,3));
check (x._1 == 2); assert (x._1 == 2);
} }

View File

@ -12,6 +12,6 @@ fn main() {
auto b = f[int](10); auto b = f[int](10);
log b._0; log b._0;
log b._1; log b._1;
check (b._0 == 10); assert (b._0 == 10);
check (b._1 == 10); assert (b._1 == 10);
} }

View File

@ -8,6 +8,6 @@ fn main() {
let int foo = 17; let int foo = 17;
let tupbox[int] tbfoo = tuplift[int](foo); let tupbox[int] tbfoo = tuplift[int](foo);
let recbox[int] rbfoo = reclift[int](foo); let recbox[int] rbfoo = reclift[int](foo);
check (tbfoo._0 == foo); assert (tbfoo._0 == foo);
check (rbfoo.x == foo); assert (rbfoo.x == foo);
} }

Some files were not shown because too many files have changed in this diff Show More