Skip to content

Commit bacfa63

Browse files
author
Eric Holk
committed
---
yaml --- r: 4785 b: refs/heads/master c: 3ab21e5 h: refs/heads/master i: 4783: 91840de v: v3
1 parent 81c3d26 commit bacfa63

File tree

7 files changed

+66
-60
lines changed

7 files changed

+66
-60
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: f023f8209040554839dc7bc91d9f796a5ff7f247
2+
refs/heads/master: 3ab21e5ee082ff1cc535f23d1be5f153cb80a985

trunk/src/lib/comm.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import task::task_id;
66

77
export _chan;
88
export _port;
9-
9+
export chan_handle;
1010
export mk_port;
1111
export send;
1212
export recv;
@@ -32,22 +32,21 @@ native "rust-intrinsic" mod rusti {
3232

3333
type port_id = int;
3434

35-
type chan<~T> = {
36-
task : task_id,
37-
port : port_id
38-
};
35+
type chan_handle<~T> = { task : task_id, port : port_id};
36+
37+
tag chan<~T> { chan_t(chan_handle<T>); }
3938
type _chan<~T> = chan<T>;
4039

4140
resource port_ptr(po: *rustrt::rust_port) {
4241
rustrt::drop_port(po);
4342
rustrt::del_port(po);
4443
}
4544

46-
type port<~T> = @port_ptr;
45+
tag port<~T> { port_t(@port_ptr); }
4746

4847
obj port_obj<~T>(raw_port : port<T>) {
49-
fn mk_chan() -> _chan<T> {
50-
chan::<T>(raw_port)
48+
fn mk_chan() -> chan<T> {
49+
chan(raw_port)
5150
}
5251

5352
fn recv() -> T {
@@ -60,21 +59,21 @@ fn mk_port<~T>() -> _port<T> {
6059
ret port_obj::<T>(port::<T>());
6160
}
6261

63-
fn send<~T>(ch : chan<T>, data : -T) {
62+
fn send<~T>(ch : &chan<T>, data : -T) {
6463
rustrt::chan_id_send(ch.task, ch.port, data);
6564
}
6665

6766
fn port<~T>() -> port<T> {
68-
@port_ptr(rustrt::new_port(sys::size_of::<T>()))
67+
port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>())))
6968
}
7069

71-
fn recv<~T>(p : port<T>) -> T {
72-
ret rusti::recv(**p)
70+
fn recv<~T>(p : &port<T>) -> T {
71+
ret rusti::recv(***p)
7372
}
7473

75-
fn chan<~T>(p : port<T>) -> chan<T> {
76-
{
74+
fn chan<~T>(p : &port<T>) -> chan<T> {
75+
chan_t({
7776
task: task::get_task_id(),
78-
port: rustrt::get_port_id(**p)
79-
}
77+
port: rustrt::get_port_id(***p)
78+
})
8079
}

trunk/src/lib/task.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import cast = unsafe::reinterpret_cast;
22
import comm;
3-
import comm::_chan;
43
import option::some;
54
import option::none;
65
import option = option::t;
@@ -33,7 +32,7 @@ native "rust" mod rustrt {
3332
type rust_task = {
3433
id : task,
3534
mutable notify_enabled : u8,
36-
mutable notify_chan : _chan<task_notification>,
35+
mutable notify_chan : comm::chan_handle<task_notification>,
3736
ctx : task_context,
3837
stack_ptr : *u8
3938
};
@@ -76,14 +75,12 @@ tag task_notification {
7675
fn join(task_port : (task_id, comm::port<task_notification>))
7776
-> task_result {
7877
let (id, port) = task_port;
79-
while true {
80-
alt comm::recv::<task_notification>(port) {
81-
exit(_id, res) {
82-
if _id == id { ret res }
83-
}
84-
}
78+
alt comm::recv::<task_notification>(port) {
79+
exit(_id, res) {
80+
if _id == id { ret res }
81+
else { fail #fmt("join received id %d, expected %d", _id, id) }
82+
}
8583
}
86-
fail
8784
}
8885

8986
fn join_id(t : task_id) -> task_result {
@@ -108,7 +105,7 @@ fn spawn(thunk : -fn() -> ()) -> task {
108105
spawn_inner(thunk, none)
109106
}
110107

111-
fn spawn_notify(thunk : -fn() -> (), notify : _chan<task_notification>)
108+
fn spawn_notify(thunk : -fn() -> (), notify : comm::chan<task_notification>)
112109
-> task {
113110
spawn_inner(thunk, some(notify))
114111
}
@@ -121,7 +118,7 @@ fn spawn_joinable(thunk : -fn()) -> (task_id, comm::port<task_notification>) {
121118

122119
// FIXME: make this a fn~ once those are supported.
123120
fn spawn_inner(thunk : -fn() -> (),
124-
notify : option<_chan<task_notification>>)
121+
notify : option<comm::chan<task_notification>>)
125122
-> task_id {
126123
let id = rustrt::new_task();
127124

@@ -144,7 +141,7 @@ fn spawn_inner(thunk : -fn() -> (),
144141
alt notify {
145142
some(c) {
146143
(**task_ptr).notify_enabled = 1u8;
147-
(**task_ptr).notify_chan = c;
144+
(**task_ptr).notify_chan = *c;
148145
}
149146
none {}
150147
};

trunk/src/test/compiletest/procsrv.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import std::os;
1414
import std::run;
1515
import std::io;
1616
import std::str;
17-
import std::comm::_chan;
18-
import std::comm::mk_port;
19-
import std::comm::_port;
17+
import std::comm::chan;
18+
import std::comm::port;
2019
import std::comm::send;
20+
import std::comm::recv;
2121

2222
export handle;
2323
export mk;
@@ -26,27 +26,27 @@ export run;
2626
export close;
2727
export reqchan;
2828

29-
type reqchan = _chan<request>;
29+
type reqchan = chan<request>;
3030

3131
type handle = {task: option::t<task_id>, chan: reqchan};
3232

3333
tag request {
34-
exec([u8], [u8], [[u8]], _chan<response>);
34+
exec([u8], [u8], [[u8]], chan<response>);
3535
stop;
3636
}
3737

3838
type response = {pid: int, infd: int, outfd: int, errfd: int};
3939

4040
fn mk() -> handle {
41-
let setupport = mk_port();
42-
let task = task::_spawn(bind fn(setupchan: _chan<_chan<request>>) {
43-
let reqport = mk_port();
44-
let reqchan = reqport.mk_chan();
41+
let setupport = port();
42+
let task = task::spawn(bind fn(setupchan: chan<chan<request>>) {
43+
let reqport = port();
44+
let reqchan = chan(reqport);
4545
send(setupchan, reqchan);
4646
worker(reqport);
47-
} (setupport.mk_chan()));
47+
} (chan(setupport)));
4848
ret {task: option::some(task),
49-
chan: setupport.recv()
49+
chan: recv(setupport)
5050
};
5151
}
5252

@@ -60,13 +60,13 @@ fn close(handle: &handle) {
6060
fn run(handle: &handle, lib_path: &str,
6161
prog: &str, args: &[str], input: &option::t<str>) ->
6262
{status: int, out: str, err: str} {
63-
let p = mk_port::<response>();
64-
let ch = p.mk_chan();
63+
let p = port();
64+
let ch = chan(p);
6565
send(handle.chan, exec(str::bytes(lib_path),
6666
str::bytes(prog),
6767
clone_ivecstr(args),
6868
ch));
69-
let resp = p.recv();
69+
let resp = recv(p);
7070

7171
writeclose(resp.infd, input);
7272
let output = readclose(resp.outfd);
@@ -99,18 +99,12 @@ fn readclose(fd: int) -> str {
9999
ret buf;
100100
}
101101

102-
fn worker(p: _port<request>) {
102+
fn worker(p: port<request>) {
103103

104104
// FIXME (787): If we declare this inside of the while loop and then
105105
// break out of it before it's ever initialized (i.e. we don't run
106-
// any tests), then the cleanups will puke, so we're initializing it
107-
// here with defaults.
108-
let execparms = {
109-
lib_path: "",
110-
prog: "",
111-
args: ~[],
112-
respchan: p.mk_chan()
113-
};
106+
// any tests), then the cleanups will puke.
107+
let execparms;
114108

115109
while true {
116110
// FIXME: Sending strings across channels seems to still
@@ -124,7 +118,7 @@ fn worker(p: _port<request>) {
124118
// put the entire alt in another block to make sure the exec
125119
// message goes out of scope. Seems like the scoping rules for
126120
// the alt discriminant are wrong.
127-
alt p.recv() {
121+
alt recv(p) {
128122
exec(lib_path, prog, args, respchan) {
129123
{
130124
lib_path: str::unsafe_from_bytes(lib_path),

trunk/src/test/run-fail/port-type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import std::comm::_chan;
44
import std::comm::mk_port;
55
import std::comm::send;
66

7-
fn echo<~T>(c: _chan<T>, oc: _chan<_chan<T>>) {
7+
fn echo<~T>(c: &_chan<T>, oc: &_chan<_chan<T>>) {
88
// Tests that the type argument in port gets
99
// visited
1010
let p = mk_port::<T>();
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std;
2-
import std::comm::_chan;
2+
import std::comm::chan;
33
import std::comm::send;
4-
import std::comm::mk_port;
4+
import std::comm::port;
55

66
// tests that ctrl's type gets inferred properly
7-
type command<K, V> = {key: K, val: V};
7+
type command<~K, ~V> = {key: K, val: V};
88

9-
fn cache_server<K, V>(c: _chan<_chan<command<K, V>>>) {
10-
let ctrl = mk_port::<_chan<command<K, V>>>();
11-
send(c, ctrl.mk_chan());
9+
fn cache_server<~K, ~V>(c: &chan<chan<command<K, V>>>) {
10+
let ctrl = port();
11+
send(c, chan(ctrl));
1212
}
1313
fn main() { }

trunk/src/test/stdtest/comm.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,19 @@ fn send_recv_fn() {
2525
comm::send(c, 42);
2626
assert(comm::recv(p) == 42);
2727
}
28+
29+
#[test]
30+
fn send_recv_fn_infer() {
31+
let p = comm::port();
32+
let c = comm::chan(p);
33+
comm::send(c, 42);
34+
assert(comm::recv(p) == 42);
35+
}
36+
37+
#[test]
38+
fn chan_chan() {
39+
let p = comm::port(), p2 = comm::port::<int>();
40+
let c = comm::chan(p);
41+
comm::send(c, comm::chan(p2));
42+
let c2 = comm::recv(p);
43+
}

0 commit comments

Comments
 (0)