From cc353aa17aabb315584a4af6fb86da6b1e254e4d Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Fri, 12 Aug 2011 17:36:52 -0700 Subject: [PATCH] Removed old object-based chans. --- src/lib/comm.rs | 32 +++----------------------- src/test/run-pass/spawn-types.rs | 4 ++-- src/test/run-pass/task-comm-0.rs | 6 ++--- src/test/run-pass/task-comm-1.rs | 5 +++-- src/test/run-pass/task-comm-11.rs | 13 +++++------ src/test/run-pass/task-comm-13.rs | 12 +++++----- src/test/run-pass/task-comm-16.rs | 21 +++++++++--------- src/test/run-pass/task-comm-2.rs | 9 +++++--- src/test/run-pass/task-comm-4.rs | 2 +- src/test/run-pass/task-comm-5.rs | 2 +- src/test/run-pass/task-comm-6.rs | 9 ++++---- src/test/run-pass/task-comm-7.rs | 37 +++++++++++++++---------------- src/test/run-pass/task-comm-8.rs | 37 +++++++++++++++---------------- src/test/run-pass/task-comm-9.rs | 13 +++++------ src/test/stdtest/comm.rs | 13 +---------- 15 files changed, 89 insertions(+), 126 deletions(-) diff --git a/src/lib/comm.rs b/src/lib/comm.rs index 96f5cb53262..b359c1d8858 100644 --- a/src/lib/comm.rs +++ b/src/lib/comm.rs @@ -4,7 +4,6 @@ import unsafe; import task; import task::task_id; -export chan_t; export _chan; export _port; @@ -36,44 +35,19 @@ native "rust-intrinsic" mod rusti { type port_id = int; -type chan_t[~T] = { +type _chan[~T] = { task : task_id, port : port_id }; -resource chan_ptr(ch: *rustrt::rust_chan) { - rustrt::drop_chan(ch); -} - resource port_ptr(po: *rustrt::rust_port) { rustrt::drop_port(po); rustrt::del_port(po); } -obj _chan[~T](raw_chan : @chan_ptr) { - fn send(v : &T) { - rustrt::chan_send(**raw_chan, - unsafe::reinterpret_cast(ptr::addr_of(v))); - } - - // Use this to get something we can send over a channel. - fn unsafe_ptr() -> *u8 { - rustrt::take_chan(**raw_chan); - ret unsafe::reinterpret_cast(**raw_chan); - } -} - -fn chan_from_unsafe_ptr[~T](ch : *u8) -> _chan[T] { - _chan(@chan_ptr(unsafe::reinterpret_cast(ch))) -} - obj _port[~T](raw_port : @port_ptr) { - fn mk_chan() -> _chan[T] { - _chan(@chan_ptr(rustrt::new_chan(**raw_port))) - } - // FIXME: rename this to chan once chan is not a keyword. - fn mk_chan2() -> chan_t[T] { + fn mk_chan() -> _chan[T] { { task: task::get_task_id(), port: rustrt::get_port_id(**raw_port) @@ -89,6 +63,6 @@ fn mk_port[~T]() -> _port[T] { _port(@port_ptr(rustrt::new_port(sys::size_of[T]()))) } -fn send[~T](ch : chan_t[T], data : -T) { +fn send[~T](ch : _chan[T], data : -T) { rustrt::chan_id_send(ch.task, ch.port, data); } diff --git a/src/test/run-pass/spawn-types.rs b/src/test/run-pass/spawn-types.rs index 6fb0b60ac5d..029c18350d3 100644 --- a/src/test/run-pass/spawn-types.rs +++ b/src/test/run-pass/spawn-types.rs @@ -10,11 +10,11 @@ import std::str; import std::comm; import std::task; -type ctx = comm::chan_t[int]; +type ctx = comm::_chan[int]; fn iotask(cx: ctx, ip: str) { assert (str::eq(ip, "localhost")); } fn main() { let p = comm::mk_port[int](); - task::_spawn(bind iotask(p.mk_chan2(), "localhost")); + task::_spawn(bind iotask(p.mk_chan(), "localhost")); } diff --git a/src/test/run-pass/task-comm-0.rs b/src/test/run-pass/task-comm-0.rs index d28d83507d8..f4bbb1faaea 100644 --- a/src/test/run-pass/task-comm-0.rs +++ b/src/test/run-pass/task-comm-0.rs @@ -3,13 +3,13 @@ use std; import std::comm; -import std::comm::chan_t; +import std::comm::_chan; import std::comm::send; import std::task; fn main() { test05(); } -fn test05_start(ch : chan_t[int]) { +fn test05_start(ch : _chan[int]) { log_err ch; send(ch, 10); log_err "sent 10"; @@ -21,7 +21,7 @@ fn test05_start(ch : chan_t[int]) { fn test05() { let po = comm::mk_port[int](); - let ch = po.mk_chan2(); + let ch = po.mk_chan(); task::_spawn(bind test05_start(ch)); let value = po.recv(); log_err value; diff --git a/src/test/run-pass/task-comm-1.rs b/src/test/run-pass/task-comm-1.rs index f634af9cee9..f5a3e268a85 100644 --- a/src/test/run-pass/task-comm-1.rs +++ b/src/test/run-pass/task-comm-1.rs @@ -1,9 +1,10 @@ use std; -import std::task::join; +import std::task::_spawn; +import std::task::join_id; fn main() { test00(); } fn start() { log "Started / Finished task."; } -fn test00() { let t: task = spawn start(); join(t); log "Completing."; } +fn test00() { let t = _spawn(bind start()); join_id(t); log "Completing."; } diff --git a/src/test/run-pass/task-comm-11.rs b/src/test/run-pass/task-comm-11.rs index 1e3dc70e18e..82f896837cf 100644 --- a/src/test/run-pass/task-comm-11.rs +++ b/src/test/run-pass/task-comm-11.rs @@ -1,16 +1,15 @@ // xfail-stage3 use std; import std::comm; +import std::task; -fn start(pcc: *u8) { - let c = comm::chan_from_unsafe_ptr(pcc); +fn start(c: comm::_chan[comm::_chan[int]]) { let p : comm::_port[int] = comm::mk_port(); - c.send(p.mk_chan().unsafe_ptr()); + comm::send(c, p.mk_chan()); } fn main() { - let p = comm::mk_port(); - let child = spawn start(p.mk_chan().unsafe_ptr()); - let pc = p.recv(); - let c : comm::_chan[int] = comm::chan_from_unsafe_ptr(pc); + let p = comm::mk_port[comm::_chan[int]](); + let child = task::_spawn(bind start(p.mk_chan())); + let c = p.recv(); } diff --git a/src/test/run-pass/task-comm-13.rs b/src/test/run-pass/task-comm-13.rs index 163ccbefb22..64f11a41421 100644 --- a/src/test/run-pass/task-comm-13.rs +++ b/src/test/run-pass/task-comm-13.rs @@ -1,17 +1,17 @@ use std; import std::task; import std::comm; +import std::comm::send; -fn start(pc: *u8, start: int, number_of_messages: int) { - let c = comm::chan_from_unsafe_ptr(pc); +fn start(c: comm::_chan[int], start: int, number_of_messages: int) { let i: int = 0; - while i < number_of_messages { c.send(start + i); i += 1; } + while i < number_of_messages { send(c, start + i); i += 1; } } fn main() { log "Check that we don't deadlock."; let p : comm::_port[int] = comm::mk_port(); - let a: task = spawn start(p.mk_chan().unsafe_ptr(), 0, 10); - task::join(a); + let a = task::_spawn(bind start(p.mk_chan(), 0, 10)); + task::join_id(a); log "Joined task"; -} \ No newline at end of file +} diff --git a/src/test/run-pass/task-comm-16.rs b/src/test/run-pass/task-comm-16.rs index b974e2052e7..9b43986e2ed 100644 --- a/src/test/run-pass/task-comm-16.rs +++ b/src/test/run-pass/task-comm-16.rs @@ -2,6 +2,7 @@ use std; import std::comm; +import std::comm::send; import std::comm::mk_port; // Tests of ports and channels on various types @@ -11,7 +12,7 @@ fn test_rec() { let po = comm::mk_port(); let ch = po.mk_chan(); let r0: r = {val0: 0, val1: 1u8, val2: '2'}; - ch.send(r0); + send(ch, r0); let r1: r; r1 = po.recv(); assert (r1.val0 == 0); @@ -23,7 +24,7 @@ fn test_vec() { let po = comm::mk_port(); let ch = po.mk_chan(); let v0: [int] = ~[0, 1, 2]; - ch.send(v0); + send(ch, v0); let v1: [int]; v1 = po.recv(); assert (v1.(0) == 0); @@ -37,7 +38,7 @@ fn test_str() { let po = comm::mk_port(); let ch = po.mk_chan(); let s0: str = "test"; - ch.send(s0); + send(ch, s0); let s1: str; s1 = po.recv(); assert (s1.(0) as u8 == 't' as u8); @@ -51,9 +52,9 @@ fn test_tag() { tag t { tag1; tag2(int); tag3(int, u8, char); } let po = comm::mk_port(); let ch = po.mk_chan(); - ch.send(tag1); - ch.send(tag2(10)); - ch.send(tag3(10, 11u8, 'A')); + send(ch, tag1); + send(ch, tag2(10)); + send(ch, tag3(10, 11u8, 'A')); // FIXME: Do port semantics really guarantee these happen in order? let t1: t; t1 = po.recv(); @@ -69,13 +70,11 @@ fn test_chan() { let ch = po.mk_chan(); let po0 = comm::mk_port(); let ch0 = po0.mk_chan(); - ch.send(ch0.unsafe_ptr()); - let pch1; - pch1 = po.recv(); - let ch1 = comm::chan_from_unsafe_ptr(pch1); + send(ch, ch0); + let ch1 = po.recv(); // Does the transmitted channel still work? - ch1.send(10); + send(ch1, 10); let i: int; i = po0.recv(); assert (i == 10); diff --git a/src/test/run-pass/task-comm-2.rs b/src/test/run-pass/task-comm-2.rs index 736504c6f67..06826954fd9 100644 --- a/src/test/run-pass/task-comm-2.rs +++ b/src/test/run-pass/task-comm-2.rs @@ -15,10 +15,13 @@ fn test00() { let number_of_tasks: int = 8; let i: int = 0; - let tasks: [task] = ~[]; - while i < number_of_tasks { i = i + 1; tasks += ~[spawn start(i)]; } + let tasks = []; + while i < number_of_tasks { + i = i + 1; + tasks += [task::_spawn(bind start(i))]; + } - for t: task in tasks { task::join(t); } + for t: task::task_id in tasks { task::join_id(t); } log "Joined all task."; } diff --git a/src/test/run-pass/task-comm-4.rs b/src/test/run-pass/task-comm-4.rs index e83fffca0e7..30342d877f0 100644 --- a/src/test/run-pass/task-comm-4.rs +++ b/src/test/run-pass/task-comm-4.rs @@ -8,7 +8,7 @@ fn test00() { let r: int = 0; let sum: int = 0; let p = comm::mk_port(); - let c = p.mk_chan2(); + let c = p.mk_chan(); send(c, 1); send(c, 2); send(c, 3); diff --git a/src/test/run-pass/task-comm-5.rs b/src/test/run-pass/task-comm-5.rs index 3126d98d99b..bb3a1e4dc70 100644 --- a/src/test/run-pass/task-comm-5.rs +++ b/src/test/run-pass/task-comm-5.rs @@ -10,7 +10,7 @@ fn test00() { let c = p.mk_chan(); let number_of_messages: int = 1000; let i: int = 0; - while i < number_of_messages { c.send(i); i += 1; } + while i < number_of_messages { comm::send(c, i+0); i += 1; } i = 0; while i < number_of_messages { r = p.recv(); sum += r; i += 1; } assert (sum == number_of_messages * (number_of_messages - 1) / 2); diff --git a/src/test/run-pass/task-comm-6.rs b/src/test/run-pass/task-comm-6.rs index 74555ded400..41dc6d203ad 100644 --- a/src/test/run-pass/task-comm-6.rs +++ b/src/test/run-pass/task-comm-6.rs @@ -1,5 +1,6 @@ use std; import std::comm; +import std::comm::send; fn main() { test00(); } @@ -14,10 +15,10 @@ fn test00() { let number_of_messages: int = 1000; let i: int = 0; while i < number_of_messages { - c0.send(i); - c1.send(i); - c2.send(i); - c3.send(i); + send(c0, i+0); + send(c1, i+0); + send(c2, i+0); + send(c3, i+0); i += 1; } i = 0; diff --git a/src/test/run-pass/task-comm-7.rs b/src/test/run-pass/task-comm-7.rs index 6040487a986..42c4e05c060 100644 --- a/src/test/run-pass/task-comm-7.rs +++ b/src/test/run-pass/task-comm-7.rs @@ -4,10 +4,9 @@ import std::comm; fn main() { test00(); } -fn test00_start(pc: *u8, start: int, number_of_messages: int) { - let c = comm::chan_from_unsafe_ptr(pc); +fn test00_start(c: comm::_chan[int], start: int, number_of_messages: int) { let i: int = 0; - while i < number_of_messages { c.send(start + i); i += 1; } + while i < number_of_messages { comm::send(c, start + i); i += 1; } } fn test00() { @@ -16,18 +15,18 @@ fn test00() { let p = comm::mk_port(); let number_of_messages: int = 10; - let t0: task = - spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 0, - number_of_messages); - let t1: task = - spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 1, - number_of_messages); - let t2: task = - spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 2, - number_of_messages); - let t3: task = - spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 3, - number_of_messages); + let t0 = + task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 0, + number_of_messages)); + let t1 = + task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 1, + number_of_messages)); + let t2 = + task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 2, + number_of_messages)); + let t3 = + task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 3, + number_of_messages)); let i: int = 0; while i < number_of_messages { @@ -42,10 +41,10 @@ fn test00() { i += 1; } - task::join(t0); - task::join(t1); - task::join(t2); - task::join(t3); + task::join_id(t0); + task::join_id(t1); + task::join_id(t2); + task::join_id(t3); assert (sum == number_of_messages * 4 * (number_of_messages * 4 - 1) / 2); } \ No newline at end of file diff --git a/src/test/run-pass/task-comm-8.rs b/src/test/run-pass/task-comm-8.rs index 6040487a986..8917f72157d 100644 --- a/src/test/run-pass/task-comm-8.rs +++ b/src/test/run-pass/task-comm-8.rs @@ -4,10 +4,9 @@ import std::comm; fn main() { test00(); } -fn test00_start(pc: *u8, start: int, number_of_messages: int) { - let c = comm::chan_from_unsafe_ptr(pc); +fn test00_start(c : comm::_chan[int], start: int, number_of_messages: int) { let i: int = 0; - while i < number_of_messages { c.send(start + i); i += 1; } + while i < number_of_messages { comm::send(c, start + i); i += 1; } } fn test00() { @@ -16,18 +15,18 @@ fn test00() { let p = comm::mk_port(); let number_of_messages: int = 10; - let t0: task = - spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 0, - number_of_messages); - let t1: task = - spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 1, - number_of_messages); - let t2: task = - spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 2, - number_of_messages); - let t3: task = - spawn test00_start(p.mk_chan().unsafe_ptr(), number_of_messages * 3, - number_of_messages); + let t0 = + task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 0, + number_of_messages)); + let t1 = + task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 1, + number_of_messages)); + let t2 = + task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 2, + number_of_messages)); + let t3 = + task::_spawn(bind test00_start(p.mk_chan(), number_of_messages * 3, + number_of_messages)); let i: int = 0; while i < number_of_messages { @@ -42,10 +41,10 @@ fn test00() { i += 1; } - task::join(t0); - task::join(t1); - task::join(t2); - task::join(t3); + task::join_id(t0); + task::join_id(t1); + task::join_id(t2); + task::join_id(t3); assert (sum == number_of_messages * 4 * (number_of_messages * 4 - 1) / 2); } \ No newline at end of file diff --git a/src/test/run-pass/task-comm-9.rs b/src/test/run-pass/task-comm-9.rs index 9a04e113ac9..27ac300c117 100644 --- a/src/test/run-pass/task-comm-9.rs +++ b/src/test/run-pass/task-comm-9.rs @@ -4,10 +4,9 @@ import std::comm; fn main() { test00(); } -fn test00_start(pc: *u8, number_of_messages: int) { - let c = comm::chan_from_unsafe_ptr(pc); +fn test00_start(c: comm::_chan[int], number_of_messages: int) { let i: int = 0; - while i < number_of_messages { c.send(i); i += 1; } + while i < number_of_messages { comm::send(c, i+0); i += 1; } } fn test00() { @@ -16,13 +15,13 @@ fn test00() { let p = comm::mk_port(); let number_of_messages: int = 10; - let t0: task = spawn test00_start(p.mk_chan().unsafe_ptr(), - number_of_messages); + let t0 = task::_spawn(bind test00_start(p.mk_chan(), + number_of_messages)); let i: int = 0; while i < number_of_messages { r = p.recv(); sum += r; log r; i += 1; } - task::join(t0); + task::join_id(t0); assert (sum == number_of_messages * (number_of_messages - 1) / 2); -} \ No newline at end of file +} diff --git a/src/test/stdtest/comm.rs b/src/test/stdtest/comm.rs index 81c5d868b67..8478e75a5ad 100644 --- a/src/test/stdtest/comm.rs +++ b/src/test/stdtest/comm.rs @@ -9,19 +9,8 @@ fn create_port_and_chan() { #[test] fn send_recv() { - let p = comm::mk_port(); - let c = p.mk_chan(); - - c.send(42); - let v = p.recv(); - log_err v; - assert(42 == v); -} - -#[test] -fn send_recv2() { let p = comm::mk_port[int](); - let c = p.mk_chan2(); + let c = p.mk_chan(); comm::send(c, 42); let v = p.recv();