about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/cell.rs13
-rw-r--r--src/libcore/comm.rs10
-rw-r--r--src/libcore/container.rs4
-rw-r--r--src/libcore/hashmap.rs8
-rw-r--r--src/libcore/io.rs4
-rw-r--r--src/libcore/mutable.rs6
-rw-r--r--src/libcore/option.rs8
-rw-r--r--src/libcore/ptr.rs12
-rw-r--r--src/libcore/repr.rs4
-rw-r--r--src/libcore/task/spawn.rs2
-rw-r--r--src/libcore/trie.rs8
-rw-r--r--src/libcore/vec.rs23
12 files changed, 66 insertions, 36 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs
index da247c648fc..cfd1b8dfef0 100644
--- a/src/libcore/cell.rs
+++ b/src/libcore/cell.rs
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use cast::transmute;
 use option;
 use prelude::*;
 
@@ -15,11 +16,21 @@ use prelude::*;
 ///
 /// Similar to a mutable option type, but friendlier.
 
-#[deriving_eq]
 pub struct Cell<T> {
     mut value: Option<T>
 }
 
+impl<T:cmp::Eq> cmp::Eq for Cell<T> {
+    pure fn eq(&self, other: &Cell<T>) -> bool {
+        unsafe {
+            let frozen_self: &Option<T> = transmute(&mut self.value);
+            let frozen_other: &Option<T> = transmute(&mut other.value);
+            frozen_self == frozen_other
+        }
+    }
+    pure fn ne(&self, other: &Cell<T>) -> bool { !self.eq(other) }
+}
+
 /// Creates a new full cell with the given value.
 pub fn Cell<T>(value: T) -> Cell<T> {
     Cell { value: Some(value) }
diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs
index 5b189abf4a3..12dc2d7e341 100644
--- a/src/libcore/comm.rs
+++ b/src/libcore/comm.rs
@@ -8,10 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use cast;
 use either::{Either, Left, Right};
 use kinds::Owned;
 use option;
 use option::{Option, Some, None, unwrap};
+use uint;
 use unstable;
 use vec;
 
@@ -283,8 +285,12 @@ impl<T: Owned> Peekable<T> for PortSet<T> {
 pure fn port_set_peek<T:Owned>(self: &PortSet<T>) -> bool {
     // It'd be nice to use self.port.each, but that version isn't
     // pure.
-    for vec::each(self.ports) |p| {
-        if p.peek() { return true }
+    for uint::range(0, vec::uniq_len(&const self.ports)) |i| {
+        // XXX: Botch pending demuting.
+        unsafe {
+            let port: &Port<T> = cast::transmute(&mut self.ports[i]);
+            if port.peek() { return true }
+        }
     }
     false
 }
diff --git a/src/libcore/container.rs b/src/libcore/container.rs
index efcf1e26534..5044b3a6c5d 100644
--- a/src/libcore/container.rs
+++ b/src/libcore/container.rs
@@ -14,10 +14,10 @@ use option::Option;
 
 pub trait Container {
     /// Return the number of elements in the container
-    pure fn len(&self) -> uint;
+    pure fn len(&const self) -> uint;
 
     /// Return true if the container contains no elements
-    pure fn is_empty(&self) -> bool;
+    pure fn is_empty(&const self) -> bool;
 }
 
 pub trait Mutable: Container {
diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs
index 20d207e9302..68a55792077 100644
--- a/src/libcore/hashmap.rs
+++ b/src/libcore/hashmap.rs
@@ -290,10 +290,10 @@ pub mod linear {
 
     impl<K:Hash + IterBytes + Eq,V> Container for LinearMap<K, V> {
         /// Return the number of elements in the map
-        pure fn len(&self) -> uint { self.size }
+        pure fn len(&const self) -> uint { self.size }
 
         /// 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<K:Hash + IterBytes + Eq,V> Mutable for LinearMap<K, V> {
@@ -555,10 +555,10 @@ pub mod linear {
 
     impl<T:Hash + IterBytes + Eq> Container for LinearSet<T> {
         /// Return the number of elements in the set
-        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
-        pure fn is_empty(&self) -> bool { self.map.is_empty() }
+        pure fn is_empty(&const self) -> bool { self.map.is_empty() }
     }
 
     impl<T:Hash + IterBytes + Eq> Mutable for LinearSet<T> {
diff --git a/src/libcore/io.rs b/src/libcore/io.rs
index b580d9c84a8..50e7a42b7b1 100644
--- a/src/libcore/io.rs
+++ b/src/libcore/io.rs
@@ -1116,7 +1116,7 @@ pub struct BytesWriter {
 impl Writer for BytesWriter {
     fn write(&self, v: &[const u8]) {
         let v_len = v.len();
-        let bytes_len = self.bytes.len();
+        let bytes_len = vec::uniq_len(&const self.bytes);
 
         let count = uint::max(bytes_len, self.pos + v_len);
         vec::reserve(&mut self.bytes, count);
@@ -1131,7 +1131,7 @@ impl Writer for BytesWriter {
     }
     fn seek(&self, offset: int, whence: SeekStyle) {
         let pos = self.pos;
-        let len = self.bytes.len();
+        let len = vec::uniq_len(&const self.bytes);
         self.pos = seek_in_buf(offset, pos, len, whence);
     }
     fn tell(&self) -> uint { self.pos }
diff --git a/src/libcore/mutable.rs b/src/libcore/mutable.rs
index 875d378b645..d0aa6e050f5 100644
--- a/src/libcore/mutable.rs
+++ b/src/libcore/mutable.rs
@@ -46,8 +46,7 @@ pub fn unwrap<T>(m: Mut<T>) -> T {
 pub impl<T> Data<T> {
     fn borrow_mut<R>(&self, op: &fn(t: &mut T) -> R) -> R {
         match self.mode {
-            Immutable => fail!(fmt!("%? currently immutable",
-                                   self.value)),
+            Immutable => fail!(~"currently immutable"),
             ReadOnly | Mutable => {}
         }
 
@@ -62,8 +61,7 @@ pub impl<T> Data<T> {
 
     fn borrow_imm<R>(&self, op: &fn(t: &T) -> R) -> R {
         match self.mode {
-          Mutable => fail!(fmt!("%? currently mutable",
-                               self.value)),
+          Mutable => fail!(~"currently mutable"),
           ReadOnly | Immutable => {}
         }
 
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index 237fc762b3c..5e5396ea121 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -228,14 +228,14 @@ pub pure fn while_some<T>(x: Option<T>, blk: &fn(v: T) -> Option<T>) {
 }
 
 #[inline(always)]
-pub pure fn is_none<T>(opt: &Option<T>) -> bool {
+pub pure fn is_none<T>(opt: &const Option<T>) -> bool {
     //! Returns true if the option equals `none`
 
     match *opt { None => true, Some(_) => false }
 }
 
 #[inline(always)]
-pub pure fn is_some<T>(opt: &Option<T>) -> bool {
+pub pure fn is_some<T>(opt: &const Option<T>) -> bool {
     //! Returns true if the option contains some value
 
     !is_none(opt)
@@ -333,11 +333,11 @@ impl<T> MutableIter<T> for Option<T> {
 pub impl<T> Option<T> {
     /// Returns true if the option equals `none`
     #[inline(always)]
-    pure fn is_none(&self) -> bool { is_none(self) }
+    pure fn is_none(&const self) -> bool { is_none(self) }
 
     /// Returns true if the option contains some value
     #[inline(always)]
-    pure fn is_some(&self) -> bool { is_some(self) }
+    pure fn is_some(&const self) -> bool { is_some(self) }
 
     /**
      * Update an optional value by optionally running its content by reference
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index 481a61f4ab7..c1b6b26d86a 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -223,8 +223,8 @@ pub unsafe fn array_each<T>(arr: **T, cb: &fn(*T)) {
 }
 
 pub trait Ptr<T> {
-    pure fn is_null(&self) -> bool;
-    pure fn is_not_null(&self) -> bool;
+    pure fn is_null(&const self) -> bool;
+    pure fn is_not_null(&const self) -> bool;
     pure fn offset(&self, count: uint) -> Self;
 }
 
@@ -232,11 +232,11 @@ pub trait Ptr<T> {
 impl<T> Ptr<T> for *T {
     /// Returns true if the pointer is equal to the null pointer.
     #[inline(always)]
-    pure fn is_null(&self) -> bool { is_null(*self) }
+    pure fn is_null(&const self) -> bool { is_null(*self) }
 
     /// Returns true if the pointer is not equal to the null pointer.
     #[inline(always)]
-    pure fn is_not_null(&self) -> bool { is_not_null(*self) }
+    pure fn is_not_null(&const self) -> bool { is_not_null(*self) }
 
     /// Calculates the offset from a pointer.
     #[inline(always)]
@@ -247,11 +247,11 @@ impl<T> Ptr<T> for *T {
 impl<T> Ptr<T> for *mut T {
     /// Returns true if the pointer is equal to the null pointer.
     #[inline(always)]
-    pure fn is_null(&self) -> bool { is_null(*self) }
+    pure fn is_null(&const self) -> bool { is_null(*self) }
 
     /// Returns true if the pointer is not equal to the null pointer.
     #[inline(always)]
-    pure fn is_not_null(&self) -> bool { is_not_null(*self) }
+    pure fn is_not_null(&const self) -> bool { is_not_null(*self) }
 
     /// Calculates the offset from a mutable pointer.
     #[inline(always)]
diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs
index e6a4a99df44..83df9b7c00f 100644
--- a/src/libcore/repr.rs
+++ b/src/libcore/repr.rs
@@ -499,7 +499,7 @@ impl TyVisitor for ReprVisitor {
     }
 
     fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool {
-        match self.var_stk[self.var_stk.len() - 1] {
+        match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] {
             Degenerate | TagMatch => {
                 if i != 0 {
                     self.writer.write_str(", ");
@@ -517,7 +517,7 @@ impl TyVisitor for ReprVisitor {
                                 _disr_val: int,
                                 n_fields: uint,
                                 _name: &str) -> bool {
-        match self.var_stk[self.var_stk.len() - 1] {
+        match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] {
             Degenerate | TagMatch => {
                 if n_fields > 0 {
                     self.writer.write_char(')');
diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs
index 0fd373b803f..40a6873ad67 100644
--- a/src/libcore/task/spawn.rs
+++ b/src/libcore/task/spawn.rs
@@ -127,7 +127,7 @@ type TaskGroupInner = &'self mut Option<TaskGroupData>;
 
 // A taskgroup is 'dead' when nothing can cause it to fail; only members can.
 pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool {
-    (&tg.members).is_empty()
+    (&const tg.members).is_empty()
 }
 
 // A list-like structure by which taskgroups keep track of all ancestor groups
diff --git a/src/libcore/trie.rs b/src/libcore/trie.rs
index 26532c1a4ff..6b2f2bb6a7d 100644
--- a/src/libcore/trie.rs
+++ b/src/libcore/trie.rs
@@ -50,11 +50,11 @@ impl<T> ReverseIter<(uint, &'self T)> for TrieMap<T> {
 impl<T> Container for TrieMap<T> {
     /// Return the number of elements in the map
     #[inline(always)]
-    pure fn len(&self) -> uint { self.length }
+    pure fn len(&const self) -> uint { self.length }
 
     /// Return true if the map contains no elements
     #[inline(always)]
-    pure fn is_empty(&self) -> bool { self.len() == 0 }
+    pure fn is_empty(&const self) -> bool { self.len() == 0 }
 }
 
 impl<T> Mutable for TrieMap<T> {
@@ -178,11 +178,11 @@ impl ReverseIter<uint> for TrieSet {
 impl Container for TrieSet {
     /// 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 Mutable for TrieSet {
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index 34d3c022dca..dc220eaed1b 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -118,6 +118,14 @@ pub pure fn len<T>(v: &[const T]) -> uint {
     as_const_buf(v, |_p, len| len)
 }
 
+// A botch to tide us over until core and std are fully demuted.
+pub pure fn uniq_len<T>(v: &const ~[T]) -> uint {
+    unsafe {
+        let v: &~[T] = ::cast::transmute(v);
+        as_const_buf(*v, |_p, len| len)
+    }
+}
+
 /**
  * Creates and initializes an immutable vector.
  *
@@ -1691,11 +1699,11 @@ pub mod traits {
 impl<T> Container for &'self [const T] {
     /// Returns true if a vector contains no elements
     #[inline]
-    pure fn is_empty(&self) -> bool { is_empty(*self) }
+    pure fn is_empty(&const self) -> bool { is_empty(*self) }
 
     /// Returns the length of a vector
     #[inline]
-    pure fn len(&self) -> uint { len(*self) }
+    pure fn len(&const self) -> uint { len(*self) }
 }
 
 pub trait CopyableVector<T> {
@@ -1707,7 +1715,14 @@ impl<T: Copy> CopyableVector<T> for &'self [const T] {
     /// Returns a copy of the elements from [`start`..`end`) from `v`.
     #[inline]
     pure fn slice(&self, start: uint, end: uint) -> ~[T] {
-        slice(*self, start, end).to_vec()
+        // XXX: Purity workaround for stage0.
+        unsafe {
+            let mut result = ~[];
+            for uint::range(start, end) |i| {
+                result.push(copy self[i]);
+            }
+            result
+        }
     }
 }
 
@@ -2484,7 +2499,7 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for &'self [A] {
 impl<A:Copy> iter::CopyableNonstrictIter<A> for ~[A] {
     pure fn each_val(&const self, f: &fn(A) -> bool) {
         let mut i = 0;
-        while i < self.len() {
+        while i < uniq_len(self) {
             if !f(copy self[i]) { break; }
             i += 1;
         }