]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #15014 : brson/rust/all-crates-experimental, r=cmr
authorbors <bors@rust-lang.org>
Thu, 19 Jun 2014 03:31:18 +0000 (03:31 +0000)
committerbors <bors@rust-lang.org>
Thu, 19 Jun 2014 03:31:18 +0000 (03:31 +0000)
This creates a stability baseline for all crates that we distribute that are not `std`. In general, all library code must start as experimental and progress in stages to become stable.

1  2 
src/libgreen/lib.rs
src/libnative/lib.rs
src/libtest/lib.rs
src/libuuid/lib.rs

diff --combined src/libgreen/lib.rs
index ee25d19e324cc8e474ff5ff21057325113e5a326,8024b5b75e74440b086588818acd8c4e2da7a584..007f63383ac1bb79fc790fee5ae8a6fa470ca5d5
  //!
  //! # Using a scheduler pool
  //!
 +//! This library adds a `GreenTaskBuilder` trait that extends the methods
 +//! available on `std::task::TaskBuilder` to allow spawning a green task,
 +//! possibly pinned to a particular scheduler thread:
 +//!
  //! ```rust
 -//! use std::rt::task::TaskOpts;
 -//! use green::{SchedPool, PoolConfig};
 -//! use green::sched::{PinnedTask, TaskFromFriend};
 +//! use std::task::TaskBuilder;
 +//! use green::{SchedPool, PoolConfig, GreenTaskBuilder};
  //!
  //! let config = PoolConfig::new();
  //! let mut pool = SchedPool::new(config);
  //!
  //! // Spawn tasks into the pool of schedulers
 -//! pool.spawn(TaskOpts::new(), proc() {
 +//! TaskBuilder::new().green(&mut pool).spawn(proc() {
  //!     // this code is running inside the pool of schedulers
  //!
  //!     spawn(proc() {
  //! let mut handle = pool.spawn_sched();
  //!
  //! // Pin a task to the spawned scheduler
 -//! let task = pool.task(TaskOpts::new(), proc() { /* ... */ });
 -//! handle.send(PinnedTask(task));
 -//!
 -//! // Schedule a task on this new scheduler
 -//! let task = pool.task(TaskOpts::new(), proc() { /* ... */ });
 -//! handle.send(TaskFromFriend(task));
 +//! TaskBuilder::new().green_pinned(&mut pool, &mut handle).spawn(proc() {
 +//!     /* ... */
 +//! });
  //!
  //! // Handles keep schedulers alive, so be sure to drop all handles before
  //! // destroying the sched pool
  //! ```
  
  #![crate_id = "green#0.11.0-pre"]
+ #![experimental]
  #![license = "MIT/ASL2"]
  #![crate_type = "rlib"]
  #![crate_type = "dylib"]
  // NB this does *not* include globs, please keep it that way.
  #![feature(macro_rules, phase)]
  #![allow(visible_private_types)]
 +#![allow(deprecated)]
 +#![feature(default_type_params)]
  
  #[cfg(test)] #[phase(plugin, link)] extern crate log;
  #[cfg(test)] extern crate rustuv;
@@@ -226,9 -225,8 +227,9 @@@ use std::rt::task::TaskOpts
  use std::rt;
  use std::sync::atomics::{SeqCst, AtomicUint, INIT_ATOMIC_UINT};
  use std::sync::deque;
 +use std::task::{TaskBuilder, Spawner};
  
 -use sched::{Shutdown, Scheduler, SchedHandle, TaskFromFriend, NewNeighbor};
 +use sched::{Shutdown, Scheduler, SchedHandle, TaskFromFriend, PinnedTask, NewNeighbor};
  use sleeper_list::SleeperList;
  use stack::StackPool;
  use task::GreenTask;
