diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2011-05-02 11:23:07 -0700 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2011-05-02 12:16:29 -0700 |
| commit | aa25f22f197682de3b18fc4c8ba068d1feda220f (patch) | |
| tree | 6d01f8fbb5680964fd9c53564c96aa58cb75d3d1 /src/lib | |
| parent | 870435caf55fe167862865bfe4196230ab7c1c6b (diff) | |
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.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/Term.rs | 2 | ||||
| -rw-r--r-- | src/lib/_int.rs | 2 | ||||
| -rw-r--r-- | src/lib/_str.rs | 14 | ||||
| -rw-r--r-- | src/lib/_uint.rs | 2 | ||||
| -rw-r--r-- | src/lib/_vec.rs | 11 | ||||
| -rw-r--r-- | src/lib/bitv.rs | 10 | ||||
| -rw-r--r-- | src/lib/deque.rs | 2 | ||||
| -rw-r--r-- | src/lib/ebml.rs | 2 | ||||
| -rw-r--r-- | src/lib/fs.rs | 2 | ||||
| -rw-r--r-- | src/lib/io.rs | 10 | ||||
| -rw-r--r-- | src/lib/linux_os.rs | 4 | ||||
| -rw-r--r-- | src/lib/macos_os.rs | 4 | ||||
| -rw-r--r-- | src/lib/posix_fs.rs | 2 | ||||
| -rw-r--r-- | src/lib/sha1.rs | 8 | ||||
| -rw-r--r-- | src/lib/win32_os.rs | 2 |
15 files changed, 39 insertions, 38 deletions
diff --git a/src/lib/Term.rs b/src/lib/Term.rs index 0d925d7d024..368fe21710e 100644 --- a/src/lib/Term.rs +++ b/src/lib/Term.rs @@ -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) { diff --git a/src/lib/_int.rs b/src/lib/_int.rs index dfd2204d007..1824d142dab 100644 --- a/src/lib/_int.rs +++ b/src/lib/_int.rs @@ -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 { diff --git a/src/lib/_str.rs b/src/lib/_str.rs index 44f14fb6e1c..ed2027e1da2 100644 --- a/src/lib/_str.rs +++ b/src/lib/_str.rs @@ -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; diff --git a/src/lib/_uint.rs b/src/lib/_uint.rs index 97108c9082b..2d373cdd2ba 100644 --- a/src/lib/_uint.rs +++ b/src/lib/_uint.rs @@ -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'; } diff --git a/src/lib/_vec.rs b/src/lib/_vec.rs index 126bf363052..4761a867494 100644 --- a/src/lib/_vec.rs +++ b/src/lib/_vec.rs @@ -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); diff --git a/src/lib/bitv.rs b/src/lib/bitv.rs index feb4296aa6e..f52b016b768 100644 --- a/src/lib/bitv.rs +++ b/src/lib/bitv.rs @@ -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) { diff --git a/src/lib/deque.rs b/src/lib/deque.rs index 776f82e99fe..ee706ae7e7d 100644 --- a/src/lib/deque.rs +++ b/src/lib/deque.rs @@ -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] { diff --git a/src/lib/ebml.rs b/src/lib/ebml.rs index f73ad4fc647..9bad0f3311d 100644 --- a/src/lib/ebml.rs +++ b/src/lib/ebml.rs @@ -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) { diff --git a/src/lib/fs.rs b/src/lib/fs.rs index 774ce11324c..e185ca3e8c2 100644 --- a/src/lib/fs.rs +++ b/src/lib/fs.rs @@ -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; diff --git a/src/lib/io.rs b/src/lib/io.rs index 4c1bf2dfb2b..7d59da30400 100644 --- a/src/lib/io.rs +++ b/src/lib/io.rs @@ -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 { diff --git a/src/lib/linux_os.rs b/src/lib/linux_os.rs index d5230e9ae09..d2a8ff97aaf 100644 --- a/src/lib/linux_os.rs +++ b/src/lib/linux_os.rs @@ -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); } diff --git a/src/lib/macos_os.rs b/src/lib/macos_os.rs index b0980bc5225..a52b02c5658 100644 --- a/src/lib/macos_os.rs +++ b/src/lib/macos_os.rs @@ -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); } diff --git a/src/lib/posix_fs.rs b/src/lib/posix_fs.rs index 03115fc7d33..f4cf12d35f2 100644 --- a/src/lib/posix_fs.rs +++ b/src/lib/posix_fs.rs @@ -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); diff --git a/src/lib/sha1.rs b/src/lib/sha1.rs index 3866be1e04c..690489db345 100644 --- a/src/lib/sha1.rs +++ b/src/lib/sha1.rs @@ -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; diff --git a/src/lib/win32_os.rs b/src/lib/win32_os.rs index a2940d8de55..1c6521e31f6 100644 --- a/src/lib/win32_os.rs +++ b/src/lib/win32_os.rs @@ -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)); } |
