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

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

View file

@ -27,7 +27,7 @@ iter range(int lo, int hi) -> int {
fn to_str(int n, uint radix) -> str
{
check (0u < radix && radix <= 16u);
assert (0u < radix && radix <= 16u);
if (n < 0) {
ret "-" + _uint.to_str((-n) as uint, radix);
} 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) {
auto b0 = s.(i);
auto w = utf8_char_width(b0);
check(w != 0u);
assert (w != 0u);
if (w == 1u) {ret tup(b0 as char, i + 1u);}
auto val = 0u;
auto end = i + w;
i += 1u;
while (i < end) {
auto byte = s.(i);
check(byte & 0xc0_u8 == tag_cont_u8);
assert (byte & 0xc0_u8 == tag_cont_u8);
val <<= 6u;
val += (byte & 0x3f_u8) as uint;
i += 1u;
@ -247,11 +247,11 @@ fn char_len(str s) -> uint {
auto total = byte_len(s);
while (i < total) {
auto chsize = utf8_char_width(s.(i));
check(chsize > 0u);
assert (chsize > 0u);
len += 1u;
i += chsize;
}
check(i == total);
assert (i == total);
ret len;
}
@ -274,7 +274,7 @@ fn push_char(&mutable str s, char ch) {
fn pop_char(&mutable str s) -> char {
auto end = byte_len(s);
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);
s = substr(s, 0u, end - 1u);
ret ch;
@ -404,7 +404,7 @@ fn slice(str s, uint begin, uint end) -> str {
fn shift_byte(&mutable str s) -> u8 {
auto len = byte_len(s);
check(len > 0u);
assert (len > 0u);
auto b = s.(0);
s = substr(s, 1u, len - 1u);
ret b;
@ -412,7 +412,7 @@ fn shift_byte(&mutable str s) -> u8 {
fn pop_byte(&mutable str s) -> u8 {
auto len = byte_len(s);
check(len > 0u);
assert (len > 0u);
auto b = s.(len - 1u);
s = substr(s, 0u, len - 1u);
ret b;

View file

@ -56,7 +56,7 @@ fn to_str(uint num, uint radix) -> str
{
auto n = num;
check (0u < radix && radix <= 16u);
assert (0u < radix && radix <= 16u);
fn digit(uint n) -> char {
alt (n) {
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 {
check (offset < len[T](v));
assert (offset < len[T](v));
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.
fn slice[T](array[T] v, uint start, uint end) -> vec[T] {
check (start <= end);
check (end <= len[T](v));
assert (start <= end);
assert (end <= len[T](v));
auto result = alloc[T](end - start);
let uint i = start;
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 {
auto ln = len[T](v);
check(ln > 0u);
assert (ln > 0u);
auto e = v.(0);
v = slice[T](v, 1u, ln);
ret e;
@ -171,7 +172,7 @@ fn shift[T](&mutable array[T] v) -> T {
fn pop[T](&mutable array[T] v) -> T {
auto ln = len[T](v);
check(ln > 0u);
assert (ln > 0u);
ln -= 1u;
auto e = v.(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 {
auto len = _vec.len[mutable uint](v1.storage);
check (_vec.len[mutable uint](v0.storage) == len);
check (v0.nbits == v1.nbits);
assert (_vec.len[mutable uint](v0.storage) == len);
assert (v0.nbits == v1.nbits);
auto changed = false;
@ -84,7 +84,7 @@ fn clone(t v) -> t {
}
fn get(&t v, uint i) -> bool {
check (i < v.nbits);
assert (i < v.nbits);
auto bits = uint_bits();
@ -129,7 +129,7 @@ fn difference(&t v0, &t v1) -> bool {
}
fn set(&t v, uint i, bool x) {
check (i < v.nbits);
assert (i < v.nbits);
auto bits = uint_bits();
@ -196,7 +196,7 @@ fn to_str(&t v) -> str {
// FIXME: can we just use structural equality on to_vec?
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 i = 0u;
while (i < len) {

View file

@ -28,7 +28,7 @@ fn create[T]() -> t[T] {
* elsewhere.
*/
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,
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 {
auto sz = size;
check (sz <= 4u);
assert (sz <= 4u);
auto val = 0u;
auto pos = start;
while (sz > 0u) {

View file

@ -10,7 +10,7 @@ type path = str;
fn dirname(path p) -> path {
auto sep = path_sep();
check (_str.byte_len(sep) == 1u);
assert (_str.byte_len(sep) == 1u);
let int i = _str.rindex(p, sep.(0));
if (i == -1) {
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;
}
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 {
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?
auto b0 = c0 as u8;
auto w = _str.utf8_char_width(b0);
check(w > 0u);
assert (w > 0u);
if (w == 1u) {ret b0 as char;}
auto val = 0u;
while (w > 1u) {
w -= 1u;
auto next = rdr.read_byte();
check(next > -1);
check(next & 0xc0 == 0x80);
assert (next > -1);
assert (next & 0xc0 == 0x80);
val <<= 6u;
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) {
check(os.libc.fseek(f, offset, convert_whence(whence)) == 0);
assert (os.libc.fseek(f, offset, convert_whence(whence)) == 0);
}
fn tell() -> uint {

View file

@ -66,7 +66,7 @@ fn dylib_filename(str base) -> str {
fn pipe() -> tup(int, int) {
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));
}
@ -76,7 +76,7 @@ fn fd_FILE(int fd) -> libc.FILE {
fn waitpid(int pid) -> int {
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);
}

View file

@ -63,7 +63,7 @@ fn dylib_filename(str base) -> str {
fn pipe() -> tup(int, int) {
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));
}
@ -73,7 +73,7 @@ fn fd_FILE(int fd) -> libc.FILE {
fn waitpid(int pid) -> int {
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);
}

View file

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

View file

@ -43,7 +43,7 @@ fn mk_sha1() -> sha1 {
fn add_input(&sha1state st, &vec[u8] msg) {
// FIXME: Should be typestate precondition
check (!st.computed);
assert (!st.computed);
for (u8 element in msg) {
st.msg_block.(st.msg_block_idx) = element;
@ -67,7 +67,7 @@ fn mk_sha1() -> sha1 {
fn process_msg_block(&sha1state st) {
// FIXME: Make precondition
check (_vec.len[mutable u32](st.h) == digest_buf_len);
assert (_vec.len[mutable u32](st.h) == digest_buf_len);
// Constants
auto k = vec(0x5A827999u32,
@ -192,7 +192,7 @@ fn mk_sha1() -> sha1 {
*/
fn pad_msg(&sha1state st) {
// 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
@ -236,7 +236,7 @@ fn mk_sha1() -> sha1 {
fn reset() {
// 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_high = 0u32;

View file

@ -53,7 +53,7 @@ fn dylib_filename(str base) -> str {
fn pipe() -> tup(int, int) {
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);
ret tup(fds.(0), fds.(1));
}