about summary refs log tree commit diff
path: root/src/lib
diff options
context:
space:
mode:
authorEric Holk <eholk@mozilla.com>2011-08-17 17:13:11 -0700
committerEric Holk <eholk@mozilla.com>2011-08-17 17:16:23 -0700
commit3ab21e5ee082ff1cc535f23d1be5f153cb80a985 (patch)
tree660373019d8287feb0bebfda5001b37c0152886d /src/lib
parentf023f8209040554839dc7bc91d9f796a5ff7f247 (diff)
Better type inference for chans and ports.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/comm.rs31
-rw-r--r--src/lib/task.rs21
2 files changed, 24 insertions, 28 deletions
diff --git a/src/lib/comm.rs b/src/lib/comm.rs
index 17c766cda1a..615686a49e0 100644
--- a/src/lib/comm.rs
+++ b/src/lib/comm.rs
@@ -6,7 +6,7 @@ import task::task_id;
 
 export _chan;
 export _port;
-
+export chan_handle;
 export mk_port;
 export send;
 export recv;
@@ -32,10 +32,9 @@ native "rust-intrinsic" mod rusti {
 
 type port_id = int;
 
-type chan<~T> = {
-    task : task_id,
-    port : port_id
-};
+type chan_handle<~T> = { task : task_id, port : port_id};
+
+tag chan<~T> { chan_t(chan_handle<T>); }
 type _chan<~T> = chan<T>;
 
 resource port_ptr(po: *rustrt::rust_port) {
@@ -43,11 +42,11 @@ resource port_ptr(po: *rustrt::rust_port) {
     rustrt::del_port(po);
 }
 
-type port<~T> = @port_ptr;
+tag port<~T> { port_t(@port_ptr); }
 
 obj port_obj<~T>(raw_port : port<T>) {
-    fn mk_chan() -> _chan<T> {
-        chan::<T>(raw_port)
+    fn mk_chan() -> chan<T> {
+        chan(raw_port)
     }
 
     fn recv() -> T {
@@ -60,21 +59,21 @@ fn mk_port<~T>() -> _port<T> {
     ret port_obj::<T>(port::<T>());
 }
 
-fn send<~T>(ch : chan<T>, data : -T) {
+fn send<~T>(ch : &chan<T>, data : -T) {
     rustrt::chan_id_send(ch.task, ch.port, data);
 }
 
 fn port<~T>() -> port<T> {
-    @port_ptr(rustrt::new_port(sys::size_of::<T>()))
+    port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>())))
 }
 
-fn recv<~T>(p : port<T>) -> T {
-    ret rusti::recv(**p)
+fn recv<~T>(p : &port<T>) -> T {
+    ret rusti::recv(***p)
 }
 
-fn chan<~T>(p : port<T>) -> chan<T> {
-    {
+fn chan<~T>(p : &port<T>) -> chan<T> {
+    chan_t({
         task: task::get_task_id(),
-        port: rustrt::get_port_id(**p)
-    }
+        port: rustrt::get_port_id(***p)
+    })
 }
diff --git a/src/lib/task.rs b/src/lib/task.rs
index 4ad160df603..9ed8e8ecdf0 100644
--- a/src/lib/task.rs
+++ b/src/lib/task.rs
@@ -1,6 +1,5 @@
 import cast = unsafe::reinterpret_cast;
 import comm;
-import comm::_chan;
 import option::some;
 import option::none;
 import option = option::t;
@@ -33,7 +32,7 @@ native "rust" mod rustrt {
 type rust_task = {
     id : task,
     mutable notify_enabled : u8,
-    mutable notify_chan : _chan<task_notification>,
+    mutable notify_chan : comm::chan_handle<task_notification>,
     ctx : task_context,
     stack_ptr : *u8
 };
@@ -76,14 +75,12 @@ tag task_notification {
 fn join(task_port : (task_id, comm::port<task_notification>))
     -> task_result {
     let (id, port) = task_port;
-    while true {
-        alt comm::recv::<task_notification>(port) {
-          exit(_id, res) {
-            if _id == id { ret res }
-          }
-        }
+    alt comm::recv::<task_notification>(port) {
+      exit(_id, res) {
+        if _id == id { ret res }
+        else { fail #fmt("join received id %d, expected %d", _id, id) }
+      }
     }
-    fail
 }
 
 fn join_id(t : task_id) -> task_result {
@@ -108,7 +105,7 @@ fn spawn(thunk : -fn() -> ()) -> task {
     spawn_inner(thunk, none)
 }
 
-fn spawn_notify(thunk : -fn() -> (), notify : _chan<task_notification>)
+fn spawn_notify(thunk : -fn() -> (), notify : comm::chan<task_notification>)
     -> task {
     spawn_inner(thunk, some(notify))
 }
@@ -121,7 +118,7 @@ fn spawn_joinable(thunk : -fn()) -> (task_id, comm::port<task_notification>) {
 
 // FIXME: make this a fn~ once those are supported.
 fn spawn_inner(thunk : -fn() -> (),
-               notify : option<_chan<task_notification>>)
+               notify : option<comm::chan<task_notification>>)
     -> task_id {
     let id = rustrt::new_task();
 
@@ -144,7 +141,7 @@ fn spawn_inner(thunk : -fn() -> (),
     alt notify {
       some(c) {
         (**task_ptr).notify_enabled = 1u8;
-        (**task_ptr).notify_chan = c;
+        (**task_ptr).notify_chan = *c;
       }
       none {}
     };