From a57e2a7f4ddb9899de6a26281c9a1a3501866db8 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 18 Jul 2014 15:59:54 -0700 Subject: [PATCH 1/4] core: Stabliize core::cmp Mark Eq, PartialEq, Ord, PartialOrd as unstable: they will change slightly after trait reform. Equiv as experimental: better solutions are desired. min/max stable. --- src/libcore/cmp.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index f374d2e9a2743..8db59bd370e76 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -37,6 +37,8 @@ //! assert!(SketchyNum {num: 25} != SketchyNum {num: 57}); //! ``` +#![stable] + use option::{Option, Some}; /// Trait for values that can be compared for equality and inequality. @@ -53,6 +55,7 @@ use option::{Option, Some}; /// Eventually, this will be implemented by default for types that implement /// `Eq`. #[lang="eq"] +#[unstable = "Definition may change slightly after trait reform"] pub trait PartialEq { /// This method tests for `self` and `other` values to be equal, and is used by `==`. fn eq(&self, other: &Self) -> bool; @@ -71,6 +74,7 @@ pub trait PartialEq { /// - reflexive: `a == a`; /// - symmetric: `a == b` implies `b == a`; and /// - transitive: `a == b` and `b == c` implies `a == c`. +#[unstable = "Definition may change slightly after trait reform"] pub trait Eq: PartialEq { // FIXME #13101: this method is used solely by #[deriving] to // assert that every component of a type implements #[deriving] @@ -86,6 +90,7 @@ pub trait Eq: PartialEq { /// An ordering is, e.g, a result of a comparison between two values. #[deriving(Clone, PartialEq, Show)] +#[stable] pub enum Ordering { /// An ordering where a compared value is less [than another]. Less = -1i, @@ -104,6 +109,7 @@ pub enum Ordering { /// true; and /// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for /// both `==` and `>`. +#[unstable = "Definition may change slightly after trait reform"] pub trait Ord: Eq + PartialOrd { /// This method returns an ordering between `self` and `other` values. /// @@ -118,8 +124,10 @@ pub trait Ord: Eq + PartialOrd { fn cmp(&self, other: &Self) -> Ordering; } +#[unstable = "Trait is unstable."] impl Eq for Ordering {} +#[unstable = "Trait is unstable."] impl Ord for Ordering { #[inline] fn cmp(&self, other: &Ordering) -> Ordering { @@ -127,6 +135,7 @@ impl Ord for Ordering { } } +#[unstable = "Trait is unstable."] impl PartialOrd for Ordering { #[inline] fn partial_cmp(&self, other: &Ordering) -> Option { @@ -140,6 +149,7 @@ impl PartialOrd for Ordering { /// If the first ordering is different, the first ordering is all that must be returned. /// If the first ordering is equal, then second ordering is returned. #[inline] +#[deprecated = "Just call .cmp() on an Ordering"] pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering { match o1 { Equal => o2, @@ -157,6 +167,7 @@ pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering { /// `NaN < 0 == false` and `NaN >= 0 == false` (cf. IEEE 754-2008 section /// 5.11). #[lang="ord"] +#[unstable = "Definition may change slightly after trait reform"] pub trait PartialOrd: PartialEq { /// This method returns an ordering between `self` and `other` values /// if one exists. @@ -202,6 +213,7 @@ pub trait PartialOrd: PartialEq { /// of different types. The most common use case for this relation is /// container types; e.g. it is often desirable to be able to use `&str` /// values to look up entries in a container with `String` keys. +#[experimental = "Better solutions may be discovered."] pub trait Equiv { /// Implement this function to decide equivalent values. fn equiv(&self, other: &T) -> bool; @@ -209,12 +221,14 @@ pub trait Equiv { /// Compare and return the minimum of two values. #[inline] +#[stable] pub fn min(v1: T, v2: T) -> T { if v1 < v2 { v1 } else { v2 } } /// Compare and return the maximum of two values. #[inline] +#[stable] pub fn max(v1: T, v2: T) -> T { if v1 > v2 { v1 } else { v2 } } @@ -227,6 +241,7 @@ mod impls { macro_rules! eq_impl( ($($t:ty)*) => ($( + #[unstable = "Trait is unstable."] impl PartialEq for $t { #[inline] fn eq(&self, other: &$t) -> bool { (*self) == (*other) } @@ -236,6 +251,7 @@ mod impls { )*) ) + #[unstable = "Trait is unstable."] impl PartialEq for () { #[inline] fn eq(&self, _other: &()) -> bool { true } @@ -247,6 +263,7 @@ mod impls { macro_rules! totaleq_impl( ($($t:ty)*) => ($( + #[unstable = "Trait is unstable."] impl Eq for $t {} )*) ) @@ -255,6 +272,7 @@ mod impls { macro_rules! ord_impl( ($($t:ty)*) => ($( + #[unstable = "Trait is unstable."] impl PartialOrd for $t { #[inline] fn partial_cmp(&self, other: &$t) -> Option { @@ -277,6 +295,7 @@ mod impls { )*) ) + #[unstable = "Trait is unstable."] impl PartialOrd for () { #[inline] fn partial_cmp(&self, _: &()) -> Option { @@ -284,6 +303,7 @@ mod impls { } } + #[unstable = "Trait is unstable."] impl PartialOrd for bool { #[inline] fn partial_cmp(&self, other: &bool) -> Option { @@ -295,6 +315,7 @@ mod impls { macro_rules! totalord_impl( ($($t:ty)*) => ($( + #[unstable = "Trait is unstable."] impl Ord for $t { #[inline] fn cmp(&self, other: &$t) -> Ordering { @@ -306,11 +327,13 @@ mod impls { )*) ) + #[unstable = "Trait is unstable."] impl Ord for () { #[inline] fn cmp(&self, _other: &()) -> Ordering { Equal } } + #[unstable = "Trait is unstable."] impl Ord for bool { #[inline] fn cmp(&self, other: &bool) -> Ordering { @@ -321,12 +344,14 @@ mod impls { totalord_impl!(char uint u8 u16 u32 u64 int i8 i16 i32 i64) // & pointers + #[unstable = "Trait is unstable."] impl<'a, T: PartialEq> PartialEq for &'a T { #[inline] fn eq(&self, other: & &'a T) -> bool { *(*self) == *(*other) } #[inline] fn ne(&self, other: & &'a T) -> bool { *(*self) != *(*other) } } + #[unstable = "Trait is unstable."] impl<'a, T: PartialOrd> PartialOrd for &'a T { #[inline] fn partial_cmp(&self, other: &&'a T) -> Option { @@ -341,19 +366,23 @@ mod impls { #[inline] fn gt(&self, other: & &'a T) -> bool { *(*self) > *(*other) } } + #[unstable = "Trait is unstable."] impl<'a, T: Ord> Ord for &'a T { #[inline] fn cmp(&self, other: & &'a T) -> Ordering { (**self).cmp(*other) } } + #[unstable = "Trait is unstable."] impl<'a, T: Eq> Eq for &'a T {} // &mut pointers + #[unstable = "Trait is unstable."] impl<'a, T: PartialEq> PartialEq for &'a mut T { #[inline] fn eq(&self, other: &&'a mut T) -> bool { **self == *(*other) } #[inline] fn ne(&self, other: &&'a mut T) -> bool { **self != *(*other) } } + #[unstable = "Trait is unstable."] impl<'a, T: PartialOrd> PartialOrd for &'a mut T { #[inline] fn partial_cmp(&self, other: &&'a mut T) -> Option { @@ -368,9 +397,11 @@ mod impls { #[inline] fn gt(&self, other: &&'a mut T) -> bool { **self > **other } } + #[unstable = "Trait is unstable."] impl<'a, T: Ord> Ord for &'a mut T { #[inline] fn cmp(&self, other: &&'a mut T) -> Ordering { (**self).cmp(*other) } } + #[unstable = "Trait is unstable."] impl<'a, T: Eq> Eq for &'a mut T {} } From 71f3d8fc1f917b5a5626bba166a54d6a68971dc1 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 18 Jul 2014 16:01:55 -0700 Subject: [PATCH 2/4] std: Stabilize default All stable. --- src/libcore/default.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcore/default.rs b/src/libcore/default.rs index 0fcc02aae0d2b..70780515dec9d 100644 --- a/src/libcore/default.rs +++ b/src/libcore/default.rs @@ -10,6 +10,8 @@ //! The `Default` trait for types which may have meaningful default values +#![stable] + /// A trait that types which have a useful default value should implement. pub trait Default { /// Return the "default value" for a type. From cf8bfde9d313f27dc72ba3a7d15618f6bbd93e9d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 18 Jul 2014 16:02:14 -0700 Subject: [PATCH 3/4] alloc: Stabilize rc module. Weak pointers experimental. Most everything else stable. --- src/liballoc/rc.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index d97bce39c2de9..8d4e788bc8035 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -148,6 +148,8 @@ fn main() { */ +#![stable] + use core::mem::transmute; use core::cell::Cell; use core::clone::Clone; @@ -171,6 +173,7 @@ struct RcBox { /// Immutable reference counted pointer type #[unsafe_no_drop_flag] +#[stable] pub struct Rc { // FIXME #12808: strange names to try to avoid interfering with // field accesses of the contained type via Deref @@ -179,6 +182,7 @@ pub struct Rc { _noshare: marker::NoShare } +#[stable] impl Rc { /// Construct a new reference-counted box pub fn new(value: T) -> Rc { @@ -203,6 +207,7 @@ impl Rc { impl Rc { /// Downgrade the reference-counted pointer to a weak reference + #[experimental = "Weak pointers may not belong in this module."] pub fn downgrade(&self) -> Weak { self.inc_weak(); Weak { @@ -238,6 +243,7 @@ impl Rc { } } +#[experimental = "Deref is experimental."] impl Deref for Rc { /// Borrow the value contained in the reference-counted box #[inline(always)] @@ -247,6 +253,7 @@ impl Deref for Rc { } #[unsafe_destructor] +#[experimental = "Drop is experimental."] impl Drop for Rc { fn drop(&mut self) { unsafe { @@ -269,7 +276,7 @@ impl Drop for Rc { } } -#[unstable] +#[unstable = "Clone is unstable."] impl Clone for Rc { #[inline] fn clone(&self) -> Rc { @@ -278,6 +285,7 @@ impl Clone for Rc { } } +#[stable] impl Default for Rc { #[inline] fn default() -> Rc { @@ -285,6 +293,7 @@ impl Default for Rc { } } +#[unstable = "PartialEq is unstable."] impl PartialEq for Rc { #[inline(always)] fn eq(&self, other: &Rc) -> bool { **self == **other } @@ -292,8 +301,10 @@ impl PartialEq for Rc { fn ne(&self, other: &Rc) -> bool { **self != **other } } +#[unstable = "Eq is unstable."] impl Eq for Rc {} +#[unstable = "PartialOrd is unstable."] impl PartialOrd for Rc { #[inline(always)] fn partial_cmp(&self, other: &Rc) -> Option { @@ -313,11 +324,13 @@ impl PartialOrd for Rc { fn ge(&self, other: &Rc) -> bool { **self >= **other } } +#[unstable = "Ord is unstable."] impl Ord for Rc { #[inline] fn cmp(&self, other: &Rc) -> Ordering { (**self).cmp(&**other) } } +#[experimental = "Show is experimental."] impl fmt::Show for Rc { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (**self).fmt(f) @@ -326,6 +339,7 @@ impl fmt::Show for Rc { /// Weak reference to a reference-counted box #[unsafe_no_drop_flag] +#[experimental = "Weak pointers may not belong in this module."] pub struct Weak { // FIXME #12808: strange names to try to avoid interfering with // field accesses of the contained type via Deref @@ -334,6 +348,7 @@ pub struct Weak { _noshare: marker::NoShare } +#[experimental = "Weak pointers may not belong in this module."] impl Weak { /// Upgrade a weak reference to a strong reference pub fn upgrade(&self) -> Option> { @@ -347,6 +362,7 @@ impl Weak { } #[unsafe_destructor] +#[experimental = "Weak pointers may not belong in this module."] impl Drop for Weak { fn drop(&mut self) { unsafe { @@ -364,6 +380,7 @@ impl Drop for Weak { } #[unstable] +#[experimental = "Weak pointers may not belong in this module."] impl Clone for Weak { #[inline] fn clone(&self) -> Weak { From 0b946f0a9099c8a116d2f51473a48d0e16b43037 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 18 Jul 2014 16:02:39 -0700 Subject: [PATCH 4/4] std: Stabilize task module. Most stable. deschedule/failing experimental because of concerns about naming and desirability. Adds task::name() to replace deprecated task::with_name(). --- src/libstd/task.rs | 59 +++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/src/libstd/task.rs b/src/libstd/task.rs index d7af92024eb5e..4b8c15a0152a3 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -91,7 +91,7 @@ //! # } //! ``` -#![experimental] +#![stable] use any::Any; use comm::channel; @@ -104,7 +104,9 @@ use rt::local::Local; use rt::task; use rt::task::Task; use str::{Str, SendStr, IntoMaybeOwned}; +use string::String; use sync::Future; +use to_str::ToString; /// A means of spawning a task pub trait Spawner { @@ -172,6 +174,7 @@ impl TaskBuilder { impl TaskBuilder { /// Name the task-to-be. Currently the name is used for identification /// only in failure messages. + #[unstable = "IntoMaybeOwned will probably change."] pub fn named>(mut self, name: T) -> TaskBuilder { self.name = Some(name.into_maybe_owned()); self @@ -184,12 +187,14 @@ impl TaskBuilder { } /// Redirect task-local stdout. + #[experimental = "May not want to make stdio overridable here."] pub fn stdout(mut self, stdout: Box) -> TaskBuilder { self.stdout = Some(stdout); self } /// Redirect task-local stderr. + #[experimental = "May not want to make stdio overridable here."] pub fn stderr(mut self, stderr: Box) -> TaskBuilder { self.stderr = Some(stderr); self @@ -288,6 +293,7 @@ impl TaskBuilder { /// future returns `result::Ok` containing the value returned by the /// function. If the child task fails then the future returns `result::Err` /// containing the argument to `fail!(...)` as an `Any` trait object. + #[experimental = "Futures are experimental."] pub fn try_future(self, f: proc():Send -> T) -> Future>> { // currently, the on_exit proc provided by librustrt only works for unit @@ -308,6 +314,7 @@ impl TaskBuilder { /// Execute a function in a newly-spawnedtask and block until the task /// completes or fails. Equivalent to `.try_future(f).unwrap()`. + #[unstable = "Error type may change."] pub fn try(self, f: proc():Send -> T) -> Result> { self.try_future(f).unwrap() } @@ -329,6 +336,7 @@ pub fn spawn(f: proc(): Send) { /// value of the function or an error if the task failed. /// /// This is equivalent to `TaskBuilder::new().try`. +#[unstable = "Error type may change."] pub fn try(f: proc(): Send -> T) -> Result> { TaskBuilder::new().try(f) } @@ -337,6 +345,7 @@ pub fn try(f: proc(): Send -> T) -> Result> { /// task's result. /// /// This is equivalent to `TaskBuilder::new().try_future`. +#[experimental = "Futures are experimental."] pub fn try_future(f: proc():Send -> T) -> Future>> { TaskBuilder::new().try_future(f) } @@ -345,6 +354,7 @@ pub fn try_future(f: proc():Send -> T) -> Future(blk: |Option<&str>| -> U) -> U { use rt::task::Task; @@ -355,7 +365,20 @@ pub fn with_task_name(blk: |Option<&str>| -> U) -> U { } } +/// Read the name of the current task. +#[stable] +pub fn name() -> Option { + use rt::task::Task; + + let task = Local::borrow(None::); + match task.name { + Some(ref name) => Some(name.as_slice().to_string()), + None => None + } +} + /// Yield control to the task scheduler. +#[unstable = "Name will change."] pub fn deschedule() { use rt::local::Local; @@ -366,6 +389,7 @@ pub fn deschedule() { /// True if the running task is currently failing (e.g. will return `true` inside a /// destructor that is run while unwinding the stack after a call to `fail!()`). +#[unstable = "May move to a different module."] pub fn failing() -> bool { use rt::task::Task; Local::borrow(None::).unwinder.unwinding() @@ -377,7 +401,6 @@ mod test { use boxed::BoxAny; use result; use result::{Ok, Err}; - use str::StrAllocating; use string::String; use std::io::{ChanReader, ChanWriter}; use prelude::*; @@ -388,38 +411,30 @@ mod test { #[test] fn test_unnamed_task() { - spawn(proc() { - with_task_name(|name| { - assert!(name.is_none()); - }) - }) + try(proc() { + assert!(name().is_none()); + }).map_err(|_| ()).unwrap(); } #[test] fn test_owned_named_task() { - TaskBuilder::new().named("ada lovelace".to_string()).spawn(proc() { - with_task_name(|name| { - assert!(name.unwrap() == "ada lovelace"); - }) - }) + TaskBuilder::new().named("ada lovelace".to_string()).try(proc() { + assert!(name().unwrap() == "ada lovelace".to_string()); + }).map_err(|_| ()).unwrap(); } #[test] fn test_static_named_task() { - TaskBuilder::new().named("ada lovelace").spawn(proc() { - with_task_name(|name| { - assert!(name.unwrap() == "ada lovelace"); - }) - }) + TaskBuilder::new().named("ada lovelace").try(proc() { + assert!(name().unwrap() == "ada lovelace".to_string()); + }).map_err(|_| ()).unwrap(); } #[test] fn test_send_named_task() { - TaskBuilder::new().named("ada lovelace".into_maybe_owned()).spawn(proc() { - with_task_name(|name| { - assert!(name.unwrap() == "ada lovelace"); - }) - }) + TaskBuilder::new().named("ada lovelace".into_maybe_owned()).try(proc() { + assert!(name().unwrap() == "ada lovelace".to_string()); + }).map_err(|_| ()).unwrap(); } #[test]