From badc580416febb2570064df955dec1cdb1a471d0 Mon Sep 17 00:00:00 2001 From: Scott Lawrence Date: Sun, 26 Jan 2014 23:13:24 -0500 Subject: [PATCH] Removing do keyword from libextra --- src/libextra/arc.rs | 72 +++++++++++------------ src/libextra/comm.rs | 20 +++---- src/libextra/dlist.rs | 4 +- src/libextra/future.rs | 16 +++--- src/libextra/json.rs | 4 +- src/libextra/sync.rs | 117 +++++++++++++++++++------------------- src/libextra/test.rs | 4 +- src/libextra/workcache.rs | 8 +-- 8 files changed, 122 insertions(+), 123 deletions(-) diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index f914fa1ac093..bf47e3bdf89e 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -28,12 +28,12 @@ * let (port, chan) = Chan::new(); * chan.send(shared_numbers.clone()); * - * do spawn { + * spawn(proc() { * let shared_numbers = port.recv(); * let local_numbers = shared_numbers.get(); * * // Work with the local numbers - * } + * }); * } * ``` */ @@ -567,12 +567,12 @@ mod tests { let (p, c) = Chan::new(); - do task::spawn { + task::spawn(proc() { let arc_v: Arc<~[int]> = p.recv(); let v = arc_v.get().clone(); assert_eq!(v[3], 4); - }; + }); c.send(arc_v.clone()); @@ -587,14 +587,14 @@ mod tests { let arc = ~MutexArc::new(false); let arc2 = ~arc.clone(); let (p,c) = Chan::new(); - do task::spawn { + task::spawn(proc() { // wait until parent gets in p.recv(); arc2.access_cond(|state, cond| { *state = true; cond.signal(); }) - } + }); arc.access_cond(|state, cond| { c.send(()); @@ -611,14 +611,14 @@ mod tests { let arc2 = ~arc.clone(); let (p, c) = Chan::new(); - do spawn { + spawn(proc() { let _ = p.recv(); arc2.access_cond(|one, cond| { cond.signal(); // Parent should fail when it wakes up. assert_eq!(*one, 0); }) - } + }); arc.access_cond(|one, cond| { c.send(()); @@ -632,11 +632,11 @@ mod tests { fn test_mutex_arc_poison() { let arc = ~MutexArc::new(1); let arc2 = ~arc.clone(); - do task::try || { + task::try(proc() { arc2.access(|one| { assert_eq!(*one, 2); }) - }; + }); arc.access(|one| { assert_eq!(*one, 1); }) @@ -649,13 +649,13 @@ mod tests { // to underlaying data. let arc = ~MutexArc::new(1); let arc2 = ~MutexArc::new(*arc); - do task::spawn || { + task::spawn(proc() { (*arc2).unsafe_access(|mutex| { (*mutex).access(|one| { assert!(*one == 1); }) }) - }; + }); } } @@ -682,11 +682,11 @@ mod tests { fn test_rw_arc_poison_wr() { let arc = RWArc::new(1); let arc2 = arc.clone(); - do task::try { + task::try(proc() { arc2.write(|one| { assert_eq!(*one, 2); }) - }; + }); arc.read(|one| { assert_eq!(*one, 1); }) @@ -696,11 +696,11 @@ mod tests { fn test_rw_arc_poison_ww() { let arc = RWArc::new(1); let arc2 = arc.clone(); - do task::try { + task::try(proc() { arc2.write(|one| { assert_eq!(*one, 2); }) - }; + }); arc.write(|one| { assert_eq!(*one, 1); }) @@ -709,13 +709,13 @@ mod tests { fn test_rw_arc_poison_dw() { let arc = RWArc::new(1); let arc2 = arc.clone(); - do task::try { + task::try(proc() { arc2.write_downgrade(|mut write_mode| { write_mode.write(|one| { assert_eq!(*one, 2); }) }) - }; + }); arc.write(|one| { assert_eq!(*one, 1); }) @@ -724,11 +724,11 @@ mod tests { fn test_rw_arc_no_poison_rr() { let arc = RWArc::new(1); let arc2 = arc.clone(); - do task::try { + task::try(proc() { arc2.read(|one| { assert_eq!(*one, 2); }) - }; + }); arc.read(|one| { assert_eq!(*one, 1); }) @@ -737,11 +737,11 @@ mod tests { fn test_rw_arc_no_poison_rw() { let arc = RWArc::new(1); let arc2 = arc.clone(); - do task::try { + task::try(proc() { arc2.read(|one| { assert_eq!(*one, 2); }) - }; + }); arc.write(|one| { assert_eq!(*one, 1); }) @@ -750,14 +750,14 @@ mod tests { fn test_rw_arc_no_poison_dr() { let arc = RWArc::new(1); let arc2 = arc.clone(); - do task::try { + task::try(proc() { arc2.write_downgrade(|write_mode| { let read_mode = arc2.downgrade(write_mode); read_mode.read(|one| { assert_eq!(*one, 2); }) }) - }; + }); arc.write(|one| { assert_eq!(*one, 1); }) @@ -768,7 +768,7 @@ mod tests { let arc2 = arc.clone(); let (p, c) = Chan::new(); - do task::spawn { + task::spawn(proc() { arc2.write(|num| { 10.times(|| { let tmp = *num; @@ -778,7 +778,7 @@ mod tests { }); c.send(()); }) - } + }); // Readers try to catch the writer in the act let mut children = ~[]; @@ -786,11 +786,11 @@ mod tests { let arc3 = arc.clone(); let mut builder = task::task(); children.push(builder.future_result()); - do builder.spawn { + builder.spawn(proc() { arc3.read(|num| { assert!(*num >= 0); }) - } + }); }); // Wait for children to pass their asserts @@ -840,19 +840,19 @@ mod tests { let ((rp1, rc1), (rp2, rc2)) = (Chan::new(), Chan::new()); reader_convos.push((rc1, rp2)); let arcn = arc.clone(); - do task::spawn { + task::spawn(proc() { rp1.recv(); // wait for downgrader to give go-ahead arcn.read(|state| { assert_eq!(*state, 31337); rc2.send(()); }) - } + }); }); // Writer task let arc2 = arc.clone(); let ((wp1, wc1), (wp2, wc2)) = (Chan::new(), Chan::new()); - do task::spawn || { + task::spawn(proc() { wp1.recv(); arc2.write_cond(|state, cond| { assert_eq!(*state, 0); @@ -867,7 +867,7 @@ mod tests { *state = 42; }); wc2.send(()); - } + }); // Downgrader (us) arc.write_downgrade(|mut write_mode| { @@ -912,7 +912,7 @@ mod tests { // writer task let xw = x.clone(); - do task::spawn { + task::spawn(proc() { xw.write_cond(|state, c| { wc.send(()); // tell downgrader it's ok to go c.wait(); @@ -921,7 +921,7 @@ mod tests { // trying to receive the "reader cloud lock hand-off". *state = false; }) - } + }); wp.recv(); // wait for writer to get in @@ -934,10 +934,10 @@ mod tests { // make a reader task to trigger the "reader cloud lock" handoff let xr = x.clone(); let (rp, rc) = Chan::new(); - do task::spawn { + task::spawn(proc() { rc.send(()); xr.read(|_state| { }) - } + }); rp.recv(); // wait for reader task to exist let read_mode = x.downgrade(write_mode); diff --git a/src/libextra/comm.rs b/src/libextra/comm.rs index 748289080532..69a1383e44da 100644 --- a/src/libextra/comm.rs +++ b/src/libextra/comm.rs @@ -115,9 +115,9 @@ mod test { pub fn basic_rendezvous_test() { let (port, chan) = rendezvous(); - do spawn { + spawn(proc() { chan.send("abc"); - } + }); assert!(port.recv() == "abc"); } @@ -126,29 +126,29 @@ mod test { fn recv_a_lot() { // Rendezvous streams should be able to handle any number of messages being sent let (port, chan) = rendezvous(); - do spawn { + spawn(proc() { 10000.times(|| { chan.send(()) }) - } + }); 10000.times(|| { port.recv() }) } #[test] fn send_and_fail_and_try_recv() { let (port, chan) = rendezvous(); - do spawn { + spawn(proc() { chan.duplex_stream.send(()); // Can't access this field outside this module fail!() - } + }); port.recv() } #[test] fn try_send_and_recv_then_fail_before_ack() { let (port, chan) = rendezvous(); - do spawn { + spawn(proc() { port.duplex_stream.recv(); fail!() - } + }); chan.try_send(()); } @@ -156,10 +156,10 @@ mod test { #[should_fail] fn send_and_recv_then_fail_before_ack() { let (port, chan) = rendezvous(); - do spawn { + spawn(proc() { port.duplex_stream.recv(); fail!() - } + }); chan.send(()); } } diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 4023a4d7e7fb..0706d4e5a687 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -971,10 +971,10 @@ mod tests { #[test] fn test_send() { let n = list_from([1,2,3]); - do spawn { + spawn(proc() { check_links(&n); assert_eq!(~[&1,&2,&3], n.iter().collect::<~[&int]>()); - } + }); } #[test] diff --git a/src/libextra/future.rs b/src/libextra/future.rs index c6c876aff793..b9121290f33f 100644 --- a/src/libextra/future.rs +++ b/src/libextra/future.rs @@ -18,7 +18,7 @@ * use extra::future::Future; * # fn fib(n: uint) -> uint {42}; * # fn make_a_sandwich() {}; - * let mut delayed_fib = do Future::spawn { fib(5000) }; + * let mut delayed_fib = Future::spawn(proc() { fib(5000) }); * make_a_sandwich(); * println!("fib(5000) = {}", delayed_fib.get()) * ``` @@ -112,9 +112,9 @@ impl Future { * waiting for the result to be received on the port. */ - do Future::from_fn { + Future::from_fn(proc() { port.recv() - } + }) } pub fn spawn(blk: proc() -> A) -> Future { @@ -127,9 +127,9 @@ impl Future { let (port, chan) = Chan::new(); - do spawn { + spawn(proc() { chan.send(blk()); - } + }); Future::from_port(port) } @@ -195,11 +195,11 @@ mod test { #[test] fn test_sendable_future() { let expected = "schlorf"; - let f = do Future::spawn { expected }; - do task::spawn { + let f = Future::spawn(proc() { expected }); + task::spawn(proc() { let mut f = f; let actual = f.get(); assert_eq!(actual, expected); - } + }); } } diff --git a/src/libextra/json.rs b/src/libextra/json.rs index a35c474337d6..d8c1cb51a118 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -2201,7 +2201,7 @@ mod tests { } fn check_err>(to_parse: &'static str, expected_error: &str) { use std::task; - let res = do task::try { + let res = task::try(proc() { // either fails in `decode` (which is what we want), or // returns Some(error_message)/None if the string was // invalid or valid JSON. @@ -2212,7 +2212,7 @@ mod tests { None } } - }; + }); match res { Ok(Some(parse_error)) => fail!("`{}` is not valid json: {}", to_parse, parse_error), diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 60929b71e5f1..3acaf8352564 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -695,11 +695,11 @@ impl<'a> RWLockReadMode<'a> { /// let c = barrier.clone(); /// // The same messages will be printed together. /// // You will NOT see any interleaving. -/// do spawn { +/// spawn(proc() { /// println!("before wait"); /// c.wait(); /// println!("after wait"); -/// } +/// }); /// }); /// ``` #[deriving(Clone)] @@ -778,11 +778,11 @@ mod tests { fn test_sem_as_mutex() { let s = Semaphore::new(1); let s2 = s.clone(); - do task::spawn { + task::spawn(proc() { s2.access(|| { 5.times(|| { task::deschedule(); }) }) - } + }); s.access(|| { 5.times(|| { task::deschedule(); }) }) @@ -793,10 +793,10 @@ mod tests { let (p, c) = Chan::new(); let s = Semaphore::new(0); let s2 = s.clone(); - do task::spawn { + task::spawn(proc() { s2.acquire(); c.send(()); - } + }); 5.times(|| { task::deschedule(); }); s.release(); let _ = p.recv(); @@ -805,11 +805,11 @@ mod tests { let (p, c) = Chan::new(); let s = Semaphore::new(0); let s2 = s.clone(); - do task::spawn { + task::spawn(proc() { 5.times(|| { task::deschedule(); }); s2.release(); let _ = p.recv(); - } + }); s.acquire(); c.send(()); } @@ -821,12 +821,12 @@ mod tests { let s2 = s.clone(); let (p1,c1) = Chan::new(); let (p2,c2) = Chan::new(); - do task::spawn { + task::spawn(proc() { s2.access(|| { let _ = p2.recv(); c1.send(()); }) - } + }); s.access(|| { c2.send(()); let _ = p1.recv(); @@ -842,11 +842,11 @@ mod tests { let mut child_data = Some((s2, c)); s.access(|| { let (s2, c) = child_data.take_unwrap(); - do task::spawn { + task::spawn(proc() { c.send(()); s2.access(|| { }); c.send(()); - } + }); let _ = p.recv(); // wait for child to come alive 5.times(|| { task::deschedule(); }); // let the child contend }); @@ -865,13 +865,12 @@ mod tests { let mut sharedstate = ~0; { let ptr: *int = &*sharedstate; - do task::spawn { + task::spawn(proc() { let sharedstate: &mut int = unsafe { cast::transmute(ptr) }; access_shared(sharedstate, &m2, 10); c.send(()); - - } + }); } { access_shared(sharedstate, &m, 10); @@ -897,24 +896,24 @@ mod tests { // Child wakes up parent m.lock_cond(|cond| { let m2 = m.clone(); - do task::spawn { + task::spawn(proc() { m2.lock_cond(|cond| { let woken = cond.signal(); assert!(woken); }) - } + }); cond.wait(); }); // Parent wakes up child let (port,chan) = Chan::new(); let m3 = m.clone(); - do task::spawn { + task::spawn(proc() { m3.lock_cond(|cond| { chan.send(()); cond.wait(); chan.send(()); }) - } + }); let _ = port.recv(); // Wait until child gets in the mutex m.lock_cond(|cond| { let woken = cond.signal(); @@ -931,13 +930,13 @@ mod tests { let mi = m.clone(); let (port, chan) = Chan::new(); ports.push(port); - do task::spawn { + task::spawn(proc() { mi.lock_cond(|cond| { chan.send(()); cond.wait(); chan.send(()); }) - } + }); }); // wait until all children get in the mutex @@ -961,9 +960,9 @@ mod tests { fn test_mutex_cond_no_waiter() { let m = Mutex::new(); let m2 = m.clone(); - do task::try { + task::try(proc() { m.lock_cond(|_x| { }) - }; + }); m2.lock_cond(|cond| { assert!(!cond.signal()); }) @@ -974,11 +973,11 @@ mod tests { let m = Mutex::new(); let m2 = m.clone(); - let result: result::Result<(), ~Any> = do task::try { + let result: result::Result<(), ~Any> = task::try(proc() { m2.lock(|| { fail!(); }) - }; + }); assert!(result.is_err()); // child task must have finished by the time try returns m.lock(|| { }) @@ -991,18 +990,18 @@ mod tests { let m = Mutex::new(); let m2 = m.clone(); - let result: result::Result<(), ~Any> = do task::try { + let result: result::Result<(), ~Any> = task::try(proc() { let (p, c) = Chan::new(); - do task::spawn { // linked + task::spawn(proc() { // linked let _ = p.recv(); // wait for sibling to get in the mutex task::deschedule(); fail!(); - } + }); m2.lock_cond(|cond| { c.send(()); // tell sibling go ahead cond.wait(); // block forever }) - }; + }); assert!(result.is_err()); // child task must have finished by the time try returns m.lock_cond(|cond| { @@ -1019,14 +1018,14 @@ mod tests { let m2 = m.clone(); let (p, c) = Chan::new(); - let result: result::Result<(), ~Any> = do task::try { + let result: result::Result<(), ~Any> = task::try(proc() { let mut sibling_convos = ~[]; 2.times(|| { let (p, c) = Chan::new(); sibling_convos.push(p); let mi = m2.clone(); // spawn sibling task - do task::spawn { // linked + task::spawn(proc() { // linked mi.lock_cond(|cond| { c.send(()); // tell sibling to go ahead (|| { @@ -1037,7 +1036,7 @@ mod tests { error!("task unwinding and done sending"); }) }) - } + }); }); for p in sibling_convos.mut_iter() { let _ = p.recv(); // wait for sibling to get in the mutex @@ -1045,7 +1044,7 @@ mod tests { m2.lock(|| { }); c.send(sibling_convos); // let parent wait on all children fail!(); - }; + }); assert!(result.is_err()); // child task must have finished by the time try returns let mut r = p.recv(); @@ -1061,52 +1060,52 @@ mod tests { let m = Mutex::new(); m.lock_cond(|cond| { let m2 = m.clone(); - do task::spawn { + task::spawn(proc() { m2.lock_cond(|cond| { cond.signal_on(0); }) - } + }); cond.wait(); }) } #[test] #[ignore(reason = "linked failure?")] fn test_mutex_different_conds() { - let result = do task::try { + let result = task::try(proc() { let m = Mutex::new_with_condvars(2); let m2 = m.clone(); let (p, c) = Chan::new(); - do task::spawn { + task::spawn(proc() { m2.lock_cond(|cond| { c.send(()); cond.wait_on(1); }) - } + }); let _ = p.recv(); m.lock_cond(|cond| { if !cond.signal_on(0) { fail!(); // success; punt sibling awake. } }) - }; + }); assert!(result.is_err()); } #[test] fn test_mutex_no_condvars() { - let result = do task::try { + let result = task::try(proc() { let m = Mutex::new_with_condvars(0); m.lock_cond(|cond| { cond.wait(); }) - }; + }); assert!(result.is_err()); - let result = do task::try { + let result = task::try(proc() { let m = Mutex::new_with_condvars(0); m.lock_cond(|cond| { cond.signal(); }) - }; + }); assert!(result.is_err()); - let result = do task::try { + let result = task::try(proc() { let m = Mutex::new_with_condvars(0); m.lock_cond(|cond| { cond.broadcast(); }) - }; + }); assert!(result.is_err()); } /************************************************************************ @@ -1141,12 +1140,12 @@ mod tests { let mut sharedstate = ~0; { let ptr: *int = &*sharedstate; - do task::spawn { + task::spawn(proc() { let sharedstate: &mut int = unsafe { cast::transmute(ptr) }; access_shared(sharedstate, &x2, mode1, 10); c.send(()); - } + }); } { access_shared(sharedstate, x, mode2, 10); @@ -1189,7 +1188,7 @@ mod tests { let x2 = x.clone(); let (p1, c1) = Chan::new(); let (p2, c2) = Chan::new(); - do task::spawn { + task::spawn(proc() { if !make_mode2_go_first { let _ = p2.recv(); // parent sends to us once it locks, or ... } @@ -1200,7 +1199,7 @@ mod tests { let _ = p2.recv(); c1.send(()); }) - } + }); if make_mode2_go_first { let _ = p1.recv(); // child sends to us once it locks, or ... } @@ -1244,24 +1243,24 @@ mod tests { // Child wakes up parent x.write_cond(|cond| { let x2 = x.clone(); - do task::spawn { + task::spawn(proc() { x2.write_cond(|cond| { let woken = cond.signal(); assert!(woken); }) - } + }); cond.wait(); }); // Parent wakes up child let (port, chan) = Chan::new(); let x3 = x.clone(); - do task::spawn { + task::spawn(proc() { x3.write_cond(|cond| { chan.send(()); cond.wait(); chan.send(()); }) - } + }); let _ = port.recv(); // Wait until child gets in the rwlock x.read(|| { }); // Must be able to get in as a reader in the meantime x.write_cond(|cond| { // Or as another writer @@ -1292,13 +1291,13 @@ mod tests { let xi = x.clone(); let (port, chan) = Chan::new(); ports.push(port); - do task::spawn { + task::spawn(proc() { lock_cond(&xi, dg1, |cond| { chan.send(()); cond.wait(); chan.send(()); }) - } + }); }); // wait until all children get in the mutex @@ -1327,11 +1326,11 @@ mod tests { let x = RWLock::new(); let x2 = x.clone(); - let result: result::Result<(), ~Any> = do task::try || { + let result: result::Result<(), ~Any> = task::try(proc() { lock_rwlock_in_mode(&x2, mode1, || { fail!(); }) - }; + }); assert!(result.is_err()); // child task must have finished by the time try returns lock_rwlock_in_mode(&x, mode2, || { }) @@ -1392,10 +1391,10 @@ mod tests { 9.times(|| { let c = barrier.clone(); let chan = chan.clone(); - do spawn { + spawn(proc() { c.wait(); chan.send(true); - } + }); }); // At this point, all spawned tasks should be blocked, diff --git a/src/libextra/test.rs b/src/libextra/test.rs index c621461fc36a..cd04cddba4a6 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -873,7 +873,7 @@ pub fn run_test(force_ignore: bool, fn run_test_inner(desc: TestDesc, monitor_ch: SharedChan, testfn: proc()) { - do spawn { + spawn(proc() { let mut task = task::task(); task.name(match desc.name { DynTestName(ref name) => SendStrOwned(name.clone()), @@ -885,7 +885,7 @@ pub fn run_test(force_ignore: bool, let task_result = result_future.recv(); let test_result = calc_result(&desc, task_result.is_ok()); monitor_ch.send((desc.clone(), test_result)); - } + }); } match testfn { diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index d8a97ae20770..70bbe02d32f1 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -414,14 +414,14 @@ impl<'a> Prep<'a> { let blk = bo.take_unwrap(); // FIXME: What happens if the task fails? - do spawn { + spawn(proc() { let mut exe = Exec { discovered_inputs: WorkMap::new(), discovered_outputs: WorkMap::new(), }; let v = blk(&mut exe); chan.send((exe, v)); - } + }); Work::from_task(self, port) } } @@ -495,7 +495,7 @@ fn test() { // FIXME (#9639): This needs to handle non-utf8 paths prep.declare_input("file", pth.as_str().unwrap(), file_content); - do prep.exec |_exe| { + prep.exec(proc(_exe) { let out = make_path(~"foo.o"); // FIXME (#9639): This needs to handle non-utf8 paths run::process_status("gcc", [pth.as_str().unwrap().to_owned(), @@ -507,7 +507,7 @@ fn test() { // FIXME (#9639): This needs to handle non-utf8 paths out.as_str().unwrap().to_owned() - } + }) }); println!("{}", s);