Skip to content

Commit ffd5722

Browse files
committed
---
yaml --- r: 57197 b: refs/heads/try c: e1be9ae h: refs/heads/master i: 57195: 4494c52 v: v3
1 parent 5cdc4ea commit ffd5722

File tree

13 files changed

+146
-60
lines changed

13 files changed

+146
-60
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: c081ffbd1e845687202a975ea2e698b623e5722f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
5-
refs/heads/try: 106fd12423491625b78326a2d2055d7e1d43464f
5+
refs/heads/try: e1be9ae22468e19d66daaebbceeeeaea2e75f903
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libcore/iterator.rs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,19 @@ impl<A, T: Iterator<A>> Iterator<A> for TakeIterator<T> {
312312
}
313313
}
314314

315+
pub struct ScanIterator<'self, A, B, T, St> {
316+
priv iter: T,
317+
priv f: &'self fn(&mut St, A) -> Option<B>,
318+
state: St
319+
}
320+
321+
impl<'self, A, B, T: Iterator<A>, St> Iterator<B> for ScanIterator<'self, A, B, T, St> {
322+
#[inline]
323+
fn next(&mut self) -> Option<B> {
324+
self.iter.next().chain(|a| (self.f)(&mut self.state, a))
325+
}
326+
}
327+
315328
pub struct UnfoldrIterator<'self, A, St> {
316329
priv f: &'self fn(&mut St) -> Option<A>,
317330
state: St
@@ -335,16 +348,25 @@ impl<'self, A, St> Iterator<A> for UnfoldrIterator<'self, A, St> {
335348
}
336349
}
337350

338-
pub struct ScanIterator<'self, A, B, T, St> {
339-
priv iter: T,
340-
priv f: &'self fn(&mut St, A) -> Option<B>,
341-
state: St
351+
/// An infinite iterator starting at `start` and advancing by `step` with each iteration
352+
pub struct Counter<A> {
353+
state: A,
354+
step: A
342355
}
343356

