diff --git a/src/test/auxiliary/cci_capture_clause.rs b/src/test/auxiliary/cci_capture_clause.rs index c22047287e62..fd319aacd05f 100644 --- a/src/test/auxiliary/cci_capture_clause.rs +++ b/src/test/auxiliary/cci_capture_clause.rs @@ -8,12 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::oldcomm::*; +use core::pipes::*; pub fn foo(x: T) -> Port { - let p = Port(); - let c = Chan(&p); - do task::spawn() |copy c, copy x| { + let (p, c) = stream(); + do task::spawn() |copy x| { c.send(x); } p diff --git a/src/test/auxiliary/test_comm.rs b/src/test/auxiliary/test_comm.rs deleted file mode 100644 index 6fd39368baec..000000000000 --- a/src/test/auxiliary/test_comm.rs +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/* - Minimized version of core::oldcomm for testing. - - Could probably be more minimal. - */ - -use core::libc::size_t; - - -/** - * A oldcommunication endpoint that can receive messages - * - * Each port has a unique per-task identity and may not be replicated or - * transmitted. If a port value is copied, both copies refer to the same - * port. Ports may be associated with multiple `chan`s. - */ -pub enum port { - port_t(@port_ptr) -} - -/// Constructs a port -pub fn port() -> port { - unsafe { - port_t(@port_ptr(rustrt::new_port(sys::size_of::() as size_t))) - } -} - -struct port_ptr { - po: *rust_port, -} - -impl port_ptr : Drop { - fn finalize(&self) { - unsafe { - debug!("in the port_ptr destructor"); - do task::unkillable { - let yield = 0u; - let yieldp = ptr::addr_of(&yield); - rustrt::rust_port_begin_detach(self.po, yieldp); - if yield != 0u { - task::yield(); - } - rustrt::rust_port_end_detach(self.po); - - while rustrt::rust_port_size(self.po) > 0u as size_t { - recv_::(self.po); - } - rustrt::del_port(self.po); - } - } - } -} - -fn port_ptr(po: *rust_port) -> port_ptr { - debug!("in the port_ptr constructor"); - port_ptr { - po: po - } -} - -/** - * Receive from a port. If no data is available on the port then the - * task will block until data becomes available. - */ -pub fn recv(p: port) -> T { recv_((**p).po) } - - -/// Receive on a raw port pointer -pub fn recv_(p: *rust_port) -> T { - unsafe { - let yield = 0; - let yieldp = ptr::addr_of(&yield); - let mut res; - res = rusti::init::(); - rustrt::port_recv(ptr::addr_of(&res) as *uint, p, yieldp); - - if yield != 0 { - // Data isn't available yet, so res has not been initialized. - task::yield(); - } else { - // In the absense of compiler-generated preemption points - // this is a good place to yield - task::yield(); - } - move res - } -} - - -/* Implementation details */ - - -enum rust_port {} - -type port_id = int; - -#[abi = "cdecl"] -extern mod rustrt { - #[legacy_exports]; - - fn new_port(unit_sz: libc::size_t) -> *rust_port; - fn del_port(po: *rust_port); - fn rust_port_begin_detach(po: *rust_port, - yield: *libc::uintptr_t); - fn rust_port_end_detach(po: *rust_port); - fn rust_port_size(po: *rust_port) -> libc::size_t; - fn port_recv(dptr: *uint, po: *rust_port, - yield: *libc::uintptr_t); -} - -#[abi = "rust-intrinsic"] -extern mod rusti { - #[legacy_exports]; - fn init() -> T; -} - - diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 58cc6a1513c5..5ae2996f39ed 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -26,7 +26,6 @@ use std::deque; use std::deque::Deque; use std::par; use core::io::WriterUtil; -use core::oldcomm::*; use core::int::abs; type node_id = i64; diff --git a/src/test/bench/msgsend-ring.rs b/src/test/bench/msgsend-ring.rs deleted file mode 100644 index 43b20ed2db41..000000000000 --- a/src/test/bench/msgsend-ring.rs +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// This test creates a bunch of tasks that simultaneously send to each -// other in a ring. The messages should all be basically -// independent. It's designed to hammer the global kernel lock, so -// that things will look really good once we get that lock out of the -// message path. - -use core::oldcomm::*; -use core::oldcomm; - -extern mod std; -use std::time; -use std::future; - -fn thread_ring(i: uint, - count: uint, - num_chan: oldcomm::Chan, - num_port: oldcomm::Port) { - // Send/Receive lots of messages. - for uint::range(0u, count) |j| { - num_chan.send(i * j); - num_port.recv(); - }; -} - -fn main() { - let args = os::args(); - let args = if os::getenv(~"RUST_BENCH").is_some() { - ~[~"", ~"100", ~"10000"] - } else if args.len() <= 1u { - ~[~"", ~"100", ~"1000"] - } else { - args - }; - - let num_tasks = uint::from_str(args[1]).get(); - let msg_per_task = uint::from_str(args[2]).get(); - - let num_port = Port(); - let mut num_chan = Chan(&num_port); - - let start = time::precise_time_s(); - - // create the ring - let mut futures = ~[]; - - for uint::range(1u, num_tasks) |i| { - let get_chan = Port(); - let get_chan_chan = Chan(&get_chan); - - let new_future = do future::spawn - |copy num_chan, move get_chan_chan| { - let p = Port(); - get_chan_chan.send(Chan(&p)); - thread_ring(i, msg_per_task, num_chan, p) - }; - futures.push(move new_future); - - num_chan = get_chan.recv(); - }; - - // do our iteration - thread_ring(0u, msg_per_task, num_chan, num_port); - - // synchronize - for futures.each |f| { f.get() }; - - let stop = time::precise_time_s(); - - // all done, report stats. - let num_msgs = num_tasks * msg_per_task; - let elapsed = (stop - start); - let rate = (num_msgs as float) / elapsed; - - io::println(fmt!("Sent %? messages in %? seconds", - num_msgs, elapsed)); - io::println(fmt!(" %? messages / second", rate)); - io::println(fmt!(" %? μs / message", 1000000. / rate)); -} diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index 5853e6e0e877..740a2754e244 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -14,6 +14,8 @@ extern mod std; use std::map; use std::map::HashMap; use std::sort; +use std::cell::Cell; +use core::pipes::*; fn print_complements() { let all = ~[Blue, Red, Yellow]; @@ -98,9 +100,9 @@ fn transform(aa: color, bb: color) -> color { fn creature( name: uint, color: color, - from_rendezvous: oldcomm::Port>, - to_rendezvous: oldcomm::Chan, - to_rendezvous_log: oldcomm::Chan<~str> + from_rendezvous: Port>, + to_rendezvous: SharedChan, + to_rendezvous_log: SharedChan<~str> ) { let mut color = color; let mut creatures_met = 0; @@ -108,8 +110,8 @@ fn creature( loop { // ask for a pairing - oldcomm::send(to_rendezvous, CreatureInfo {name: name, color: color}); - let resp = oldcomm::recv(from_rendezvous); + to_rendezvous.send(CreatureInfo {name: name, color: color}); + let resp = from_rendezvous.recv(); // log and change, or print and quit match resp { @@ -126,7 +128,7 @@ fn creature( // log creatures met and evil clones of self let report = fmt!("%u", creatures_met) + ~" " + show_number(evil_clones_met); - oldcomm::send(to_rendezvous_log, report); + to_rendezvous_log.send(report); break; } } @@ -135,61 +137,54 @@ fn creature( fn rendezvous(nn: uint, set: ~[color]) { - pub fn spawn_listener(+f: fn~(oldcomm::Port)) -> oldcomm::Chan { - let setup_po = oldcomm::Port(); - let setup_ch = oldcomm::Chan(&setup_po); - do task::spawn |move f| { - let po = oldcomm::Port(); - let ch = oldcomm::Chan(&po); - oldcomm::send(setup_ch, ch); - f(move po); - } - oldcomm::recv(setup_po) - } - // these ports will allow us to hear from the creatures - let from_creatures: oldcomm::Port = oldcomm::Port(); - let from_creatures_log: oldcomm::Port<~str> = oldcomm::Port(); + let (from_creatures, to_rendezvous) = stream::(); + let to_rendezvous = SharedChan(to_rendezvous); + let (from_creatures_log, to_rendezvous_log) = stream::<~str>(); + let to_rendezvous_log = SharedChan(to_rendezvous_log); // these channels will be passed to the creatures so they can talk to us - let to_rendezvous = oldcomm::Chan(&from_creatures); - let to_rendezvous_log = oldcomm::Chan(&from_creatures_log); // these channels will allow us to talk to each creature by 'name'/index - let to_creature: ~[oldcomm::Chan>] = + let to_creature: ~[Chan>] = vec::mapi(set, |ii, col| { // create each creature as a listener with a port, and // give us a channel to talk to each let ii = ii; let col = *col; - do spawn_listener |from_rendezvous, move ii, move col| { - creature(ii, col, from_rendezvous, to_rendezvous, - to_rendezvous_log); + let to_rendezvous = to_rendezvous.clone(); + let to_rendezvous_log = to_rendezvous_log.clone(); + let (from_rendezvous, to_creature) = stream(); + let from_rendezvous = Cell(from_rendezvous); + do task::spawn |move ii, move col| { + creature(ii, col, from_rendezvous.take(), to_rendezvous.clone(), + to_rendezvous_log.clone()); } + to_creature }); let mut creatures_met = 0; // set up meetings... for nn.times { - let fst_creature: CreatureInfo = oldcomm::recv(from_creatures); - let snd_creature: CreatureInfo = oldcomm::recv(from_creatures); + let fst_creature: CreatureInfo = from_creatures.recv(); + let snd_creature: CreatureInfo = from_creatures.recv(); creatures_met += 2; - oldcomm::send(to_creature[fst_creature.name], Some(snd_creature)); - oldcomm::send(to_creature[snd_creature.name], Some(fst_creature)); + to_creature[fst_creature.name].send(Some(snd_creature)); + to_creature[snd_creature.name].send(Some(fst_creature)); } // tell each creature to stop for vec::eachi(to_creature) |_ii, to_one| { - oldcomm::send(*to_one, None); + to_one.send(None); } // save each creature's meeting stats let mut report = ~[]; for vec::each(to_creature) |_to_one| { - report.push(oldcomm::recv(from_creatures_log)); + report.push(from_creatures_log.recv()); } // print each color in the set diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index a2f83e3f84f3..fab0af479cc9 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -129,7 +129,6 @@ fn make_sequence_processor(sz: uint, from_parent: pipes::Port<~[u8]>, _ => { ~"" } }; - //oldcomm::send(to_parent, fmt!("yay{%u}", sz)); to_parent.send(move buffer); } diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index b56552d46fe0..c146b6ac3711 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -14,7 +14,7 @@ A parallel version of fibonacci numbers. This version is meant mostly as a way of stressing and benchmarking - the task system. It supports a lot of oldcommand-line arguments to + the task system. It supports a lot of old command-line arguments to control how it runs. */ diff --git a/src/test/bench/task-perf-linked-failure.rs b/src/test/bench/task-perf-linked-failure.rs index c58f07dad2e4..d2dd0eaf7458 100644 --- a/src/test/bench/task-perf-linked-failure.rs +++ b/src/test/bench/task-perf-linked-failure.rs @@ -19,21 +19,26 @@ // Creates in the background 'num_tasks' tasks, all blocked forever. // Doesn't return until all such tasks are ready, but doesn't block forever itself. + +use core::pipes::*; + fn grandchild_group(num_tasks: uint) { - let po = oldcomm::Port(); - let ch = oldcomm::Chan(&po); + let (po, ch) = stream(); + let ch = SharedChan(ch); for num_tasks.times { + let ch = ch.clone(); do task::spawn { // linked - oldcomm::send(ch, ()); - oldcomm::recv(oldcomm::Port::<()>()); // block forever + ch.send(()); + let (p, _c) = stream::<()>(); + p.recv(); // block forever } } error!("Grandchild group getting started"); for num_tasks.times { // Make sure all above children are fully spawned; i.e., enlisted in // their ancestor groups. - oldcomm::recv(po); + po.recv(); } error!("Grandchild group ready to go."); // Master grandchild task exits early. diff --git a/src/test/bench/task-perf-one-million.rs b/src/test/bench/task-perf-one-million.rs index e4c7718325ff..c5092ecaecc0 100644 --- a/src/test/bench/task-perf-one-million.rs +++ b/src/test/bench/task-perf-one-million.rs @@ -10,79 +10,55 @@ // Test for concurrent tasks -enum msg { - ready(oldcomm::Chan), - start, - done(int), -} +use core::pipes::*; -fn calc(children: uint, parent_ch: oldcomm::Chan) { - let port = oldcomm::Port(); - let chan = oldcomm::Chan(&port); - let mut child_chs = ~[]; - let mut sum = 0; +fn calc(children: uint, parent_wait_chan: &Chan>>) { - for iter::repeat (children) { + let wait_ports: ~[Port>>] = do vec::from_fn(children) |_| { + let (wait_port, wait_chan) = stream::>>(); do task::spawn { - calc(0u, chan); - }; - } - - for iter::repeat (children) { - match oldcomm::recv(port) { - ready(child_ch) => { - child_chs.push(child_ch); - } - _ => fail ~"task-perf-one-million failed (port not ready)" + calc(children / 2, &wait_chan); } - } + wait_port + }; - oldcomm::send(parent_ch, ready(chan)); + let child_start_chans: ~[Chan>] = vec::map_consume(wait_ports, |port| port.recv()); - match oldcomm::recv(port) { - start => { - for vec::each(child_chs) |child_ch| { - oldcomm::send(*child_ch, start); - } - } - _ => fail ~"task-perf-one-million failed (port not in start state)" - } + let (start_port, start_chan) = stream::>(); + parent_wait_chan.send(start_chan); + let parent_result_chan: Chan = start_port.recv(); - for iter::repeat (children) { - match oldcomm::recv(port) { - done(child_sum) => { sum += child_sum; } - _ => fail ~"task-perf-one-million failed (port not done)" - } - } + let child_sum_ports: ~[Port] = do vec::map_consume(child_start_chans) |child_start_chan| { + let (child_sum_port, child_sum_chan) = stream::(); + child_start_chan.send(child_sum_chan); + child_sum_port + }; - oldcomm::send(parent_ch, done(sum + 1)); + let mut sum = 0; + vec::consume(child_sum_ports, |_, sum_port| sum += sum_port.recv() ); + + parent_result_chan.send(sum + 1); } fn main() { let args = os::args(); let args = if os::getenv(~"RUST_BENCH").is_some() { - ~[~"", ~"100000"] + ~[~"", ~"30"] } else if args.len() <= 1u { - ~[~"", ~"100"] + ~[~"", ~"10"] } else { args }; let children = uint::from_str(args[1]).get(); - let port = oldcomm::Port(); - let chan = oldcomm::Chan(&port); + let (wait_port, wait_chan) = stream(); do task::spawn { - calc(children, chan); - }; - match oldcomm::recv(port) { - ready(chan) => { - oldcomm::send(chan, start); - } - _ => fail ~"task-perf-one-million failed (port not ready)" - } - let sum = match oldcomm::recv(port) { - done(sum) => { sum } - _ => fail ~"task-perf-one-million failed (port not done)" + calc(children, &wait_chan); }; + + let start_chan = wait_port.recv(); + let (sum_port, sum_chan) = stream::(); + start_chan.send(sum_chan); + let sum = sum_port.recv(); error!("How many tasks? %d tasks.", sum); } diff --git a/src/test/bench/task-perf-word-count-generic.rs b/src/test/bench/task-perf-word-count-generic.rs deleted file mode 100644 index 17444018356e..000000000000 --- a/src/test/bench/task-perf-word-count-generic.rs +++ /dev/null @@ -1,384 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/*! - A parallel word-frequency counting program. - - This is meant primarily to demonstrate Rust's MapReduce framework. - - It takes a list of files on the oldcommand line and outputs a list of - words along with how many times each word is used. - -*/ - -// xfail-pretty - -#[allow(structural_records)]; // Pipes - -extern mod std; - -use core::option; -use std::map; -use std::map::HashMap; -use core::hash::Hash; -use core::io::{ReaderUtil, WriterUtil}; - -use std::time; - -use core::oldcomm::Chan; -use core::oldcomm::Port; -use core::oldcomm::recv; -use core::oldcomm::send; -use core::cmp::Eq; -use core::to_bytes::IterBytes; - -macro_rules! move_out ( - { $x:expr } => { unsafe { let y = move *ptr::addr_of(&($x)); move y } } -) - -trait word_reader { - fn read_word() -> Option<~str>; -} - -// These used to be in task, but they disappeared. -pub type joinable_task = Port<()>; -pub fn spawn_joinable(+f: fn~()) -> joinable_task { - let p = Port(); - let c = Chan(&p); - do task::spawn() |move f| { - f(); - c.send(()); - } - p -} - -pub fn join(t: joinable_task) { - t.recv() -} - -impl io::Reader: word_reader { - fn read_word() -> Option<~str> { read_word(self) } -} - -fn file_word_reader(filename: ~str) -> word_reader { - match io::file_reader(&Path(filename)) { - result::Ok(f) => { f as word_reader } - result::Err(e) => { fail fmt!("%?", e) } - } -} - -fn map(f: fn~() -> word_reader, emit: map_reduce::putter<~str, int>) { - let f = f(); - loop { - match f.read_word() { - Some(w) => { emit(&w, 1); } - None => { break; } - } - } -} - -fn reduce(word: &~str, get: map_reduce::getter) { - let mut count = 0; - - loop { match get() { Some(_) => { count += 1; } None => { break; } } } - - io::println(fmt!("%s\t%?", *word, count)); -} - -pub struct box { - mut contents: Option, -} - -pub impl box { - fn swap(f: fn(+v: T) -> T) { - let mut tmp = None; - self.contents <-> tmp; - self.contents = Some(f(option::unwrap(move tmp))); - } - - fn unwrap() -> T { - let mut tmp = None; - self.contents <-> tmp; - option::unwrap(move tmp) - } -} - -pub fn box(+x: T) -> box { - box { - contents: Some(move x) - } -} - -mod map_reduce { - use core::oldcomm::*; - - use std::map::HashMap; - use std::map; - - pub type putter = fn(&K, V); - - pub type mapper = fn~(K1, putter); - - pub type getter = fn() -> Option; - - pub type reducer = fn~(&K, getter); - - enum ctrl_proto { - find_reducer(K, Chan>>), - mapper_done - } - - - proto! ctrl_proto ( - open: send { - find_reducer(K) -> reducer_response, - mapper_done -> ! - } - - reducer_response: recv { - reducer(::core::oldcomm::Chan<::map_reduce::reduce_proto>) - -> open - } - ) - - pub enum reduce_proto { - emit_val(V), - done, - addref, - release - } - - fn start_mappers( - map: &mapper, - ctrls: &mut ~[ctrl_proto::server::open], - inputs: &~[K1]) - -> ~[::joinable_task] - { - let mut tasks = ~[]; - for inputs.each |i| { - let (ctrl, ctrl_server) = ctrl_proto::init(); - let ctrl = ::box(move ctrl); - let i = copy *i; - let m = copy *map; - tasks.push(::spawn_joinable(|move ctrl, move i| map_task(copy m, &ctrl, i))); - ctrls.push(move ctrl_server); - } - move tasks - } - - fn map_task( - map: mapper, - ctrl: &::box>, - input: K1) - { - // log(error, "map_task " + input); - let intermediates: HashMap>> - = map::HashMap(); - - do map(input) |key: &K2, val| { - let mut c = None; - let found: Option>> - = intermediates.find(*key); - match found { - Some(_c) => { c = Some(_c); } - None => { - do ctrl.swap |ctrl| { - let ctrl = ctrl_proto::client::find_reducer(move ctrl, *key); - match pipes::recv(move ctrl) { - ctrl_proto::reducer(c_, ctrl) => { - c = Some(c_); - move_out!(ctrl) - } - } - } - intermediates.insert(*key, c.get()); - send(c.get(), addref); - } - } - send(c.get(), emit_val(val)); - } - - fn finish( - _k: K, v: Chan<::map_reduce::reduce_proto>) - { - send(v, release); - } - for intermediates.each_value |v| { send(v, release) } - ctrl_proto::client::mapper_done(ctrl.unwrap()); - } - - fn reduce_task( - reduce: ~reducer, - key: K, - out: Chan>>) - { - let p = Port(); - - send(out, Chan(&p)); - - let mut ref_count = 0; - let mut is_done = false; - - fn get(p: Port<::map_reduce::reduce_proto>, - ref_count: &mut int, is_done: &mut bool) - -> Option { - while !*is_done || *ref_count > 0 { - match recv(p) { - emit_val(v) => { - // error!("received %d", v); - return Some(v); - } - done => { - // error!("all done"); - *is_done = true; - } - addref => { *ref_count += 1; } - release => { *ref_count -= 1; } - } - } - return None; - } - - (*reduce)(&key, || get(p, &mut ref_count, &mut is_done) ); - } - - pub fn map_reduce( - map: mapper, - reduce: reducer, - inputs: ~[K1]) - { - let mut ctrl = ~[]; - - // This task becomes the master control task. It task::_spawns - // to do the rest. - - let reducers = map::HashMap(); - let mut tasks = start_mappers(&map, &mut ctrl, &inputs); - let mut num_mappers = vec::len(inputs) as int; - - while num_mappers > 0 { - let (_ready, message, ctrls) = pipes::select(move ctrl); - match option::unwrap(move message) { - ctrl_proto::mapper_done => { - // error!("received mapper terminated."); - num_mappers -= 1; - ctrl = move ctrls; - } - ctrl_proto::find_reducer(k, cc) => { - let c; - // log(error, "finding reducer for " + k); - match reducers.find(k) { - Some(_c) => { - // log(error, - // "reusing existing reducer for " + k); - c = _c; - } - None => { - // log(error, "creating new reducer for " + k); - let p = Port(); - let ch = Chan(&p); - let r = copy reduce, kk = k; - tasks.push(::spawn_joinable(|move r| - reduce_task(~copy r, kk, ch) - )); - c = recv(p); - reducers.insert(k, c); - } - } - ctrl = vec::append_one( - move ctrls, - ctrl_proto::server::reducer(move_out!(cc), c)); - } - } - } - - for reducers.each_value |v| { send(v, done) } - - for tasks.each |t| { ::join(*t); } - } -} - -fn main() { - let argv = os::args(); - if vec::len(argv) < 2u && !os::getenv(~"RUST_BENCH").is_some() { - let out = io::stdout(); - - out.write_line(fmt!("Usage: %s ...", argv[0])); - - return; - } - - let readers: ~[fn~() -> word_reader] = if argv.len() >= 2 { - vec::view(argv, 1u, argv.len()).map(|f| { - let f = copy *f; - fn~() -> word_reader { file_word_reader(copy f) } - }) - } - else { - let num_readers = 50; - let words_per_reader = 600; - vec::from_fn( - num_readers, - |_i| fn~() -> word_reader { - random_word_reader(words_per_reader) as word_reader - }) - }; - - let start = time::precise_time_ns(); - - map_reduce::map_reduce(map, reduce, readers); - let stop = time::precise_time_ns(); - - let elapsed = (stop - start) / 1000000u64; - - log(error, ~"MapReduce completed in " - + u64::str(elapsed) + ~"ms"); -} - -fn read_word(r: io::Reader) -> Option<~str> { - let mut w = ~""; - - while !r.eof() { - let c = r.read_char(); - - if is_word_char(c) { - w += str::from_char(c); - } else { if w != ~"" { return Some(w); } } - } - return None; -} - -fn is_word_char(c: char) -> bool { - char::is_alphabetic(c) || char::is_digit(c) || c == '_' -} - -struct random_word_reader { - mut remaining: uint, - rng: rand::Rng, -} - -impl random_word_reader: word_reader { - fn read_word() -> Option<~str> { - if self.remaining > 0 { - self.remaining -= 1; - let len = self.rng.gen_uint_range(1, 4); - Some(self.rng.gen_str(len)) - } - else { None } - } -} - -fn random_word_reader(count: uint) -> random_word_reader { - random_word_reader { - remaining: count, - rng: rand::Rng() - } -} diff --git a/src/test/compile-fail/no-capture-arc.rs b/src/test/compile-fail/no-capture-arc.rs index c5a5f9e74d0d..b374a03eaba2 100644 --- a/src/test/compile-fail/no-capture-arc.rs +++ b/src/test/compile-fail/no-capture-arc.rs @@ -12,7 +12,6 @@ extern mod std; use std::arc; -use core::oldcomm::*; fn main() { let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; diff --git a/src/test/compile-fail/no-reuse-move-arc.rs b/src/test/compile-fail/no-reuse-move-arc.rs index a959772f5d24..1de8362e23a2 100644 --- a/src/test/compile-fail/no-reuse-move-arc.rs +++ b/src/test/compile-fail/no-reuse-move-arc.rs @@ -10,7 +10,6 @@ extern mod std; use std::arc; -use core::oldcomm::*; fn main() { let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; diff --git a/src/test/compile-fail/no-send-res-ports.rs b/src/test/compile-fail/no-send-res-ports.rs index 4dd0df31aab8..080f7fe3c6ea 100644 --- a/src/test/compile-fail/no-send-res-ports.rs +++ b/src/test/compile-fail/no-send-res-ports.rs @@ -8,22 +8,24 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +struct Port(@T); + fn main() { struct foo { - _x: oldcomm::Port<()>, + _x: Port<()>, } impl foo : Drop { fn finalize(&self) {} } - fn foo(x: oldcomm::Port<()>) -> foo { + fn foo(x: Port<()>) -> foo { foo { _x: x } } - let x = ~mut Some(foo(oldcomm::Port())); + let x = ~mut Some(foo(Port(@()))); do task::spawn |move x| { //~ ERROR not a sendable value let mut y = None; diff --git a/src/test/compile-fail/unsendable-class.rs b/src/test/compile-fail/unsendable-class.rs index 7f60e3ec87a0..b5bb05d5c695 100644 --- a/src/test/compile-fail/unsendable-class.rs +++ b/src/test/compile-fail/unsendable-class.rs @@ -25,7 +25,6 @@ fn foo(i:int, j: @~str) -> foo { fn main() { let cat = ~"kitty"; - let po = oldcomm::Port(); //~ ERROR missing `owned` - let ch = oldcomm::Chan(&po); //~ ERROR missing `owned` - oldcomm::send(ch, foo(42, @(move cat))); //~ ERROR missing `owned` + let (_, ch) = pipes::stream(); //~ ERROR missing `owned` + ch.send(foo(42, @(move cat))); //~ ERROR missing `owned` } diff --git a/src/test/run-fail/linked-failure.rs b/src/test/run-fail/linked-failure.rs index 8154329f7ae3..d592fb80f768 100644 --- a/src/test/run-fail/linked-failure.rs +++ b/src/test/run-fail/linked-failure.rs @@ -12,13 +12,11 @@ // error-pattern:1 == 2 extern mod std; -use oldcomm::Port; -use oldcomm::recv; fn child() { assert (1 == 2); } fn main() { - let p = Port::(); + let (p, _c) = pipes::stream::(); task::spawn(|| child() ); - let x = recv(p); + let x = p.recv(); } diff --git a/src/test/run-fail/linked-failure2.rs b/src/test/run-fail/linked-failure2.rs index 1a95118d0a61..dc571af636ea 100644 --- a/src/test/run-fail/linked-failure2.rs +++ b/src/test/run-fail/linked-failure2.rs @@ -11,15 +11,11 @@ // error-pattern:fail -extern mod std; -use oldcomm::Chan; -use oldcomm::Port; -use oldcomm::recv; fn child() { fail; } fn main() { - let p = Port::(); + let (p, _c) = pipes::stream::<()>(); task::spawn(|| child() ); task::yield(); } diff --git a/src/test/run-fail/linked-failure3.rs b/src/test/run-fail/linked-failure3.rs index 5df06ff6f81f..b9f785a79583 100644 --- a/src/test/run-fail/linked-failure3.rs +++ b/src/test/run-fail/linked-failure3.rs @@ -11,20 +11,17 @@ // error-pattern:fail -extern mod std; -use oldcomm::Port; -use oldcomm::recv; fn grandchild() { fail ~"grandchild dies"; } fn child() { - let p = Port::(); + let (p, _c) = pipes::stream::(); task::spawn(|| grandchild() ); - let x = recv(p); + let x = p.recv(); } fn main() { - let p = Port::(); + let (p, _c) = pipes::stream::(); task::spawn(|| child() ); - let x = recv(p); + let x = p.recv(); } diff --git a/src/test/run-fail/linked-failure4.rs b/src/test/run-fail/linked-failure4.rs index ea9c9f22e220..23ddc7573197 100644 --- a/src/test/run-fail/linked-failure4.rs +++ b/src/test/run-fail/linked-failure4.rs @@ -10,24 +10,20 @@ // except according to those terms. // error-pattern:1 == 2 -extern mod std; -use oldcomm::Chan; -use oldcomm::Port; -use oldcomm::recv; fn child() { assert (1 == 2); } fn parent() { - let p = Port::(); + let (p, _c) = pipes::stream::(); task::spawn(|| child() ); - let x = recv(p); + let x = p.recv(); } // This task is not linked to the failure chain, but since the other // tasks are going to fail the kernel, this one will fail too fn sleeper() { - let p = Port::(); - let x = recv(p); + let (p, _c) = pipes::stream::(); + let x = p.recv(); } fn main() { diff --git a/src/test/run-fail/port-type.rs b/src/test/run-fail/port-type.rs deleted file mode 100644 index bd1541302a40..000000000000 --- a/src/test/run-fail/port-type.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// error-pattern:meep -extern mod std; -use oldcomm::Chan; -use oldcomm::Port; -use oldcomm::send; -use oldcomm::recv; - -fn echo(c: Chan, oc: Chan>) { - // Tests that the type argument in port gets - // visited - let p = Port::(); - send(oc, Chan(&p)); - - let x = recv(p); - send(c, move x); -} - -fn main() { fail ~"meep"; } diff --git a/src/test/run-fail/task-comm-recv-block.rs b/src/test/run-fail/task-comm-recv-block.rs index 6c70dd09d57f..9c8ec2492554 100644 --- a/src/test/run-fail/task-comm-recv-block.rs +++ b/src/test/run-fail/task-comm-recv-block.rs @@ -10,8 +10,6 @@ // error-pattern:goodfail -extern mod std; - fn goodfail() { task::yield(); fail ~"goodfail"; @@ -19,9 +17,9 @@ fn goodfail() { fn main() { task::spawn(|| goodfail() ); - let po = oldcomm::Port(); + let (po, _c) = pipes::stream(); // We shouldn't be able to get past this recv since there's no // message available - let i: int = oldcomm::recv(po); + let i: int = po.recv(); fail ~"badfail"; } diff --git a/src/test/run-pass/acyclic-unwind.rs b/src/test/run-pass/acyclic-unwind.rs deleted file mode 100644 index 8f3152055737..000000000000 --- a/src/test/run-pass/acyclic-unwind.rs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// xfail-test -// -*- rust -*- - -extern mod std; - -fn f(c: oldcomm::_chan) { - type t = {_0: int, _1: int, _2: int}; - - // Allocate a box. - let x: @t = @{_0: 1, _1: 2, _2: 3}; - - // Signal parent that we've allocated a box. - oldcomm::send(c, 1); - - - loop { - // spin waiting for the parent to kill us. - debug!("child waiting to die..."); - - // while waiting to die, the messages we are - // sending to the channel are never received - // by the parent, therefore this test cases drops - // messages on the floor - oldcomm::send(c, 1); - } -} - -fn main() { - let p = oldcomm::mk_port(); - task::_spawn(bind f(p.mk_chan())); - let i: int; - - // synchronize on event from child. - i = p.recv(); - - debug!("parent exiting, killing child"); -} diff --git a/src/test/run-pass/auto-encode.rs b/src/test/run-pass/auto-encode.rs index ee8cf89d528a..28ae13896f0c 100644 --- a/src/test/run-pass/auto-encode.rs +++ b/src/test/run-pass/auto-encode.rs @@ -15,7 +15,7 @@ extern mod std; // These tests used to be separate files, but I wanted to refactor all -// the oldcommon code. +// the common code. use cmp::Eq; use std::ebml; diff --git a/src/test/run-pass/basic-1.rs b/src/test/run-pass/basic-1.rs deleted file mode 100644 index 87fd1443db9e..000000000000 --- a/src/test/run-pass/basic-1.rs +++ /dev/null @@ -1,34 +0,0 @@ -// -*- rust -*- -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -fn a(c: ::core::oldcomm::Chan) { ::core::oldcomm::send(c, 10); } - -fn main() { - let p = ::core::oldcomm::Port(); - let ch = ::core::oldcomm::Chan(&p); - task::spawn(|| a(ch) ); - task::spawn(|| a(ch) ); - let mut n: int = 0; - n = ::core::oldcomm::recv(p); - n = ::core::oldcomm::recv(p); - // debug!("Finished."); -} - -fn b(c: ::core::oldcomm::Chan) { - // debug!("task b0"); - // debug!("task b1"); - // debug!("task b2"); - // debug!("task b3"); - // debug!("task b4"); - // debug!("task b5"); - ::core::oldcomm::send(c, 10); -} diff --git a/src/test/run-pass/basic-2.rs b/src/test/run-pass/basic-2.rs deleted file mode 100644 index 0e542e157cf9..000000000000 --- a/src/test/run-pass/basic-2.rs +++ /dev/null @@ -1,37 +0,0 @@ -// -*- rust -*- -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -fn a(c: ::core::oldcomm::Chan) { - debug!("task a0"); - debug!("task a1"); - ::core::oldcomm::send(c, 10); -} - -fn main() { - let p = ::core::oldcomm::Port(); - let ch = ::core::oldcomm::Chan(&p); - task::spawn(|| a(ch) ); - task::spawn(|| b(ch) ); - let mut n: int = 0; - n = ::core::oldcomm::recv(p); - n = ::core::oldcomm::recv(p); - debug!("Finished."); -} - -fn b(c: ::core::oldcomm::Chan) { - debug!("task b0"); - debug!("task b1"); - debug!("task b2"); - debug!("task b2"); - debug!("task b3"); - ::core::oldcomm::send(c, 10); -} diff --git a/src/test/run-pass/basic.rs b/src/test/run-pass/basic.rs deleted file mode 100644 index ac029b63eef4..000000000000 --- a/src/test/run-pass/basic.rs +++ /dev/null @@ -1,58 +0,0 @@ -// -*- rust -*- -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -fn a(c: ::core::oldcomm::Chan) { - if true { - debug!("task a"); - debug!("task a"); - debug!("task a"); - debug!("task a"); - debug!("task a"); - } - ::core::oldcomm::send(c, 10); -} - -fn k(x: int) -> int { return 15; } - -fn g(x: int, y: ~str) -> int { - log(debug, x); - log(debug, y); - let z: int = k(1); - return z; -} - -fn main() { - let mut n: int = 2 + 3 * 7; - let s: ~str = ~"hello there"; - let p = oldcomm::Port(); - let ch = ::core::oldcomm::Chan(&p); - task::spawn(|| a(ch) ); - task::spawn(|| b(ch) ); - let mut x: int = 10; - x = g(n, s); - log(debug, x); - n = ::core::oldcomm::recv(p); - n = ::core::oldcomm::recv(p); - debug!("children finished, root finishing"); -} - -fn b(c: ::core::oldcomm::Chan) { - if true { - debug!("task b"); - debug!("task b"); - debug!("task b"); - debug!("task b"); - debug!("task b"); - debug!("task b"); - } - ::core::oldcomm::send(c, 10); -} diff --git a/src/test/run-pass/capture_nil.rs b/src/test/run-pass/capture_nil.rs index 893912d5c058..6d57084f85af 100644 --- a/src/test/run-pass/capture_nil.rs +++ b/src/test/run-pass/capture_nil.rs @@ -24,10 +24,11 @@ // course preferable, as the value itself is // irrelevant). -fn foo(&&x: ()) -> ::core::oldcomm::Port<()> { - let p = ::core::oldcomm::Port(); - let c = ::core::oldcomm::Chan(&p); - do task::spawn() |copy c, copy x| { +use core::pipes::*; + +fn foo(&&x: ()) -> Port<()> { + let (p, c) = stream::<()>(); + do task::spawn() |copy x| { c.send(x); } p diff --git a/src/test/run-pass/cci_capture_clause.rs b/src/test/run-pass/cci_capture_clause.rs index a439d2af8fc0..6a04dbee8dca 100644 --- a/src/test/run-pass/cci_capture_clause.rs +++ b/src/test/run-pass/cci_capture_clause.rs @@ -18,8 +18,6 @@ extern mod cci_capture_clause; -use core::oldcomm::recv; - fn main() { cci_capture_clause::foo(()).recv() } diff --git a/src/test/run-pass/chan-leak.rs b/src/test/run-pass/chan-leak.rs deleted file mode 100644 index 43825b03c296..000000000000 --- a/src/test/run-pass/chan-leak.rs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Issue #763 - -enum request { quit, close(::core::oldcomm::Chan), } - -type ctx = ::core::oldcomm::Chan; - -fn request_task(c: ::core::oldcomm::Chan) { - let p = ::core::oldcomm::Port(); - ::core::oldcomm::send(c, ::core::oldcomm::Chan(&p)); - let mut req: request; - req = ::core::oldcomm::recv(p); - // Need to drop req before receiving it again - req = ::core::oldcomm::recv(p); -} - -fn new_cx() -> ctx { - let p = ::core::oldcomm::Port(); - let ch = ::core::oldcomm::Chan(&p); - let t = task::spawn(|| request_task(ch) ); - let mut cx: ctx; - cx = ::core::oldcomm::recv(p); - return cx; -} - -fn main() { - let cx = new_cx(); - - let p = ::core::oldcomm::Port::(); - ::core::oldcomm::send(cx, close(::core::oldcomm::Chan(&p))); - ::core::oldcomm::send(cx, quit); -} diff --git a/src/test/run-pass/comm.rs b/src/test/run-pass/comm.rs index 7a79d2360684..4197a63107cc 100644 --- a/src/test/run-pass/comm.rs +++ b/src/test/run-pass/comm.rs @@ -9,19 +9,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use core::pipes::*; fn main() { - let p = oldcomm::Port(); - let ch = ::core::oldcomm::Chan(&p); - let t = task::spawn(|| child(ch) ); - let y = ::core::oldcomm::recv(p); + let (p, ch) = stream(); + let t = task::spawn(|| child(&ch) ); + let y = p.recv(); error!("received"); log(error, y); assert (y == 10); } -fn child(c: ::core::oldcomm::Chan) { +fn child(c: &Chan) { error!("sending"); - ::core::oldcomm::send(c, 10); + c.send(10); error!("value sent"); } diff --git a/src/test/run-pass/decl-with-recv.rs b/src/test/run-pass/decl-with-recv.rs deleted file mode 100644 index a3679f71a6b1..000000000000 --- a/src/test/run-pass/decl-with-recv.rs +++ /dev/null @@ -1,22 +0,0 @@ -// -*- rust -*- -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -fn main() { - let po = ::core::oldcomm::Port(); - let ch = ::core::oldcomm::Chan(&po); - ::core::oldcomm::send(ch, 10); - let i = ::core::oldcomm::recv(po); - assert (i == 10); - ::core::oldcomm::send(ch, 11); - let j = ::core::oldcomm::recv(po); - assert (j == 11); -} diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 6232f0c6e06d..2f4d69ee8560 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -20,20 +20,14 @@ extern mod std; use std::map; use std::map::HashMap; -use core::oldcomm::Chan; -use core::oldcomm::Port; -use core::oldcomm::send; -use core::oldcomm::recv; +use core::pipes::*; pub fn map(filename: ~str, emit: map_reduce::putter) { emit(filename, ~"1"); } mod map_reduce { use std::map; use std::map::HashMap; - use core::oldcomm::Chan; - use core::oldcomm::Port; - use core::oldcomm::send; - use core::oldcomm::recv; + use core::pipes::*; pub type putter = fn@(~str, ~str); @@ -41,39 +35,42 @@ mod map_reduce { enum ctrl_proto { find_reducer(~[u8], Chan), mapper_done, } - fn start_mappers(ctrl: Chan, inputs: ~[~str]) { + fn start_mappers(ctrl: SharedChan, inputs: ~[~str]) { for inputs.each |i| { + let ctrl = ctrl.clone(); let i = copy *i; - task::spawn(|move i| map_task(ctrl, copy i) ); + task::spawn(|move i| map_task(ctrl.clone(), copy i) ); } } - fn map_task(ctrl: Chan, input: ~str) { + fn map_task(ctrl: SharedChan, input: ~str) { let intermediates = map::HashMap(); - fn emit(im: map::HashMap<~str, int>, ctrl: Chan, key: ~str, + fn emit(im: map::HashMap<~str, int>, ctrl: SharedChan, key: ~str, val: ~str) { let mut c; match im.find(copy key) { Some(_c) => { c = _c } None => { - let p = Port(); + let (pp, cc) = stream(); error!("sending find_reducer"); - send(ctrl, find_reducer(str::to_bytes(key), Chan(&p))); + ctrl.send(find_reducer(str::to_bytes(key), cc)); error!("receiving"); - c = recv(p); + c = pp.recv(); log(error, c); im.insert(key, c); } } } - ::map(input, |a,b| emit(intermediates, ctrl, a, b) ); - send(ctrl, mapper_done); + let ctrl_clone = ctrl.clone(); + ::map(input, |a,b| emit(intermediates, ctrl.clone(), a, b) ); + ctrl_clone.send(mapper_done); } pub fn map_reduce(inputs: ~[~str]) { - let ctrl = Port(); + let (ctrl_port, ctrl_chan) = stream(); + let ctrl_chan = SharedChan(ctrl_chan); // This task becomes the master control task. It spawns others // to do the rest. @@ -82,12 +79,12 @@ mod map_reduce { reducers = map::HashMap(); - start_mappers(Chan(&ctrl), copy inputs); + start_mappers(ctrl_chan, copy inputs); let mut num_mappers = vec::len(inputs) as int; while num_mappers > 0 { - match recv(ctrl) { + match ctrl_port.recv() { mapper_done => { num_mappers -= 1; } find_reducer(k, cc) => { let mut c; @@ -95,7 +92,7 @@ mod map_reduce { Some(_c) => { c = _c; } None => { c = 0; } } - send(cc, c); + cc.send(c); } } } diff --git a/src/test/run-pass/issue-507.rs b/src/test/run-pass/issue-507.rs deleted file mode 100644 index 52f202a2deb4..000000000000 --- a/src/test/run-pass/issue-507.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -/* - This is a test case for Issue 507. - - https://github.com/graydon/rust/issues/507 -*/ - -fn grandchild(c: ::core::oldcomm::Chan) { ::core::oldcomm::send(c, 42); } - -fn child(c: ::core::oldcomm::Chan) { - task::spawn(|| grandchild(c) ) -} - -fn main() { - let p = ::core::oldcomm::Port(); - let ch = ::core::oldcomm::Chan(&p); - - task::spawn(|| child(ch) ); - - let x: int = ::core::oldcomm::recv(p); - - log(debug, x); - - assert (x == 42); -} diff --git a/src/test/run-pass/issue-687.rs b/src/test/run-pass/issue-687.rs deleted file mode 100644 index 53827bb63fa3..000000000000 --- a/src/test/run-pass/issue-687.rs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -enum msg { closed, received(~[u8]), } - -fn producer(c: ::core::oldcomm::Chan<~[u8]>) { - ::core::oldcomm::send(c, ~[1u8, 2u8, 3u8, 4u8]); - let empty: ~[u8] = ~[]; - ::core::oldcomm::send(c, empty); -} - -fn packager(cb: ::core::oldcomm::Chan<::core::oldcomm::Chan<~[u8]>>, msg: ::core::oldcomm::Chan) { - let p: ::core::oldcomm::Port<~[u8]> = ::core::oldcomm::Port(); - ::core::oldcomm::send(cb, ::core::oldcomm::Chan(&p)); - loop { - debug!("waiting for bytes"); - let data = ::core::oldcomm::recv(p); - debug!("got bytes"); - if vec::len(data) == 0u { - debug!("got empty bytes, quitting"); - break; - } - debug!("sending non-empty buffer of length"); - log(debug, vec::len(data)); - ::core::oldcomm::send(msg, received(data)); - debug!("sent non-empty buffer"); - } - debug!("sending closed message"); - ::core::oldcomm::send(msg, closed); - debug!("sent closed message"); -} - -fn main() { - let p: ::core::oldcomm::Port = ::core::oldcomm::Port(); - let ch = ::core::oldcomm::Chan(&p); - let recv_reader: ::core::oldcomm::Port<::core::oldcomm::Chan<~[u8]>> = ::core::oldcomm::Port(); - let recv_reader_chan = ::core::oldcomm::Chan(&recv_reader); - let pack = task::spawn(|| packager(recv_reader_chan, ch) ); - - let source_chan: ::core::oldcomm::Chan<~[u8]> = ::core::oldcomm::recv(recv_reader); - let prod = task::spawn(|| producer(source_chan) ); - - loop { - let msg = ::core::oldcomm::recv(p); - match msg { - closed => { debug!("Got close message"); break; } - received(data) => { - debug!("Got data. Length is:"); - log(debug, vec::len::(data)); - } - } - } -} diff --git a/src/test/run-pass/issue-783.rs b/src/test/run-pass/issue-783.rs deleted file mode 100644 index 75404c01fc53..000000000000 --- a/src/test/run-pass/issue-783.rs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn a() { - fn doit() { - fn b(c: ::core::oldcomm::Chan<::core::oldcomm::Chan>) { - let p = ::core::oldcomm::Port(); - ::core::oldcomm::send(c, ::core::oldcomm::Chan(&p)); - } - let p = ::core::oldcomm::Port(); - let ch = ::core::oldcomm::Chan(&p); - task::spawn(|| b(ch) ); - ::core::oldcomm::recv(p); - } - let mut i = 0; - while i < 100 { - doit(); - i += 1; - } -} - -fn main() { - for iter::repeat(100u) { - task::spawn(|| a() ); - } -} diff --git a/src/test/run-pass/ivec-tag.rs b/src/test/run-pass/ivec-tag.rs index 31651ab7c20a..b890160ea172 100644 --- a/src/test/run-pass/ivec-tag.rs +++ b/src/test/run-pass/ivec-tag.rs @@ -1,13 +1,14 @@ -fn producer(c: ::core::oldcomm::Chan<~[u8]>) { - ::core::oldcomm::send(c, +use core::pipes::*; + +fn producer(c: &Chan<~[u8]>) { + c.send( ~[1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8, 9u8, 10u8, 11u8, 12u8, 13u8]); } fn main() { - let p: ::core::oldcomm::Port<~[u8]> = ::core::oldcomm::Port(); - let ch = ::core::oldcomm::Chan(&p); - let prod = task::spawn(|| producer(ch) ); + let (p, ch) = stream::<~[u8]>(); + let prod = task::spawn(|| producer(&ch) ); - let data: ~[u8] = ::core::oldcomm::recv(p); + let data: ~[u8] = p.recv(); } diff --git a/src/test/run-pass/lazychan.rs b/src/test/run-pass/lazychan.rs deleted file mode 100644 index 4e5ce6cd0915..000000000000 --- a/src/test/run-pass/lazychan.rs +++ /dev/null @@ -1,30 +0,0 @@ -// -*- rust -*- -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let p = ::core::oldcomm::Port(); - let ch = ::core::oldcomm::Chan(&p); - let mut y: int; - - task::spawn(|| child(ch) ); - y = ::core::oldcomm::recv(p); - debug!("received 1"); - log(debug, y); - assert (y == 10); - - task::spawn(|| child(ch) ); - y = ::core::oldcomm::recv(p); - debug!("received 2"); - log(debug, y); - assert (y == 10); -} - -fn child(c: ::core::oldcomm::Chan) { ::core::oldcomm::send(c, 10); } diff --git a/src/test/run-pass/leaky_comm.rs b/src/test/run-pass/leaky_comm.rs deleted file mode 100644 index 44498d961575..000000000000 --- a/src/test/run-pass/leaky_comm.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// xfail-fast -// aux-build:test_comm.rs - -extern mod test_comm; - -fn main() { - let p = test_comm::port(); - - match None:: { - None => {} - Some(_) => { - if 0 == test_comm::recv(p) { - error!("floop"); - } - else { - error!("bloop"); - } - }} -} diff --git a/src/test/run-pass/many.rs b/src/test/run-pass/many.rs deleted file mode 100644 index 23153b79cd94..000000000000 --- a/src/test/run-pass/many.rs +++ /dev/null @@ -1,35 +0,0 @@ -// -*- rust -*- -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -extern mod std; - -fn sub(parent: oldcomm::Chan, id: int) { - if id == 0 { - oldcomm::send(parent, 0); - } else { - let p = oldcomm::Port(); - let ch = oldcomm::Chan(&p); - let child = task::spawn(|| sub(ch, id - 1) ); - let y = oldcomm::recv(p); - oldcomm::send(parent, y + 1); - } -} - -fn main() { - let p = oldcomm::Port(); - let ch = oldcomm::Chan(&p); - let child = task::spawn(|| sub(ch, 200) ); - let y = oldcomm::recv(p); - debug!("transmission complete"); - log(debug, y); - assert (y == 200); -} diff --git a/src/test/run-pass/rt-circular-buffer.rs b/src/test/run-pass/rt-circular-buffer.rs deleted file mode 100644 index 2b43fca58b72..000000000000 --- a/src/test/run-pass/rt-circular-buffer.rs +++ /dev/null @@ -1,112 +0,0 @@ -// -*- rust -*- -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -// Regression tests for circular_buffer when using a unit -// that has a size that is not a power of two - -// A 12-byte unit to ::core::oldcomm::send over the channel -struct Record {val1: u32, val2: u32, val3: u32} - - -// Assuming that the default buffer size needs to hold 8 units, -// then the minimum buffer size needs to be 96. That's not a -// power of two so needs to be rounded up. Don't trigger any -// assertions. -fn test_init() { - let myport = ::core::oldcomm::Port(); - let mychan = ::core::oldcomm::Chan(&myport); - let val: Record = Record {val1: 0u32, val2: 0u32, val3: 0u32}; - ::core::oldcomm::send(mychan, val); -} - - -// Dump lots of items into the channel so it has to grow. -// Don't trigger any assertions. -fn test_grow() { - let myport = ::core::oldcomm::Port(); - let mychan = ::core::oldcomm::Chan(&myport); - for uint::range(0u, 100u) |i| { - let val: Record = Record {val1: 0u32, val2: 0u32, val3: 0u32}; - ::core::oldcomm::send(mychan, val); - } -} - - -// Don't allow the buffer to shrink below it's original size -fn test_shrink1() { - let myport = ::core::oldcomm::Port(); - let mychan = ::core::oldcomm::Chan(&myport); - ::core::oldcomm::send(mychan, 0i8); - let x = ::core::oldcomm::recv(myport); -} - -fn test_shrink2() { - let myport = ::core::oldcomm::Port(); - let mychan = ::core::oldcomm::Chan(&myport); - for uint::range(0u, 100u) |_i| { - let val: Record = Record {val1: 0u32, val2: 0u32, val3: 0u32}; - ::core::oldcomm::send(mychan, val); - } - for uint::range(0u, 100u) |_i| { let x = ::core::oldcomm::recv(myport); } -} - - -// Test rotating the buffer when the unit size is not a power of two -fn test_rotate() { - let myport = ::core::oldcomm::Port(); - let mychan = ::core::oldcomm::Chan(&myport); - for uint::range(0u, 100u) |i| { - let val = Record {val1: i as u32, val2: i as u32, val3: i as u32}; - ::core::oldcomm::send(mychan, val); - let x = ::core::oldcomm::recv(myport); - assert (x.val1 == i as u32); - assert (x.val2 == i as u32); - assert (x.val3 == i as u32); - } -} - - -// Test rotating and growing the buffer when -// the unit size is not a power of two -fn test_rotate_grow() { - let myport = ::core::oldcomm::Port::(); - let mychan = ::core::oldcomm::Chan(&myport); - for uint::range(0u, 10u) |j| { - for uint::range(0u, 10u) |i| { - let val: Record = - Record {val1: i as u32, val2: i as u32, val3: i as u32}; - ::core::oldcomm::send(mychan, val); - } - for uint::range(0u, 10u) |i| { - let x = ::core::oldcomm::recv(myport); - assert (x.val1 == i as u32); - assert (x.val2 == i as u32); - assert (x.val3 == i as u32); - } - } -} - -fn main() { - test_init(); - test_grow(); - test_shrink1(); - test_shrink2(); - test_rotate(); - test_rotate_grow(); -} -// Local Variables: -// mode: rust; -// fill-column: 78; -// indent-tabs-mode: nil -// c-basic-offset: 4 -// buffer-file-coding-system: utf-8-unix -// End: diff --git a/src/test/run-pass/rt-sched-1.rs b/src/test/run-pass/rt-sched-1.rs index 6c3f7e96c5aa..95fbf4c9ef01 100644 --- a/src/test/run-pass/rt-sched-1.rs +++ b/src/test/run-pass/rt-sched-1.rs @@ -10,6 +10,8 @@ // Tests of the runtime's scheduler interface +use core::pipes::*; + type sched_id = int; type task_id = *libc::c_void; @@ -26,8 +28,7 @@ extern mod rustrt { fn main() { unsafe { - let po = oldcomm::Port(); - let ch = oldcomm::Chan(&po); + let (po, ch) = stream(); let parent_sched_id = rustrt::rust_get_sched_id(); error!("parent %?", parent_sched_id); let num_threads = 1u; @@ -41,12 +42,12 @@ fn main() { error!("child_sched_id %?", child_sched_id); assert child_sched_id != parent_sched_id; assert child_sched_id == new_sched_id; - oldcomm::send(ch, ()); + ch.send(()); } }; let fptr = cast::reinterpret_cast(&ptr::addr_of(&f)); rustrt::start_task(new_task_id, fptr); cast::forget(move f); - oldcomm::recv(po); + po.recv(); } } diff --git a/src/test/run-pass/send-iloop.rs b/src/test/run-pass/send-iloop.rs index 6e6c64f4533c..28877f7eb949 100644 --- a/src/test/run-pass/send-iloop.rs +++ b/src/test/run-pass/send-iloop.rs @@ -17,13 +17,15 @@ fn die() { fn iloop() { task::spawn(|| die() ); - let p = oldcomm::Port::<()>(); - let c = oldcomm::Chan(&p); + let (p, c) = core::pipes::stream::<()>(); loop { // Sending and receiving here because these actions yield, - // at which point our child can kill us - oldcomm::send(c, ()); - oldcomm::recv(p); + // at which point our child can kill us. + c.send(()); + p.recv(); + // The above comment no longer makes sense but I'm + // reluctant to remove a linked failure test case. + task::yield(); } } diff --git a/src/test/run-pass/send-resource.rs b/src/test/run-pass/send-resource.rs index 39ef99a72b61..be0546c6883c 100644 --- a/src/test/run-pass/send-resource.rs +++ b/src/test/run-pass/send-resource.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use core::pipes::*; + struct test { f: int, } @@ -23,14 +25,13 @@ fn test(f: int) -> test { } fn main() { - let p = ::core::oldcomm::Port(); - let c = ::core::oldcomm::Chan(&p); + let (p, c) = stream(); do task::spawn() { - let p = ::core::oldcomm::Port(); - c.send(::core::oldcomm::Chan(&p)); + let (pp, cc) = stream(); + c.send(cc); - let _r = p.recv(); + let _r = pp.recv(); } p.recv().send(test(42)); diff --git a/src/test/run-pass/send-type-inference.rs b/src/test/run-pass/send-type-inference.rs index 8cb597a0d792..a4dbb673ca87 100644 --- a/src/test/run-pass/send-type-inference.rs +++ b/src/test/run-pass/send-type-inference.rs @@ -8,11 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use core::pipes::*; + // tests that ctrl's type gets inferred properly type command = {key: K, val: V}; -fn cache_server(c: oldcomm::Chan>>) { - let ctrl = oldcomm::Port(); - oldcomm::send(c, oldcomm::Chan(&ctrl)); +fn cache_server(c: Chan>>) { + let (ctrl_port, ctrl_chan) = core::pipes::stream(); + c.send(ctrl_chan); } fn main() { } diff --git a/src/test/run-pass/sendable-class.rs b/src/test/run-pass/sendable-class.rs index e027bddb8f18..0a1afc68a5b1 100644 --- a/src/test/run-pass/sendable-class.rs +++ b/src/test/run-pass/sendable-class.rs @@ -23,7 +23,6 @@ fn foo(i:int, j: char) -> foo { } fn main() { - let po = oldcomm::Port::(); - let ch = oldcomm::Chan(&po); - oldcomm::send(ch, foo(42, 'c')); + let (_po, ch) = pipes::stream(); + ch.send(foo(42, 'c')); } \ No newline at end of file diff --git a/src/test/run-pass/sendfn-generic-fn.rs b/src/test/run-pass/sendfn-generic-fn.rs index 44165119b0d5..8cc1d77a3d3c 100644 --- a/src/test/run-pass/sendfn-generic-fn.rs +++ b/src/test/run-pass/sendfn-generic-fn.rs @@ -11,11 +11,6 @@ // xfail-fast #[legacy_modes]; -extern mod std; - -use oldcomm::Chan; -use oldcomm::send; - fn main() { test05(); } struct Pair { a: A, b: B } diff --git a/src/test/run-pass/spawn-types.rs b/src/test/run-pass/spawn-types.rs index 78914f0531f8..f722a91d1969 100644 --- a/src/test/run-pass/spawn-types.rs +++ b/src/test/run-pass/spawn-types.rs @@ -14,17 +14,15 @@ Arnold. */ -extern mod std; +use core::pipes::*; +type ctx = Chan; -type ctx = oldcomm::Chan; - -fn iotask(cx: ctx, ip: ~str) { +fn iotask(cx: &ctx, ip: ~str) { assert (ip == ~"localhost"); } fn main() { - let p = oldcomm::Port::(); - let ch = oldcomm::Chan(&p); - task::spawn(|| iotask(ch, ~"localhost") ); + let (p, ch) = stream::(); + task::spawn(|| iotask(&ch, ~"localhost") ); } diff --git a/src/test/run-pass/task-comm-chan-cleanup.rs b/src/test/run-pass/task-comm-chan-cleanup.rs deleted file mode 100644 index f2c0c807e82f..000000000000 --- a/src/test/run-pass/task-comm-chan-cleanup.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -extern mod std; - -fn main() { - let p = oldcomm::Port(); - let c = oldcomm::Chan(&p); - oldcomm::send(c, ~"coffee"); -} \ No newline at end of file diff --git a/src/test/run-pass/task-comm-chan-cleanup2.rs b/src/test/run-pass/task-comm-chan-cleanup2.rs deleted file mode 100644 index f2c0c807e82f..000000000000 --- a/src/test/run-pass/task-comm-chan-cleanup2.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -extern mod std; - -fn main() { - let p = oldcomm::Port(); - let c = oldcomm::Chan(&p); - oldcomm::send(c, ~"coffee"); -} \ No newline at end of file diff --git a/src/test/run-pass/task-comm-chan-cleanup3.rs b/src/test/run-pass/task-comm-chan-cleanup3.rs deleted file mode 100644 index 23b87fb73520..000000000000 --- a/src/test/run-pass/task-comm-chan-cleanup3.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -extern mod std; - -fn main() { - let c = { - let p = oldcomm::Port(); - oldcomm::Chan(&p) - }; - oldcomm::send(c, ~"coffee"); -} \ No newline at end of file diff --git a/src/test/run-pass/task-comm-chan-cleanup4.rs b/src/test/run-pass/task-comm-chan-cleanup4.rs deleted file mode 100644 index 2afdcc632680..000000000000 --- a/src/test/run-pass/task-comm-chan-cleanup4.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -extern mod std; - -// We're trying to trigger a race between send and port destruction that -// results in the string not being freed - -fn starship(&&ch: oldcomm::Chan<~str>) { - for int::range(0, 10) |_i| { - oldcomm::send(ch, ~"pew pew"); - } -} - -fn starbase() { - for int::range(0, 10) |_i| { - let p = oldcomm::Port(); - let c = oldcomm::Chan(&p); - task::spawn(|| starship(c) ); - task::yield(); - } -} - -fn main() { - for int::range(0, 10) |_i| { - task::spawn(|| starbase() ); - } -} \ No newline at end of file diff --git a/src/test/run-pass/task-comm-chan-nil.rs b/src/test/run-pass/task-comm-chan-nil.rs index 620262065a5c..ae2ee7880bda 100644 --- a/src/test/run-pass/task-comm-chan-nil.rs +++ b/src/test/run-pass/task-comm-chan-nil.rs @@ -16,9 +16,8 @@ extern mod std; // any size, but rustc currently can because they do have size. Whether // or not this is desirable I don't know, but here's a regression test. fn main() { - let po = oldcomm::Port(); - let ch = oldcomm::Chan(&po); - oldcomm::send(ch, ()); - let n: () = oldcomm::recv(po); + let (po, ch) = pipes::stream(); + ch.send(()); + let n: () = po.recv(); assert (n == ()); } diff --git a/src/test/run-pass/task-comm.rs b/src/test/run-pass/task-comm.rs deleted file mode 100644 index 311da9762b3c..000000000000 --- a/src/test/run-pass/task-comm.rs +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - test00(); - // test01(); - test02(); - test04(); - test05(); - test06(); -} - -fn test00_start(ch: ::core::oldcomm::Chan, message: int, count: int) { - debug!("Starting test00_start"); - let mut i: int = 0; - while i < count { - debug!("Sending Message"); - ::core::oldcomm::send(ch, message + 0); - i = i + 1; - } - debug!("Ending test00_start"); -} - -fn test00() { - let number_of_tasks: int = 1; - let number_of_messages: int = 4; - debug!("Creating tasks"); - - let po = ::core::oldcomm::Port(); - let ch = ::core::oldcomm::Chan(&po); - - let mut i: int = 0; - - let mut results = ~[]; - while i < number_of_tasks { - i = i + 1; - do task::task().future_result(|+r| { - results.push(move r); - }).spawn |copy i| { - test00_start(ch, i, number_of_messages); - } - } - let mut sum: int = 0; - for results.each |r| { - i = 0; - while i < number_of_messages { sum += ::core::oldcomm::recv(po); i = i + 1; } - } - - for results.each |r| { r.recv(); } - - debug!("Completed: Final number is: "); - assert (sum == - number_of_messages * - (number_of_tasks * number_of_tasks + number_of_tasks) / - 2); -} - -fn test01() { - let p = ::core::oldcomm::Port(); - debug!("Reading from a port that is never written to."); - let value: int = ::core::oldcomm::recv(p); - log(debug, value); -} - -fn test02() { - let p = ::core::oldcomm::Port(); - let c = ::core::oldcomm::Chan(&p); - debug!("Writing to a local task channel."); - ::core::oldcomm::send(c, 42); - debug!("Reading from a local task port."); - let value: int = ::core::oldcomm::recv(p); - log(debug, value); -} - -fn test04_start() { - debug!("Started task"); - let mut i: int = 1024 * 1024; - while i > 0 { i = i - 1; } - debug!("Finished task"); -} - -fn test04() { - debug!("Spawning lots of tasks."); - let mut i: int = 4; - while i > 0 { i = i - 1; task::spawn(|| test04_start() ); } - debug!("Finishing up."); -} - -fn test05_start(ch: ::core::oldcomm::Chan) { - ::core::oldcomm::send(ch, 10); - ::core::oldcomm::send(ch, 20); - ::core::oldcomm::send(ch, 30); - ::core::oldcomm::send(ch, 30); - ::core::oldcomm::send(ch, 30); -} - -fn test05() { - let po = ::core::oldcomm::Port(); - let ch = ::core::oldcomm::Chan(&po); - task::spawn(|| test05_start(ch) ); - let mut value: int; - value = ::core::oldcomm::recv(po); - value = ::core::oldcomm::recv(po); - value = ::core::oldcomm::recv(po); - log(debug, value); -} - -fn test06_start(&&task_number: int) { - debug!("Started task."); - let mut i: int = 0; - while i < 1000000 { i = i + 1; } - debug!("Finished task."); -} - -fn test06() { - let number_of_tasks: int = 4; - debug!("Creating tasks"); - - let mut i: int = 0; - - let mut results = ~[]; - while i < number_of_tasks { - i = i + 1; - do task::task().future_result(|+r| { - results.push(move r); - }).spawn |copy i| { - test06_start(i); - }; - } - - - for results.each |r| { r.recv(); } -} - - - - - - - - - - diff --git a/src/test/run-pass/task-compare.rs b/src/test/run-pass/task-compare.rs deleted file mode 100644 index fd45910ee88f..000000000000 --- a/src/test/run-pass/task-compare.rs +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// xfail-test -/** - A test case for issue #577, which also exposes #588 -*/ - -extern mod std; - -fn child() { } - -struct notify { - ch: oldcomm::Chan, v: @mut bool, -} - -impl notify : Drop { - fn finalize(&self) { - error!("notify: task=%? v=%x unwinding=%b b=%b", - task::get_task(), - ptr::addr_of(&(*(self.v))) as uint, - task::failing(), - *(self.v)); - let b = *(self.v); - oldcomm::send(self.ch, b); - } -} - -fn notify(ch: oldcomm::Chan, v: @mut bool) -> notify { - notify { - ch: ch, - v: v - } -} - -fn joinable(+f: fn~()) -> oldcomm::Port { - fn wrapper(+c: oldcomm::Chan, +f: fn()) { - let b = @mut false; - error!("wrapper: task=%? allocated v=%x", - task::get_task(), - ptr::addr_of(&(*b)) as uint); - let _r = notify(c, b); - f(); - *b = true; - } - let p = oldcomm::Port(); - let c = oldcomm::Chan(&p); - do task::spawn_unlinked { wrapper(c, copy f) }; - p -} - -fn join(port: oldcomm::Port) -> bool { - oldcomm::recv(port) -} - -fn main() { - // tasks - let t1; - let t2; - - let c1 = child, c2 = child; - t1 = joinable(c1); - t2 = joinable(c2); - - assert (t1 == t1); - assert (t1 != t2); - - // ports - let p1; - let p2; - - p1 = oldcomm::Port::(); - p2 = oldcomm::Port::(); - - assert (p1 == p1); - assert (p1 != p2); - - // channels - let c1 = oldcomm::Chan(p1); - let c2 = oldcomm::Chan(p2); - - assert (c1 == c1); - assert (c1 != c2); - - join(t1); - join(t2); -} diff --git a/src/test/run-pass/task-killjoin-rsrc.rs b/src/test/run-pass/task-killjoin-rsrc.rs index 029bab51770d..ca4e8916cc0c 100644 --- a/src/test/run-pass/task-killjoin-rsrc.rs +++ b/src/test/run-pass/task-killjoin-rsrc.rs @@ -13,8 +13,10 @@ // A port of task-killjoin to use a class with a dtor to manage // the join. +use core::pipes::*; + struct notify { - ch: oldcomm::Chan, v: @mut bool, + ch: Chan, v: @mut bool, } impl notify : Drop { @@ -25,19 +27,19 @@ impl notify : Drop { task::failing(), *(self.v)); let b = *(self.v); - oldcomm::send(self.ch, b); + self.ch.send(b); } } -fn notify(ch: oldcomm::Chan, v: @mut bool) -> notify { +fn notify(ch: Chan, v: @mut bool) -> notify { notify { ch: ch, v: v } } -fn joinable(+f: fn~()) -> oldcomm::Port { - fn wrapper(+c: oldcomm::Chan, +f: fn()) { +fn joinable(f: fn~()) -> Port { + fn wrapper(c: Chan, f: fn()) { let b = @mut false; error!("wrapper: task=%? allocated v=%x", task::get_task(), @@ -46,14 +48,19 @@ fn joinable(+f: fn~()) -> oldcomm::Port { f(); *b = true; } - let p = oldcomm::Port(); - let c = oldcomm::Chan(&p); - do task::spawn_unlinked { wrapper(c, f) }; + let (p, c) = stream(); + let c = ~mut Some(c); + do task::spawn_unlinked { + let mut cc = None; + *c <-> cc; + let ccc = option::unwrap(cc); + wrapper(ccc, f) + } p } -fn join(port: oldcomm::Port) -> bool { - oldcomm::recv(port) +fn join(port: Port) -> bool { + port.recv() } fn supervised() { diff --git a/src/test/run-pass/task-spawn-move-and-copy.rs b/src/test/run-pass/task-spawn-move-and-copy.rs index 4ee2413ab197..ef54d3c8ddb3 100644 --- a/src/test/run-pass/task-spawn-move-and-copy.rs +++ b/src/test/run-pass/task-spawn-move-and-copy.rs @@ -8,9 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use core::pipes::*; + fn main() { - let p = oldcomm::Port::(); - let ch = oldcomm::Chan(&p); + let (p, ch) = stream::(); let x = ~1; let x_in_parent = ptr::addr_of(&(*x)) as uint; @@ -18,19 +19,19 @@ fn main() { let y = ~2; let y_in_parent = ptr::addr_of(&(*y)) as uint; - task::spawn(fn~(copy ch, copy y, move x) { + task::spawn(fn~(copy y, move x) { let x_in_child = ptr::addr_of(&(*x)) as uint; - oldcomm::send(ch, x_in_child); + ch.send(x_in_child); let y_in_child = ptr::addr_of(&(*y)) as uint; - oldcomm::send(ch, y_in_child); + ch.send(y_in_child); }); // Ensure last-use analysis doesn't move y to child. let _q = y; - let x_in_child = oldcomm::recv(p); + let x_in_child = p.recv(); assert x_in_parent == x_in_child; - let y_in_child = oldcomm::recv(p); + let y_in_child = p.recv(); assert y_in_parent != y_in_child; } diff --git a/src/test/run-pass/unique-send-2.rs b/src/test/run-pass/unique-send-2.rs index c1709f2ca23d..fbf4e0bd757b 100644 --- a/src/test/run-pass/unique-send-2.rs +++ b/src/test/run-pass/unique-send-2.rs @@ -8,25 +8,26 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern mod std; +use core::pipes::*; -fn child(c: oldcomm::Chan<~uint>, i: uint) { - oldcomm::send(c, ~i); +fn child(c: &SharedChan<~uint>, i: uint) { + c.send(~i); } fn main() { - let p = oldcomm::Port(); - let ch = oldcomm::Chan(&p); + let (p, ch) = stream(); + let ch = SharedChan(ch); let n = 100u; let mut expected = 0u; for uint::range(0u, n) |i| { - task::spawn(|| child(ch, i) ); + let ch = ch.clone(); + task::spawn(|| child(&ch, i) ); expected += i; } let mut actual = 0u; for uint::range(0u, n) |_i| { - let j = oldcomm::recv(p); + let j = p.recv(); actual += *j; } diff --git a/src/test/run-pass/unique-send.rs b/src/test/run-pass/unique-send.rs index 6bbfabc87570..17827bb39caa 100644 --- a/src/test/run-pass/unique-send.rs +++ b/src/test/run-pass/unique-send.rs @@ -8,12 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern mod std; +use core::pipes::*; fn main() { - let p = oldcomm::Port(); - let c = oldcomm::Chan(&p); - oldcomm::send(c, ~100); - let v = oldcomm::recv(p); + let (p, c) = stream(); + c.send(~100); + let v = p.recv(); assert v == ~100; } \ No newline at end of file diff --git a/src/test/run-pass/unwind-resource.rs b/src/test/run-pass/unwind-resource.rs index 263ac090c99c..c591c3d10865 100644 --- a/src/test/run-pass/unwind-resource.rs +++ b/src/test/run-pass/unwind-resource.rs @@ -11,34 +11,36 @@ // xfail-win32 extern mod std; +use core::pipes::*; + struct complainer { - c: oldcomm::Chan, + c: SharedChan, } impl complainer : Drop { fn finalize(&self) { error!("About to send!"); - oldcomm::send(self.c, true); + self.c.send(true); error!("Sent!"); } } -fn complainer(c: oldcomm::Chan) -> complainer { +fn complainer(c: SharedChan) -> complainer { error!("Hello!"); complainer { c: c } } -fn f(c: oldcomm::Chan) { +fn f(c: SharedChan) { let _c = move complainer(c); fail; } fn main() { - let p = oldcomm::Port(); - let c = oldcomm::Chan(&p); - task::spawn_unlinked(|| f(c) ); + let (p, c) = stream(); + let c = SharedChan(c); + task::spawn_unlinked(|| f(c.clone()) ); error!("hiiiiiiiii"); - assert oldcomm::recv(p); + assert p.recv(); }