Skip to content

Commit 71e17aa

Browse files
committed
---
yaml --- r: 80765 b: refs/heads/try c: ec8f884 h: refs/heads/master i: 80763: 89e5dd3 v: v3
1 parent 25b1dae commit 71e17aa

File tree

8 files changed

+68
-59
lines changed

8 files changed

+68
-59
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: 15c9dc7a86d14f4aba3e23f91af65671aa4b5001
5+
refs/heads/try: ec8f88417c2ced5bed685c6bc94d11a7c0840f96
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: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use treemap::TreeMap;
3131
use std::clone::Clone;
3232
use std::comm::{stream, SharedChan, GenericPort, GenericChan};
3333
use std::libc;
34+
use std::either;
3435
use std::io;
3536
use std::result;
3637
use std::task;
@@ -126,8 +127,8 @@ pub type MetricDiff = TreeMap<~str,MetricChange>;
126127
pub fn test_main(args: &[~str], tests: ~[TestDescAndFn]) {
127128
let opts =
128129
match parse_opts(args) {
129-
Ok(o) => o,
130-
Err(msg) => fail!(msg)
130+
either::Left(o) => o,
131+
either::Right(m) => fail!(m)
131132
};
132133
if !run_tests_console(&opts, tests) { fail!("Some tests failed"); }
133134
}
@@ -168,7 +169,7 @@ pub struct TestOpts {
168169
logfile: Option<Path>
169170
}
170171

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

173174
fn optgroups() -> ~[getopts::groups::OptGroup] {
174175
~[groups::optflag("", "ignored", "Run ignored tests"),
@@ -227,7 +228,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
227228
let matches =
228229
match groups::getopts(args_, optgroups()) {
229230
Ok(m) => m,
230-
Err(f) => return Err(getopts::fail_str(f))
231+
Err(f) => return either::Right(getopts::fail_str(f))
231232
};
232233

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

276-
Ok(test_opts)
277+
either::Left(test_opts)
277278
}
278279

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

1158+
use std::either;
11571159
use std::comm::{stream, SharedChan};
11581160
use tempfile;
11591161
use std::os;
@@ -1234,8 +1236,8 @@ mod tests {
12341236
fn first_free_arg_should_be_a_filter() {
12351237
let args = ~[~"progname", ~"filter"];
12361238
let opts = match parse_opts(args) {
1237-
Ok(o) => o,
1238-
_ => fail!("Malformed arg in first_free_arg_should_be_a_filter")
1239+
either::Left(o) => o,
1240+
_ => fail!("Malformed arg in first_free_arg_should_be_a_filter")
12391241
};
12401242
assert!("filter" == opts.filter.clone().unwrap());
12411243
}
@@ -1244,8 +1246,8 @@ mod tests {
12441246
fn parse_ignored_flag() {
12451247
let args = ~[~"progname", ~"filter", ~"--ignored"];
12461248
let opts = match parse_opts(args) {
1247-
Ok(o) => o,
1248-
_ => fail!("Malformed arg in parse_ignored_flag")
1249+
either::Left(o) => o,
1250+
_ => fail!("Malformed arg in parse_ignored_flag")
12491251
};
12501252
assert!((opts.run_ignored));
12511253
}

branches/try/src/libextra/workcache.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ 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};
2223
use std::{io, os, task};
2324

2425
/**
@@ -251,9 +252,9 @@ struct Exec {
251252
discovered_outputs: WorkMap
252253
}
253254
254-
enum Work<'self, T> {
255-
WorkValue(T),
256-
WorkFromTask(&'self Prep<'self>, PortOne<(Exec, T)>),
255+
struct Work<'self, T> {
256+
prep: &'self Prep<'self>,
257+
res: Option<Either<T,PortOne<(Exec,T)>>>
257258
}
258259
259260
fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
@@ -425,15 +426,15 @@ impl<'self> Prep<'self> {
425426
db.prepare(self.fn_name, &self.declared_inputs)
426427
};
427428

428-
match cached {
429+
let res = match cached {
429430
Some((ref disc_in, ref disc_out, ref res))
430431
if self.all_fresh("declared input",&self.declared_inputs) &&
431432
self.all_fresh("discovered input", disc_in) &&
432433
self.all_fresh("discovered output", disc_out) => {
433434
debug!("Cache hit!");
434435
debug!("Trying to decode: %? / %? / %?",
435436
disc_in, disc_out, *res);
436-
Work::from_value(json_decode(*res))
437+
Left(json_decode(*res))
437438
}
438439

439440
_ => {
@@ -452,9 +453,10 @@ impl<'self> Prep<'self> {
452453
let v = blk(&mut exe);
453454
chan.send((exe, v));
454455
}
455-
Work::from_task(self, port)
456+
Right(port)
456457
}
457-
}
458+
};
459+
Work::new(self, res)
458460
}
459461
}
460462

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

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)
468+
pub fn new(p: &'self Prep<'self>, e: Either<T,PortOne<(Exec,T)>>) -> Work<'self, T> {
469+
Work { prep: p, res: Some(e) }
472470
}
473471

474472
pub fn unwrap(self) -> T {
475-
match self {
476-
WorkValue(v) => v,
477-
WorkFromTask(prep, port) => {
473+
let Work { prep, res } = self;
474+
match res {
475+
None => fail!(),
476+
Some(Left(v)) => v,
477+
Some(Right(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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
1313
use option::*;
1414
use os;
15+
use either::*;
1516
use rt;
16-
use rt::logging::{Logger, StdErrLogger, OwnedString};
17+
use rt::logging::{Logger, StdErrLogger};
1718

1819
/// Turns on logging to stdout globally
1920
pub fn console_on() {
@@ -56,12 +57,12 @@ fn newsched_log_str(msg: ~str) {
5657
match optional_task {
5758
Some(local) => {
5859
// Use the available logger
59-
(*local).logger.log(OwnedString(msg));
60+
(*local).logger.log(Left(msg));
6061
}
6162
None => {
6263
// There is no logger anywhere, just write to stderr
6364
let mut logger = StdErrLogger;
64-
logger.log(OwnedString(msg));
65+
logger.log(Left(msg));
6566
}
6667
}
6768
}

branches/try/src/libstd/num/num.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ pub trait Primitive: Clone
279279
+ DeepClone
280280
+ Num
281281
+ NumCast
282+
+ Orderable
282283
+ Bounded
283284
+ Neg<Self>
284285
+ Add<Self,Self>

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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::*;
1011
use libc::{uintptr_t, exit, STDERR_FILENO};
1112
use option::{Some, None, Option};
1213
use rt::util::dumb_println;
@@ -167,32 +168,29 @@ fn update_log_settings(crate_map: *u8, settings: ~str) {
167168
}
168169
}
169170

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

180175
pub struct StdErrLogger;
181176

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

186181
if !should_log_console() {
187182
return;
188183
}
189184

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

198196
// Truncate the string

branches/try/src/libstd/sys.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ 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;
139140
use option::{Some, None};
140141
use rt::in_green_task_context;
141142
use rt::task::Task;
142143
use rt::local::Local;
143-
use rt::logging::{Logger, OwnedString};
144+
use rt::logging::Logger;
144145
use str::Str;
145146

146147
unsafe {
@@ -163,7 +164,7 @@ pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
163164
msg, file, line as int)
164165
};
165166

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

0 commit comments

Comments
 (0)