344-
impl<'self, A, B, T: Iterator<A>, St> Iterator<B> for ScanIterator<'self, A, B, T, St> {
345-
#[inline]
346-
fn next(&mut self) -> Option<B> {
347-
self.iter.next().chain(|a| (self.f)(&mut self.state, a))
357+
pub impl<A> Counter<A> {
358+
#[inline(always)]
359+
fn new(start: A, step: A) -> Counter<A> {
360+
Counter{state: start, step: step}
361+
}
362+
}
363+
364+
impl<A: Add<A, A> + Clone> Iterator<A> for Counter<A> {
365+
#[inline(always)]
366+
fn next(&mut self) -> Option<A> {
367+
let result = self.state.clone();
368+
self.state = self.state.add(&self.step); // FIXME: #6050
369+
Some(result)
348370
}
349371
}
350372

@@ -353,6 +375,13 @@ mod tests {
353375
use super::*;
354376
use prelude::*;
355377

378+
#[test]
379+
fn test_counter_to_vec() {
380+
let mut it = Counter::new(0, 5).take(10);
381+
let xs = iter::iter_to_vec(|f| it.advance(f));
382+
assert_eq!(xs, ~[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
383+
}
384+
356385
#[test]
357386
fn test_iterator_chain() {
358387
let xs = [0u, 1, 2, 3, 4, 5];

branches/try/src/libcore/sys.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,42 @@ pub fn log_str<T>(t: &T) -> ~str {
165165
}
166166
}
167167

168-
/** Initiate task failure */
168+
/// Trait for initiating task failure.
169+
pub trait FailWithCause {
170+
/// Fail the current task, taking ownership of `cause`
171+
fn fail_with(cause: Self, file: &'static str, line: uint) -> !;
172+
}
173+
174+
impl FailWithCause for ~str {
175+
fn fail_with(cause: ~str, file: &'static str, line: uint) -> ! {
176+
do str::as_buf(cause) |msg_buf, _msg_len| {
177+
do str::as_buf(file) |file_buf, _file_len| {
178+
unsafe {
179+
let msg_buf = cast::transmute(msg_buf);
180+
let file_buf = cast::transmute(file_buf);
181+
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
182+
}
183+
}
184+
}
185+
}
186+
}
187+
188+
impl FailWithCause for &'static str {
189+
fn fail_with(cause: &'static str, file: &'static str, line: uint) -> ! {
190+
do str::as_buf(cause) |msg_buf, _msg_len| {
191+
do str::as_buf(file) |file_buf, _file_len| {
192+
unsafe {
193+
let msg_buf = cast::transmute(msg_buf);
194+
let file_buf = cast::transmute(file_buf);
195+
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
196+
}
197+
}
198+
}
199+
}
200+
}
201+
202+
// NOTE: remove function after snapshot
203+
#[cfg(stage0)]
169204
pub fn begin_unwind(msg: ~str, file: ~str, line: uint) -> ! {
170205
do str::as_buf(msg) |msg_buf, _msg_len| {
171206
do str::as_buf(file) |file_buf, _file_len| {
@@ -187,6 +222,8 @@ pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
187222
}
188223
}
189224

225+
// NOTE: remove function after snapshot
226+
#[cfg(stage0)]
190227
pub fn fail_assert(msg: &str, file: &str, line: uint) -> ! {
191228
let (msg, file) = (msg.to_owned(), file.to_owned());
192229
begin_unwind(~"assertion failed: " + msg, file, line)
@@ -297,6 +334,14 @@ mod tests {
297334
assert!(new_f(20) == 30);
298335
}
299336
}
337+
338+
#[test]
339+
#[should_fail]
340+
fn fail_static() { FailWithCause::fail_with("cause", file!(), line!()) }
341+
342+
#[test]
343+
#[should_fail]
344+
fn fail_owned() { FailWithCause::fail_with(~"cause", file!(), line!()) }
300345
}
301346

302347
// Local Variables:

branches/try/src/libsyntax/ext/auto_encode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ fn mk_enum_deser_body(
11011101
};
11021102
11031103
let quoted_expr = copy quote_expr!(
1104-
::core::sys::begin_unwind(~"explicit failure", ~"empty", 1);
1104+
::core::sys::FailWithCause::fail_with("explicit failure", "empty", 1);
11051105
).node;
11061106
11071107
let impossible_case = ast::arm {

branches/try/src/libsyntax/ext/build.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,12 @@ pub fn mk_unreachable(cx: @ext_ctxt, span: span) -> @ast::expr {
474474
~[
475475
cx.ident_of(~"core"),
476476
cx.ident_of(~"sys"),
477-
cx.ident_of(~"begin_unwind"),
477+
cx.ident_of(~"FailWithCause"),
478+
cx.ident_of(~"fail_with"),
478479
],
479480
~[
480-
mk_uniq_str(cx, span, ~"internal error: entered unreachable code"),
481-
mk_uniq_str(cx, span, loc.file.name),
481+
mk_base_str(cx, span, ~"internal error: entered unreachable code"),
482+
mk_base_str(cx, span, loc.file.name),
482483
mk_uint(cx, span, loc.line),
483484
]
484485
)

branches/try/src/libsyntax/ext/expand.rs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ pub fn core_macros() -> ~str {
415415
__log(1u32, fmt!( $($arg),+ ))
416416
)
417417
)
418+
418419
macro_rules! warn (
419420
($arg:expr) => (
420421
__log(2u32, fmt!( \"%?\", $arg ))
@@ -423,6 +424,7 @@ pub fn core_macros() -> ~str {
423424
__log(2u32, fmt!( $($arg),+ ))
424425
)
425426
)
427+
426428
macro_rules! info (
427429
($arg:expr) => (
428430
__log(3u32, fmt!( \"%?\", $arg ))
@@ -431,6 +433,7 @@ pub fn core_macros() -> ~str {
431433
__log(3u32, fmt!( $($arg),+ ))
432434
)
433435
)
436+
434437
macro_rules! debug (
435438
($arg:expr) => (
436439
__log(4u32, fmt!( \"%?\", $arg ))
@@ -441,35 +444,48 @@ pub fn core_macros() -> ~str {
441444
)
442445

443446
macro_rules! fail(
444-
($msg: expr) => (
445-
::core::sys::begin_unwind($msg, file!().to_owned(), line!())
446-
);
447447
() => (
448-
fail!(~\"explicit failure\")
448+
fail!(\"explicit failure\")
449+
);
450+
($msg:expr) => (
451+
::core::sys::FailWithCause::fail_with($msg, file!(), line!())
452+
);
453+
($( $arg:expr ),+) => (
454+
::core::sys::FailWithCause::fail_with(fmt!( $($arg),+ ), file!(), line!())
449455
)
450456
)
451457

452458
macro_rules! assert(
453459
($cond:expr) => {
454460
if !$cond {
455-
::core::sys::fail_assert(stringify!($cond), file!(), line!())
461+
::core::sys::FailWithCause::fail_with(
462+
~\"assertion failed: \" + stringify!($cond), file!(), line!())
456463
}
457464
};
458465
($cond:expr, $msg:expr) => {
459466
if !$cond {
460-
::core::sys::fail_assert($msg, file!(), line!())
467+
::core::sys::FailWithCause::fail_with($msg, file!(), line!())
468+
}
469+
};
470+
($cond:expr, $( $arg:expr ),+) => {
471+
if !$cond {
472+
::core::sys::FailWithCause::fail_with(fmt!( $($arg),+ ), file!(), line!())
461473
}
462474
}
463475
)
464476

465477
macro_rules! assert_eq (
466-
($given:expr , $expected:expr) =>
467-
({let given_val = $given;
468-
let expected_val = $expected;
469-
// check both directions of equality....
470-
if !((given_val == expected_val) && (expected_val == given_val)) {
471-
fail!(fmt!(\"expected: %?, given: %?\",expected_val,given_val));
472-
}}))
478+
($given:expr , $expected:expr) => (
479+
{
480+
let given_val = $given;
481+
let expected_val = $expected;
482+
// check both directions of equality....
483+
if !((given_val == expected_val) && (expected_val == given_val)) {
484+
fail!(fmt!(\"left: %? != right: %?\", given_val, expected_val));
485+
}
486+
}
487+
)
488+
)
473489

474490
macro_rules! condition (
475491

branches/try/src/libsyntax/ext/tt/transcribe.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ use core::hashmap::HashMap;
2222
use core::option;
2323
use core::vec;
2424

25-
/* FIXME #2811: figure out how to have a uniquely linked stack, and change to
26-
`~` */
2725
///an unzipping of `token_tree`s
2826
struct TtFrame {
2927
forest: @mut ~[ast::token_tree],

branches/try/src/rt/isaac/randport.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ rand.c: By Bob Jenkins. My random number generator, ISAAC. Public Domain
66
970719: use context, not global variables, for internal state
77
980324: make a portable version
88
010626: Note this is public domain
9-
100725: Mask on use of >32 bits, not on assignment: from Paul Eggert
109
------------------------------------------------------------------------------
1110
*/
1211
#ifndef STANDARD
@@ -28,37 +27,37 @@ rand.c: By Bob Jenkins. My random number generator, ISAAC. Public Domain
2827

2928
void isaac(randctx *ctx)
3029
{
31-
ub4 a,b,x,y,*m,*mm,*m2,*r,*mend;
30+
register ub4 a,b,x,y,*m,*mm,*m2,*r,*mend;
3231
mm=ctx->randmem; r=ctx->randrsl;
33-
a = ctx->randa; b = ctx->randb + (++ctx->randc);
32+
a = ctx->randa; b = (ctx->randb + (++ctx->randc)) & 0xffffffff;
3433
for (m = mm, mend = m2 = m+(RANDSIZ/2); m<mend; )
3534
{
3635
rngstep( a<<13, a, b, mm, m, m2, r, x);
37-
rngstep( (a & 0xffffffff) >>6 , a, b, mm, m, m2, r, x);
36+
rngstep( a>>6 , a, b, mm, m, m2, r, x);
3837
rngstep( a<<2 , a, b, mm, m, m2, r, x);
39-
rngstep( (a & 0xffffffff) >>16, a, b, mm, m, m2, r, x);
38+
rngstep( a>>16, a, b, mm, m, m2, r, x);
4039
}
4140
for (m2 = mm; m2<mend; )
4241
{
4342
rngstep( a<<13, a, b, mm, m, m2, r, x);
44-
rngstep( (a & 0xffffffff) >>6 , a, b, mm, m, m2, r, x);
43+
rngstep( a>>6 , a, b, mm, m, m2, r, x);
4544
rngstep( a<<2 , a, b, mm, m, m2, r, x);
46-
rngstep( (a & 0xffffffff) >>16, a, b, mm, m, m2, r, x);
45+
rngstep( a>>16, a, b, mm, m, m2, r, x);
4746
}
4847
ctx->randb = b; ctx->randa = a;
4948
}
5049

5150

5251
#define mix(a,b,c,d,e,f,g,h) \
5352
{ \
54-
a^=b<<11; d+=a; b+=c; \
55-
b^=(c&0xffffffff)>>2; e+=b; c+=d; \
56-
c^=d<<8; f+=c; d+=e; \
57-
d^=(e&0xffffffff)>>16; g+=d; e+=f; \
58-
e^=f<<10; h+=e; f+=g; \
59-
f^=(g&0xffffffff)>>4; a+=f; g+=h; \
60-
g^=h<<8; b+=g; h+=a; \
61-
h^=(a&0xffffffff)>>9; c+=h; a+=b; \
53+
a^=b<<11; d+=a; b+=c; \
54+
b^=c>>2; e+=b; c+=d; \
55+
c^=d<<8; f+=c; d+=e; \
56+
d^=e>>16; g+=d; e+=f; \
57+
e^=f<<10; h+=e; f+=g; \
58+
f^=g>>4; a+=f; g+=h; \
59+
g^=h<<8; b+=g; h+=a; \
60+
h^=a>>9; c+=h; a+=b; \
6261
}
6362

6463
/* if (flag==TRUE), then use the contents of randrsl[] to initialize mm[]. */
@@ -82,21 +81,17 @@ void randinit(randctx *ctx, word flag)
8281
/* initialize using the contents of r[] as the seed */
8382
for (i=0; i<RANDSIZ; i+=8)
8483
{
85-
a+=r[i ]; b+=r[i+1];
86-
c+=r[i+2]; d+=r[i+3];
87-
e+=r[i+4]; f+=r[i+5];
88-
g+=r[i+6]; h+=r[i+7];
84+
a+=r[i ]; b+=r[i+1]; c+=r[i+2]; d+=r[i+3];
85+
e+=r[i+4]; f+=r[i+5]; g+=r[i+6]; h+=r[i+7];
8986
mix(a,b,c,d,e,f,g,h);
9087
m[i ]=a; m[i+1]=b; m[i+2]=c; m[i+3]=d;
9188
m[i+4]=e; m[i+5]=f; m[i+6]=g; m[i+7]=h;
9289
}
9390
/* do a second pass to make all of the seed affect all of m */
9491
for (i=0; i<RANDSIZ; i+=8)
9592
{
96-
a+=m[i ]; b+=m[i+1];
97-
c+=m[i+2]; d+=m[i+3];
98-
e+=m[i+4]; f+=m[i+5];
99-
g+=m[i+6]; h+=m[i+7];
93+
a+=m[i ]; b+=m[i+1]; c+=m[i+2]; d+=m[i+3];
94+
e+=m[i+4]; f+=m[i+5]; g+=m[i+6]; h+=m[i+7];
10095
mix(a,b,c,d,e,f,g,h);
10196
m[i ]=a; m[i+1]=b; m[i+2]=c; m[i+3]=d;
10297
m[i+4]=e; m[i+5]=f; m[i+6]=g; m[i+7]=h;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// error-pattern:illegal borrow: borrowed value does not live long enough
2+
3+
fn main() {
4+
let v = ~"test";
5+
let sslice = str::slice(v, 0, v.len());
6+
fail!(sslice);
7+
}

branches/try/src/test/compile-fail/die-not-unique.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

branches/try/src/test/compile-fail/fail-expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:mismatched types
11+
// error-pattern:failed to find an implementation of trait core::sys::FailWithCause for int
1212

1313
fn main() { fail!(5); }

branches/try/src/test/compile-fail/fail-type-err.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:expected `~str` but found `~[int]`
11+
// error-pattern:failed to find an implementation of trait core::sys::FailWithCause for ~[int]
1212
fn main() { fail!(~[0i]); }

branches/try/src/test/run-fail/assert-eq-macro-fail.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// error-pattern:expected: 15, given: 14
1+
// error-pattern:left: 14 != right: 15
22

33
#[deriving(Eq)]
44
struct Point { x : int }

0 commit comments

Comments
 (0)