]> git.lizzy.rs Git - rust.git/commitdiff
libextra: Remove `~fn()` from libextra.
authorPatrick Walton <pcwalton@mimiga.net>
Mon, 18 Nov 2013 23:39:02 +0000 (15:39 -0800)
committerPatrick Walton <pcwalton@mimiga.net>
Tue, 19 Nov 2013 02:27:30 +0000 (18:27 -0800)
src/libextra/future.rs
src/libextra/task_pool.rs
src/libextra/test.rs
src/libextra/workcache.rs

index 8f28be49782538138ba9df88be424a94c6653520..640ced24badd189ada93f5cdf9b499a9cccda1f8 100644 (file)
@@ -36,7 +36,7 @@ pub struct Future<A> {
 }
 
 enum FutureState<A> {
-    Pending(~fn() -> A),
+    Pending(proc() -> A),
     Evaluating,
     Forced(A)
 }
@@ -92,7 +92,7 @@ pub fn from_value(val: A) -> Future<A> {
         Future {state: Forced(val)}
     }
 
-    pub fn from_fn(f: ~fn() -> A) -> Future<A> {
+    pub fn from_fn(f: proc() -> A) -> Future<A> {
         /*!
          * Create a future from a function.
          *
@@ -120,7 +120,7 @@ pub fn from_port(port: PortOne<A>) -> Future<A> {
         }
     }
 
-    pub fn spawn(blk: ~fn() -> A) -> Future<A> {
+    pub fn spawn(blk: proc() -> A) -> Future<A> {
         /*!
          * Create a future from a unique closure.
          *
@@ -137,7 +137,7 @@ pub fn spawn(blk: ~fn() -> A) -> Future<A> {
         Future::from_port(port)
     }
 
-    pub fn spawn_with<B: Send>(v: B, blk: ~fn(B) -> A) -> Future<A> {
+    pub fn spawn_with<B: Send>(v: B, blk: proc(B) -> A) -> Future<A> {
         /*!
          * Create a future from a unique closure taking one argument.
          *
index f7db66dc4e0c491253d5342b7b304c6b00a08024..2ee3daacf80cdb2007b1c87e4517a56c0b88880c 100644 (file)
@@ -23,7 +23,7 @@
 #[cfg(test)] use std::task::SingleThreaded;
 
 enum Msg<T> {
-    Execute(~fn(&T)),
+    Execute(proc(&T)),
     Quit
 }
 
@@ -49,7 +49,7 @@ impl<T> TaskPool<T> {
     /// local data to be kept around in that task.
     pub fn new(n_tasks: uint,
                opt_sched_mode: Option<SchedMode>,
-               init_fn_factory: ~fn() -> ~fn(uint) -> T)
+               init_fn_factory: &fn() -> proc(uint) -> T)
                -> TaskPool<T> {
         assert!(n_tasks >= 1);
 
@@ -57,7 +57,7 @@ pub fn new(n_tasks: uint,
             let (port, chan) = comm::stream::<Msg<T>>();
             let init_fn = init_fn_factory();
 
-            let task_body: ~fn() = || {
+            let task_body: proc() = || {
                 let local_data = init_fn(i);
                 loop {
                     match port.recv() {
@@ -88,7 +88,7 @@ pub fn new(n_tasks: uint,
 
     /// Executes the function `f` on a task in the pool. The function
     /// receives a reference to the local data returned by the `init_fn`.
-    pub fn execute(&mut self, f: ~fn(&T)) {
+    pub fn execute(&mut self, f: proc(&T)) {
         self.channels[self.next_index].send(Execute(f));
         self.next_index += 1;
         if self.next_index == self.channels.len() { self.next_index = 0; }
@@ -97,8 +97,8 @@ pub fn execute(&mut self, f: ~fn(&T)) {
 
 #[test]
 fn test_task_pool() {
-    let f: ~fn() -> ~fn(uint) -> uint = || {
-        let g: ~fn(uint) -> uint = |i| i;
+    let f: proc() -> proc(uint) -> uint = || {
+        let g: proc(uint) -> uint = |i| i;
         g
     };
     let mut pool = TaskPool::new(4, Some(SingleThreaded), f);
index 14fee38dada2c6971d623247ad88a3d871091718..acb3d538c982a620f8c88e32dcd9fa38f648528b 100644 (file)
@@ -74,6 +74,11 @@ fn padded_name(&self, column_count: uint, align: NamePadding) -> ~str {
     }
 }
 
+/// Represents a benchmark function.
+pub trait TDynBenchFn {
+    fn run(&self, harness: &mut BenchHarness);
+}
+
 // A function that runs a test. If the function returns successfully,
 // the test succeeds; if the function fails then the test fails. We
 // may need to come up with a more clever definition of test in order
@@ -81,10 +86,10 @@ fn padded_name(&self, column_count: uint, align: NamePadding) -> ~str {
 pub enum TestFn {
     StaticTestFn(extern fn()),
     StaticBenchFn(extern fn(&mut BenchHarness)),
-    StaticMetricFn(~fn(&mut MetricMap)),
-    DynTestFn(~fn()),
-    DynMetricFn(~fn(&mut MetricMap)),
-    DynBenchFn(~fn(&mut BenchHarness))
+    StaticMetricFn(proc(&mut MetricMap)),
+    DynTestFn(proc()),
+    DynMetricFn(proc(&mut MetricMap)),
+    DynBenchFn(~TDynBenchFn)
 }
 
 impl TestFn {
@@ -859,7 +864,7 @@ pub fn run_test(force_ignore: bool,
 
     fn run_test_inner(desc: TestDesc,
                       monitor_ch: SharedChan<MonitorMsg>,
-                      testfn: ~fn()) {
+                      testfn: proc()) {
         let testfn_cell = ::std::cell::Cell::new(testfn);
         do task::spawn {
             let mut task = task::task();
@@ -878,8 +883,8 @@ fn run_test_inner(desc: TestDesc,
     }
 
     match testfn {
-        DynBenchFn(benchfn) => {
-            let bs = ::test::bench::benchmark(benchfn);
+        DynBenchFn(bencher) => {
+            let bs = ::test::bench::benchmark(|harness| bencher.run(harness));
             monitor_ch.send((desc, TrBench(bs)));
             return;
         }
index 89e50f53ab464c175a2ffd2abeccccd637eaeda0..02855eb9777d2831eebcec8c631c284e9bb61536 100644 (file)
@@ -394,14 +394,14 @@ fn all_fresh(&self, cat: &str, map: &WorkMap) -> bool {
     pub fn exec<T:Send +
         Encodable<json::Encoder> +
         Decodable<json::Decoder>>(
-            &'self self, blk: ~fn(&mut Exec) -> T) -> T {
+            &'self self, blk: proc(&mut Exec) -> T) -> T {
         self.exec_work(blk).unwrap()
     }
 
     fn exec_work<T:Send +
         Encodable<json::Encoder> +
         Decodable<json::Decoder>>( // FIXME(#5121)
-            &'self self, blk: ~fn(&mut Exec) -> T) -> Work<'self, T> {
+            &'self self, blk: proc(&mut Exec) -> T) -> Work<'self, T> {
         let mut bo = Some(blk);
 
         debug!("exec_work: looking up {} and {:?}", self.fn_name,