about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-03-16 11:11:31 -0700
committerPatrick Walton <pcwalton@mimiga.net>2013-03-18 17:21:16 -0700
commite78f2e2ac577f9c47cd58af52d3bcd496254545d (patch)
treef05564837fe02f676458ea86b705709715c44017 /src/libstd
parentc4db4faefaf13ac814f34c2a6cf105b7684de019 (diff)
downloadrust-e78f2e2ac577f9c47cd58af52d3bcd496254545d.tar.gz
rust-e78f2e2ac577f9c47cd58af52d3bcd496254545d.zip
librustc: Make the compiler ignore purity.
For bootstrapping purposes, this commit does not remove all uses of
the keyword "pure" -- doing so would cause the compiler to no longer
bootstrap due to some syntax extensions ("deriving" in particular).
Instead, it makes the compiler ignore "pure". Post-snapshot, we can
remove "pure" from the language.

There are quite a few (~100) borrow check errors that were essentially
all the result of mutable fields or partial borrows of `@mut`. Per
discussions with Niko I think we want to allow partial borrows of
`@mut` but detect obvious footguns. We should also improve the error
message when `@mut` is erroneously reborrowed.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/bitv.rs4
-rw-r--r--src/libstd/deque.rs4
-rw-r--r--src/libstd/flatpipes.rs6
-rw-r--r--src/libstd/json.rs10
-rw-r--r--src/libstd/net_tcp.rs5
-rw-r--r--src/libstd/oldmap.rs18
-rw-r--r--src/libstd/priority_queue.rs4
-rw-r--r--src/libstd/sha1.rs2
-rw-r--r--src/libstd/smallintmap.rs11
-rw-r--r--src/libstd/sort.rs33
-rw-r--r--src/libstd/test.rs6
-rw-r--r--src/libstd/treemap.rs8
12 files changed, 68 insertions, 43 deletions
diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs
index 9cf2d145eac..430a5eab64e 100644
--- a/src/libstd/bitv.rs
+++ b/src/libstd/bitv.rs
@@ -700,8 +700,8 @@ impl cmp::Eq for BitvSet {
 }
 
 impl Container for BitvSet {
-    pure fn len(&self) -> uint { self.size }
-    pure fn is_empty(&self) -> bool { self.size == 0 }
+    pure fn len(&const self) -> uint { self.size }
+    pure fn is_empty(&const self) -> bool { self.size == 0 }
 }
 
 impl Mutable for BitvSet {
diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs
index 90269e28b8a..86304f48e79 100644
--- a/src/libstd/deque.rs
+++ b/src/libstd/deque.rs
@@ -23,10 +23,10 @@ pub struct Deque<T> {
 
 impl<T> Container for Deque<T> {
     /// Return the number of elements in the deque
-    pure fn len(&self) -> uint { self.nelts }
+    pure fn len(&const self) -> uint { self.nelts }
 
     /// Return true if the deque contains no elements
-    pure fn is_empty(&self) -> bool { self.len() == 0 }
+    pure fn is_empty(&const self) -> bool { self.len() == 0 }
 }
 
 impl<T> Mutable for Deque<T> {
diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs
index e2e09f1d675..c5515c63b29 100644
--- a/src/libstd/flatpipes.rs
+++ b/src/libstd/flatpipes.rs
@@ -569,12 +569,12 @@ pub mod bytepipes {
 
     impl BytePort for PipeBytePort {
         fn try_recv(&self, count: uint) -> Option<~[u8]> {
-            if self.buf.len() >= count {
+            if vec::uniq_len(&const self.buf) >= count {
                 let mut bytes = ::core::util::replace(&mut self.buf, ~[]);
                 self.buf = bytes.slice(count, bytes.len());
                 bytes.truncate(count);
                 return Some(bytes);
-            } else if self.buf.len() > 0 {
+            } else if vec::uniq_len(&const self.buf) > 0 {
                 let mut bytes = ::core::util::replace(&mut self.buf, ~[]);
                 fail_unless!(count > bytes.len());
                 match self.try_recv(count - bytes.len()) {
@@ -584,7 +584,7 @@ pub mod bytepipes {
                     }
                     None => return None
                 }
-            } else if self.buf.is_empty() {
+            } else if vec::uniq_len(&const self.buf) == 0 {
                 match self.port.try_recv() {
                     Some(buf) => {
                         fail_unless!(!buf.is_empty());
diff --git a/src/libstd/json.rs b/src/libstd/json.rs
index e52d08c40fe..f2f37604fb5 100644
--- a/src/libstd/json.rs
+++ b/src/libstd/json.rs
@@ -757,12 +757,16 @@ pub fn Decoder(json: Json) -> Decoder {
 
 priv impl Decoder/&self {
     fn peek(&self) -> &'self Json {
-        if self.stack.len() == 0 { self.stack.push(&self.json); }
-        self.stack[self.stack.len() - 1]
+        if vec::uniq_len(&const self.stack) == 0 {
+            self.stack.push(&self.json);
+        }
+        self.stack[vec::uniq_len(&const self.stack) - 1]
     }
 
     fn pop(&self) -> &'self Json {
-        if self.stack.len() == 0 { self.stack.push(&self.json); }
+        if vec::uniq_len(&const self.stack) == 0 {
+            self.stack.push(&self.json);
+        }
         self.stack.pop()
     }
 }
diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs
index 54fbae956ce..a93e94e0d04 100644
--- a/src/libstd/net_tcp.rs
+++ b/src/libstd/net_tcp.rs
@@ -879,7 +879,8 @@ impl io::Reader for TcpSocketBuf {
 
           // If possible, copy up to `len` bytes from the internal
           // `data.buf` into `buf`
-          let nbuffered = self.data.buf.len() - self.data.buf_off;
+          let nbuffered = vec::uniq_len(&const self.data.buf) -
+                self.data.buf_off;
           let needed = len - count;
             if nbuffered > 0 {
                 unsafe {
@@ -931,7 +932,7 @@ impl io::Reader for TcpSocketBuf {
     }
     fn read_byte(&self) -> int {
         loop {
-          if self.data.buf.len() > self.data.buf_off {
+          if vec::uniq_len(&const self.data.buf) > self.data.buf_off {
             let c = self.data.buf[self.data.buf_off];
             self.data.buf_off += 1;
             return c as int
diff --git a/src/libstd/oldmap.rs b/src/libstd/oldmap.rs
index a4b00e4dd04..0a07a24e8ee 100644
--- a/src/libstd/oldmap.rs
+++ b/src/libstd/oldmap.rs
@@ -101,7 +101,7 @@ pub mod chained {
         }
 
         pure fn search_tbl(&self, k: &K, h: uint) -> SearchResult<K,V> {
-            let idx = h % vec::len(self.chains);
+            let idx = h % vec::uniq_len(&const self.chains);
             match copy self.chains[idx] {
               None => {
                 debug!("search_tbl: none, comp %u, hash %u, idx %u",
@@ -121,7 +121,7 @@ pub mod chained {
         }
 
         fn rehash(@self) {
-            let n_old_chains = self.chains.len();
+            let n_old_chains = vec::uniq_len(&const self.chains);
             let n_new_chains: uint = uint::next_power_of_two(n_old_chains+1u);
             let mut new_chains = chains(n_new_chains);
             for self.each_entry |entry| {
@@ -137,7 +137,7 @@ pub mod chained {
         pure fn each_entry(&self, blk: &fn(@Entry<K,V>) -> bool) {
             // n.b. we can't use vec::iter() here because self.chains
             // is stored in a mutable location.
-            let mut i = 0u, n = self.chains.len();
+            let mut i = 0u, n = vec::uniq_len(&const self.chains);
             while i < n {
                 let mut chain = self.chains[i];
                 loop {
@@ -161,8 +161,8 @@ pub mod chained {
     }
 
     impl<K:Eq + IterBytes + Hash,V> Container for HashMap_<K, V> {
-        pure fn len(&self) -> uint { self.count }
-        pure fn is_empty(&self) -> bool { self.count == 0 }
+        pure fn len(&const self) -> uint { self.count }
+        pure fn is_empty(&const self) -> bool { self.count == 0 }
     }
 
     pub impl<K:Eq + IterBytes + Hash,V> HashMap_<K, V> {
@@ -179,7 +179,7 @@ pub mod chained {
             match self.search_tbl(&k, hash) {
               NotFound => {
                 self.count += 1u;
-                let idx = hash % vec::len(self.chains);
+                let idx = hash % vec::uniq_len(&const self.chains);
                 let old_chain = self.chains[idx];
                 self.chains[idx] = Some(@Entry {
                     hash: hash,
@@ -188,7 +188,7 @@ pub mod chained {
                     next: old_chain});
 
                 // consider rehashing if more 3/4 full
-                let nchains = vec::len(self.chains);
+                let nchains = vec::uniq_len(&const self.chains);
                 let load = util::Rational {
                     num: (self.count + 1u) as int,
                     den: nchains as int,
@@ -271,7 +271,7 @@ pub mod chained {
             match self.search_tbl(&key, hash) {
               NotFound => {
                 self.count += 1u;
-                let idx = hash % vec::len(self.chains);
+                let idx = hash % vec::uniq_len(&const self.chains);
                 let old_chain = self.chains[idx];
                 self.chains[idx] = Some(@Entry {
                     hash: hash,
@@ -280,7 +280,7 @@ pub mod chained {
                     next: old_chain});
 
                 // consider rehashing if more 3/4 full
-                let nchains = vec::len(self.chains);
+                let nchains = vec::uniq_len(&const self.chains);
                 let load = util::Rational {
                     num: (self.count + 1u) as int,
                     den: nchains as int,
diff --git a/src/libstd/priority_queue.rs b/src/libstd/priority_queue.rs
index b9b5075c434..a5a291c5b18 100644
--- a/src/libstd/priority_queue.rs
+++ b/src/libstd/priority_queue.rs
@@ -37,10 +37,10 @@ impl<T:Ord> BaseIter<T> for PriorityQueue<T> {
 
 impl<T:Ord> Container for PriorityQueue<T> {
     /// Returns the length of the queue
-    pure fn len(&self) -> uint { self.data.len() }
+    pure fn len(&const self) -> uint { vec::uniq_len(&const self.data) }
 
     /// Returns true if a queue contains no elements
-    pure fn is_empty(&self) -> bool { self.data.is_empty() }
+    pure fn is_empty(&const self) -> bool { self.len() == 0 }
 }
 
 impl<T:Ord> Mutable for PriorityQueue<T> {
diff --git a/src/libstd/sha1.rs b/src/libstd/sha1.rs
index b1ef0233d97..f7e31bc7df7 100644
--- a/src/libstd/sha1.rs
+++ b/src/libstd/sha1.rs
@@ -91,7 +91,7 @@ pub fn sha1() -> @Sha1 {
     }
     fn process_msg_block(st: &mut Sha1State) {
         fail_unless!((vec::len(st.h) == digest_buf_len));
-        fail_unless!((vec::len(*st.work_buf) == work_buf_len));
+        fail_unless!((vec::uniq_len(st.work_buf) == work_buf_len));
         let mut t: int; // Loop counter
         let mut w = st.work_buf;
 
diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs
index c63ef9b7258..dc2688a20e7 100644
--- a/src/libstd/smallintmap.rs
+++ b/src/libstd/smallintmap.rs
@@ -50,18 +50,19 @@ impl<V> ReverseIter<(uint, &'self V)> for SmallIntMap<V> {
 
 impl<V> Container for SmallIntMap<V> {
     /// Return the number of elements in the map
-    pure fn len(&self) -> uint {
+    pure fn len(&const self) -> uint {
         let mut sz = 0;
-        for self.v.each |item| {
-            if item.is_some() {
-                sz += 1;
+        for uint::range(0, vec::uniq_len(&const self.v)) |i| {
+            match self.v[i] {
+                Some(_) => sz += 1,
+                None => {}
             }
         }
         sz
     }
 
     /// Return true if the map contains no elements
-    pure fn is_empty(&self) -> bool { self.len() == 0 }
+    pure fn is_empty(&const self) -> bool { self.len() == 0 }
 }
 
 impl<V> Mutable for SmallIntMap<V> {
diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs
index 43c68196eb8..40be303a147 100644
--- a/src/libstd/sort.rs
+++ b/src/libstd/sort.rs
@@ -68,9 +68,14 @@ fn part<T>(arr: &mut [T], left: uint,
     let mut storage_index: uint = left;
     let mut i: uint = left;
     while i < right {
-        if compare_func(&arr[i], &arr[right]) {
-            arr[i] <-> arr[storage_index];
-            storage_index += 1;
+        // XXX: Unsafe because borrow check doesn't handle this right
+        unsafe {
+            let a: &T = cast::transmute(&mut arr[i]);
+            let b: &T = cast::transmute(&mut arr[right]);
+            if compare_func(a, b) {
+                arr[i] <-> arr[storage_index];
+                storage_index += 1;
+            }
         }
         i += 1;
     }
@@ -451,7 +456,10 @@ impl<T:Copy + Ord> MergeState<T> {
                 base2: uint, len2: uint) {
         fail_unless!(len1 != 0 && len2 != 0 && base1+len1 == base2);
 
-        let mut tmp = vec::slice(array, base1, base1+len1).to_vec();
+        let mut tmp = ~[];
+        for uint::range(base1, base1+len1) |i| {
+            tmp.push(array[i]);
+        }
 
         let mut c1 = 0;
         let mut c2 = base2;
@@ -554,7 +562,10 @@ impl<T:Copy + Ord> MergeState<T> {
                 base2: uint, len2: uint) {
         fail_unless!(len1 != 1 && len2 != 0 && base1 + len1 == base2);
 
-        let mut tmp = vec::slice(array, base2, base2+len2).to_vec();
+        let mut tmp = ~[];
+        for uint::range(base2, base2+len2) |i| {
+            tmp.push(array[i]);
+        }
 
         let mut c1 = base1 + len1 - 1;
         let mut c2 = len2 - 1;
@@ -702,7 +713,11 @@ fn copy_vec<T:Copy>(dest: &mut [T], s1: uint,
                     from: &[const T], s2: uint, len: uint) {
     fail_unless!(s1+len <= dest.len() && s2+len <= from.len());
 
-    let slice = vec::slice(from, s2, s2+len).to_vec();
+    let mut slice = ~[];
+    for uint::range(s2, s2+len) |i| {
+        slice.push(from[i]);
+    }
+
     for slice.eachi |i, v| {
         dest[s1+i] = *v;
     }
@@ -721,7 +736,7 @@ mod test_qsort3 {
         quick_sort3::<int>(v1);
         let mut i = 0;
         while i < len {
-            debug!(v2[i]);
+            // debug!(v2[i]);
             fail_unless!((v2[i] == v1[i]));
             i += 1;
         }
@@ -768,7 +783,7 @@ mod test_qsort {
         quick_sort::<int>(v1, leual);
         let mut i = 0u;
         while i < len {
-            debug!(v2[i]);
+            // debug!(v2[i]);
             fail_unless!((v2[i] == v1[i]));
             i += 1;
         }
@@ -919,7 +934,7 @@ mod test_tim_sort {
         tim_sort::<int>(v1);
         let mut i = 0u;
         while i < len {
-            debug!(v2[i]);
+            // debug!(v2[i]);
             fail_unless!((v2[i] == v1[i]));
             i += 1u;
         }
diff --git a/src/libstd/test.rs b/src/libstd/test.rs
index 63cf4c998df..fcc60c8d978 100644
--- a/src/libstd/test.rs
+++ b/src/libstd/test.rs
@@ -358,7 +358,11 @@ pub fn run_tests_console(opts: &TestOpts,
 
 fn print_failures(st: @ConsoleTestState) {
     st.out.write_line(~"\nfailures:");
-    let mut failures = st.failures.map(|t| t.name.to_str());
+    let mut failures = ~[];
+    for uint::range(0, vec::uniq_len(&const st.failures)) |i| {
+        let name = copy st.failures[i].name;
+        failures.push(name.to_str());
+    }
     sort::tim_sort(failures);
     for vec::each(failures) |name| {
         st.out.write_line(fmt!("    %s", name.to_str()));
diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs
index 7192da7b88e..f4d58568ae7 100644
--- a/src/libstd/treemap.rs
+++ b/src/libstd/treemap.rs
@@ -106,10 +106,10 @@ impl<'self, K: TotalOrd, V>
 
 impl<K: TotalOrd, V> Container for TreeMap<K, V> {
     /// Return the number of elements in the map
-    pure fn len(&self) -> uint { self.length }
+    pure fn len(&const self) -> uint { self.length }
 
     /// Return true if the map contains no elements
-    pure fn is_empty(&self) -> bool { self.root.is_none() }
+    pure fn is_empty(&const self) -> bool { self.root.is_none() }
 }
 
 impl<K: TotalOrd, V> Mutable for TreeMap<K, V> {
@@ -276,11 +276,11 @@ impl<T: Ord + TotalOrd> Ord for TreeSet<T> {
 impl<T: TotalOrd> Container for TreeSet<T> {
     /// Return the number of elements in the set
     #[inline(always)]
-    pure fn len(&self) -> uint { self.map.len() }
+    pure fn len(&const self) -> uint { self.map.len() }
 
     /// Return true if the set contains no elements
     #[inline(always)]
-    pure fn is_empty(&self) -> bool { self.map.is_empty() }
+    pure fn is_empty(&const self) -> bool { self.map.is_empty() }
 }
 
 impl<T: TotalOrd> Mutable for TreeSet<T> {