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/at_vec.rs18
-rw-r--r--src/libcore/cast.rs61
-rw-r--r--src/libcore/comm.rs84
-rw-r--r--src/libcore/flate.rs4
-rw-r--r--src/libcore/gc.rs2
-rw-r--r--src/libcore/managed.rs8
-rw-r--r--src/libcore/option.rs15
-rw-r--r--src/libcore/path.rs21
-rw-r--r--src/libcore/pipes.rs38
-rw-r--r--src/libcore/ptr.rs19
-rw-r--r--src/libcore/rand.rs2
-rw-r--r--src/libcore/rt/thread.rs8
-rw-r--r--src/libcore/rt/uv/mod.rs16
-rw-r--r--src/libcore/rt/uvll.rs6
-rw-r--r--src/libcore/stackwalk.rs3
-rw-r--r--src/libcore/str.rs3
-rw-r--r--src/libcore/sys.rs2
-rw-r--r--src/libcore/task/local_data_priv.rs10
-rw-r--r--src/libcore/task/mod.rs4
-rw-r--r--src/libcore/task/spawn.rs2
-rw-r--r--src/libcore/unstable/intrinsics.rs3
-rw-r--r--src/libcore/vec.rs66
22 files changed, 232 insertions, 163 deletions
diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs
index 6ce1acf5947..9f59f1d8fe4 100644
--- a/src/libcore/at_vec.rs
+++ b/src/libcore/at_vec.rs
@@ -14,7 +14,6 @@ use cast::transmute;
 use kinds::Copy;
 use old_iter;
 use option::Option;
-use ptr::addr_of;
 use sys;
 use uint;
 use vec;
@@ -40,8 +39,7 @@ pub mod rustrt {
 #[inline(always)]
 pub fn capacity<T>(v: @[T]) -> uint {
     unsafe {
-        let repr: **raw::VecRepr =
-            ::cast::transmute(addr_of(&v));
+        let repr: **raw::VecRepr = transmute(&v);
         (**repr).unboxed.alloc / sys::size_of::<T>()
     }
 }
@@ -187,13 +185,12 @@ pub mod traits {}
 
 pub mod raw {
     use at_vec::{capacity, rustrt};
-    use cast::transmute;
+    use cast::{transmute, transmute_copy};
     use libc;
-    use unstable::intrinsics::{move_val_init};
-    use ptr::addr_of;
     use ptr;
     use sys;
     use uint;
+    use unstable::intrinsics::{move_val_init};
     use vec;
 
     pub type VecRepr = vec::raw::VecRepr;
@@ -208,18 +205,17 @@ pub mod raw {
      */
     #[inline(always)]
     pub unsafe fn set_len<T>(v: @[T], new_len: uint) {
-        let repr: **mut VecRepr = ::cast::transmute(addr_of(&v));
+        let repr: **mut VecRepr = transmute(&v);
         (**repr).unboxed.fill = new_len * sys::size_of::<T>();
     }
 
     #[inline(always)]
     pub unsafe fn push<T>(v: &mut @[T], initval: T) {
-        let repr: **VecRepr = ::cast::reinterpret_cast(&v);
+        let repr: **VecRepr = transmute_copy(&v);
         let fill = (**repr).unboxed.fill;
         if (**repr).unboxed.alloc > fill {
             push_fast(v, initval);
-        }
-        else {
+        } else {
             push_slow(v, initval);
         }
     }
@@ -229,7 +225,7 @@ pub mod raw {
         let repr: **mut 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 = &((**repr).unboxed.data);
         let p = ptr::offset(p, fill) as *mut T;
         move_val_init(&mut(*p), initval);
     }
diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs
index 1d214f402f5..6fb737d3770 100644
--- a/src/libcore/cast.rs
+++ b/src/libcore/cast.rs
@@ -10,21 +10,56 @@
 
 //! Unsafe casting functions
 
+use sys;
+use unstable;
+
 pub mod rusti {
     #[abi = "rust-intrinsic"]
     #[link_name = "rusti"]
     pub extern "rust-intrinsic" {
         fn forget<T>(+x: T);
+
+        #[cfg(stage0)]
         fn reinterpret_cast<T, U>(&&e: T) -> U;
+
+        #[cfg(stage1)]
+        #[cfg(stage2)]
+        #[cfg(stage3)]
+        fn transmute<T,U>(e: T) -> U;
     }
 }
 
 /// Casts the value at `src` to U. The two types must have the same length.
 #[inline(always)]
+#[cfg(stage0)]
 pub unsafe fn reinterpret_cast<T, U>(src: &T) -> U {
     rusti::reinterpret_cast(*src)
 }
 
+/// Unsafely copies and casts the value at `src` to U, even if the value is
+/// noncopyable. The two types must have the same length.
+#[inline(always)]
+#[cfg(stage0)]
+pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
+    rusti::reinterpret_cast(*src)
+}
+
+#[inline(always)]
+#[cfg(stage1)]
+#[cfg(stage2)]
+#[cfg(stage3)]
+pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
+    let mut dest: U = unstable::intrinsics::init();
+    {
+        let dest_ptr: *mut u8 = rusti::transmute(&mut dest);
+        let src_ptr: *u8 = rusti::transmute(src);
+        unstable::intrinsics::memmove64(dest_ptr,
+                                        src_ptr,
+                                        sys::size_of::<U>() as u64);
+    }
+    dest
+}
+
 /**
  * Move a thing into the void
  *
@@ -53,12 +88,21 @@ pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
  *     assert!(transmute("L") == ~[76u8, 0u8]);
  */
 #[inline(always)]
+#[cfg(stage0)]
 pub unsafe fn transmute<L, G>(thing: L) -> G {
     let newthing: G = reinterpret_cast(&thing);
     forget(thing);
     newthing
 }
 
+#[inline(always)]
+#[cfg(stage1)]
+#[cfg(stage2)]
+#[cfg(stage3)]
+pub unsafe fn transmute<L, G>(thing: L) -> G {
+    rusti::transmute(thing)
+}
+
 /// Coerce an immutable reference to be mutable.
 #[inline(always)]
 pub unsafe fn transmute_mut<'a,T>(ptr: &'a T) -> &'a mut T { transmute(ptr) }
