Skip to content

Commit 8504649

Browse files
committed
---
yaml --- r: 80779 b: refs/heads/try c: 1c26513 h: refs/heads/master i: 80777: a9fbf6f 80775: b53419d v: v3
1 parent 0c2fff2 commit 8504649

File tree

7 files changed

+59
-67
lines changed

7 files changed

+59
-67
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: 4c6bf4872012c010f84dc7fa2cdfe87522533f89
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cbd1eefbd350797b783df119fed7956d7e1c74ad
5-
refs/heads/try: 5d905f1314d243eb1572588f7e7e98768f8bb711
5+
refs/heads/try: 1c26513ef9a58fa3e6703320cc37427aa229bbbd
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libextra/test.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use treemap::TreeMap;
3131
use std::clone::Clone;
3232
use std::comm::{stream, SharedChan, GenericPort, GenericChan};
3333
use std::libc;
34-
use std::either;
3534
use std::io;
3635
use std::result;
3736
use std::task;
@@ -127,8 +126,8 @@ pub type MetricDiff = TreeMap<~str,MetricChange>;
127126
pub fn test_main(args: &[~str], tests: ~[TestDescAndFn]) {
128127
let opts =
129128
match parse_opts(args) {
130-
either::Left(o) => o,
131-
either::Right(m) => fail!(m)
129+
Ok(o) => o,
130+
Err(msg) => fail!(msg)
132131
};
133132
if !run_tests_console(&opts, tests) { fail!("Some tests failed"); }
134133
}
@@ -169,7 +168,7 @@ pub struct TestOpts {
169168
logfile: Option<Path>
170169
}
171170

172-
type OptRes = Either<TestOpts, ~str>;
171+
type OptRes = Result<TestOpts, ~str>;
173172

174173
fn optgroups() -> ~[getopts::groups::OptGroup] {
175174
~[groups::optflag("", "ignored", "Run ignored tests"),
@@ -228,7 +227,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
228227
let matches =
229228
match groups::getopts(args_, optgroups()) {
230229
Ok(m) => m,
231-
Err(f) => return either::Right(getopts::fail_str(f))
230+
Err(f) => return Err(getopts::fail_str(f))
232231
};
233232

234233
if getopts::opt_present(&matches, "h") { usage(args[0], "h"); }
@@ -274,7 +273,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
274273
logfile: logfile
275274
};
276275

277-
either::Left(test_opts)
276+
Ok(test_opts)
278277
}
279278

