Skip to content

Commit 99dc7db

Browse files
committed
---
yaml --- r: 148916 b: refs/heads/try2 c: 6aad3bf h: refs/heads/master v: v3
1 parent 8df1dcf commit 99dc7db

File tree

98 files changed

+819
-374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+819
-374
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 56080c476712e478ffe4ef8d6d727c0e3d21cfd0
8+
refs/heads/try2: 6aad3bf944da209d1852c51144ba584de400a10c
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/mk/crates.mk

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,27 @@
4949
# automatically generated for all stage/host/target combinations.
5050
################################################################################
5151

52-
TARGET_CRATES := std extra green rustuv native flate arena glob term semver uuid
52+
TARGET_CRATES := std extra green rustuv native flate arena glob term semver uuid serialize sync
5353
HOST_CRATES := syntax rustc rustdoc
5454
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
5555
TOOLS := compiletest rustdoc rustc
5656

5757
DEPS_std := native:rustrt
58-
DEPS_extra := std term
58+
DEPS_extra := std serialize sync term
5959
DEPS_green := std
6060
DEPS_rustuv := std native:uv native:uv_support
6161
DEPS_native := std
62-
DEPS_syntax := std extra term
63-
DEPS_rustc := syntax native:rustllvm flate arena
64-
DEPS_rustdoc := rustc native:sundown
62+
DEPS_syntax := std extra term serialize
63+
DEPS_rustc := syntax native:rustllvm flate arena serialize sync
64+
DEPS_rustdoc := rustc native:sundown serialize sync
6565
DEPS_flate := std native:miniz
6666
DEPS_arena := std extra
6767
DEPS_glob := std
68+
DEPS_serialize := std
6869
DEPS_term := std
6970
DEPS_semver := std
70-
DEPS_uuid := std extra
71+
DEPS_uuid := std serialize
72+
DEPS_sync := std
7173

7274
TOOL_DEPS_compiletest := extra green rustuv
7375
TOOL_DEPS_rustdoc := rustdoc green rustuv

branches/try2/mk/tests.mk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ check-test: cleantestlibs cleantmptestlogs all check-stage2-rfail
183183
$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
184184

185185
check-lite: cleantestlibs cleantmptestlogs \
186-
check-stage2-std check-stage2-extra check-stage2-rpass \
187-
check-stage2-rustuv check-stage2-native check-stage2-green \
186+
$(foreach crate,$(TARGET_CRATES),check-stage2-$(crate)) \
187+
check-stage2-rpass \
188188
check-stage2-rfail check-stage2-cfail check-stage2-rmake
189189
$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
190190

@@ -861,7 +861,8 @@ $(foreach host,$(CFG_HOST), \
861861
$(eval $(foreach target,$(CFG_TARGET), \
862862
$(eval $(call DEF_CHECK_FAST_FOR_T_H,,$(target),$(host))))))
863863

864-
check-fast: tidy check-fast-H-$(CFG_BUILD) check-stage2-std check-stage2-extra
864+
check-fast: tidy check-fast-H-$(CFG_BUILD) \
865+
$(foreach crate,$(TARGET_CRATES),check-stage2-$(crate))
865866
$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
866867

867868
define DEF_CHECK_FAST_FOR_H

branches/try2/src/doc/guide-tasks.md

Lines changed: 75 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,51 @@ data through the global _exchange heap_.
3939

4040
While Rust's type system provides the building blocks needed for safe
4141
and efficient tasks, all of the task functionality itself is implemented
42-
in the standard and extra libraries, which are still under development
42+
in the standard and sync libraries, which are still under development
4343
and do not always present a consistent or complete interface.
4444

4545
For your reference, these are the standard modules involved in Rust
4646
concurrency at this writing:
4747

