From 090040bf4037a094e50b03d79e4baf5cd89c912b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 5 May 2014 18:56:44 -0700 Subject: librustc: Remove `~EXPR`, `~TYPE`, and `~PAT` from the language, except for `~str`/`~[]`. Note that `~self` still remains, since I forgot to add support for `Box` before the snapshot. How to update your code: * Instead of `~EXPR`, you should write `box EXPR`. * Instead of `~TYPE`, you should write `Box`. * Instead of `~PATTERN`, you should write `box PATTERN`. [breaking-change] --- src/libstd/sync/arc.rs | 3 ++- src/libstd/sync/atomics.rs | 11 ++++++----- src/libstd/sync/deque.rs | 21 ++++++++++++--------- src/libstd/sync/mpsc_queue.rs | 5 +++-- src/libstd/sync/spsc_queue.rs | 5 +++-- 5 files changed, 26 insertions(+), 19 deletions(-) (limited to 'src/libstd/sync') diff --git a/src/libstd/sync/arc.rs b/src/libstd/sync/arc.rs index 0cf975a4c1c..d277c514e44 100644 --- a/src/libstd/sync/arc.rs +++ b/src/libstd/sync/arc.rs @@ -26,6 +26,7 @@ use clone::Clone; use iter::Iterator; use kinds::Send; use ops::Drop; +use owned::Box; use ptr::RawPtr; use sync::atomics::{fence, AtomicUint, Relaxed, Acquire, Release}; use ty::Unsafe; @@ -157,7 +158,7 @@ impl Drop for UnsafeArc{ // happened before), and an "acquire" operation before deleting the object. // [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html) fence(Acquire); - let _: ~ArcData = cast::transmute(self.data); + let _: Box> = cast::transmute(self.data); } } } diff --git a/src/libstd/sync/atomics.rs b/src/libstd/sync/atomics.rs index a3c1c33f77c..2fba59c3233 100644 --- a/src/libstd/sync/atomics.rs +++ b/src/libstd/sync/atomics.rs @@ -88,7 +88,7 @@ //! } //! }); //! -//! shared_big_object.swap(~BigObject, SeqCst); +//! shared_big_object.swap(box BigObject, SeqCst); //! } //! ``` //! @@ -112,6 +112,7 @@ use cast; use std::kinds::marker; use option::{Option,Some,None}; use ops::Drop; +use owned::Box; use ty::Unsafe; /// An atomic boolean type. @@ -663,7 +664,7 @@ impl AtomicPtr { impl AtomicOption { /// Create a new `AtomicOption` - pub fn new(p: ~T) -> AtomicOption { + pub fn new(p: Box) -> AtomicOption { unsafe { AtomicOption { p: Unsafe::new(cast::transmute(p)) } } } @@ -672,7 +673,7 @@ impl AtomicOption { /// Store a value, returning the old value #[inline] - pub fn swap(&self, val: ~T, order: Ordering) -> Option<~T> { + pub fn swap(&self, val: Box, order: Ordering) -> Option> { unsafe { let val = cast::transmute(val); @@ -687,7 +688,7 @@ impl AtomicOption { /// Remove the value, leaving the `AtomicOption` empty. #[inline] - pub fn take(&self, order: Ordering) -> Option<~T> { + pub fn take(&self, order: Ordering) -> Option> { unsafe { self.swap(cast::transmute(0), order) } } @@ -697,7 +698,7 @@ impl AtomicOption { /// the option was already `Some`, returns `Some` of the rejected /// value. #[inline] - pub fn fill(&self, val: ~T, order: Ordering) -> Option<~T> { + pub fn fill(&self, val: Box, order: Ordering) -> Option> { unsafe { let val = cast::transmute(val); let expected = cast::transmute(0); diff --git a/src/libstd/sync/deque.rs b/src/libstd/sync/deque.rs index 22ed66b708b..d06062f02ac 100644 --- a/src/libstd/sync/deque.rs +++ b/src/libstd/sync/deque.rs @@ -56,6 +56,7 @@ use libc; use mem; use ops::Drop; use option::{Option, Some, None}; +use owned::Box; use ptr; use ptr::RawPtr; use sync::arc::UnsafeArc; @@ -117,7 +118,7 @@ pub enum Stolen { /// will only use this structure when allocating a new buffer or deallocating a /// previous one. pub struct BufferPool { - pool: Exclusive>>, + pool: Exclusive>>>, } /// An internal buffer used by the chase-lev deque. This structure is actually @@ -154,7 +155,7 @@ impl BufferPool { (Worker { deque: a }, Stealer { deque: b }) } - fn alloc(&mut self, bits: int) -> ~Buffer { + fn alloc(&mut self, bits: int) -> Box> { unsafe { self.pool.with(|pool| { match pool.iter().position(|x| x.size() >= (1 << bits)) { @@ -165,7 +166,7 @@ impl BufferPool { } } - fn free(&mut self, buf: ~Buffer) { + fn free(&mut self, buf: Box>) { unsafe { let mut buf = Some(buf); self.pool.with(|pool| { @@ -400,6 +401,7 @@ mod tests { use super::{Data, BufferPool, Abort, Empty, Worker, Stealer}; use cast; + use owned::Box; use rt::thread::Thread; use rand; use rand::Rng; @@ -471,7 +473,7 @@ mod tests { t.join(); } - fn stampede(mut w: Worker<~int>, s: Stealer<~int>, + fn stampede(mut w: Worker>, s: Stealer>, nthreads: int, amt: uint) { for _ in range(0, amt) { w.push(box 20); @@ -486,7 +488,7 @@ mod tests { let mut s = s; while (*unsafe_remaining).load(SeqCst) > 0 { match s.steal() { - Data(~20) => { + Data(box 20) => { (*unsafe_remaining).fetch_sub(1, SeqCst); } Data(..) => fail!(), @@ -499,7 +501,7 @@ mod tests { while remaining.load(SeqCst) > 0 { match w.pop() { - Some(~20) => { remaining.fetch_sub(1, SeqCst); } + Some(box 20) => { remaining.fetch_sub(1, SeqCst); } Some(..) => fail!(), None => {} } @@ -512,7 +514,7 @@ mod tests { #[test] fn run_stampede() { - let mut pool = BufferPool::<~int>::new(); + let mut pool = BufferPool::>::new(); let (w, s) = pool.deque(); stampede(w, s, 8, 10000); } @@ -520,7 +522,7 @@ mod tests { #[test] fn many_stampede() { static AMT: uint = 4; - let mut pool = BufferPool::<~int>::new(); + let mut pool = BufferPool::>::new(); let threads = range(0, AMT).map(|_| { let (w, s) = pool.deque(); Thread::start(proc() { @@ -605,7 +607,8 @@ mod tests { let s = s.clone(); let unique_box = box AtomicUint::new(0); let thread_box = unsafe { - *cast::transmute::<&~AtomicUint,**mut AtomicUint>(&unique_box) + *cast::transmute::<&Box, + **mut AtomicUint>(&unique_box) }; (Thread::start(proc() { unsafe { diff --git a/src/libstd/sync/mpsc_queue.rs b/src/libstd/sync/mpsc_queue.rs index 315e412446d..e05959e2591 100644 --- a/src/libstd/sync/mpsc_queue.rs +++ b/src/libstd/sync/mpsc_queue.rs @@ -42,6 +42,7 @@ use cast; use kinds::Send; use ops::Drop; use option::{Option, None, Some}; +use owned::Box; use ptr::RawPtr; use sync::atomics::{AtomicPtr, Release, Acquire, AcqRel, Relaxed}; @@ -120,7 +121,7 @@ impl Queue { assert!((*tail).value.is_none()); assert!((*next).value.is_some()); let ret = (*next).value.take_unwrap(); - let _: ~Node = cast::transmute(tail); + let _: Box> = cast::transmute(tail); return Data(ret); } @@ -145,7 +146,7 @@ impl Drop for Queue { let mut cur = self.tail; while !cur.is_null() { let next = (*cur).next.load(Relaxed); - let _: ~Node = cast::transmute(cur); + let _: Box> = cast::transmute(cur); cur = next; } } diff --git a/src/libstd/sync/spsc_queue.rs b/src/libstd/sync/spsc_queue.rs index f155bdca446..7854a0e168e 100644 --- a/src/libstd/sync/spsc_queue.rs +++ b/src/libstd/sync/spsc_queue.rs @@ -37,6 +37,7 @@ use cast; use kinds::Send; use ops::Drop; use option::{Some, None, Option}; +use owned::Box; use ptr::RawPtr; use sync::atomics::{AtomicPtr, Relaxed, AtomicUint, Acquire, Release}; @@ -187,7 +188,7 @@ impl Queue { (*self.tail_prev.load(Relaxed)).next.store(next, Relaxed); // We have successfully erased all references to 'tail', so // now we can safely drop it. - let _: ~Node = cast::transmute(tail); + let _: Box> = cast::transmute(tail); } } return ret; @@ -215,7 +216,7 @@ impl Drop for Queue { let mut cur = self.first; while !cur.is_null() { let next = (*cur).next.load(Relaxed); - let _n: ~Node = cast::transmute(cur); + let _n: Box> = cast::transmute(cur); cur = next; } } -- cgit 1.4.1-3-g733a5