280279
pub fn opt_shard(maybestr: Option<~str>) -> Option<(uint,uint)> {
@@ -1155,7 +1154,6 @@ mod tests {
11551154
StaticTestName, DynTestName, DynTestFn};
11561155
use test::{TestOpts, run_test};
11571156

1158-
use std::either;
11591157
use std::comm::{stream, SharedChan};
11601158
use tempfile;
11611159
use std::os;
@@ -1236,8 +1234,8 @@ mod tests {
12361234
fn first_free_arg_should_be_a_filter() {
12371235
let args = ~[~"progname", ~"filter"];
12381236
let opts = match parse_opts(args) {
1239-
either::Left(o) => o,
1240-
_ => fail!("Malformed arg in first_free_arg_should_be_a_filter")
1237+
Ok(o) => o,
1238+
_ => fail!("Malformed arg in first_free_arg_should_be_a_filter")
12411239
};
12421240
assert!("filter" == opts.filter.clone().unwrap());
12431241
}
@@ -1246,8 +1244,8 @@ mod tests {
12461244
fn parse_ignored_flag() {
12471245
let args = ~[~"progname", ~"filter", ~"--ignored"];
12481246
let opts = match parse_opts(args) {
1249-
either::Left(o) => o,
1250-
_ => fail!("Malformed arg in parse_ignored_flag")
1247+
Ok(o) => o,
1248+
_ => fail!("Malformed arg in parse_ignored_flag")
12511249
};
12521250
assert!((opts.run_ignored));
12531251
}

branches/try/src/libextra/workcache.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use arc::{Arc,RWArc};
1919
use treemap::TreeMap;
2020
use std::cell::Cell;
2121
use std::comm::{PortOne, oneshot};
22-
use std::either::{Either, Left, Right};
2322
use std::{io, os, task};
2423

2524
/**
@@ -252,9 +251,9 @@ struct Exec {
252251
discovered_outputs: WorkMap
253252
}
254253
255-
struct Work<'self, T> {
256-
prep: &'self Prep<'self>,
257-
res: Option<Either<T,PortOne<(Exec,T)>>>
254+
enum Work<'self, T> {
255+
WorkValue(T),
256+
WorkFromTask(&'self Prep<'self>, PortOne<(Exec, T)>),
258257
}
259258
260259
fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
@@ -426,15 +425,15 @@ impl<'self> Prep<'self> {
426425
db.prepare(self.fn_name, &self.declared_inputs)
427426
};
428427

429-
let res = match cached {
428+
match cached {
430429
Some((ref disc_in, ref disc_out, ref res))
431430
if self.all_fresh("declared input",&self.declared_inputs) &&
432431
self.all_fresh("discovered input", disc_in) &&
433432
self.all_fresh("discovered output", disc_out) => {
434433
debug!("Cache hit!");
435434
debug!("Trying to decode: %? / %? / %?",
436435
disc_in, disc_out, *res);
437-
Left(json_decode(*res))
436+
Work::from_value(json_decode(*res))
438437
}
439438

440439
_ => {
@@ -453,10 +452,9 @@ impl<'self> Prep<'self> {
453452
let v = blk(&mut exe);
454453
chan.send((exe, v));
455454
}
456-
Right(port)
455+
Work::from_task(self, port)
457456
}
458-
};
459-
Work::new(self, res)
457+
}
460458
}
461459
}
462460

@@ -465,16 +463,18 @@ impl<'self, T:Send +
465463
Decodable<json::Decoder>>
466464
Work<'self, T> { // FIXME(#5121)
467465

468-
pub fn new(p: &'self Prep<'self>, e: Either<T,PortOne<(Exec,T)>>) -> Work<'self, T> {
469-
Work { prep: p, res: Some(e) }
466+
pub fn from_value(elt: T) -> Work<'self, T> {
467+
WorkValue(elt)
468+
}
469+
pub fn from_task(prep: &'self Prep<'self>, port: PortOne<(Exec, T)>)
470+
-> Work<'self, T> {
471+
WorkFromTask(prep, port)
470472
}
471473

472474
pub fn unwrap(self) -> T {
473-
let Work { prep, res } = self;
474-
match res {
475-
None => fail!(),
476-
Some(Left(v)) => v,
477-
Some(Right(port)) => {
475+
match self {
476+
WorkValue(v) => v,
477+
WorkFromTask(prep, port) => {
478478
let (exe, v) = port.recv();
479479
let s = json_encode(&v);
480480
do prep.ctxt.db.write |db| {

branches/try/src/libstd/logging.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
1313
use option::*;
1414
use os;
15-
use either::*;
1615
use rt;
17-
use rt::logging::{Logger, StdErrLogger};
16+
use rt::logging::{Logger, StdErrLogger, OwnedString};
1817

1918
/// Turns on logging to stdout globally
2019
pub fn console_on() {
@@ -57,12 +56,12 @@ fn newsched_log_str(msg: ~str) {
5756
match optional_task {
5857
Some(local) => {
5958
// Use the available logger
60-
(*local).logger.log(Left(msg));
59+
(*local).logger.log(OwnedString(msg));
6160
}
6261
None => {
6362
// There is no logger anywhere, just write to stderr
6463
let mut logger = StdErrLogger;
65-
logger.log(Left(msg));
64+
logger.log(OwnedString(msg));
6665
}
6766
}
6867
}

branches/try/src/libstd/rt/logging.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10-
use either::*;
1110
use libc::{uintptr_t, exit, STDERR_FILENO};
1211
use option::{Some, None, Option};
1312
use rt::util::dumb_println;
@@ -168,29 +167,32 @@ fn update_log_settings(crate_map: *u8, settings: ~str) {
168167
}
169168
}
170169

170+
/// Represent a string with `Send` bound.
171+
pub enum SendableString {
172+
OwnedString(~str),
173+
StaticString(&'static str)
174+
}
175+
171176
pub trait Logger {
172-
fn log(&mut self, msg: Either<~str, &'static str>);
177+
fn log(&mut self, msg: SendableString);
173178
}
174179

175180
pub struct StdErrLogger;
176181

177182
impl Logger for StdErrLogger {
178-
fn log(&mut self, msg: Either<~str, &'static str>) {
183+
fn log(&mut self, msg: SendableString) {
179184
use io::{Writer, WriterUtil};
180185

181186
if !should_log_console() {
182187
return;
183188
}
184189

185190
let s: &str = match msg {
186-
Left(ref s) => {
187-
let s: &str = *s;
188-
s
189-
}
190-
Right(ref s) => {
191-
let s: &str = *s;
192-
s
193-
}
191+
OwnedString(ref s) => {
192+
let slc: &str = *s;
193+
slc
194+
},
195+
StaticString(s) => s,
194196
};
195197

196198
// Truncate the string

branches/try/src/libstd/sys.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,11 @@ impl FailWithCause for &'static str {
136136

137137
// FIXME #4427: Temporary until rt::rt_fail_ goes away
138138
pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
139-
use either::Left;
140139
use option::{Some, None};
141140
use rt::in_green_task_context;
142141
use rt::task::Task;
143142
use rt::local::Local;
144-
use rt::logging::Logger;
143+
use rt::logging::{Logger, OwnedString};
145144
use str::Str;
146145

147146
unsafe {
@@ -164,7 +163,7 @@ pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
164163
msg, file, line as int)
165164
};
166165

167-
task.logger.log(Left(msg));
166+
task.logger.log(OwnedString(msg));
168167
}
169168
} else {
170169
rterrln!("failed in non-task context at '%s', %s:%i",

0 commit comments

Comments
 (0)