4848
* [`std::task`] - All code relating to tasks and task scheduling,
4949
* [`std::comm`] - The message passing interface,
50-
* [`extra::comm`] - Additional messaging types based on `std::comm`,
51-
* [`extra::sync`] - More exotic synchronization tools, including locks,
52-
* [`extra::arc`] - The Arc (atomically reference counted) type,
53-
for safely sharing immutable data,
54-
* [`extra::future`] - A type representing values that may be computed concurrently and retrieved at a later time.
50+
* [`sync::DuplexStream`] - An extension of `pipes::stream` that allows both sending and receiving,
51+
* [`sync::SyncChan`] - An extension of `pipes::stream` that provides synchronous message sending,
52+
* [`sync::SyncPort`] - An extension of `pipes::stream` that acknowledges each message received,
53+
* [`sync::rendezvous`] - Creates a stream whose channel, upon sending a message, blocks until the
54+
message is received.
55+
* [`sync::Arc`] - The Arc (atomically reference counted) type, for safely sharing immutable data,
56+
* [`sync::RWArc`] - A dual-mode Arc protected by a reader-writer lock,
57+
* [`sync::MutexArc`] - An Arc with mutable data protected by a blocking mutex,
58+
* [`sync::Semaphore`] - A counting, blocking, bounded-waiting semaphore,
59+
* [`sync::Mutex`] - A blocking, bounded-waiting, mutual exclusion lock with an associated
60+
FIFO condition variable,
61+
* [`sync::RWLock`] - A blocking, no-starvation, reader-writer lock with an associated condvar,
62+
* [`sync::Barrier`] - A barrier enables multiple tasks to synchronize the beginning
63+
of some computation,
64+
* [`sync::TaskPool`] - A task pool abstraction,
65+
* [`sync::Future`] - A type encapsulating the result of a computation which may not be complete,
66+
* [`sync::one`] - A "once initialization" primitive
67+
* [`sync::mutex`] - A proper mutex implementation regardless of the "flavor of task" which is
68+
acquiring the lock.
5569

5670
[`std::task`]: std/task/index.html
5771
[`std::comm`]: std/comm/index.html
58-
[`extra::comm`]: extra/comm/index.html
59-
[`extra::sync`]: extra/sync/index.html
60-
[`extra::arc`]: extra/arc/index.html
61-
[`extra::future`]: extra/future/index.html
72+
[`sync::DuplexStream`]: sync/struct.DuplexStream.html
73+
[`sync::SyncChan`]: sync/struct.SyncChan.html
74+
[`sync::SyncPort`]: sync/struct.SyncPort.html
75+
[`sync::rendezvous`]: sync/fn.rendezvous.html
76+
[`sync::Arc`]: sync/struct.Arc.html
77+
[`sync::RWArc`]: sync/struct.RWArc.html
78+
[`sync::MutexArc`]: sync/struct.MutexArc.html
79+
[`sync::Semaphore`]: sync/struct.Semaphore.html
80+
[`sync::Mutex`]: sync/struct.Mutex.html
81+
[`sync::RWLock`]: sync/struct.RWLock.html
82+
[`sync::Barrier`]: sync/struct.Barrier.html
83+
[`sync::TaskPool`]: sync/struct.TaskPool.html
84+
[`sync::Future`]: sync/struct.Future.html
85+
[`sync::one`]: sync/one/index.html
86+
[`sync::mutex`]: sync/mutex/index.html
6287

6388
# Basics
6489

@@ -254,21 +279,25 @@ let result = ports.iter().fold(0, |accum, port| accum + port.recv() );
254279
~~~
255280

256281
## Backgrounding computations: Futures
257-
With `extra::future`, rust has a mechanism for requesting a computation and getting the result
282+
With `sync::Future`, rust has a mechanism for requesting a computation and getting the result
258283
later.
259284

260285
The basic example below illustrates this.
261286

262287
~~~
288+
# extern mod sync;
289+
290+
# fn main() {
263291
# fn make_a_sandwich() {};
264292
fn fib(n: u64) -> u64 {
265293
// lengthy computation returning an uint
266294
12586269025
267295
}
268296
269-
let mut delayed_fib = extra::future::Future::spawn(proc() fib(50));
297+
let mut delayed_fib = sync::Future::spawn(proc() fib(50));
270298
make_a_sandwich();
271299
println!("fib(50) = {:?}", delayed_fib.get())
300+
# }
272301
~~~
273302

274303
The call to `future::spawn` returns immediately a `future` object regardless of how long it
@@ -281,6 +310,7 @@ Here is another example showing how futures allow you to background computations
281310
be distributed on the available cores.
282311

