diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-05-05 18:56:44 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-05-06 23:12:54 -0700 |
| commit | 090040bf4037a094e50b03d79e4baf5cd89c912b (patch) | |
| tree | 27fa91d623889d59260d3db167abdfa8c4288849 /src/libstd/rt | |
| parent | 24f6f26e633e50b5b59f9d0f6cca0b1e49e215d9 (diff) | |
| download | rust-090040bf4037a094e50b03d79e4baf5cd89c912b.tar.gz rust-090040bf4037a094e50b03d79e4baf5cd89c912b.zip | |
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<self>` before the snapshot. How to update your code: * Instead of `~EXPR`, you should write `box EXPR`. * Instead of `~TYPE`, you should write `Box<Type>`. * Instead of `~PATTERN`, you should write `box PATTERN`. [breaking-change]
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/args.rs | 7 | ||||
| -rw-r--r-- | src/libstd/rt/at_exit_imp.rs | 5 | ||||
| -rw-r--r-- | src/libstd/rt/backtrace.rs | 10 | ||||
| -rw-r--r-- | src/libstd/rt/global_heap.rs | 7 | ||||
| -rw-r--r-- | src/libstd/rt/local.rs | 34 | ||||
| -rw-r--r-- | src/libstd/rt/local_ptr.rs | 33 | ||||
| -rw-r--r-- | src/libstd/rt/mod.rs | 16 | ||||
| -rw-r--r-- | src/libstd/rt/rtio.rs | 51 | ||||
| -rw-r--r-- | src/libstd/rt/stack.rs | 3 | ||||
| -rw-r--r-- | src/libstd/rt/task.rs | 41 | ||||
| -rw-r--r-- | src/libstd/rt/thread.rs | 19 | ||||
| -rw-r--r-- | src/libstd/rt/thread_local_storage.rs | 6 | ||||
| -rw-r--r-- | src/libstd/rt/unwind.rs | 16 |
13 files changed, 139 insertions, 109 deletions
diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index 092efcad831..17e6f6b7698 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -67,6 +67,7 @@ mod imp { use clone::Clone; use option::{Option, Some, None}; use iter::Iterator; + use owned::Box; use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; use mem; #[cfg(not(test))] use str::StrSlice; @@ -91,7 +92,7 @@ mod imp { with_lock(|| unsafe { let ptr = get_global_ptr(); let val = mem::replace(&mut *ptr, None); - val.as_ref().map(|s: &~~[~[u8]]| (**s).clone()) + val.as_ref().map(|s: &Box<~[~[u8]]>| (**s).clone()) }) } @@ -106,7 +107,7 @@ mod imp { pub fn clone() -> Option<~[~[u8]]> { with_lock(|| unsafe { let ptr = get_global_ptr(); - (*ptr).as_ref().map(|s: &~~[~[u8]]| (**s).clone()) + (*ptr).as_ref().map(|s: &Box<~[~[u8]]>| (**s).clone()) }) } @@ -117,7 +118,7 @@ mod imp { } } - fn get_global_ptr() -> *mut Option<~~[~[u8]]> { + fn get_global_ptr() -> *mut Option<Box<~[~[u8]]>> { unsafe { cast::transmute(&global_args_ptr) } } diff --git a/src/libstd/rt/at_exit_imp.rs b/src/libstd/rt/at_exit_imp.rs index 2c8e159aeb9..051bc494adc 100644 --- a/src/libstd/rt/at_exit_imp.rs +++ b/src/libstd/rt/at_exit_imp.rs @@ -17,6 +17,7 @@ use iter::Iterator; use kinds::Send; use mem; use option::{Some, None}; +use owned::Box; use ptr::RawPtr; use unstable::sync::Exclusive; use slice::OwnedVector; @@ -36,7 +37,7 @@ pub fn init() { unsafe { rtassert!(!RUNNING); rtassert!(QUEUE.is_null()); - let state: ~Queue = box Exclusive::new(vec!()); + let state: Box<Queue> = box Exclusive::new(vec!()); QUEUE = cast::transmute(state); } } @@ -58,7 +59,7 @@ pub fn run() { rtassert!(!RUNNING); rtassert!(!QUEUE.is_null()); RUNNING = true; - let state: ~Queue = cast::transmute(QUEUE); + let state: Box<Queue> = cast::transmute(QUEUE); QUEUE = 0 as *mut Queue; let mut vec = None; state.with(|arr| { diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 26494f1acd9..ee8041f6880 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -129,7 +129,7 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> { // see src/librustc/back/link.rs for these mappings demangle! ( "$SP$" => "@", - "$UP$" => "~", + "$UP$" => "Box", "$RP$" => "*", "$BP$" => "&", "$LT$" => "<", @@ -858,15 +858,15 @@ mod test { #[test] fn demangle_dollars() { - t!("_ZN4$UP$E", "~"); - t!("_ZN8$UP$testE", "~test"); - t!("_ZN8$UP$test4foobE", "~test::foob"); + t!("_ZN4$UP$E", "Box"); + t!("_ZN8$UP$testE", "Boxtest"); + t!("_ZN8$UP$test4foobE", "Boxtest::foob"); t!("_ZN8$x20test4foobE", " test::foob"); } #[test] fn demangle_many_dollars() { t!("_ZN12test$x20test4foobE", "test test::foob"); - t!("_ZN12test$UP$test4foobE", "test~test::foob"); + t!("_ZN12test$UP$test4foobE", "testBoxtest::foob"); } } diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs index 094bbd13889..7d54c3faf42 100644 --- a/src/libstd/rt/global_heap.rs +++ b/src/libstd/rt/global_heap.rs @@ -72,9 +72,10 @@ pub unsafe fn realloc_raw(ptr: *mut u8, size: uint) -> *mut u8 { #[lang="exchange_malloc"] #[inline] pub unsafe fn exchange_malloc(size: uint) -> *mut u8 { - // The compiler never calls `exchange_free` on ~ZeroSizeType, so zero-size - // allocations can point to this `static`. It would be incorrect to use a null - // pointer, due to enums assuming types like unique pointers are never null. + // The compiler never calls `exchange_free` on Box<ZeroSizeType>, so + // zero-size allocations can point to this `static`. It would be incorrect + // to use a null pointer, due to enums assuming types like unique pointers + // are never null. static EMPTY: () = (); if size == 0 { diff --git a/src/libstd/rt/local.rs b/src/libstd/rt/local.rs index 828bbc118c1..05d1f1764b5 100644 --- a/src/libstd/rt/local.rs +++ b/src/libstd/rt/local.rs @@ -9,17 +9,18 @@ // except according to those terms. use option::Option; +use owned::Box; use rt::task::Task; use rt::local_ptr; /// Encapsulates some task-local data. pub trait Local<Borrowed> { - fn put(value: ~Self); - fn take() -> ~Self; - fn try_take() -> Option<~Self>; + fn put(value: Box<Self>); + fn take() -> Box<Self>; + fn try_take() -> Option<Box<Self>>; fn exists(unused_value: Option<Self>) -> bool; fn borrow(unused_value: Option<Self>) -> Borrowed; - unsafe fn unsafe_take() -> ~Self; + unsafe fn unsafe_take() -> Box<Self>; unsafe fn unsafe_borrow() -> *mut Self; unsafe fn try_unsafe_borrow() -> Option<*mut Self>; } @@ -27,11 +28,11 @@ pub trait Local<Borrowed> { #[allow(visible_private_types)] impl Local<local_ptr::Borrowed<Task>> for Task { #[inline] - fn put(value: ~Task) { unsafe { local_ptr::put(value) } } + fn put(value: Box<Task>) { unsafe { local_ptr::put(value) } } #[inline] - fn take() -> ~Task { unsafe { local_ptr::take() } } + fn take() -> Box<Task> { unsafe { local_ptr::take() } } #[inline] - fn try_take() -> Option<~Task> { unsafe { local_ptr::try_take() } } + fn try_take() -> Option<Box<Task>> { unsafe { local_ptr::try_take() } } fn exists(_: Option<Task>) -> bool { local_ptr::exists() } #[inline] fn borrow(_: Option<Task>) -> local_ptr::Borrowed<Task> { @@ -40,7 +41,7 @@ impl Local<local_ptr::Borrowed<Task>> for Task { } } #[inline] - unsafe fn unsafe_take() -> ~Task { local_ptr::unsafe_take() } + unsafe fn unsafe_take() -> Box<Task> { local_ptr::unsafe_take() } #[inline] unsafe fn unsafe_borrow() -> *mut Task { local_ptr::unsafe_borrow() } #[inline] @@ -54,6 +55,7 @@ mod test { use option::{None, Option}; use unstable::run_in_bare_thread; use super::*; + use owned::Box; use rt::task::Task; #[test] @@ -61,7 +63,7 @@ mod test { run_in_bare_thread(proc() { let task = box Task::new(); Local::put(task); - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); cleanup_task(task); }); } @@ -71,11 +73,11 @@ mod test { run_in_bare_thread(proc() { let task = box Task::new(); Local::put(task); - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); cleanup_task(task); let task = box Task::new(); Local::put(task); - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); cleanup_task(task); }); } @@ -89,7 +91,7 @@ mod test { unsafe { let _task: *mut Task = Local::unsafe_borrow(); } - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); cleanup_task(task); }); } @@ -104,7 +106,7 @@ mod test { let _ = Local::borrow(None::<Task>); } - let task: ~Task = Local::take(); + let task: Box<Task> = Local::take(); cleanup_task(task); }); } @@ -115,15 +117,15 @@ mod test { let task = box Task::new(); Local::put(task); - let t: ~Task = Local::try_take().unwrap(); - let u: Option<~Task> = Local::try_take(); + let t: Box<Task> = Local::try_take().unwrap(); + let u: Option<Box<Task>> = Local::try_take(); assert!(u.is_none()); cleanup_task(t); }); } - fn cleanup_task(mut t: ~Task) { + fn cleanup_task(mut t: Box<Task>) { t.destroyed = true; } diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index f60cfa23e81..39c0d9a5482 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -10,7 +10,7 @@ //! Access to a single thread-local pointer. //! -//! The runtime will use this for storing ~Task. +//! The runtime will use this for storing Box<Task>. //! //! FIXME: Add runtime checks for usage of inconsistent pointer types. //! and for overwriting an existing pointer. @@ -19,6 +19,7 @@ use cast; use ops::{Drop, Deref, DerefMut}; +use owned::Box; use ptr::RawPtr; #[cfg(windows)] // mingw-w32 doesn't like thread_local things @@ -43,7 +44,7 @@ impl<T> Drop for Borrowed<T> { if self.val.is_null() { rtabort!("Aiee, returning null borrowed object!"); } - let val: ~T = cast::transmute(self.val); + let val: Box<T> = cast::transmute(self.val); put::<T>(val); rtassert!(exists()); } @@ -84,6 +85,7 @@ pub unsafe fn borrow<T>() -> Borrowed<T> { pub mod compiled { use cast; use option::{Option, Some, None}; + use owned::Box; use ptr::RawPtr; #[cfg(test)] @@ -154,7 +156,7 @@ pub mod compiled { /// /// Does not validate the pointer type. #[inline(never)] // see comments above - pub unsafe fn put<T>(sched: ~T) { + pub unsafe fn put<T>(sched: Box<T>) { RT_TLS_PTR = cast::transmute(sched) } @@ -164,10 +166,10 @@ pub mod compiled { /// /// Does not validate the pointer type. #[inline(never)] // see comments above - pub unsafe fn take<T>() -> ~T { + pub unsafe fn take<T>() -> Box<T> { let ptr = RT_TLS_PTR; rtassert!(!ptr.is_null()); - let ptr: ~T = cast::transmute(ptr); + let ptr: Box<T> = cast::transmute(ptr); // can't use `as`, due to type not matching with `cfg(test)` RT_TLS_PTR = cast::transmute(0); ptr @@ -179,12 +181,12 @@ pub mod compiled { /// /// Does not validate the pointer type. #[inline(never)] // see comments above - pub unsafe fn try_take<T>() -> Option<~T> { + pub unsafe fn try_take<T>() -> Option<Box<T>> { let ptr = RT_TLS_PTR; if ptr.is_null() { None } else { - let ptr: ~T = cast::transmute(ptr); + let ptr: Box<T> = cast::transmute(ptr); // can't use `as`, due to type not matching with `cfg(test)` RT_TLS_PTR = cast::transmute(0); Some(ptr) @@ -198,7 +200,7 @@ pub mod compiled { /// Does not validate the pointer type. /// Leaves the old pointer in TLS for speed. #[inline(never)] // see comments above - pub unsafe fn unsafe_take<T>() -> ~T { + pub unsafe fn unsafe_take<T>() -> Box<T> { cast::transmute(RT_TLS_PTR) } @@ -234,6 +236,7 @@ pub mod compiled { pub mod native { use cast; use option::{Option, Some, None}; + use owned::Box; use ptr; use ptr::RawPtr; use tls = rt::thread_local_storage; @@ -259,7 +262,7 @@ pub mod native { /// /// Does not validate the pointer type. #[inline] - pub unsafe fn put<T>(sched: ~T) { + pub unsafe fn put<T>(sched: Box<T>) { let key = tls_key(); let void_ptr: *mut u8 = cast::transmute(sched); tls::set(key, void_ptr); @@ -271,13 +274,13 @@ pub mod native { /// /// Does not validate the pointer type. #[inline] - pub unsafe fn take<T>() -> ~T { + pub unsafe fn take<T>() -> Box<T> { let key = tls_key(); let void_ptr: *mut u8 = tls::get(key); if void_ptr.is_null() { rtabort!("thread-local pointer is null. bogus!"); } - let ptr: ~T = cast::transmute(void_ptr); + let ptr: Box<T> = cast::transmute(void_ptr); tls::set(key, ptr::mut_null()); return ptr; } @@ -288,14 +291,14 @@ pub mod native { /// /// Does not validate the pointer type. #[inline] - pub unsafe fn try_take<T>() -> Option<~T> { + pub unsafe fn try_take<T>() -> Option<Box<T>> { match maybe_tls_key() { Some(key) => { let void_ptr: *mut u8 = tls::get(key); if void_ptr.is_null() { None } else { - let ptr: ~T = cast::transmute(void_ptr); + let ptr: Box<T> = cast::transmute(void_ptr); tls::set(key, ptr::mut_null()); Some(ptr) } @@ -311,13 +314,13 @@ pub mod native { /// Does not validate the pointer type. /// Leaves the old pointer in TLS for speed. #[inline] - pub unsafe fn unsafe_take<T>() -> ~T { + pub unsafe fn unsafe_take<T>() -> Box<T> { let key = tls_key(); let void_ptr: *mut u8 = tls::get(key); if void_ptr.is_null() { rtabort!("thread-local pointer is null. bogus!"); } - let ptr: ~T = cast::transmute(void_ptr); + let ptr: Box<T> = cast::transmute(void_ptr); return ptr; } diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index b407bf8897c..e79e3056838 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -57,6 +57,7 @@ Several modules in `core` are clients of `rt`: use any::Any; use kinds::Send; use option::Option; +use owned::Box; use result::Result; use task::TaskOpts; @@ -151,22 +152,25 @@ pub static DEFAULT_ERROR_CODE: int = 101; pub trait Runtime { // Necessary scheduling functions, used for channels and blocking I/O // (sometimes). - fn yield_now(~self, cur_task: ~Task); - fn maybe_yield(~self, cur_task: ~Task); - fn deschedule(~self, times: uint, cur_task: ~Task, + fn yield_now(~self, cur_task: Box<Task>); + fn maybe_yield(~self, cur_task: Box<Task>); + fn deschedule(~self, times: uint, cur_task: Box<Task>, f: |BlockedTask| -> Result<(), BlockedTask>); - fn reawaken(~self, to_wake: ~Task); + fn reawaken(~self, to_wake: Box<Task>); // Miscellaneous calls which are very different depending on what context // you're in. - fn spawn_sibling(~self, cur_task: ~Task, opts: TaskOpts, f: proc():Send); + fn spawn_sibling(~self, + cur_task: Box<Task>, + opts: TaskOpts, + f: proc():Send); fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>>; /// The (low, high) edges of the current stack. fn stack_bounds(&self) -> (uint, uint); // (lo, hi) fn can_block(&self) -> bool; // FIXME: This is a serious code smell and this should not exist at all. - fn wrap(~self) -> ~Any; + fn wrap(~self) -> Box<Any>; } /// One-time runtime initialization. diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs index fc8c79549af..fe9f4932a2a 100644 --- a/src/libstd/rt/rtio.rs +++ b/src/libstd/rt/rtio.rs @@ -18,6 +18,7 @@ use libc; use kinds::Send; use ops::Drop; use option::{Option, Some, None}; +use owned::Box; use path::Path; use result::Err; use rt::local::Local; @@ -40,9 +41,10 @@ pub trait Callback { pub trait EventLoop { fn run(&mut self); fn callback(&mut self, arg: proc():Send); - fn pausable_idle_callback(&mut self, - ~Callback:Send) -> ~PausableIdleCallback:Send; - fn remote_callback(&mut self, ~Callback:Send) -> ~RemoteCallback:Send; + fn pausable_idle_callback(&mut self, Box<Callback:Send>) + -> Box<PausableIdleCallback:Send>; + fn remote_callback(&mut self, Box<Callback:Send>) + -> Box<RemoteCallback:Send>; /// The asynchronous I/O services. Not all event loops may provide one. fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory>; @@ -114,7 +116,7 @@ impl<'a> LocalIo<'a> { // // In order to get around this, we just transmute a copy out of the task // in order to have what is likely a static lifetime (bad). - let mut t: ~Task = Local::take(); + let mut t: Box<Task> = Local::take(); let ret = t.local_io().map(|t| { unsafe { cast::transmute_copy(&t) } }); @@ -149,21 +151,23 @@ impl<'a> LocalIo<'a> { pub trait IoFactory { // networking fn tcp_connect(&mut self, addr: SocketAddr, - timeout: Option<u64>) -> IoResult<~RtioTcpStream:Send>; - fn tcp_bind(&mut self, addr: SocketAddr) -> IoResult<~RtioTcpListener:Send>; - fn udp_bind(&mut self, addr: SocketAddr) -> IoResult<~RtioUdpSocket:Send>; + timeout: Option<u64>) -> IoResult<Box<RtioTcpStream:Send>>; + fn tcp_bind(&mut self, addr: SocketAddr) + -> IoResult<Box<RtioTcpListener:Send>>; + fn udp_bind(&mut self, addr: SocketAddr) + -> IoResult<Box<RtioUdpSocket:Send>>; fn unix_bind(&mut self, path: &CString) - -> IoResult<~RtioUnixListener:Send>; + -> IoResult<Box<RtioUnixListener:Send>>; fn unix_connect(&mut self, path: &CString, - timeout: Option<u64>) -> IoResult<~RtioPipe:Send>; + timeout: Option<u64>) -> IoResult<Box<RtioPipe:Send>>; fn get_host_addresses(&mut self, host: Option<&str>, servname: Option<&str>, hint: Option<ai::Hint>) -> IoResult<~[ai::Info]>; // filesystem operations fn fs_from_raw_fd(&mut self, fd: c_int, close: CloseBehavior) - -> ~RtioFileStream:Send; + -> Box<RtioFileStream:Send>; fn fs_open(&mut self, path: &CString, fm: FileMode, fa: FileAccess) - -> IoResult<~RtioFileStream:Send>; + -> IoResult<Box<RtioFileStream:Send>>; fn fs_unlink(&mut self, path: &CString) -> IoResult<()>; fn fs_stat(&mut self, path: &CString) -> IoResult<FileStat>; fn fs_mkdir(&mut self, path: &CString, @@ -184,23 +188,24 @@ pub trait IoFactory { IoResult<()>; // misc - fn timer_init(&mut self) -> IoResult<~RtioTimer:Send>; + fn timer_init(&mut self) -> IoResult<Box<RtioTimer:Send>>; fn spawn(&mut self, config: ProcessConfig) - -> IoResult<(~RtioProcess:Send, ~[Option<~RtioPipe:Send>])>; + -> IoResult<(Box<RtioProcess:Send>, + ~[Option<Box<RtioPipe:Send>>])>; fn kill(&mut self, pid: libc::pid_t, signal: int) -> IoResult<()>; - fn pipe_open(&mut self, fd: c_int) -> IoResult<~RtioPipe:Send>; + fn pipe_open(&mut self, fd: c_int) -> IoResult<Box<RtioPipe:Send>>; fn tty_open(&mut self, fd: c_int, readable: bool) - -> IoResult<~RtioTTY:Send>; + -> IoResult<Box<RtioTTY:Send>>; fn signal(&mut self, signal: Signum, channel: Sender<Signum>) - -> IoResult<~RtioSignal:Send>; + -> IoResult<Box<RtioSignal:Send>>; } pub trait RtioTcpListener : RtioSocket { - fn listen(~self) -> IoResult<~RtioTcpAcceptor:Send>; + fn listen(~self) -> IoResult<Box<RtioTcpAcceptor:Send>>; } pub trait RtioTcpAcceptor : RtioSocket { - fn accept(&mut self) -> IoResult<~RtioTcpStream:Send>; + fn accept(&mut self) -> IoResult<Box<RtioTcpStream:Send>>; fn accept_simultaneously(&mut self) -> IoResult<()>; fn dont_accept_simultaneously(&mut self) -> IoResult<()>; fn set_timeout(&mut self, timeout: Option<u64>); @@ -214,7 +219,7 @@ pub trait RtioTcpStream : RtioSocket { fn nodelay(&mut self) -> IoResult<()>; fn keepalive(&mut self, delay_in_seconds: uint) -> IoResult<()>; fn letdie(&mut self) -> IoResult<()>; - fn clone(&self) -> ~RtioTcpStream:Send; + fn clone(&self) -> Box<RtioTcpStream:Send>; fn close_write(&mut self) -> IoResult<()>; } @@ -238,7 +243,7 @@ pub trait RtioUdpSocket : RtioSocket { fn hear_broadcasts(&mut self) -> IoResult<()>; fn ignore_broadcasts(&mut self) -> IoResult<()>; - fn clone(&self) -> ~RtioUdpSocket:Send; + fn clone(&self) -> Box<RtioUdpSocket:Send>; } pub trait RtioTimer { @@ -268,15 +273,15 @@ pub trait RtioProcess { pub trait RtioPipe { fn read(&mut self, buf: &mut [u8]) -> IoResult<uint>; fn write(&mut self, buf: &[u8]) -> IoResult<()>; - fn clone(&self) -> ~RtioPipe:Send; + fn clone(&self) -> Box<RtioPipe:Send>; } pub trait RtioUnixListener { - fn listen(~self) -> IoResult<~RtioUnixAcceptor:Send>; + fn listen(~self) -> IoResult<Box<RtioUnixAcceptor:Send>>; } pub trait RtioUnixAcceptor { - fn accept(&mut self) -> IoResult<~RtioPipe:Send>; + fn accept(&mut self) -> IoResult<Box<RtioPipe:Send>>; fn set_timeout(&mut self, timeout: Option<u64>); } diff --git a/src/libstd/rt/stack.rs b/src/libstd/rt/stack.rs index 963ff000c4a..b9bcd1de8fc 100644 --- a/src/libstd/rt/stack.rs +++ b/src/libstd/rt/stack.rs @@ -37,6 +37,7 @@ pub static RED_ZONE: uint = 20 * 1024; #[cfg(not(test))] // in testing, use the original libstd's version pub extern "C" fn rust_stack_exhausted() { use option::{Option, None, Some}; + use owned::Box; use rt::local::Local; use rt::task::Task; use str::Str; @@ -85,7 +86,7 @@ pub extern "C" fn rust_stack_exhausted() { // #9854 - unwinding on windows through __morestack has never worked // #2361 - possible implementation of not using landing pads - let task: Option<~Task> = Local::try_take(); + let task: Option<Box<Task>> = Local::try_take(); let name = match task { Some(ref task) => { task.name.as_ref().map(|n| n.as_slice()) diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index ae5786604c7..5b29de5a8c1 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -24,6 +24,7 @@ use kinds::Send; use local_data; use ops::Drop; use option::{Option, Some, None}; +use owned::Box; use prelude::drop; use result::{Result, Ok, Err}; use rt::Runtime; @@ -51,19 +52,20 @@ pub struct Task { pub destroyed: bool, pub name: Option<SendStr>, - pub stdout: Option<~Writer:Send>, - pub stderr: Option<~Writer:Send>, + pub stdout: Option<Box<Writer:Send>>, + pub stderr: Option<Box<Writer:Send>>, - imp: Option<~Runtime:Send>, + imp: Option<Box<Runtime:Send>>, } pub struct GarbageCollector; pub struct LocalStorage(pub Option<local_data::Map>); -/// A handle to a blocked task. Usually this means having the ~Task pointer by -/// ownership, but if the task is killable, a killer can steal it at any time. +/// A handle to a blocked task. Usually this means having the Box<Task> +/// pointer by ownership, but if the task is killable, a killer can steal it +/// at any time. pub enum BlockedTask { - Owned(~Task), + Owned(Box<Task>), Shared(UnsafeArc<AtomicUint>), } @@ -109,12 +111,12 @@ impl Task { /// This function is *not* meant to be abused as a "try/catch" block. This /// is meant to be used at the absolute boundaries of a task's lifetime, and /// only for that purpose. - pub fn run(~self, mut f: ||) -> ~Task { + pub fn run(~self, mut f: ||) -> Box<Task> { // Need to put ourselves into TLS, but also need access to the unwinder. // Unsafely get a handle to the task so we can continue to use it after // putting it in tls (so we can invoke the unwinder). let handle: *mut Task = unsafe { - *cast::transmute::<&~Task, &*mut Task>(&self) + *cast::transmute::<&Box<Task>, &*mut Task>(&self) }; Local::put(self); @@ -187,7 +189,7 @@ impl Task { let me: *mut Task = Local::unsafe_borrow(); (*me).death.collect_failure((*me).unwinder.result()); } - let mut me: ~Task = Local::take(); + let mut me: Box<Task> = Local::take(); me.destroyed = true; return me; } @@ -195,7 +197,7 @@ impl Task { /// Inserts a runtime object into this task, transferring ownership to the /// task. It is illegal to replace a previous runtime object in this task /// with this argument. - pub fn put_runtime(&mut self, ops: ~Runtime:Send) { + pub fn put_runtime(&mut self, ops: Box<Runtime:Send>) { assert!(self.imp.is_none()); self.imp = Some(ops); } @@ -207,12 +209,12 @@ impl Task { /// /// It is recommended to only use this method when *absolutely necessary*. /// This function may not be available in the future. - pub fn maybe_take_runtime<T: 'static>(&mut self) -> Option<~T> { + pub fn maybe_take_runtime<T: 'static>(&mut self) -> Option<Box<T>> { // This is a terrible, terrible function. The general idea here is to - // take the runtime, cast it to ~Any, check if it has the right type, - // and then re-cast it back if necessary. The method of doing this is - // pretty sketchy and involves shuffling vtables of trait objects - // around, but it gets the job done. + // take the runtime, cast it to Box<Any>, check if it has the right + // type, and then re-cast it back if necessary. The method of doing + // this is pretty sketchy and involves shuffling vtables of trait + // objects around, but it gets the job done. // // FIXME: This function is a serious code smell and should be avoided at // all costs. I have yet to think of a method to avoid this @@ -225,7 +227,8 @@ impl Task { Ok(t) => Some(t), Err(t) => { let (_, obj): (uint, uint) = cast::transmute(t); - let obj: ~Runtime:Send = cast::transmute((vtable, obj)); + let obj: Box<Runtime:Send> = + cast::transmute((vtable, obj)); self.put_runtime(obj); None } @@ -308,7 +311,7 @@ impl Iterator<BlockedTask> for BlockedTasks { impl BlockedTask { /// Returns Some if the task was successfully woken; None if already killed. - pub fn wake(self) -> Option<~Task> { + pub fn wake(self) -> Option<Box<Task>> { match self { Owned(task) => Some(task), Shared(arc) => unsafe { @@ -326,7 +329,7 @@ impl BlockedTask { #[cfg(test)] pub fn trash(self) { assert!(self.wake().is_none()); } /// Create a blocked task, unless the task was already killed. - pub fn block(task: ~Task) -> BlockedTask { + pub fn block(task: Box<Task>) -> BlockedTask { Owned(task) } @@ -367,7 +370,7 @@ impl BlockedTask { if blocked_task_ptr & 0x1 == 0 { Owned(cast::transmute(blocked_task_ptr)) } else { - let ptr: ~UnsafeArc<AtomicUint> = + let ptr: Box<UnsafeArc<AtomicUint>> = cast::transmute(blocked_task_ptr & !1); Shared(*ptr) } diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs index a836958279b..bc9a0b3460a 100644 --- a/src/libstd/rt/thread.rs +++ b/src/libstd/rt/thread.rs @@ -22,6 +22,7 @@ use kinds::Send; use libc; use ops::Drop; use option::{Option, Some, None}; +use owned::Box; use uint; type StartFn = extern "C" fn(*libc::c_void) -> imp::rust_thread_return; @@ -31,7 +32,7 @@ type StartFn = extern "C" fn(*libc::c_void) -> imp::rust_thread_return; pub struct Thread<T> { native: imp::rust_thread, joined: bool, - packet: ~Option<T>, + packet: Box<Option<T>>, } static DEFAULT_STACK_SIZE: uint = 1024 * 1024; @@ -45,7 +46,7 @@ extern fn thread_start(main: *libc::c_void) -> imp::rust_thread_return { use rt::stack; unsafe { stack::record_stack_bounds(0, uint::MAX); - let f: ~proc() = cast::transmute(main); + let f: Box<proc()> = cast::transmute(main); (*f)(); cast::transmute(0 as imp::rust_thread_return) } @@ -78,11 +79,11 @@ impl Thread<()> { pub fn start_stack<T: Send>(stack: uint, main: proc():Send -> T) -> Thread<T> { // We need the address of the packet to fill in to be stable so when - // `main` fills it in it's still valid, so allocate an extra ~ box to do + // `main` fills it in it's still valid, so allocate an extra box to do // so. let packet = box None; let packet2: *mut Option<T> = unsafe { - *cast::transmute::<&~Option<T>, **mut Option<T>>(&packet) + *cast::transmute::<&Box<Option<T>>, **mut Option<T>>(&packet) }; let main = proc() unsafe { *packet2 = Some(main()); }; let native = unsafe { imp::create(stack, box main) }; @@ -152,13 +153,14 @@ mod imp { use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES, SIZE_T, BOOL, LPVOID, DWORD, LPDWORD, HANDLE}; use os; + use owned::Box; use ptr; use rt::stack::RED_ZONE; pub type rust_thread = HANDLE; pub type rust_thread_return = DWORD; - pub unsafe fn create(stack: uint, p: ~proc():Send) -> rust_thread { + pub unsafe fn create(stack: uint, p: Box<proc():Send>) -> rust_thread { let arg: *mut libc::c_void = cast::transmute(p); // FIXME On UNIX, we guard against stack sizes that are too small but // that's because pthreads enforces that stacks are at least @@ -175,7 +177,7 @@ mod imp { if ret as uint == 0 { // be sure to not leak the closure - let _p: ~proc():Send = cast::transmute(arg); + let _p: Box<proc():Send> = cast::transmute(arg); fail!("failed to spawn native thread: {}", os::last_os_error()); } return ret; @@ -218,13 +220,14 @@ mod imp { use libc; use mem; use os; + use owned::Box; use ptr; use rt::stack::RED_ZONE; pub type rust_thread = libc::pthread_t; pub type rust_thread_return = *u8; - pub unsafe fn create(stack: uint, p: ~proc():Send) -> rust_thread { + pub unsafe fn create(stack: uint, p: Box<proc():Send>) -> rust_thread { let mut native: libc::pthread_t = mem::uninit(); let mut attr: libc::pthread_attr_t = mem::uninit(); assert_eq!(pthread_attr_init(&mut attr), 0); @@ -257,7 +260,7 @@ mod imp { if ret != 0 { // be sure to not leak the closure - let _p: ~proc():Send = cast::transmute(arg); + let _p: Box<proc():Send> = cast::transmute(arg); fail!("failed to spawn native thread: {}", os::last_os_error()); } native diff --git a/src/libstd/rt/thread_local_storage.rs b/src/libstd/rt/thread_local_storage.rs index fceff80e792..77062068636 100644 --- a/src/libstd/rt/thread_local_storage.rs +++ b/src/libstd/rt/thread_local_storage.rs @@ -10,6 +10,8 @@ #![allow(dead_code)] +#[cfg(test)] +use owned::Box; #[cfg(unix)] use libc::c_int; #[cfg(unix)] @@ -99,11 +101,11 @@ fn tls_smoke_test() { let value = box 20; create(&mut key); set(key, transmute(value)); - let value: ~int = transmute(get(key)); + let value: Box<int> = transmute(get(key)); assert_eq!(value, box 20); let value = box 30; set(key, transmute(value)); - let value: ~int = transmute(get(key)); + let value: Box<int> = transmute(get(key)); assert_eq!(value, box 30); } } diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 98623c35b78..3ba97f381ab 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -64,6 +64,7 @@ use fmt; use kinds::Send; use mem; use option::{Some, None, Option}; +use owned::Box; use prelude::drop; use ptr::RawPtr; use result::{Err, Ok}; @@ -78,7 +79,7 @@ use uw = rt::libunwind; pub struct Unwinder { unwinding: bool, - cause: Option<~Any:Send> + cause: Option<Box<Any:Send>> } impl Unwinder { @@ -128,7 +129,7 @@ impl Unwinder { } } - pub fn begin_unwind(&mut self, cause: ~Any:Send) -> ! { + pub fn begin_unwind(&mut self, cause: Box<Any:Send>) -> ! { rtdebug!("begin_unwind()"); self.unwinding = true; @@ -154,7 +155,8 @@ impl Unwinder { exception: *uw::_Unwind_Exception) { rtdebug!("exception_cleanup()"); unsafe { - let _: ~uw::_Unwind_Exception = cast::transmute(exception); + let _: Box<uw::_Unwind_Exception> = + cast::transmute(exception); } } } @@ -374,14 +376,16 @@ pub fn begin_unwind<M: Any + Send>(msg: M, file: &'static str, line: uint) -> ! /// Do this split took the LLVM IR line counts of `fn main() { fail!() /// }` from ~1900/3700 (-O/no opts) to 180/590. #[inline(never)] #[cold] // this is the slow path, please never inline this -fn begin_unwind_inner(msg: ~Any:Send, file: &'static str, line: uint) -> ! { +fn begin_unwind_inner(msg: Box<Any:Send>, + file: &'static str, + line: uint) -> ! { let mut task; { let msg_s = match msg.as_ref::<&'static str>() { Some(s) => *s, None => match msg.as_ref::<~str>() { Some(s) => s.as_slice(), - None => "~Any", + None => "Box<Any>", } }; @@ -392,7 +396,7 @@ fn begin_unwind_inner(msg: ~Any:Send, file: &'static str, line: uint) -> ! { // order to get some better diagnostics, we print on failure and // immediately abort the whole process if there is no local task // available. - let opt_task: Option<~Task> = Local::try_take(); + let opt_task: Option<Box<Task>> = Local::try_take(); task = match opt_task { Some(t) => t, None => { |
