From 54f4dcd76aafe33c553f6b58fe3e808f055465e1 Mon Sep 17 00:00:00 2001 From: Marvin Löbel Date: Sun, 27 Oct 2013 20:12:40 +0100 Subject: Prepared `std::sys` for removal, and made `begin_unwind` simpler - `begin_unwind` is now generic over any `T: Any + Send`. - Every value you fail with gets boxed as an `~Any`. - Because of implementation details, `&'static str` and `~str` are still handled specially behind the scenes. - Changed the big macro source string in libsyntax to a raw string literal, and enabled doc comments there. --- src/libstd/task/mod.rs | 48 ++++++++++++++++++++++++++++++++---------------- src/libstd/task/spawn.rs | 7 +++---- 2 files changed, 35 insertions(+), 20 deletions(-) (limited to 'src/libstd/task') diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index 023ba6f7108..cdb70f00dfe 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -60,7 +60,8 @@ use comm::{stream, Chan, GenericChan, GenericPort, Port, Peekable}; use result::{Result, Ok, Err}; use rt::in_green_task_context; use rt::local::Local; -use rt::task::{UnwindReasonAny, UnwindReasonLinked, UnwindReasonStr}; +use rt::task::{UnwindMessageAny, UnwindMessageLinked}; +use rt::task::{UnwindMessageStrStatic, UnwindMessageStrOwned}; use rt::task::{UnwindResult, Success, Failure}; use send_str::{SendStr, IntoSendStr}; use unstable::finally::Finally; @@ -93,9 +94,10 @@ pub struct LinkedFailure; fn wrap_as_any(res: UnwindResult) -> TaskResult { match res { Success => Ok(()), - Failure(UnwindReasonStr(s)) => Err(~s as ~Any), - Failure(UnwindReasonAny(a)) => Err(a), - Failure(UnwindReasonLinked) => Err(~LinkedFailure as ~Any) + Failure(UnwindMessageAny(a)) => Err(a), + Failure(UnwindMessageLinked) => Err(~LinkedFailure as ~Any), + Failure(UnwindMessageStrOwned(s)) => Err(~s as ~Any), + Failure(UnwindMessageStrStatic(s)) => Err(~s as ~Any), } } @@ -1425,38 +1427,52 @@ fn test_indestructible() { } #[test] -fn test_try_fail_cause_static_str() { +fn test_try_fail_message_static_str() { match do try { fail!("static string"); } { - Err(ref e) if e.is::() => {} - Err(_) | Ok(()) => fail!() + Err(e) => { + type T = &'static str; + assert!(e.is::()); + assert_eq!(*e.move::().unwrap(), "static string"); + } + Ok(()) => fail!() } } #[test] -fn test_try_fail_cause_owned_str() { +fn test_try_fail_message_owned_str() { match do try { fail!(~"owned string"); } { - Err(ref e) if e.is::() => {} - Err(_) | Ok(()) => fail!() + Err(e) => { + type T = ~str; + assert!(e.is::()); + assert_eq!(*e.move::().unwrap(), ~"owned string"); + } + Ok(()) => fail!() } } #[test] -fn test_try_fail_cause_any() { +fn test_try_fail_message_any() { match do try { fail!(~413u16 as ~Any); } { - Err(ref e) if e.is::() => {} - Err(_) | Ok(()) => fail!() + Err(e) => { + type T = ~Any; + assert!(e.is::()); + let any = e.move::().unwrap(); + assert!(any.is::()); + assert_eq!(*any.move::().unwrap(), 413u16); + } + Ok(()) => fail!() } } #[ignore(reason = "linked failure")] #[test] -fn test_try_fail_cause_linked() { +fn test_try_fail_message_linked() { match do try { do spawn { fail!() @@ -1468,11 +1484,11 @@ fn test_try_fail_cause_linked() { } #[test] -fn test_try_fail_cause_any_wrapped() { +fn test_try_fail_message_unit_struct() { struct Juju; match do try { - fail!(~Juju) + fail!(Juju) } { Err(ref e) if e.is::() => {} Err(_) | Ok(()) => fail!() diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index a08bf8f3147..4a98e396bbc 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -83,12 +83,11 @@ use local_data; use rt::local::Local; use rt::sched::{Scheduler, Shutdown, TaskFromFriend}; use rt::task::{Task, Sched}; -use rt::task::{UnwindReasonLinked, UnwindReasonStr}; +use rt::task::{UnwindMessageLinked, UnwindMessageStrStatic}; use rt::task::{UnwindResult, Success, Failure}; use rt::thread::Thread; use rt::work_queue::WorkQueue; use rt::{in_green_task_context, new_event_loop, KillHandle}; -use send_str::IntoSendStr; use task::SingleThreaded; use task::TaskOpts; use task::unkillable; @@ -325,7 +324,7 @@ impl Drop for Taskgroup { do RuntimeGlue::with_task_handle_and_failing |me, failing| { if failing { for x in self.notifier.mut_iter() { - x.task_result = Some(Failure(UnwindReasonLinked)); + x.task_result = Some(Failure(UnwindMessageLinked)); } // Take everybody down with us. After this point, every // other task in the group will see 'tg' as none, which @@ -380,7 +379,7 @@ impl AutoNotify { notify_chan: chan, // Un-set above when taskgroup successfully made. - task_result: Some(Failure(UnwindReasonStr("AutoNotify::new()".into_send_str()))) + task_result: Some(Failure(UnwindMessageStrStatic("AutoNotify::new()"))) } } } -- cgit 1.4.1-3-g733a5