From 3bdd515e47cc2e52e1ad82b74ecf0b47fbaf756c Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 9 Nov 2017 10:53:37 +1100 Subject: [PATCH] Allow "assert foo", not just "assert foo < bar". --- gen/c/std/flate.c | 2 +- lang/check/bounds.go | 8 ++++++++ std/flate/decode_huffman_fast.puffs | 8 ++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/gen/c/std/flate.c b/gen/c/std/flate.c index 944a0c4b..c1a44da1 100644 --- a/gen/c/std/flate.c +++ b/gen/c/std/flate.c @@ -2017,7 +2017,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast( b_rend_src = b_rptr_src + len; } - if ((a_dst.private_impl.mark != NULL) != true) { + if (!(a_dst.private_impl.mark != NULL)) { status = PUFFS_FLATE__ERROR_BAD_ARGUMENT; goto exit; } diff --git a/lang/check/bounds.go b/lang/check/bounds.go index f3d6fb3e..d67a5d99 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -310,8 +310,15 @@ func (q *checker) bcheckStatement(n *a.Node) error { } func (q *checker) bcheckAssert(n *a.Assert) error { + // TODO: check, here or elsewhere, that the condition is pure. condition := n.Condition() + for _, x := range q.facts { + if x.Eq(condition) { + return nil + } + } err := errFailed + if cv := condition.ConstValue(); cv != nil { if cv.Cmp(one) == 0 { err = nil @@ -325,6 +332,7 @@ func (q *checker) bcheckAssert(n *a.Assert) error { } else if condition.ID0().IsBinaryOp() && condition.ID0().Key() != t.KeyAs { err = q.proveBinaryOp(condition.ID0().Key(), condition.LHS().Expr(), condition.RHS().Expr()) } + if err != nil { if err == errFailed { return fmt.Errorf("check: cannot prove %q", condition.String(q.tm)) diff --git a/std/flate/decode_huffman_fast.puffs b/std/flate/decode_huffman_fast.puffs index 37a3f3a1..b2bee1e2 100644 --- a/std/flate/decode_huffman_fast.puffs +++ b/std/flate/decode_huffman_fast.puffs @@ -21,7 +21,7 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() { // correctness and performance. // TODO: make this a func pre-condition. - if in.dst.is_marked() != true { // TODO: if not in.dst.is_marked() { + if not in.dst.is_marked() { return error "bad argument" } @@ -65,7 +65,7 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() { // code requires up to 2 + 2 + 2 == 6 bytes, and there are two codes (one // from H-L and one from H-D). Therefore, we check for at least 12 bytes. while:loop(in.dst.available() >= 258) and (in.src.available() >= 12), - inv in.dst.is_marked() == true, // TODO: remove the redundant "== true". + inv in.dst.is_marked(), { // Ensure that we have at least 15 bits of input. if n_bits < 15 { @@ -268,7 +268,7 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() { // its presence minimizes the diff between decode_huffman_fast and // decode_huffman_slow. while true, - inv in.dst.is_marked() == true, + inv in.dst.is_marked(), { // Copy from this.history. if (distance as u64) > in.dst.since_mark().length() { @@ -298,7 +298,7 @@ pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() { // "etc", but its presence minimizes the diff between // decode_huffman_fast and decode_huffman_slow. while true, - inv in.dst.is_marked() == true, + inv in.dst.is_marked(), { n_copied = in.dst.copy_from_slice32(s:this.history[hdist:], length:hlen) if hlen <= n_copied {