@@ -112,11 +156,20 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
 
 #[cfg(test)]
 mod tests {
-    use cast::{bump_box_refcount, reinterpret_cast, transmute};
+    use cast::{bump_box_refcount, transmute};
 
     #[test]
+    #[cfg(stage0)]
     fn test_reinterpret_cast() {
-        assert!(1u == unsafe { reinterpret_cast(&1) });
+        assert!(1u == unsafe { ::cast::reinterpret_cast(&1) });
+    }
+
+    #[test]
+    #[cfg(stage1)]
+    #[cfg(stage2)]
+    #[cfg(stage3)]
+    fn test_transmute_copy() {
+        assert!(1u == unsafe { ::cast::transmute_copy(&1) });
     }
 
     #[test]
@@ -125,8 +178,8 @@ mod tests {
             let box = @~"box box box";       // refcount 1
             bump_box_refcount(box);         // refcount 2
             let ptr: *int = transmute(box); // refcount 2
-            let _box1: @~str = reinterpret_cast(&ptr);
-            let _box2: @~str = reinterpret_cast(&ptr);
+            let _box1: @~str = ::cast::transmute_copy(&ptr);
+            let _box2: @~str = ::cast::transmute_copy(&ptr);
             assert!(*_box1 == ~"box box box");
             assert!(*_box2 == ~"box box box");
             // Will destroy _box1 and _box2. Without the bump, this would
diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs
index 2656115dca2..50a3bba049b 100644
--- a/src/libcore/comm.rs
+++ b/src/libcore/comm.rs
@@ -327,6 +327,7 @@ impl<T: Owned> ::clone::Clone for SharedChan<T> {
 #[allow(non_camel_case_types)]
 pub mod oneshot {
     priv use core::kinds::Owned;
+    use ptr::to_unsafe_ptr;
 
     pub fn init<T: Owned>() -> (client::Oneshot<T>, server::Oneshot<T>) {
         pub use core::pipes::HasBuffer;
@@ -341,7 +342,7 @@ pub mod oneshot {
         do ::core::pipes::entangle_buffer(buffer) |buffer, data| {
             {
                 data.Oneshot.set_buffer(buffer);
-                ::ptr::addr_of(&(data.Oneshot))
+                to_unsafe_ptr(&data.Oneshot)
             }
         }
     }
@@ -394,24 +395,55 @@ pub mod oneshot {
 }
 
 /// The send end of a oneshot pipe.
-pub type ChanOne<T> = oneshot::client::Oneshot<T>;
+pub struct ChanOne<T> {
+    contents: oneshot::client::Oneshot<T>
+}
+
+impl<T> ChanOne<T> {
+    pub fn new(contents: oneshot::client::Oneshot<T>) -> ChanOne<T> {
+        ChanOne {
+            contents: contents
+        }
+    }
+}
+
 /// The receive end of a oneshot pipe.
-pub type PortOne<T> = oneshot::server::Oneshot<T>;
+pub struct PortOne<T> {
+    contents: oneshot::server::Oneshot<T>
+}
+
+impl<T> PortOne<T> {
+    pub fn new(contents: oneshot::server::Oneshot<T>) -> PortOne<T> {
+        PortOne {
+            contents: contents
+        }
+    }
+}
 
 /// Initialiase a (send-endpoint, recv-endpoint) oneshot pipe pair.
 pub fn oneshot<T: Owned>() -> (PortOne<T>, ChanOne<T>) {
     let (chan, port) = oneshot::init();
-    (port, chan)
+    (PortOne::new(port), ChanOne::new(chan))
 }
 
 pub impl<T: Owned> PortOne<T> {
     fn recv(self) -> T { recv_one(self) }
     fn try_recv(self) -> Option<T> { try_recv_one(self) }
+    fn unwrap(self) -> oneshot::server::Oneshot<T> {
+        match self {
+            PortOne { contents: s } => s
+        }
+    }
 }
 
 pub impl<T: Owned> ChanOne<T> {
     fn send(self, data: T) { send_one(self, data) }
     fn try_send(self, data: T) -> bool { try_send_one(self, data) }
+    fn unwrap(self) -> oneshot::client::Oneshot<T> {
+        match self {
+            ChanOne { contents: s } => s
+        }
+    }
 }
 
 /**
@@ -419,33 +451,47 @@ pub impl<T: Owned> ChanOne<T> {
  * closed.
  */
 pub fn recv_one<T: Owned>(port: PortOne<T>) -> T {
-    let oneshot::send(message) = recv(port);
-    message
+    match port {
+        PortOne { contents: port } => {
+            let oneshot::send(message) = recv(port);
+            message
+        }
+    }
 }
 
 /// Receive a message from a oneshot pipe unless the connection was closed.
 pub fn try_recv_one<T: Owned> (port: PortOne<T>) -> Option<T> {
-    let message = try_recv(port);
-
-    if message.is_none() { None }
-    else {
-        let oneshot::send(message) = message.unwrap();
-        Some(message)
+    match port {
+        PortOne { contents: port } => {
+            let message = try_recv(port);
+
+            if message.is_none() {
+                None
+            } else {
+                let oneshot::send(message) = message.unwrap();
+                Some(message)
+            }
+        }
     }
 }
 
 /// Send a message on a oneshot pipe, failing if the connection was closed.
 pub fn send_one<T: Owned>(chan: ChanOne<T>, data: T) {
-    oneshot::client::send(chan, data);
+    match chan {
+        ChanOne { contents: chan } => oneshot::client::send(chan, data),
+    }
 }
 
 /**
  * Send a message on a oneshot pipe, or return false if the connection was
  * closed.
  */
-pub fn try_send_one<T: Owned>(chan: ChanOne<T>, data: T)
-        -> bool {
-    oneshot::client::try_send(chan, data).is_some()
+pub fn try_send_one<T: Owned>(chan: ChanOne<T>, data: T) -> bool {
+    match chan {
+        ChanOne { contents: chan } => {
+            oneshot::client::try_send(chan, data).is_some()
+        }
+    }
 }
 
 
@@ -519,11 +565,11 @@ mod test {
 
     #[test]
     fn test_oneshot() {
-        let (c, p) = oneshot::init();
+        let (p, c) = oneshot();
 
-        oneshot::client::send(c, ());
+        c.send(());
 
-        recv_one(p)
+        p.recv()
     }
 
     #[test]
diff --git a/src/libcore/flate.rs b/src/libcore/flate.rs
index 5c4181c10cf..c3518cc8b6e 100644
--- a/src/libcore/flate.rs
+++ b/src/libcore/flate.rs
@@ -53,7 +53,7 @@ pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] {
             let res =
                 rustrt::tdefl_compress_mem_to_heap(b as *c_void,
                                                    len as size_t,
-                                                   ptr::addr_of(&outsz),
+                                                   &outsz,
                                                    lz_norm);
             assert!(res as int != 0);
             let out = vec::raw::from_buf_raw(res as *u8,
@@ -71,7 +71,7 @@ pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] {
             let res =
                 rustrt::tinfl_decompress_mem_to_heap(b as *c_void,
                                                      len as size_t,
-                                                     ptr::addr_of(&outsz),
+                                                     &outsz,
                                                      0);
             assert!(res as int != 0);
             let out = vec::raw::from_buf_raw(res as *u8,
diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs
index a6bae3c7663..0d0a98359d1 100644
--- a/src/libcore/gc.rs
+++ b/src/libcore/gc.rs
@@ -338,7 +338,7 @@ pub fn cleanup_stack_for_failure() {
         // own stack roots on the stack anyway.
         let sentinel_box = ~0;
         let sentinel: **Word = if expect_sentinel() {
-            cast::transmute(ptr::addr_of(&sentinel_box))
+            cast::transmute(&sentinel_box)
         } else {
             ptr::null()
         };
diff --git a/src/libcore/managed.rs b/src/libcore/managed.rs
index 2bd3959acf4..debca1ead82 100644
--- a/src/libcore/managed.rs
+++ b/src/libcore/managed.rs
@@ -10,7 +10,7 @@
 
 //! Operations on managed box types
 
-use ptr;
+use ptr::to_unsafe_ptr;
 
 #[cfg(notest)] use cmp::{Eq, Ord};
 
@@ -38,13 +38,15 @@ pub mod raw {
 #[inline(always)]
 pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
     //! Determine if two shared boxes point to the same object
-    ptr::addr_of(&(*a)) == ptr::addr_of(&(*b))
+    let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
+    a_ptr == b_ptr
 }
 
 #[inline(always)]
 pub fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
     //! Determine if two mutable shared boxes point to the same object
-    ptr::addr_of(&(*a)) == ptr::addr_of(&(*b))
+    let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
+    a_ptr == b_ptr
 }
 
 #[cfg(notest)]
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index d3519854a0a..17192b4257b 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -49,7 +49,6 @@ use num::Zero;
 use old_iter::{BaseIter, MutableIter, ExtendedIter};
 use old_iter;
 
-#[cfg(test)] use ptr;
 #[cfg(test)] use str;
 
 /// The option type
@@ -481,12 +480,14 @@ pub impl<T:Copy + Zero> Option<T> {
 
 #[test]
 fn test_unwrap_ptr() {
-    let x = ~0;
-    let addr_x = ptr::addr_of(&(*x));
-    let opt = Some(x);
-    let y = opt.unwrap();
-    let addr_y = ptr::addr_of(&(*y));
-    assert!(addr_x == addr_y);
+    unsafe {
+        let x = ~0;
+        let addr_x: *int = ::cast::transmute(&*x);
+        let opt = Some(x);
+        let y = opt.unwrap();
+        let addr_y: *int = ::cast::transmute(&*y);
+        assert!(addr_x == addr_y);
+    }
 }
 
 #[test]
diff --git a/src/libcore/path.rs b/src/libcore/path.rs
index edc61299af9..462c5be3bcf 100644
--- a/src/libcore/path.rs
+++ b/src/libcore/path.rs
@@ -21,6 +21,11 @@ use str;
 use to_str::ToStr;
 use ascii::{AsciiCast, AsciiStr};
 
+#[cfg(windows)]
+pub use Path = self::WindowsPath;
+#[cfg(unix)]
+pub use Path = self::PosixPath;
+
 #[deriving(Clone, Eq)]
 pub struct WindowsPath {
     host: Option<~str>,
@@ -72,22 +77,6 @@ pub trait GenericPath {
     fn is_absolute(&self) -> bool;
 }
 
-#[cfg(windows)]
-pub type Path = WindowsPath;
-
-#[cfg(windows)]
-pub fn Path(s: &str) -> Path {
-    WindowsPath(s)
-}
-
-#[cfg(unix)]
-pub type Path = PosixPath;
-
-#[cfg(unix)]
-pub fn Path(s: &str) -> Path {
-    PosixPath(s)
-}
-
 #[cfg(target_os = "linux")]
 #[cfg(target_os = "android")]
 mod stat {
diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs
index 2ec3afca612..95b24d20a4b 100644
--- a/src/libcore/pipes.rs
+++ b/src/libcore/pipes.rs
@@ -82,7 +82,7 @@ bounded and unbounded protocols allows for less code duplication.
 
 */
 
-use cast::{forget, reinterpret_cast, transmute};
+use cast::{forget, transmute, transmute_copy};
 use either::{Either, Left, Right};
 use kinds::Owned;
 use libc;
@@ -95,7 +95,7 @@ use vec;
 static SPIN_COUNT: uint = 0;
 
 macro_rules! move_it (
-    { $x:expr } => ( unsafe { let y = *ptr::addr_of(&($x)); y } )
+    { $x:expr } => ( unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } )
 )
 
 #[deriving(Eq)]
@@ -131,7 +131,7 @@ pub struct PacketHeader {
     mut state: State,
     mut blocked_task: *rust_task,
 
-    // This is a reinterpret_cast of a ~buffer, that can also be cast
+    // This is a transmute_copy of a ~buffer, that can also be cast
     // to a buffer_header if need be.
     mut buffer: *libc::c_void,
 }
@@ -170,12 +170,12 @@ pub impl PacketHeader {
     // thing. You'll proobably want to forget them when you're done.
     unsafe fn buf_header(&self) -> ~BufferHeader {
         assert!(self.buffer.is_not_null());
-        reinterpret_cast(&self.buffer)
+        transmute_copy(&self.buffer)
     }
 
     fn set_buffer<T:Owned>(&self, b: ~Buffer<T>) {
         unsafe {
-            self.buffer = reinterpret_cast(&b);
+            self.buffer = transmute_copy(&b);
         }
     }
 }
@@ -211,14 +211,14 @@ fn unibuffer<T>() -> ~Buffer<Packet<T>> {
     };
 
     unsafe {
-        b.data.header.buffer = reinterpret_cast(&b);
+        b.data.header.buffer = transmute_copy(&b);
     }
     b
 }
 
 pub fn packet<T>() -> *Packet<T> {
     let b = unibuffer();
-    let p = ptr::addr_of(&(b.data));
+    let p = ptr::to_unsafe_ptr(&(b.data));
     // We'll take over memory management from here.
     unsafe { forget(b) }
     p
@@ -229,7 +229,7 @@ pub fn entangle_buffer<T:Owned,Tstart:Owned>(
     init: &fn(*libc::c_void, x: &T) -> *Packet<Tstart>)
     -> (SendPacketBuffered<Tstart, T>, RecvPacketBuffered<Tstart, T>)
 {
-    let p = init(unsafe { reinterpret_cast(&buffer) }, &buffer.data);
+    let p = init(unsafe { transmute_copy(&buffer) }, &buffer.data);
     unsafe { forget(buffer) }
     (SendPacketBuffered(p), RecvPacketBuffered(p))
 }
@@ -305,7 +305,7 @@ impl<T> ::ops::Drop for BufferResource<T> {
     fn finalize(&self) {
         unsafe {
             let b = move_it!(self.buffer);
-            //let p = ptr::addr_of(*b);
+            //let p = ptr::to_unsafe_ptr(*b);
             //error!("drop %?", p);
             let old_count = intrinsics::atomic_xsub_rel(&mut b.header.ref_count, 1);
             //let old_count = atomic_xchng_rel(b.header.ref_count, 0);
@@ -322,7 +322,7 @@ impl<T> ::ops::Drop for BufferResource<T> {
 }
 
 fn BufferResource<T>(b: ~Buffer<T>) -> BufferResource<T> {
-    //let p = ptr::addr_of(*b);
+    //let p = ptr::to_unsafe_ptr(*b);
     //error!("take %?", p);
     unsafe { intrinsics::atomic_xadd_acq(&mut b.header.ref_count, 1) };
 
@@ -336,7 +336,7 @@ pub fn send<T,Tbuffer>(p: SendPacketBuffered<T,Tbuffer>, payload: T) -> bool {
     let header = p.header();
     let p_ = p.unwrap();
     let p = unsafe { &*p_ };
-    assert!(ptr::addr_of(&(p.header)) == header);
+    assert!(ptr::to_unsafe_ptr(&(p.header)) == header);
     assert!(p.payload.is_none());
     p.payload = Some(payload);
     let old_state = swap_state_rel(&mut p.header.state, Full);
@@ -356,7 +356,7 @@ pub fn send<T,Tbuffer>(p: SendPacketBuffered<T,Tbuffer>, payload: T) -> bool {
                 unsafe {
                     rustrt::task_signal_event(
                         old_task,
-                        ptr::addr_of(&(p.header)) as *libc::c_void);
+                        ptr::to_unsafe_ptr(&(p.header)) as *libc::c_void);
                     rustrt::rust_task_deref(old_task);
                 }
             }
@@ -521,7 +521,7 @@ fn sender_terminate<T:Owned>(p: *Packet<T>) {
             unsafe {
                 rustrt::task_signal_event(
                     old_task,
-                    ptr::addr_of(&(p.header)) as *libc::c_void);
+                    ptr::to_unsafe_ptr(&(p.header)) as *libc::c_void);
                 rustrt::rust_task_deref(old_task);
             }
         }
@@ -665,7 +665,7 @@ pub fn SendPacketBuffered<T,Tbuffer>(p: *Packet<T>)
         p: Some(p),
         buffer: unsafe {
             Some(BufferResource(
-                get_buffer(ptr::addr_of(&((*p).header)))))
+                get_buffer(ptr::to_unsafe_ptr(&((*p).header)))))
         }
     }
 }
@@ -681,7 +681,7 @@ pub impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
         match self.p {
           Some(packet) => unsafe {
             let packet = &*packet;
-            let header = ptr::addr_of(&(packet.header));
+            let header = ptr::to_unsafe_ptr(&(packet.header));
             //forget(packet);
             header
           },
@@ -747,7 +747,7 @@ impl<T:Owned,Tbuffer:Owned> Selectable for RecvPacketBuffered<T, Tbuffer> {
         match self.p {
           Some(packet) => unsafe {
             let packet = &*packet;
-            let header = ptr::addr_of(&(packet.header));
+            let header = ptr::to_unsafe_ptr(&(packet.header));
             //forget(packet);
             header
           },
@@ -763,7 +763,7 @@ pub fn RecvPacketBuffered<T,Tbuffer>(p: *Packet<T>)
         p: Some(p),
         buffer: unsafe {
             Some(BufferResource(
-                get_buffer(ptr::addr_of(&((*p).header)))))
+                get_buffer(ptr::to_unsafe_ptr(&((*p).header)))))
         }
     }
 }
@@ -885,9 +885,9 @@ mod test {
 
     #[test]
     fn test_oneshot() {
-        let (c, p) = oneshot::init();
+        let (p, c) = oneshot();
 
-        oneshot::client::send(c, ());
+        c.send(());
 
         recv_one(p)
     }
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index 94474c3c02d..86b36834bbd 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -39,17 +39,6 @@ pub mod libc_ {
     }
 }
 
-pub mod rusti {
-    #[abi = "rust-intrinsic"]
-    pub extern "rust-intrinsic" {
-        fn addr_of<T>(&&val: T) -> *T;
-    }
-}
-
-/// Get an unsafe pointer to a value
-#[inline(always)]
-pub fn addr_of<T>(val: &T) -> *T { unsafe { rusti::addr_of(*val) } }
-
 /// Calculate the offset from a pointer
 #[inline(always)]
 pub fn offset<T>(ptr: *T, count: uint) -> *T {
@@ -130,7 +119,7 @@ pub unsafe fn set_memory<T>(dst: *mut T, c: int, count: uint) {
 /**
   Transform a region pointer - &T - to an unsafe pointer - *T.
   This is safe, but is implemented with an unsafe block due to
-  reinterpret_cast.
+  transmute.
 */
 #[inline(always)]
 pub fn to_unsafe_ptr<T>(thing: &T) -> *T {
@@ -140,7 +129,7 @@ pub fn to_unsafe_ptr<T>(thing: &T) -> *T {
 /**
   Transform a const region pointer - &const T - to a const unsafe pointer -
   *const T. This is safe, but is implemented with an unsafe block due to
-  reinterpret_cast.
+  transmute.
 */
 #[inline(always)]
 pub fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
@@ -150,7 +139,7 @@ pub fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
 /**
   Transform a mutable region pointer - &mut T - to a mutable unsafe pointer -
   *mut T. This is safe, but is implemented with an unsafe block due to
-  reinterpret_cast.
+  transmute.
 */
 #[inline(always)]
 pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
@@ -160,7 +149,7 @@ pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
 /**
   Cast a region pointer - &T - to a uint.
   This is safe, but is implemented with an unsafe block due to
-  reinterpret_cast.
+  transmute.
 
   (I couldn't think of a cutesy name for this one.)
 */
diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs
index 52944391851..967a8cdf49b 100644
--- a/src/libcore/rand.rs
+++ b/src/libcore/rand.rs
@@ -698,7 +698,7 @@ impl<R: Rng> Rng for @R {
  * generator.
  */
 pub fn random<T: Rand>() -> T {
-    task_rng().gen()
+    (*task_rng()).gen()
 }
 
 #[cfg(test)]
diff --git a/src/libcore/rt/thread.rs b/src/libcore/rt/thread.rs
index 910e445f47b..0f1ae09bd94 100644
--- a/src/libcore/rt/thread.rs
+++ b/src/libcore/rt/thread.rs
@@ -21,10 +21,10 @@ pub struct Thread {
 
 pub impl Thread {
     fn start(main: ~fn()) -> Thread {
-        fn substart(main: &fn()) -> *raw_thread {
-            unsafe { rust_raw_thread_start(&main) }
+        fn substart(main: &~fn()) -> *raw_thread {
+            unsafe { rust_raw_thread_start(main) }
         }
-        let raw = substart(main);
+        let raw = substart(&main);
         Thread {
             main: main,
             raw_thread: raw
@@ -39,6 +39,6 @@ impl Drop for Thread {
 }
 
 extern {
-    pub unsafe fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread;
+    pub unsafe fn rust_raw_thread_start(f: &(~fn())) -> *raw_thread;
     pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
 }
diff --git a/src/libcore/rt/uv/mod.rs b/src/libcore/rt/uv/mod.rs
index 4cbc8d70569..cb7925abdcd 100644
--- a/src/libcore/rt/uv/mod.rs
+++ b/src/libcore/rt/uv/mod.rs
@@ -366,14 +366,15 @@ pub fn slice_to_uv_buf(v: &[u8]) -> Buf {
 
 /// Transmute an owned vector to a Buf
 pub fn vec_to_uv_buf(v: ~[u8]) -> Buf {
-    let data = unsafe { malloc(v.len() as size_t) } as *u8;
-    assert!(data.is_not_null());
-    do vec::as_imm_buf(v) |b, l| {
-        let data = data as *mut u8;
-        unsafe { ptr::copy_memory(data, b, l) }
+    unsafe {
+        let data = malloc(v.len() as size_t) as *u8;
+        assert!(data.is_not_null());
+        do vec::as_imm_buf(v) |b, l| {
+            let data = data as *mut u8;
+            ptr::copy_memory(data, b, l)
+        }
+        uvll::buf_init(data, v.len())
     }
-    let buf = unsafe { uvll::buf_init(data, v.len()) };
-    return buf;
 }
 
 /// Transmute a Buf that was once a ~[u8] back to ~[u8]
@@ -384,6 +385,7 @@ pub fn vec_from_uv_buf(buf: Buf) -> Option<~[u8]> {
         return Some(v);
     } else {
         // No buffer
+        rtdebug!("No buffer!");
         return None;
     }
 }
diff --git a/src/libcore/rt/uvll.rs b/src/libcore/rt/uvll.rs
index b7eff217ff8..c9a696fcd15 100644
--- a/src/libcore/rt/uvll.rs
+++ b/src/libcore/rt/uvll.rs
@@ -252,7 +252,7 @@ pub unsafe fn async_send(async_handle: *uv_async_t) {
 }
 pub unsafe fn buf_init(input: *u8, len: uint) -> uv_buf_t {
     let out_buf = uv_buf_t { base: ptr::null(), len: 0 as size_t };
-    let out_buf_ptr = ptr::addr_of(&out_buf);
+    let out_buf_ptr = ptr::to_unsafe_ptr(&out_buf);
     rust_uv_buf_init(out_buf_ptr, input, len as size_t);
     return out_buf;
 }
@@ -330,7 +330,7 @@ pub unsafe fn free_base_of_buf(buf: uv_buf_t) {
 
 pub unsafe fn get_last_err_info(uv_loop: *c_void) -> ~str {
     let err = last_error(uv_loop);
-    let err_ptr = ptr::addr_of(&err);
+    let err_ptr = ptr::to_unsafe_ptr(&err);
     let err_name = str::raw::from_c_str(err_name(err_ptr));
     let err_msg = str::raw::from_c_str(strerror(err_ptr));
     return fmt!("LIBUV ERROR: name: %s msg: %s",
@@ -339,7 +339,7 @@ pub unsafe fn get_last_err_info(uv_loop: *c_void) -> ~str {
 
 pub unsafe fn get_last_err_data(uv_loop: *c_void) -> uv_err_data {
     let err = last_error(uv_loop);
-    let err_ptr = ptr::addr_of(&err);
+    let err_ptr = ptr::to_unsafe_ptr(&err);
     let err_name = str::raw::from_c_str(err_name(err_ptr));
     let err_msg = str::raw::from_c_str(strerror(err_ptr));
     uv_err_data { err_name: err_name, err_msg: err_msg }
diff --git a/src/libcore/stackwalk.rs b/src/libcore/stackwalk.rs
index be5f8989368..ebf36e4e09a 100644
--- a/src/libcore/stackwalk.rs
+++ b/src/libcore/stackwalk.rs
@@ -93,7 +93,10 @@ pub mod rustrt {
 pub mod rusti {
     #[abi = "rust-intrinsic"]
     pub extern "rust-intrinsic" {
+        #[cfg(stage0)]
         pub fn frame_address(f: &once fn(x: *u8));
+        #[cfg(not(stage0))]
+        pub fn frame_address(+f: &once fn(x: *u8));
     }
 }
 
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index 92c965256ce..064bffa0056 100644
--- a/src/libcore/str.rs
+++ b/src/libcore/str.rs
@@ -18,6 +18,7 @@
  */
 
 use at_vec;
+use cast::transmute;
 use cast;
 use char;
 use clone::Clone;
@@ -2045,7 +2046,7 @@ pub fn as_c_str<T>(s: &str, f: &fn(*libc::c_char) -> T) -> T {
 #[inline(always)]
 pub fn as_buf<T>(s: &str, f: &fn(*u8, uint) -> T) -> T {
     unsafe {
-        let v : *(*u8,uint) = ::cast::transmute(ptr::addr_of(&s));
+        let v : *(*u8,uint) = transmute(&s);
         let (buf,len) = *v;
         f(buf, len)
     }
diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs
index bdc3a17308d..8cad0a22886 100644
--- a/src/libcore/sys.rs
+++ b/src/libcore/sys.rs
@@ -154,7 +154,7 @@ pub fn pref_align_of_val<T>(_val: &T) -> uint {
 #[inline(always)]
 pub fn refcount<T>(t: @T) -> uint {
     unsafe {
-        let ref_ptr: *uint = cast::reinterpret_cast(&t);
+        let ref_ptr: *uint = cast::transmute_copy(&t);
         *ref_ptr - 1
     }
 }
diff --git a/src/libcore/task/local_data_priv.rs b/src/libcore/task/local_data_priv.rs
index 5d1cba79c05..67bc3adeb41 100644
--- a/src/libcore/task/local_data_priv.rs
+++ b/src/libcore/task/local_data_priv.rs
@@ -59,9 +59,7 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
     let map_ptr = rt::rust_get_task_local_data(task);
     if map_ptr.is_null() {
         let map: TaskLocalMap = @mut ~[];
-        // Use reinterpret_cast -- transmute would take map away from us also.
-        rt::rust_set_task_local_data(
-            task, cast::transmute(map));
+        rt::rust_set_task_local_data(task, cast::transmute(map));
         rt::rust_task_local_data_atexit(task, cleanup_task_local_map);
         // Also need to reference it an extra time to keep it for now.
         let nonmut = cast::transmute::<TaskLocalMap,
@@ -77,12 +75,10 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
     }
 }
 
-unsafe fn key_to_key_value<T:Durable>(
-    key: LocalDataKey<T>) -> *libc::c_void {
-
+unsafe fn key_to_key_value<T:Durable>(key: LocalDataKey<T>) -> *libc::c_void {
     // Keys are closures, which are (fnptr,envptr) pairs. Use fnptr.
     // Use reintepret_cast -- transmute would leak (forget) the closure.
-    let pair: (*libc::c_void, *libc::c_void) = cast::reinterpret_cast(&key);
+    let pair: (*libc::c_void, *libc::c_void) = cast::transmute_copy(&key);
     pair.first()
 }
 
diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs
index 2163a0e325f..96429932b18 100644
--- a/src/libcore/task/mod.rs
+++ b/src/libcore/task/mod.rs
@@ -1028,10 +1028,10 @@ fn avoid_copying_the_body(spawnfn: &fn(v: ~fn())) {
     let (p, ch) = stream::<uint>();
 
     let x = ~1;
-    let x_in_parent = ptr::addr_of(&(*x)) as uint;
+    let x_in_parent = ptr::to_unsafe_ptr(&*x) as uint;
 
     do spawnfn || {
-        let x_in_child = ptr::addr_of(&(*x)) as uint;
+        let x_in_child = ptr::to_unsafe_ptr(&*x) as uint;
         ch.send(x_in_child);
     }
 
diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs
index 43fdee67b7a..507643ea5ec 100644
--- a/src/libcore/task/spawn.rs
+++ b/src/libcore/task/spawn.rs
@@ -93,7 +93,7 @@ use util;
 #[cfg(test)] use task::default_task_opts;
 
 macro_rules! move_it (
-    { $x:expr } => ( unsafe { let y = *ptr::addr_of(&($x)); y } )
+    { $x:expr } => ( unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } )
 )
 
 type TaskSet = HashSet<*rust_task>;
diff --git a/src/libcore/unstable/intrinsics.rs b/src/libcore/unstable/intrinsics.rs
index a18ad173886..b58429a10aa 100644
--- a/src/libcore/unstable/intrinsics.rs
+++ b/src/libcore/unstable/intrinsics.rs
@@ -47,9 +47,8 @@ pub extern "rust-intrinsic" {
     pub fn forget<T>(_: T) -> ();
 
     // XXX: intrinsic uses legacy modes
+    #[cfg(stage0)]
     fn reinterpret_cast<T,U>(&&src: T) -> U;
-    // XXX: intrinsic uses legacy modes
-    fn addr_of<T>(&&scr: T) -> *T;
 
     pub fn needs_drop<T>() -> bool;
 
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index ef42647411a..86767dc5bad 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -26,11 +26,11 @@ use iterator::Iterator;
 use kinds::Copy;
 use libc;
 use option::{None, Option, Some};
-use unstable::intrinsics;
+use ptr::to_unsafe_ptr;
 use ptr;
-use ptr::addr_of;
 use sys;
 use uint;
+use unstable::intrinsics;
 use vec;
 
 #[cfg(notest)] use cmp::Equiv;
@@ -117,7 +117,7 @@ pub fn reserve_at_least<T>(v: &mut ~[T], n: uint) {
 #[inline(always)]
 pub fn capacity<T>(v: &const ~[T]) -> uint {
     unsafe {
-        let repr: **raw::VecRepr = ::cast::transmute(v);
+        let repr: **raw::VecRepr = transmute(v);
         (**repr).unboxed.alloc / sys::nonzero_size_of::<T>()
     }
 }
@@ -131,7 +131,7 @@ pub fn len<T>(v: &const [T]) -> uint {
 // A botch to tide us over until core and std are fully demuted.
 pub fn uniq_len<T>(v: &const ~[T]) -> uint {
     unsafe {
-        let v: &~[T] = ::cast::transmute(v);
+        let v: &~[T] = transmute(v);
         as_const_buf(*v, |_p, len| len)
     }
 }
@@ -280,9 +280,8 @@ pub fn slice<'r,T>(v: &'r [T], start: uint, end: uint) -> &'r [T] {
     assert!(end <= len(v));
     do as_imm_buf(v) |p, _len| {
         unsafe {
-            ::cast::transmute(
-                (ptr::offset(p, start),
-                  (end - start) * sys::nonzero_size_of::<T>()))
+            transmute((ptr::offset(p, start),
+                       (end - start) * sys::nonzero_size_of::<T>()))
         }
     }
 }
@@ -295,9 +294,8 @@ pub fn mut_slice<'r,T>(v: &'r mut [T], start: uint, end: uint)
     assert!(end <= v.len());
     do as_mut_buf(v) |p, _len| {
         unsafe {
-            ::cast::transmute(
-                (ptr::mut_offset(p, start),
-                  (end - start) * sys::nonzero_size_of::<T>()))
+            transmute((ptr::mut_offset(p, start),
+                       (end - start) * sys::nonzero_size_of::<T>()))
         }
     }
 }
@@ -310,9 +308,8 @@ pub fn const_slice<'r,T>(v: &'r const [T], start: uint, end: uint)
     assert!(end <= len(v));
     do as_const_buf(v) |p, _len| {
         unsafe {
-            ::cast::transmute(
-                (ptr::const_offset(p, start),
-                  (end - start) * sys::nonzero_size_of::<T>()))
+            transmute((ptr::const_offset(p, start),
+                       (end - start) * sys::nonzero_size_of::<T>()))
         }
     }
 }
@@ -489,14 +486,14 @@ pub fn shift<T>(v: &mut ~[T]) -> T {
         {
             let first_slice = slice(*v, 0, 1);
             let last_slice = slice(*v, next_ln, ln);
-            raw::copy_memory(::cast::transmute(last_slice), first_slice, 1);
+            raw::copy_memory(transmute(last_slice), first_slice, 1);
         }
 
         // Memcopy everything to the left one element
         {
             let init_slice = slice(*v, 0, next_ln);
             let tail_slice = slice(*v, 1, ln);
-            raw::copy_memory(::cast::transmute(init_slice),
+            raw::copy_memory(transmute(init_slice),
                              tail_slice,
                              next_ln);
         }
@@ -626,7 +623,7 @@ pub fn swap_remove<T>(v: &mut ~[T], index: uint) -> T {
 #[inline(always)]
 pub fn push<T>(v: &mut ~[T], initval: T) {
     unsafe {
-        let repr: **raw::VecRepr = ::cast::transmute(&mut *v);
+        let repr: **raw::VecRepr = transmute(&mut *v);
         let fill = (**repr).unboxed.fill;
         if (**repr).unboxed.alloc > fill {
             push_fast(v, initval);
@@ -640,10 +637,10 @@ pub fn push<T>(v: &mut ~[T], initval: T) {
 // 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: **mut raw::VecRepr = ::cast::transmute(v);
+    let repr: **mut raw::VecRepr = transmute(v);
     let fill = (**repr).unboxed.fill;
     (**repr).unboxed.fill += sys::nonzero_size_of::<T>();
-    let p = addr_of(&((**repr).unboxed.data));
+    let p = to_unsafe_ptr(&((**repr).unboxed.data));
     let p = ptr::offset(p, fill) as *mut T;
     intrinsics::move_val_init(&mut(*p), initval);
 }
@@ -1622,8 +1619,7 @@ pub fn as_imm_buf<T,U>(s: &[T],
     // instead!
 
     unsafe {
-        let v : *(*T,uint) =
-            ::cast::transmute(addr_of(&s));
+        let v : *(*T,uint) = transmute(&s);
         let (buf,len) = *v;
         f(buf, len / sys::nonzero_size_of::<T>())
     }
@@ -1633,8 +1629,7 @@ pub fn as_imm_buf<T,U>(s: &[T],
 #[inline(always)]
 pub fn as_const_buf<T,U>(s: &const [T], f: &fn(*const T, uint) -> U) -> U {
     unsafe {
-        let v : *(*const T,uint) =
-            ::cast::transmute(addr_of(&s));
+        let v : *(*const T,uint) = transmute(&s);
         let (buf,len) = *v;
         f(buf, len / sys::nonzero_size_of::<T>())
     }
@@ -1644,8 +1639,7 @@ pub fn as_const_buf<T,U>(s: &const [T], f: &fn(*const T, uint) -> U) -> U {
 #[inline(always)]
 pub fn as_mut_buf<T,U>(s: &mut [T], f: &fn(*mut T, uint) -> U) -> U {
     unsafe {
-        let v : *(*mut T,uint) =
-            ::cast::transmute(addr_of(&s));
+        let v : *(*mut T,uint) = transmute(&s);
         let (buf,len) = *v;
         f(buf, len / sys::nonzero_size_of::<T>())
     }
@@ -2429,13 +2423,13 @@ pub struct UnboxedVecRepr {
 
 /// Unsafe operations
 pub mod raw {
+    use cast::transmute;
     use kinds::Copy;
     use managed;
     use option::{None, Some};
-    use unstable::intrinsics;
-    use ptr::addr_of;
     use ptr;
     use sys;
+    use unstable::intrinsics;
     use vec::{UnboxedVecRepr, as_const_buf, as_mut_buf, len, with_capacity};
 
     /// The internal representation of a (boxed) vector
@@ -2458,7 +2452,7 @@ pub mod raw {
      */
     #[inline(always)]
     pub unsafe fn set_len<T>(v: &mut ~[T], new_len: uint) {
-        let repr: **mut VecRepr = ::cast::transmute(v);
+        let repr: **mut VecRepr = transmute(v);
         (**repr).unboxed.fill = new_len * sys::nonzero_size_of::<T>();
     }
 
@@ -2473,22 +2467,22 @@ pub mod raw {
      */
     #[inline(always)]
     pub unsafe fn to_ptr<T>(v: &[T]) -> *T {
-        let repr: **SliceRepr = ::cast::transmute(&v);
-        ::cast::transmute(addr_of(&((**repr).data)))
+        let repr: **SliceRepr = transmute(&v);
+        transmute(&((**repr).data))
     }
 
     /** see `to_ptr()` */
     #[inline(always)]
     pub unsafe fn to_const_ptr<T>(v: &const [T]) -> *const T {
-        let repr: **SliceRepr = ::cast::transmute(&v);
-        ::cast::transmute(addr_of(&((**repr).data)))
+        let repr: **SliceRepr = transmute(&v);
+        transmute(&((**repr).data))
     }
 
     /** see `to_ptr()` */
     #[inline(always)]
     pub unsafe fn to_mut_ptr<T>(v: &mut [T]) -> *mut T {
-        let repr: **SliceRepr = ::cast::transmute(&v);
-        ::cast::transmute(addr_of(&((**repr).data)))
+        let repr: **SliceRepr = transmute(&v);
+        transmute(&((**repr).data))
     }
 
     /**
@@ -2500,8 +2494,7 @@ pub mod raw {
                                     len: uint,
                                     f: &fn(v: &[T]) -> U) -> U {
         let pair = (p, len * sys::nonzero_size_of::<T>());
-        let v : *(&'blk [T]) =
-            ::cast::transmute(addr_of(&pair));
+        let v : *(&'blk [T]) = transmute(&pair);
         f(*v)
     }
 
@@ -2514,8 +2507,7 @@ pub mod raw {
                                         len: uint,
                                         f: &fn(v: &mut [T]) -> U) -> U {
         let pair = (p, len * sys::nonzero_size_of::<T>());
-        let v : *(&'blk mut [T]) =
-            ::cast::transmute(addr_of(&pair));
+        let v : *(&'blk mut [T]) = transmute(&pair);
         f(*v)
     }