about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-10-05 14:58:42 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-10-05 15:37:01 -0700
commite16dbb7888504ef5d0de0c14493fc8ecc492ee30 (patch)
tree80c1bde3c3f3b0cf47993dfe769418cc2ac55323 /src/libcore
parente3cb70fa8a6f9163352f26ae2614ab4c9a261838 (diff)
Demode some code using by-mutbl-ref; warn about by-mutbl-ref
The parser now warns about use of mutbl-ref mode, though it's kind
of a lie since this commit doesn't remove support for the mode.

Changed move_val_init to have stage0 and stage1/2 versions, the latter of
which is demoded.

Changed the type that the typechecker expects the move_val_init
intrinsic to have. After this is pushed, I can make a new snapshot,
which will remove the need for the stage0 versions.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/at_vec.rs18
-rw-r--r--src/libcore/vec.rs49
2 files changed, 66 insertions, 1 deletions
diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs
index 5e1111c20d3..8c023a7cb4c 100644
--- a/src/libcore/at_vec.rs
+++ b/src/libcore/at_vec.rs
@@ -21,7 +21,11 @@ extern mod rustrt {
 #[abi = "rust-intrinsic"]
 extern mod rusti {
     #[legacy_exports];
+    #[cfg(stage0)]
     fn move_val_init<T>(&dst: T, -src: T);
+    #[cfg(stage1)]
+    #[cfg(stage2)]
+    fn move_val_init<T>(dst: &mut T, -src: T);
 }
 
 /// Returns the number of elements the vector can hold without reallocating
@@ -176,7 +180,9 @@ pub mod raw {
             push_slow(v, move initval);
         }
     }
+
     // This doesn't bother to make sure we have space.
+    #[cfg(stage0)]
     #[inline(always)] // really pretty please
     pub unsafe fn push_fast<T>(v: &mut @[const T], initval: T) {
         let repr: **VecRepr = ::cast::reinterpret_cast(&v);
@@ -186,6 +192,18 @@ pub mod raw {
         let p = ptr::offset(p, fill) as *mut T;
         rusti::move_val_init(*p, move initval);
     }
+    // This doesn't bother to make sure we have space.
+    #[cfg(stage1)]
+    #[cfg(stage2)]
+    #[inline(always)] // really pretty please
+    pub unsafe fn push_fast<T>(v: &mut @[const T], initval: T) {
+        let repr: **VecRepr = ::cast::reinterpret_cast(&v);
+        let fill = (**repr).unboxed.fill;
+        (**repr).unboxed.fill += sys::size_of::<T>();
+        let p = addr_of(&((**repr).unboxed.data));
+        let p = ptr::offset(p, fill) as *mut T;
+        rusti::move_val_init(&mut(*p), move initval);
+    }
 
     pub unsafe fn push_slow<T>(v: &mut @[const T], initval: T) {
         reserve_at_least(v, v.len() + 1u);
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index a157071c955..ce1193aa730 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -18,9 +18,14 @@ extern mod rustrt {
 
 #[abi = "rust-intrinsic"]
 extern mod rusti {
+    #[cfg(stage0)]
     fn move_val_init<T>(&dst: T, -src: T);
+    #[cfg(stage1)]
+    #[cfg(stage2)]
+    fn move_val_init<T>(dst: &mut T, -src: T);
 }
 
+
 /// Returns true if a vector contains no elements
 pub pure fn is_empty<T>(v: &[const T]) -> bool {
     as_const_buf(v, |_p, len| len == 0u)
@@ -98,6 +103,7 @@ pub pure fn len<T>(v: &[const T]) -> uint {
  * Creates an immutable vector of size `n_elts` and initializes the elements
  * to the value returned by the function `op`.
  */
+#[cfg(stage0)]
 pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
     unsafe {
         let mut v = with_capacity(n_elts);
@@ -112,6 +118,22 @@ pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
         return move v;
     }
 }
+#[cfg(stage1)]
+#[cfg(stage2)]
+pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
+    unsafe {
+        let mut v = with_capacity(n_elts);
+        do as_mut_buf(v) |p, _len| {
+            let mut i: uint = 0u;
+            while i < n_elts {
+                rusti::move_val_init(&mut(*ptr::mut_offset(p, i)), op(i));
+                i += 1u;
+            }
+        }
+        raw::set_len(&mut v, n_elts);
+        return move v;
+    }
+}
 
 /**
  * Creates and initializes an immutable vector.
@@ -481,6 +503,7 @@ pub fn push<T>(v: &mut ~[T], initval: T) {
     }
 }
 
+#[cfg(stage0)]
 // This doesn't bother to make sure we have space.
 #[inline(always)] // really pretty please
 unsafe fn push_fast<T>(v: &mut ~[T], initval: T) {
@@ -491,6 +514,18 @@ unsafe fn push_fast<T>(v: &mut ~[T], initval: T) {
     let p = ptr::offset(p, fill) as *mut T;
     rusti::move_val_init(*p, move initval);
 }
+#[cfg(stage1)]
+#[cfg(stage2)]
+// This doesn't bother to make sure we have space.
+#[inline(always)] // really pretty please
+unsafe fn push_fast<T>(v: &mut ~[T], initval: T) {
+    let repr: **raw::VecRepr = ::cast::transmute(v);
+    let fill = (**repr).unboxed.fill;
+    (**repr).unboxed.fill += sys::size_of::<T>();
+    let p = addr_of(&((**repr).unboxed.data));
+    let p = ptr::offset(p, fill) as *mut T;
+    rusti::move_val_init(&mut(*p), move initval);
+}
 
 #[inline(never)]
 fn push_slow<T>(v: &mut ~[T], initval: T) {
@@ -1758,6 +1793,18 @@ pub mod raw {
         as_const_buf(v, |p, _len| *ptr::const_offset(p, i))
     }
 
+    #[cfg(stage0)]
+    #[inline(always)]
+    pub unsafe fn init_elem<T>(v: &[mut T], i: uint, val: T) {
+        let mut box = Some(move val);
+        do as_mut_buf(v) |p, _len| {
+            let mut box2 = None;
+            box2 <-> box;
+            rusti::move_val_init(*ptr::mut_offset(p, i),
+                                 option::unwrap(move box2));
+        }
+    }
+    #[cfg(stage1)]
     /**
      * Unchecked vector index assignment.  Does not drop the
      * old value and hence is only suitable when the vector
@@ -1769,7 +1816,7 @@ pub mod raw {
         do as_mut_buf(v) |p, _len| {
             let mut box2 = None;
             box2 <-> box;
-            rusti::move_val_init(*ptr::mut_offset(p, i),
+            rusti::move_val_init(&mut(*ptr::mut_offset(p, i)),
                                  option::unwrap(move box2));
         }
     }