Skip to content

Commit 8bf671a

Browse files
committed
---
yaml --- r: 31739 b: refs/heads/dist-snap c: f110e8f h: refs/heads/master i: 31737: 861736b 31735: 7bbbef4 v: v3
1 parent e7962f4 commit 8bf671a

File tree

18 files changed

+302
-225
lines changed

18 files changed

+302
-225
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: a76e4334b39a2287b039f858c3bd3d5f5d6e2449
10+
refs/heads/dist-snap: f110e8f21c707cb4bbb5e54b45f4458987920322
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/doc/tutorial.md

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ When complete, `make install` will place the following programs into
196196
`/usr/local/bin`:
197197

198198
* `rustc`, the Rust compiler
199-
* `rustdoc`, the API-documentation tool
199+
* `rustdoc`, the API-documentation tool
200200
* `cargo`, the Rust package manager
201201

202202
[wiki-get-started]: https://github.com/mozilla/rust/wiki/Note-getting-started-developing-Rust
@@ -2960,11 +2960,7 @@ do spawn {
29602960
~~~~
29612961

29622962
This child will perform the expensive computation send the result
2963-
over the channel. (Under the hood, `chan` was captured by the
2964-
closure that forms the body of the child task. This capture is
2965-
allowed because channels are sendable.)
2966-
2967-
Finally, the parent continues by performing
2963+
over the channel. Finally, the parent continues by performing
29682964
some other expensive computation and then waiting for the child's result
29692965
to arrive on the port:
29702966

@@ -2982,10 +2978,10 @@ let result = port.recv();
29822978

29832979
A very common thing to do is to spawn a child task where the parent
29842980
and child both need to exchange messages with each
2985-
other. The function `task::spawn_conversation()` supports this pattern.
2986-
We'll look briefly at how it is used.
2981+
other. The function `task::spawn_listener()` supports this pattern. We'll look
2982+
briefly at how it is used.
29872983

2988-
To see how `spawn_conversation()` works, we will create a child task
2984+
To see how `spawn_listener()` works, we will create a child task
29892985
that receives `uint` messages, converts them to a string, and sends
29902986
the string in response. The child terminates when `0` is received.
29912987
Here is the function that implements the child task:
@@ -3010,11 +3006,11 @@ loops, reading from the `from_parent` port and then sending its
30103006
response to the `to_parent` channel. The actual response itself is
30113007
simply the strified version of the received value,
30123008
`uint::to_str(value)`.
3013-
3009+
30143010
Here is the code for the parent task:
30153011

30163012
~~~~
3017-
# import task::{spawn_conversation};
3013+
# import task::{spawn_listener};
30183014
# import comm::{chan, port, methods};
30193015
# fn stringifier(from_parent: comm::port<uint>,
30203016
# to_parent: comm::chan<~str>) {
@@ -3024,30 +3020,32 @@ Here is the code for the parent task:
30243020
# }
30253021
# fn main() {
30263022
3027-
let (from_child, to_child) = do spawn_conversation |from_parent, to_parent| {
3023+
let from_child = port();
3024+
let to_parent = from_child.chan();
3025+
let to_child = do spawn_listener |from_parent| {
30283026
stringifier(from_parent, to_parent);
30293027
};
30303028
30313029
to_child.send(22u);
30323030
assert from_child.recv() == ~"22";
30333031
30343032
to_child.send(23u);
3035-
to_child.send(0u);
3036-
30373033
assert from_child.recv() == ~"23";
3034+
3035+
to_child.send(0u);
30383036
assert from_child.recv() == ~"0";
30393037
30403038
# }
30413039
~~~~
30423040

3043-
The parent task calls `spawn_conversation` with a function that takes
3044-
a `from_parent` port and a `to_parent` channel. In return, it gets a
3045-
`from_child` channel and a `to_child` port. As a result, both parent
3046-
and child can send and receive data to and from the other.
3047-
3048-
`spawn_conversation`
3049-
will create two port/channel pairs, passing one set to the child task
3050-
and returning the other set to the caller.
3041+
The parent first sets up a port to receive data from and a channel
3042+
that the child can use to send data to that port. The call to
3043+
`spawn_listener()` will spawn the child task, providing it with a port
3044+
on which to receive data from its parent, and returning to the parent
3045+
the associated channel. Finally, the closure passed to
3046+
`spawn_listener()` that forms the body of the child task captures the
3047+
`to_parent` channel in its environment, so both parent and child
3048+
can send and receive data to and from the other.
30513049

30523050
# Testing
30533051

branches/dist-snap/src/libcore/priv.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ unsafe fn chan_from_global_ptr<T: send>(
4040
log(debug,~"is probably zero...");
4141
// There's no global channel. We must make it
4242
43-
let (setup_po, setup_ch) = do task_fn().spawn_conversation
44-
|setup_po, setup_ch| {
43+
let setup_po = comm::port();
44+
let setup_ch = comm::chan(setup_po);
45+
let setup_ch = do task_fn().spawn_listener |setup_po| {
4546
let po = comm::port::<T>();
4647
let ch = comm::chan(po);
4748
comm::send(setup_ch, ch);

branches/dist-snap/src/libcore/task.rs

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export spawn_unlinked;
5252
export spawn_supervised;
5353
export spawn_with;
5454
export spawn_listener;
55-
export spawn_conversation;
5655
export spawn_sched;
5756
export try;
5857

@@ -377,20 +376,6 @@ impl task_builder for task_builder {
377376
comm::recv(setup_po)
378377
}
379378
380-
/**
381-
* Runs a new task, setting up communication in both directions
382-
*/
383-
fn spawn_conversation<A: send, B: send>
384-
(+f: fn~(comm::port<A>, comm::chan<B>))
385-
-> (comm::port<B>, comm::chan<A>) {
386-
let from_child = comm::port();
387-
let to_parent = comm::chan(from_child);
388-
let to_child = do self.spawn_listener |from_parent| {
389-
f(from_parent, to_parent)
390-
};
391-
(from_child, to_child)
392-
}
393-
394379
/**
395380
* Execute a function in another task and return either the return value
396381
* of the function or result::err.
@@ -489,24 +474,31 @@ fn spawn_listener<A:send>(+f: fn~(comm::port<A>)) -> comm::chan<A> {
489474
/*!
490475
* Runs a new task while providing a channel from the parent to the child
491476
*
477+
* Sets up a communication channel from the current task to the new
478+
* child task, passes the port to child's body, and returns a channel
479+
* linked to the port to the parent.
480+
*
481+
* This encapsulates some boilerplate handshaking logic that would
482+
* otherwise be required to establish communication from the parent
483+
* to the child.
484+
*
485+
* The simplest way to establish bidirectional communication between
486+
* a parent in child is as follows:
487+
*
488+
* let po = comm::port();
489+
* let ch = comm::chan(po);
490+
* let ch = do spawn_listener |po| {
491+
* // Now the child has a port called 'po' to read from and
492+
* // an environment-captured channel called 'ch'.
493+
* };
494+
* // Likewise, the parent has both a 'po' and 'ch'
495+
*
492496
* This function is equivalent to `task().spawn_listener(f)`.
493497
*/
494498
495499
task().spawn_listener(f)
496500
}
497501
498-
fn spawn_conversation<A: send, B: send>
499-
(+f: fn~(comm::port<A>, comm::chan<B>))
500-
-> (comm::port<B>, comm::chan<A>) {
501-
/*!
502-
* Runs a new task, setting up communication in both directions
503-
*
504-
* This function is equivalent to `task().spawn_conversation(f)`.
505-
*/
506-
507-
task().spawn_conversation(f)
508-
}
509-
510502
fn spawn_sched(mode: sched_mode, +f: fn~()) {
511503
/*!
512504
* Creates a new scheduler and executes a task on it
@@ -1724,17 +1716,6 @@ fn test_spawn_listiner_bidi() {
17241716
assert res == ~"pong";
17251717
}
17261718

1727-
#[test]
1728-
fn test_spawn_conversation() {
1729-
let (recv_str, send_int) = do spawn_conversation |recv_int, send_str| {
1730-
let input = comm::recv(recv_int);
1731-
let output = int::str(input);
1732-
comm::send(send_str, output);
1733-
};
1734-
comm::send(send_int, 1);
1735-
assert comm::recv(recv_str) == ~"1";
1736-
}
1737-
17381719
#[test]
17391720
fn test_try_success() {
17401721
match do try {

branches/dist-snap/src/libsyntax/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@ type variant_arg = {ty: @ty, id: node_id};
636636
#[auto_serialize]
637637
enum variant_kind {
638638
tuple_variant_kind(~[variant_arg]),
639-
struct_variant_kind(@struct_def)
639+
struct_variant_kind(@struct_def),
640+
enum_variant_kind(~[variant])
640641
}
641642

642643
#[auto_serialize]

branches/dist-snap/src/libsyntax/ext/auto_serialize.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,9 @@ fn deser_enum(cx: ext_ctxt, tps: deser_tps_map, e_name: ast::ident,
913913
};
914914
}
915915
ast::struct_variant_kind(*) =>
916-
fail ~"struct variants unimplemented"
916+
fail ~"struct variants unimplemented",
917+
ast::enum_variant_kind(*) =>
918+
fail ~"enum variants unimplemented"
917919
}
918920

919921
{pats: ~[@{id: cx.next_id(),

branches/dist-snap/src/libsyntax/fold.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,11 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
564564
dtor: dtor
565565
})
566566
}
567+
568+
enum_variant_kind(variants) => {
569+
let variants = vec::map(variants, |x| fld.fold_variant(x));
570+
kind = enum_variant_kind(variants);
571+
}
567572
}
568573

569574
let fold_attribute = |x| fold_attribute_(x, fld);

branches/dist-snap/src/libsyntax/parse/parser.rs

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,27 @@ import dvec::{dvec, extensions};
1717
import vec::{push};
1818
import ast::{_mod, add, alt_check, alt_exhaustive, arg, arm, attribute,
1919
bind_by_ref, bind_by_implicit_ref, bind_by_value,
20-
bitand, bitor, bitxor, blk,
21-
blk_check_mode, bound_const, bound_copy, bound_send, bound_trait,
22-
bound_owned, box, by_copy, by_move, by_mutbl_ref, by_ref, by_val,
23-
capture_clause, capture_item, cdir_dir_mod, cdir_src_mod,
24-
cdir_view_item, class_immutable, class_member, class_method,
25-
class_mutable, crate, crate_cfg, crate_directive, decl,
26-
decl_item, decl_local, default_blk, deref, div, expl, expr,
27-
expr_, expr_addr_of, expr_match, expr_again, expr_assert,
28-
expr_assign, expr_assign_op, expr_binary, expr_block, expr_break,
29-
expr_call, expr_cast, expr_copy, expr_do_body,
30-
expr_fail, expr_field, expr_fn, expr_fn_block, expr_if,
31-
expr_index, expr_lit, expr_log, expr_loop,
32-
expr_loop_body, expr_mac, expr_move, expr_path, expr_rec,
33-
expr_repeat, expr_ret, expr_swap, expr_struct, expr_tup,
34-
expr_unary, expr_unary_move, expr_vec, expr_vstore, expr_while,
35-
extern_fn, field, fn_decl, foreign_item, foreign_item_fn,
36-
foreign_mod, ident, impure_fn, infer, inherited, init_assign,
37-
init_move, initializer, instance_var, item, item_, item_class,
38-
item_const, item_enum, item_fn, item_foreign_mod, item_impl,
39-
item_mac, item_mod, item_trait, item_ty, lit, lit_, lit_bool,
40-
lit_float, lit_int, lit_int_unsuffixed, lit_nil, lit_str,
41-
lit_uint, local, m_const, m_imm, m_mutbl, mac_, mac_aq,
20+
bitand, bitor, bitxor, blk, blk_check_mode, bound_const,
21+
bound_copy, bound_send, bound_trait, bound_owned, box, by_copy,
22+
by_move, by_mutbl_ref, by_ref, by_val, capture_clause,
23+
capture_item, cdir_dir_mod, cdir_src_mod, cdir_view_item,
24+
class_immutable, class_member, class_method, class_mutable,
25+
crate, crate_cfg, crate_directive, decl, decl_item, decl_local,
26+
default_blk, deref, div, enum_variant_kind, expl, expr, expr_,
27+
expr_addr_of, expr_match, expr_again, expr_assert, expr_assign,
28+
expr_assign_op, expr_binary, expr_block, expr_break, expr_call,
29+
expr_cast, expr_copy, expr_do_body, expr_fail, expr_field,
30+
expr_fn, expr_fn_block, expr_if, expr_index, expr_lit, expr_log,
31+
expr_loop, expr_loop_body, expr_mac, expr_move, expr_path,
32+
expr_rec, expr_repeat, expr_ret, expr_swap, expr_struct,
33+
expr_tup, expr_unary, expr_unary_move, expr_vec, expr_vstore,
34+
expr_while, extern_fn, field, fn_decl, foreign_item,
35+
foreign_item_fn, foreign_mod, ident, impure_fn, infer, inherited,
36+
init_assign, init_move, initializer, instance_var, item, item_,
37+
item_class, item_const, item_enum, item_fn, item_foreign_mod,
38+
item_impl, item_mac, item_mod, item_trait, item_ty, lit, lit_,
39+
lit_bool, lit_float, lit_int, lit_int_unsuffixed, lit_nil,
40+
lit_str, lit_uint, local, m_const, m_imm, m_mutbl, mac_, mac_aq,
4241
mac_ellipsis, mac_invoc, mac_invoc_tt, mac_var, matcher,
4342
match_nonterminal, match_seq, match_tok, method, mode, mt, mul,
4443
mutability, neg, noreturn, not, pat, pat_box, pat_enum,
@@ -2842,30 +2841,8 @@ class parser {
28422841
}
28432842
}
28442843

2845-
fn parse_item_enum() -> item_info {
2846-
let id = self.parse_ident();
2847-
self.parse_region_param();
2848-
let ty_params = self.parse_ty_params();
2844+
fn parse_enum_body(ty_params: ~[ast::ty_param]) -> ~[ast::variant] {
28492845
let mut variants: ~[variant] = ~[];
2850-
// Newtype syntax
2851-
if self.token == token::EQ {
2852-
self.check_restricted_keywords_(*id);
2853-
self.bump();
2854-
let ty = self.parse_ty(false);
2855-
self.expect(token::SEMI);
2856-
let variant =
2857-
spanned(ty.span.lo, ty.span.hi,
2858-
{name: id,
2859-
attrs: ~[],
2860-
kind: tuple_variant_kind
2861-
(~[{ty: ty, id: self.get_id()}]),
2862-
id: self.get_id(),
2863-
disr_expr: none,
2864-
vis: public});
2865-
return (id, item_enum(~[variant], ty_params), none);
2866-
}
2867-
self.expect(token::LBRACE);
2868-
28692846
let mut all_nullary = true, have_disr = false;
28702847

28712848
while self.token != token::RBRACE {
@@ -2954,6 +2931,34 @@ class parser {
29542931
self.fatal(~"discriminator values can only be used with a c-like \
29552932
enum");
29562933
}
2934+
2935+
return variants;
2936+
}
2937+
2938+
fn parse_item_enum() -> item_info {
2939+
let id = self.parse_ident();
2940+
self.parse_region_param();
2941+
let ty_params = self.parse_ty_params();
2942+
// Newtype syntax
2943+
if self.token == token::EQ {
2944+
self.check_restricted_keywords_(*id);
2945+
self.bump();
2946+
let ty = self.parse_ty(false);
2947+
self.expect(token::SEMI);
2948+
let variant =
2949+
spanned(ty.span.lo, ty.span.hi,
2950+
{name: id,
2951+
attrs: ~[],
2952+
kind: tuple_variant_kind
2953+
(~[{ty: ty, id: self.get_id()}]),
2954+
id: self.get_id(),
2955+
disr_expr: none,
2956+
vis: public});
2957+
return (id, item_enum(~[variant], ty_params), none);
2958+
}
2959+
self.expect(token::LBRACE);
2960+
2961+
let variants = self.parse_enum_body(ty_params);
29572962
(id, item_enum(variants, ty_params), none)
29582963
}
29592964

0 commit comments

Comments
 (0)