@@@ -447,7 -445,6 +448,7 @@@ impl SchedPool 
      /// This is useful to create a task which can then be sent to a specific
      /// scheduler created by `spawn_sched` (and possibly pin it to that
      /// scheduler).
 +    #[deprecated = "use the green and green_pinned methods of GreenTaskBuilder instead"]
      pub fn task(&mut self, opts: TaskOpts, f: proc():Send) -> Box<GreenTask> {
          GreenTask::configure(&mut self.stack_pool, opts, f)
      }
      /// New tasks are spawned in a round-robin fashion to the schedulers in this
      /// pool, but tasks can certainly migrate among schedulers once they're in
      /// the pool.
 +    #[deprecated = "use the green and green_pinned methods of GreenTaskBuilder instead"]
      pub fn spawn(&mut self, opts: TaskOpts, f: proc():Send) {
          let task = self.task(opts, f);
  
@@@ -568,54 -564,3 +569,54 @@@ impl Drop for SchedPool 
          }
      }
  }
 +
 +/// A spawner for green tasks
 +pub struct GreenSpawner<'a>{
 +    pool: &'a mut SchedPool,
 +    handle: Option<&'a mut SchedHandle>
 +}
 +
 +impl<'a> Spawner for GreenSpawner<'a> {
 +    #[inline]
 +    fn spawn(self, opts: TaskOpts, f: proc():Send) {
 +        let GreenSpawner { pool, handle } = self;
 +        match handle {
 +            None    => pool.spawn(opts, f),
 +            Some(h) => h.send(PinnedTask(pool.task(opts, f)))
 +        }
 +    }
 +}
 +
 +/// An extension trait adding `green` configuration methods to `TaskBuilder`.
 +pub trait GreenTaskBuilder {
 +    fn green<'a>(self, &'a mut SchedPool) -> TaskBuilder<GreenSpawner<'a>>;
 +    fn green_pinned<'a>(self, &'a mut SchedPool, &'a mut SchedHandle)
 +                        -> TaskBuilder<GreenSpawner<'a>>;
 +}
 +
 +impl<S: Spawner> GreenTaskBuilder for TaskBuilder<S> {
 +    fn green<'a>(self, pool: &'a mut SchedPool) -> TaskBuilder<GreenSpawner<'a>> {
 +        self.spawner(GreenSpawner {pool: pool, handle: None})
 +    }
 +
 +    fn green_pinned<'a>(self, pool: &'a mut SchedPool, handle: &'a mut SchedHandle)
 +                        -> TaskBuilder<GreenSpawner<'a>> {
 +        self.spawner(GreenSpawner {pool: pool, handle: Some(handle)})
 +    }
 +}
 +
 +#[cfg(test)]
 +mod test {
 +    use std::task::TaskBuilder;
 +    use super::{SchedPool, PoolConfig, GreenTaskBuilder};
 +
 +    #[test]
 +    fn test_green_builder() {
 +        let mut pool = SchedPool::new(PoolConfig::new());
 +        let res = TaskBuilder::new().green(&mut pool).try(proc() {
 +            "Success!".to_string()
 +        });
 +        assert_eq!(res.ok().unwrap(), "Success!".to_string());
 +        pool.shutdown();
 +    }
 +}
diff --combined src/libnative/lib.rs
index 40b99c5bbdb1d0bb08d4d948cf5c46e1024a959e,e72d5c3b87564d5becc3cbd93e72439cdc1b46c0..24f1b9b9407db72de79d57e1dcfb0a723967354a
  //! ```rust
  //! extern crate native;
  //!
 +//! use std::task::TaskBuilder;
 +//! use native::NativeTaskBuilder;
 +//!
  //! fn main() {
  //!     // We're not sure whether this main function is run in 1:1 or M:N mode.
  //!
 -//!     native::task::spawn(proc() {
 +//!     TaskBuilder::new().native().spawn(proc() {
  //!         // this code is guaranteed to be run on a native thread
  //!     });
  //! }
  //! ```
  
  #![crate_id = "native#0.11.0-pre"]
+ #![experimental]
  #![license = "MIT/ASL2"]
  #![crate_type = "rlib"]
  #![crate_type = "dylib"]
@@@ -53,8 -51,7 +54,8 @@@
         html_root_url = "http://doc.rust-lang.org/")]
  #![deny(unused_result, unused_must_use)]
  #![allow(non_camel_case_types)]
 -#![feature(macro_rules)]
 +#![allow(deprecated)]
 +#![feature(default_type_params)]
  
  // NB this crate explicitly does *not* allow glob imports, please seriously
  //    consider whether they're needed before adding that feature here (the
