Skip to content

Commit 83a6a0e

Browse files
committed
---
yaml --- r: 83262 b: refs/heads/try c: ff85389 h: refs/heads/master v: v3
1 parent 8995d63 commit 83a6a0e

Some content is hidden

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

59 files changed

+2330
-1364
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 0e4d1fc8cae42e15e00f71d9f439b01bb25a86ae
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
5-
refs/heads/try: 2d22c0c8e4b32d563abf2aaf5630b089b3564f27
5+
refs/heads/try: ff85389344d6fe4a318559b66b97c24b8fddf1e4
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/doc/tutorial-tasks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ fn fib(n: uint) -> uint {
280280
12586269025
281281
}
282282
283-
let mut delayed_fib = extra::future::spawn (|| fib(50) );
283+
let mut delayed_fib = extra::future::Future::spawn (|| fib(50) );
284284
make_a_sandwich();
285285
println(fmt!("fib(50) = %?", delayed_fib.get()))
286286
~~~
@@ -304,7 +304,7 @@ fn partial_sum(start: uint) -> f64 {
304304
}
305305
306306
fn main() {
307-
let mut futures = vec::from_fn(1000, |ind| do extra::future::spawn { partial_sum(ind) });
307+
let mut futures = vec::from_fn(1000, |ind| do extra::future::Future::spawn { partial_sum(ind) });
308308
309309
let mut final_res = 0f64;
310310
for ft in futures.mut_iter() {

branches/try/mk/rt.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ RUNTIME_CXXS_$(1)_$(2) := \
7171
rt/sync/lock_and_signal.cpp \
7272
rt/sync/rust_thread.cpp \
7373
rt/rust_builtin.cpp \
74-
rt/rust_run_program.cpp \
7574
rt/rust_rng.cpp \
7675
rt/rust_upcall.cpp \
7776
rt/rust_uv.cpp \

branches/try/src/compiletest/compiletest.rs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,64 +91,62 @@ pub fn parse_config(args: ~[~str]) -> config {
9191
let matches =
9292
&match getopts::groups::getopts(args_, groups) {
9393
Ok(m) => m,
94-
Err(f) => fail!(getopts::fail_str(f))
94+
Err(f) => fail!(f.to_err_msg())
9595
};
9696

97-
if getopts::opt_present(matches, "h") || getopts::opt_present(matches, "help") {
97+
if matches.opt_present("h") || matches.opt_present("help") {
9898
let message = fmt!("Usage: %s [OPTIONS] [TESTNAME...]", argv0);
9999
println(getopts::groups::usage(message, groups));
100100
println("");
101101
fail!()
102102
}
103103

104104
fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
105-
Path(getopts::opt_str(m, nm))
105+
Path(m.opt_str(nm).unwrap())
106106
}
107107

108108
config {
109-
compile_lib_path: getopts::opt_str(matches, "compile-lib-path"),
110-
run_lib_path: getopts::opt_str(matches, "run-lib-path"),
109+
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
110+
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
111111
rustc_path: opt_path(matches, "rustc-path"),
112-
clang_path: getopts::opt_maybe_str(matches, "clang-path").map_move(|s| Path(s)),
113-
llvm_bin_path: getopts::opt_maybe_str(matches, "llvm-bin-path").map_move(|s| Path(s)),
112+
clang_path: matches.opt_str("clang-path").map_move(|s| Path(s)),
113+
llvm_bin_path: matches.opt_str("llvm-bin-path").map_move(|s| Path(s)),
114114
src_base: opt_path(matches, "src-base"),
115115
build_base: opt_path(matches, "build-base"),
116116
aux_base: opt_path(matches, "aux-base"),
117-
stage_id: getopts::opt_str(matches, "stage-id"),
118-
mode: str_mode(getopts::opt_str(matches, "mode")),
119-
run_ignored: getopts::opt_present(matches, "ignored"),
117+
stage_id: matches.opt_str("stage-id").unwrap(),
118+
mode: str_mode(matches.opt_str("mode").unwrap()),
119+
run_ignored: matches.opt_present("ignored"),
120120
filter:
121121
if !matches.free.is_empty() {
122122
Some(matches.free[0].clone())
123123
} else {
124124
None
125125
},
126-
logfile: getopts::opt_maybe_str(matches, "logfile").map_move(|s| Path(s)),
127-
save_metrics: getopts::opt_maybe_str(matches, "save-metrics").map_move(|s| Path(s)),
126+
logfile: matches.opt_str("logfile").map_move(|s| Path(s)),
127+
save_metrics: matches.opt_str("save-metrics").map_move(|s| Path(s)),
128128
ratchet_metrics:
129-
getopts::opt_maybe_str(matches, "ratchet-metrics").map_move(|s| Path(s)),
129+
matches.opt_str("ratchet-metrics").map_move(|s| Path(s)),
130130
ratchet_noise_percent:
131-
getopts::opt_maybe_str(matches,
132-
"ratchet-noise-percent").map_move(|s|
133-
from_str::<f64>(s).unwrap()),
134-
runtool: getopts::opt_maybe_str(matches, "runtool"),
135-
rustcflags: getopts::opt_maybe_str(matches, "rustcflags"),
136-
jit: getopts::opt_present(matches, "jit"),
137-
target: opt_str2(getopts::opt_maybe_str(matches, "target")).to_str(),
138-
adb_path: opt_str2(getopts::opt_maybe_str(matches, "adb-path")).to_str(),
131+
matches.opt_str("ratchet-noise-percent").and_then(|s| from_str::<f64>(s)),
132+
runtool: matches.opt_str("runtool"),
133+
rustcflags: matches.opt_str("rustcflags"),
134+
jit: matches.opt_present("jit"),
135+
target: opt_str2(matches.opt_str("target")).to_str(),
136+
adb_path: opt_str2(matches.opt_str("adb-path")).to_str(),
139137
adb_test_dir:
140-
opt_str2(getopts::opt_maybe_str(matches, "adb-test-dir")).to_str(),
138+
opt_str2(matches.opt_str("adb-test-dir")).to_str(),
141139
adb_device_status:
142-
if (opt_str2(getopts::opt_maybe_str(matches, "target")) ==
140+
if (opt_str2(matches.opt_str("target")) ==
143141
~"arm-linux-androideabi") {
144-
if (opt_str2(getopts::opt_maybe_str(matches, "adb-test-dir")) !=
142+
if (opt_str2(matches.opt_str("adb-test-dir")) !=
145143
~"(none)" &&
146-
opt_str2(getopts::opt_maybe_str(matches, "adb-test-dir")) !=
144+
opt_str2(matches.opt_str("adb-test-dir")) !=
147145
~"") { true }
148146
else { false }
149147
} else { false },
150-
test_shard: test::opt_shard(getopts::opt_maybe_str(matches, "test-shard")),
151-
verbose: getopts::opt_present(matches, "verbose")
148+
test_shard: test::opt_shard(matches.opt_str("test-shard")),
149+
verbose: matches.opt_present("verbose")
152150
}
153151
}
154152

branches/try/src/libextra/future.rs

Lines changed: 62 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,11 @@ use std::comm::{PortOne, oneshot};
3232
use std::task;
3333
use std::util::replace;
3434

35-
#[doc = "The future type"]
35+
/// A type encapsulating the result of a computation which may not be complete
3636
pub struct Future<A> {
3737
priv state: FutureState<A>,
3838
}
3939

40-
// n.b. It should be possible to get rid of this.
41-
// Add a test, though -- tjc
42-
// FIXME(#2829) -- futures should not be copyable, because they close
43-
// over ~fn's that have pipes and so forth within!
44-
#[unsafe_destructor]
45-
impl<A> Drop for Future<A> {
46-
fn drop(&mut self) {}
47-
}
48-
4940
enum FutureState<A> {
5041
Pending(~fn() -> A),
5142
Evaluating,
@@ -71,156 +62,148 @@ impl<A> Future<A> {
7162
_ => fail!( "Logic error." ),
7263
}
7364
}
74-
}
7565

76-
impl<A> Future<A> {
7766
pub fn get_ref<'a>(&'a mut self) -> &'a A {
7867
/*!
7968
* Executes the future's closure and then returns a borrowed
8069
* pointer to the result. The borrowed pointer lasts as long as
8170
* the future.
8271
*/
83-
unsafe {
84-
{
85-
match self.state {
86-
Forced(ref mut v) => { return cast::transmute(v); }
87-
Evaluating => fail!("Recursive forcing of future!"),
88-
Pending(_) => {}
89-
}
90-
}
91-
{
92-
let state = replace(&mut self.state, Evaluating);
93-
match state {
72+
match self.state {
73+
Forced(ref v) => return v,
74+
Evaluating => fail!("Recursive forcing of future!"),
75+
Pending(_) => {
76+
match replace(&mut self.state, Evaluating) {
9477
Forced(_) | Evaluating => fail!("Logic error."),
9578
Pending(f) => {
9679
self.state = Forced(f());
97-
cast::transmute(self.get_ref())
80+
self.get_ref()
9881
}
9982
}
10083
}
10184
}
10285
}
103-
}
104-
105-
pub fn from_value<A>(val: A) -> Future<A> {
106-
/*!
107-
* Create a future from a value.
108-
*
109-
* The value is immediately available and calling `get` later will
110-
* not block.
111-
*/
11286

113-
Future {state: Forced(val)}
114-
}
87+
pub fn from_value(val: A) -> Future<A> {
88+
/*!
89+
* Create a future from a value.
90+
*
91+
* The value is immediately available and calling `get` later will
92+
* not block.
93+
*/
11594

116-
pub fn from_port<A:Send>(port: PortOne<A>) -> Future<A> {
117-
/*!
118-
* Create a future from a port
119-
*
120-
* The first time that the value is requested the task will block
121-
* waiting for the result to be received on the port.
122-
*/
95+
Future {state: Forced(val)}
96+
}
12397

124-
let port = Cell::new(port);
125-
do from_fn {
126-
port.take().recv()
98+
pub fn from_fn(f: ~fn() -> A) -> Future<A> {
99+
/*!
100+
* Create a future from a function.
101+
*
102+
* The first time that the value is requested it will be retrieved by
103+
* calling the function. Note that this function is a local
104+
* function. It is not spawned into another task.
105+
*/
106+
107+
Future {state: Pending(f)}
127108
}
128109
}
129110

130-
pub fn from_fn<A>(f: ~fn() -> A) -> Future<A> {
131-
/*!
132-
* Create a future from a function.
133-
*
134-
* The first time that the value is requested it will be retrieved by
135-
* calling the function. Note that this function is a local
136-
* function. It is not spawned into another task.
137-
*/
111+
impl<A:Send> Future<A> {
112+
pub fn from_port(port: PortOne<A>) -> Future<A> {
113+
/*!
114+
* Create a future from a port
115+
*
116+
* The first time that the value is requested the task will block
117+
* waiting for the result to be received on the port.
118+
*/
119+
120+
let port = Cell::new(port);
121+
do Future::from_fn {
122+
port.take().recv()
123+
}
124+
}
138125

139-
Future {state: Pending(f)}
140-
}
126+
pub fn spawn(blk: ~fn() -> A) -> Future<A> {
127+
/*!
128+
* Create a future from a unique closure.
129+
*
130+
* The closure will be run in a new task and its result used as the
131+
* value of the future.
132+
*/
141133

142-
pub fn spawn<A:Send>(blk: ~fn() -> A) -> Future<A> {
143-
/*!
144-
* Create a future from a unique closure.
145-
*
146-
* The closure will be run in a new task and its result used as the
147-
* value of the future.
148-
*/
134+
let (port, chan) = oneshot();
149135

150-
let (port, chan) = oneshot();
136+
do task::spawn_with(chan) |chan| {
137+
chan.send(blk());
138+
}
151139

152-
let chan = Cell::new(chan);
153-
do task::spawn {
154-
let chan = chan.take();
155-
chan.send(blk());
140+
Future::from_port(port)
156141
}
157-
158-
return from_port(port);
159142
}
160143

161144
#[cfg(test)]
162145
mod test {
163-
use future::*;
146+
use future::Future;
164147

165148
use std::cell::Cell;
166149
use std::comm::oneshot;
167150
use std::task;
168151

169152
#[test]
170153
fn test_from_value() {
171-
let mut f = from_value(~"snail");
154+
let mut f = Future::from_value(~"snail");
172155
assert_eq!(f.get(), ~"snail");
173156
}
174157
175158
#[test]
176159
fn test_from_port() {
177160
let (po, ch) = oneshot();
178161
ch.send(~"whale");
179-
let mut f = from_port(po);
162+
let mut f = Future::from_port(po);
180163
assert_eq!(f.get(), ~"whale");
181164
}
182165
183166
#[test]
184167
fn test_from_fn() {
185-
let mut f = from_fn(|| ~"brail");
168+
let mut f = Future::from_fn(|| ~"brail");
186169
assert_eq!(f.get(), ~"brail");
187170
}
188171
189172
#[test]
190173
fn test_interface_get() {
191-
let mut f = from_value(~"fail");
174+
let mut f = Future::from_value(~"fail");
192175
assert_eq!(f.get(), ~"fail");
193176
}
194177
195178
#[test]
196179
fn test_interface_unwrap() {
197-
let f = from_value(~"fail");
180+
let f = Future::from_value(~"fail");
198181
assert_eq!(f.unwrap(), ~"fail");
199182
}
200183
201184
#[test]
202185
fn test_get_ref_method() {
203-
let mut f = from_value(22);
186+
let mut f = Future::from_value(22);
204187
assert_eq!(*f.get_ref(), 22);
205188
}
206189
207190
#[test]
208191
fn test_spawn() {
209-
let mut f = spawn(|| ~"bale");
192+
let mut f = Future::spawn(|| ~"bale");
210193
assert_eq!(f.get(), ~"bale");
211194
}
212195
213196
#[test]
214197
#[should_fail]
215198
fn test_futurefail() {
216-
let mut f = spawn(|| fail!());
199+
let mut f = Future::spawn(|| fail!());
217200
let _x: ~str = f.get();
218201
}
219202
220203
#[test]
221204
fn test_sendable_future() {
222205
let expected = "schlorf";
223-
let f = Cell::new(do spawn { expected });
206+
let f = Cell::new(do Future::spawn { expected });
224207
do task::spawn {
225208
let mut f = f.take();
226209
let actual = f.get();

0 commit comments

Comments
 (0)