283312
~~~
313+
# extern mod sync;
284314
# use std::vec;
285315
fn partial_sum(start: uint) -> f64 {
286316
let mut local_sum = 0f64;
@@ -291,7 +321,7 @@ fn partial_sum(start: uint) -> f64 {
291321
}
292322
293323
fn main() {
294-
let mut futures = vec::from_fn(1000, |ind| extra::future::Future::spawn( proc() { partial_sum(ind) }));
324+
let mut futures = vec::from_fn(1000, |ind| sync::Future::spawn( proc() { partial_sum(ind) }));
295325
296326
let mut final_res = 0f64;
297327
for ft in futures.mut_iter() {
@@ -309,16 +339,17 @@ add up to a significant amount of wasted memory and would require copying the sa
309339
necessary.
310340

311341
To tackle this issue, one can use an Atomically Reference Counted wrapper (`Arc`) as implemented in
312-
the `extra` library of Rust. With an Arc, the data will no longer be copied for each task. The Arc
342+
the `sync` library of Rust. With an Arc, the data will no longer be copied for each task. The Arc
313343
acts as a reference to the shared data and only this reference is shared and cloned.
314344

315345
Here is a small example showing how to use Arcs. We wish to run concurrently several computations on
316346
a single large vector of floats. Each task needs the full vector to perform its duty.
317347

318348
~~~
349+
# extern mod sync;
319350
# use std::vec;
320351
# use std::rand;
321-
use extra::arc::Arc;
352+
use sync::Arc;
322353
323354
fn pnorm(nums: &~[f64], p: uint) -> f64 {
324355
nums.iter().fold(0.0, |a,b| a+(*b).powf(&(p as f64)) ).powf(&(1.0 / (p as f64)))
@@ -348,39 +379,48 @@ at the power given as argument and takes the inverse power of this value). The A
348379
created by the line
349380

350381
~~~
351-
# use extra::arc::Arc;
382+
# extern mod sync;
383+
# use sync::Arc;
352384
# use std::vec;
353385
# use std::rand;
386+
# fn main() {
354387
# let numbers = vec::from_fn(1000000, |_| rand::random::<f64>());
355388
let numbers_arc=Arc::new(numbers);
389+
# }
356390
~~~
357391

358392
and a clone of it is sent to each task
359393

360394
~~~
361-
# use extra::arc::Arc;
395+
# extern mod sync;
396+
# use sync::Arc;
362397
# use std::vec;
363398
# use std::rand;
399+
# fn main() {
364400
# let numbers=vec::from_fn(1000000, |_| rand::random::<f64>());
365401
# let numbers_arc = Arc::new(numbers);
366402
# let (port, chan) = Chan::new();
367403
chan.send(numbers_arc.clone());
404+
# }
368405
~~~
369406

370407
copying only the wrapper and not its contents.
371408

372409
Each task recovers the underlying data by
373410

374411
~~~
375-
# use extra::arc::Arc;
412+
# extern mod sync;
413+
# use sync::Arc;
376414
# use std::vec;
377415
# use std::rand;
416+
# fn main() {
378417
# let numbers=vec::from_fn(1000000, |_| rand::random::<f64>());
379418
# let numbers_arc=Arc::new(numbers);
380419
# let (port, chan) = Chan::new();
381420
# chan.send(numbers_arc.clone());
382421
# let local_arc : Arc<~[f64]> = port.recv();
383422
let task_numbers = local_arc.get();
423+
# }
384424
~~~
385425

386426
and can use it as if it were local.
@@ -450,25 +490,27 @@ proceed).
450490

451491
A very common thing to do is to spawn a child task where the parent
452492
and child both need to exchange messages with each other. The
453-
function `extra::comm::DuplexStream()` supports this pattern. We'll
493+
function `sync::comm::DuplexStream()` supports this pattern. We'll
454494
look briefly at how to use it.
455495

456496
To see how `DuplexStream()` works, we will create a child task
457497
that repeatedly receives a `uint` message, converts it to a string, and sends
458498
the string in response. The child terminates when it receives `0`.
459499
Here is the function that implements the child task:
460500

461-
~~~{.ignore .linked-failure}
462-
# use extra::comm::DuplexStream;
463-
# use std::uint;
464-
fn stringifier(channel: &DuplexStream<~str, uint>) {
465-
let mut value: uint;
466-
loop {
467-
value = channel.recv();
468-
channel.send(uint::to_str(value));
469-
if value == 0 { break; }
501+
~~~
502+
# extern mod sync;
503+
# fn main() {
504+
# use sync::DuplexStream;
505+
fn stringifier(channel: &DuplexStream<~str, uint>) {
506+
let mut value: uint;
507+
loop {
508+
value = channel.recv();
509+
channel.send(value.to_str());
510+
if value == 0 { break; }
511+
}
470512
}
471-
}
513+
# }
472514
~~~~
473515
474516
The implementation of `DuplexStream` supports both sending and
@@ -481,15 +523,15 @@ response itself is simply the stringified version of the received value,
481523
482524
Here is the code for the parent task:
483525
484-
~~~{.ignore .linked-failure}
526+
~~~
527+
# extern mod sync;
485528
# use std::task::spawn;
486-
# use std::uint;
487-
# use extra::comm::DuplexStream;
529+
# use sync::DuplexStream;
488530
# fn stringifier(channel: &DuplexStream<~str, uint>) {
489531
# let mut value: uint;
490532
# loop {
491533
# value = channel.recv();
492-
# channel.send(uint::to_str(value));
534+
# channel.send(value.to_str());
493535
# if value == 0u { break; }
494536
# }
495537
# }

branches/try2/src/doc/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ li {list-style-type: none; }
4141
* [The `flate` compression library](flate/index.html)
4242
* [The `glob` file path matching library](glob/index.html)
4343
* [The `semver` version collation library](semver/index.html)
44+
* [The `serialize` value encoding/decoding library](serialize/index.html)
45+
* [The `sync` library for concurrency-enabled mechanisms and primitives](sync/index.html)
4446
* [The `term` terminal-handling library](term/index.html)
45-
* [The UUID library](uuid/index.html)
47+
* [The `uuid` 128-bit universally unique identifier library](uuid/index.html)
4648

4749
# Tooling
4850

branches/try2/src/doc/tutorial.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ fn angle(vector: (f64, f64)) -> f64 {
509509
let pi = f64::consts::PI;
510510
match vector {
511511
(0.0, y) if y < 0.0 => 1.5 * pi,
512-
(0.0, y) => 0.5 * pi,
512+
(0.0, _) => 0.5 * pi,
513513
(x, y) => atan(y / x)
514514
}
515515
}
@@ -519,7 +519,9 @@ A variable name in a pattern matches any value, *and* binds that name
519519
to the value of the matched value inside of the arm's action. Thus, `(0.0,
520520
y)` matches any tuple whose first element is zero, and binds `y` to
521521
the second element. `(x, y)` matches any two-element tuple, and binds both
522-
elements to variables.
522+
elements to variables. `(0.0,_)` matches any tuple whose first element is zero
523+
and does not bind anything to the second element.
524+
523525
A subpattern can also be bound to a variable, using `variable @ pattern`. For
524526
example:
525527

branches/try2/src/etc/licenseck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"libstd/sync/mpsc_queue.rs", # BSD
4242
"libstd/sync/spsc_queue.rs", # BSD
4343
"libstd/sync/mpmc_bounded_queue.rs", # BSD
44-
"libextra/sync/mpsc_intrusive.rs", # BSD
44+
"libsync/sync/mpsc_intrusive.rs", # BSD
4545
]
4646

4747
def check_license(name, contents):

branches/try2/src/libextra/dlist.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ use std::iter;
3030

3131
use container::Deque;
3232

33+
use serialize::{Encodable, Decodable, Encoder, Decoder};
34+
3335
/// A doubly-linked list.
3436
pub struct DList<T> {
3537
priv length: uint,
@@ -628,6 +630,31 @@ impl<A: Clone> Clone for DList<A> {
628630
}
629631
}
630632

633+
impl<
634+
S: Encoder,
635+
T: Encodable<S>
636+
> Encodable<S> for DList<T> {
637+
fn encode(&self, s: &mut S) {
638+
s.emit_seq(self.len(), |s| {
639+
for (i, e) in self.iter().enumerate() {
640+
s.emit_seq_elt(i, |s| e.encode(s));
641+
}
642+
})
643+
}
644+
}
645+
646+
impl<D:Decoder,T:Decodable<D>> Decodable<D> for DList<T> {
647+
fn decode(d: &mut D) -> DList<T> {
648+
let mut list = DList::new();
649+
d.read_seq(|d, len| {
650+
for i in range(0u, len) {
651+
list.push_back(d.read_seq_elt(i, |d| Decodable::decode(d)));
652+
}
653+
});
654+
list
655+
}
656+
}
657+
631658
#[cfg(test)]
632659
mod tests {
633660
use container::Deque;

0 commit comments

Comments
 (0)