@@@ -69,8 -66,6 +70,8 @@@ use std::os
  use std::rt;
  use std::str;
  
 +pub use task::NativeTaskBuilder;
 +
  pub mod io;
  pub mod task;
  
diff --combined src/libtest/lib.rs
index 112ffd7c1a4a480899e26bbc345a25845d2f23b5,0415c20425be11b4b606b0f6e8d75320a3196118..4df8cfdd490ee541f47719ff61dad2d316a692cf
@@@ -24,6 -24,7 +24,7 @@@
  // build off of.
  
  #![crate_id = "test#0.11.0-pre"]
+ #![experimental]
  #![comment = "Rust internal test library only used by rustc"]
  #![license = "MIT/ASL2"]
  #![crate_type = "rlib"]
@@@ -1049,13 -1050,14 +1050,13 @@@ pub fn run_test(opts: &TestOpts
              if nocapture {
                  drop((stdout, stderr));
              } else {
 -                task.opts.stdout = Some(box stdout as Box<Writer + Send>);
 -                task.opts.stderr = Some(box stderr as Box<Writer + Send>);
 +                task = task.stdout(box stdout as Box<Writer + Send>);
 +                task = task.stderr(box stderr as Box<Writer + Send>);
              }
 -            let result_future = task.future_result();
 -            task.spawn(testfn);
 +            let result_future = task.try_future(testfn);
  
              let stdout = reader.read_to_end().unwrap().move_iter().collect();
 -            let task_result = result_future.recv();
 +            let task_result = result_future.unwrap();
              let test_result = calc_result(&desc, task_result.is_ok());
              monitor_ch.send((desc.clone(), test_result, stdout));
          })
diff --combined src/libuuid/lib.rs
index b68b435da4bb0a7d427504083e4586d6fa4a5fce,e65eeb824672cae3f19cd03d55e13ec2588342bd..19627e2c2ce5017ecf7e8a8a35e841554487c5e0
@@@ -55,6 -55,7 +55,7 @@@ Examples of string representations
  */
  
  #![crate_id = "uuid#0.11.0-pre"]
+ #![experimental]
  #![crate_type = "rlib"]
  #![crate_type = "dylib"]
  #![license = "MIT/ASL2"]
@@@ -209,6 -210,8 +210,6 @@@ impl Uuid 
      /// * `d3` A 16-bit word
      /// * `d4` Array of 8 octets
      pub fn from_fields(d1: u32, d2: u16, d3: u16, d4: &[u8]) -> Uuid {
 -        use std::mem::{to_be16, to_be32};
 -
          // First construct a temporary field-based struct
          let mut fields = UuidFields {
                  data1: 0,
                  data4: [0, ..8]
          };
  
 -        fields.data1 = to_be32(d1);
 -        fields.data2 = to_be16(d2);
 -        fields.data3 = to_be16(d3);
 +        fields.data1 = d1.to_be();
 +        fields.data2 = d2.to_be();
 +        fields.data3 = d3.to_be();
          slice::bytes::copy_memory(fields.data4, d4);
  
          unsafe {
      ///
      /// Example: `550e8400-e29b-41d4-a716-446655440000`
      pub fn to_hyphenated_str(&self) -> String {
 -        use std::mem::{to_be16, to_be32};
          // Convert to field-based struct as it matches groups in output.
          // Ensure fields are in network byte order, as per RFC.
          let mut uf: UuidFields;
          unsafe {
              uf = transmute_copy(&self.bytes);
          }
 -        uf.data1 = to_be32(uf.data1);
 -        uf.data2 = to_be16(uf.data2);
 -        uf.data3 = to_be16(uf.data3);
 +        uf.data1 = uf.data1.to_be();
 +        uf.data2 = uf.data2.to_be();
 +        uf.data3 = uf.data3.to_be();
          let s = format!("{:08x}-{:04x}-{:04x}-{:02x}{:02x}-\
                           {:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
              uf.data1,