Skip to content

Commit 67b8ebc

Browse files
committed
---
yaml --- r: 72184 b: refs/heads/dist-snap c: a0c2949 h: refs/heads/master v: v3
1 parent b4d4db0 commit 67b8ebc

File tree

171 files changed

+7216
-7025
lines changed

Some content is hidden

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

171 files changed

+7216
-7025
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: b50030718cf28f2a5a81857a26b57442734fe854
10-
refs/heads/dist-snap: a11c032f36658667bb08382cc409455b0a1d0a61
10+
refs/heads/dist-snap: a0c2949e7c8c67fc7739482de8cee374a253b523
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ do spawn {
16701670
~~~~
16711671

16721672
If you want to see the output of `debug!` statements, you will need to turn on `debug!` logging.
1673-
To enable `debug!` logging, set the RUST_LOG environment variable to `debug` (e.g., with bash, `export RUST_LOG=debug`)
1673+
To enable `debug!` logging, set the RUST_LOG environment variable to the name of your crate, which, for a file named `foo.rs`, will be `foo` (e.g., with bash, `export RUST_LOG=foo`).
16741674

16751675
## For loops
16761676

branches/dist-snap/src/etc/unicode.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,49 @@ def escape_char(c):
112112
return "'\\u%4.4x'" % c
113113
return "'\\U%8.8x'" % c
114114

115+
def ch_prefix(ix):
116+
if ix == 0:
117+
return " "
118+
if ix % 2 == 0:
119+
return ",\n "
120+
else:
121+
return ", "
122+
123+
def emit_bsearch_range_table(f):
124+
f.write("""
125+
pure fn bsearch_range_table(c: char, r: &[(char,char)]) -> bool {
126+
use cmp::{EQ, LT, GT};
127+
use vec::bsearch;
128+
use option::None;
129+
(do bsearch(r) |&(lo,hi)| {
130+
if lo <= c && c <= hi { EQ }
131+
else if hi < c { LT }
132+
else { GT }
133+
}) != None
134+
}\n\n
135+
""");
136+
115137
def emit_property_module(f, mod, tbl):
138+
f.write("pub mod %s {\n" % mod)
139+
keys = tbl.keys()
140+
keys.sort()
141+
emit_bsearch_range_table(f);
142+
for cat in keys:
143+
f.write(" const %s_table : &[(char,char)] = &[\n" % cat)
144+
ix = 0
145+
for pair in tbl[cat]:
146+
f.write(ch_prefix(ix))
147+
f.write("(%s, %s)" % (escape_char(pair[0]), escape_char(pair[1])))
148+
ix += 1
149+
f.write("\n ];\n\n")
150+
151+
f.write(" pub pure fn %s(c: char) -> bool {\n" % cat)
152+
f.write(" bsearch_range_table(c, %s_table)\n" % cat)
153+
f.write(" }\n\n")
154+
f.write("}\n")
155+
156+
157+
def emit_property_module_old(f, mod, tbl):
116158
f.write("mod %s {\n" % mod)
117159
keys = tbl.keys()
118160
keys.sort()
@@ -193,8 +235,9 @@ def emit_decomp_module(f, canon, compat):
193235
rf = open(r, "w")
194236

195237
(canon_decomp, compat_decomp, gencats) = load_unicode_data("UnicodeData.txt")
196-
emit_decomp_module(rf, canon_decomp, compat_decomp)
197238
emit_property_module(rf, "general_category", gencats)
198239

240+
#emit_decomp_module(rf, canon_decomp, compat_decomp)
241+
199242
derived = load_derived_core_properties("DerivedCoreProperties.txt")
200243
emit_property_module(rf, "derived_property", derived)

branches/dist-snap/src/etc/x86.supp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@
583583
{
584584
llvm-optimization-reads-uninitialized-memory-3
585585
Memcheck:Cond
586-
fun:_ZN4test9run_tests4anon13expr_fn_*
586+
fun:_ZN4test9run_tests*
587587
...
588588
}
589589

branches/dist-snap/src/libcore/comm.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ pub mod streamp {
112112

113113
#[allow(non_camel_case_types)]
114114
pub mod server {
115-
priv use core::kinds::Owned;
116-
117115
#[allow(non_camel_case_types)]
118116
pub type Open<T> = ::core::pipes::RecvPacket<super::Open<T>>;
119117
}
@@ -388,8 +386,6 @@ pub mod oneshot {
388386
389387
#[allow(non_camel_case_types)]
390388
pub mod server {
391-
priv use core::kinds::Owned;
392-
393389
#[allow(non_camel_case_types)]
394390
pub type Oneshot<T> =
395391
::core::pipes::RecvPacketBuffered<super::Oneshot<T>,

branches/dist-snap/src/libcore/core.rc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ pub use str::{StrSlice};
9595
pub use container::{Container, Mutable};
9696
pub use vec::{CopyableVector, ImmutableVector};
9797
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
98-
pub use vec::{OwnedVector, OwnedCopyableVector};
98+
pub use vec::{OwnedVector, OwnedCopyableVector, MutableVector};
9999
pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
100100
pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times};
101+
pub use iter::{ExtendedMutableIter};
101102

102103
pub use num::{Num, NumCast};
103104
pub use ptr::Ptr;

branches/dist-snap/src/libcore/hashmap.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use container::{Container, Mutable, Map, Set};
1717
use cmp::{Eq, Equiv};
1818
use hash::Hash;
19-
use to_bytes::IterBytes;
2019
use iter::BaseIter;
2120
use hash::Hash;
2221
use iter;
@@ -72,7 +71,7 @@ fn linear_map_with_capacity_and_keys<K:Eq + Hash,V>(
7271
}
7372
}
7473

75-
priv impl<K:Hash + IterBytes + Eq,V> HashMap<K, V> {
74+
priv impl<K:Hash + Eq,V> HashMap<K, V> {
7675
#[inline(always)]
7776
fn to_bucket(&self, h: uint) -> uint {
7877
// A good hash function with entropy spread over all of the
@@ -111,9 +110,8 @@ priv impl<K:Hash + IterBytes + Eq,V> HashMap<K, V> {
111110
}
112111

113112
#[inline(always)]
114-
fn bucket_for_key_equiv<Q:Hash + IterBytes + Equiv<K>>(&self,
115-
k: &Q)
116-
-> SearchResult {
113+
fn bucket_for_key_equiv<Q:Hash + Equiv<K>>(&self, k: &Q)
114+
-> SearchResult {
117115
let hash = k.hash_keyed(self.k0, self.k1) as uint;
118116
self.bucket_for_key_with_hash_equiv(hash, k)
119117
}
@@ -303,15 +301,15 @@ priv impl<K:Hash + IterBytes + Eq,V> HashMap<K, V> {
303301
}
304302
}
305303
306-
impl<K:Hash + IterBytes + Eq,V> Container for HashMap<K, V> {
304+
impl<K:Hash + Eq,V> Container for HashMap<K, V> {
307305
/// Return the number of elements in the map
308306
fn len(&const self) -> uint { self.size }
309307
310308
/// Return true if the map contains no elements
311309
fn is_empty(&const self) -> bool { self.len() == 0 }
312310
}
313311
314-
impl<K:Hash + IterBytes + Eq,V> Mutable for HashMap<K, V> {
312+
impl<K:Hash + Eq,V> Mutable for HashMap<K, V> {
315313
/// Clear the map, removing all key-value pairs.
316314
fn clear(&mut self) {
317315
for uint::range(0, self.buckets.len()) |idx| {
@@ -321,7 +319,7 @@ impl<K:Hash + IterBytes + Eq,V> Mutable for HashMap<K, V> {
321319
}
322320
}
323321
324-
impl<K:Hash + IterBytes + Eq,V> Map<K, V> for HashMap<K, V> {
322+
impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
325323
/// Return true if the map contains a value for the specified key
326324
fn contains_key(&self, k: &K) -> bool {
327325
match self.bucket_for_key(k) {
@@ -458,7 +456,7 @@ impl<K:Hash + IterBytes + Eq,V> Map<K, V> for HashMap<K, V> {
458456
}
459457
}
460458
461-
pub impl<K: Hash + IterBytes + Eq, V> HashMap<K, V> {
459+
pub impl<K: Hash + Eq, V> HashMap<K, V> {
462460
/// Create an empty HashMap
463461
fn new() -> HashMap<K, V> {
464462
HashMap::with_capacity(INITIAL_CAPACITY)
@@ -669,8 +667,7 @@ pub impl<K: Hash + IterBytes + Eq, V> HashMap<K, V> {
669667

670668
/// Return true if the map contains a value for the specified key,
671669
/// using equivalence
672-
fn contains_key_equiv<Q:Hash + IterBytes + Equiv<K>>(&self, key: &Q)
673-
-> bool {
670+
fn contains_key_equiv<Q:Hash + Equiv<K>>(&self, key: &Q) -> bool {
674671
match self.bucket_for_key_equiv(key) {
675672
FoundEntry(_) => {true}
676673
TableFull | FoundHole(_) => {false}
@@ -680,8 +677,7 @@ pub impl<K: Hash + IterBytes + Eq, V> HashMap<K, V> {
680677
/// Return the value corresponding to the key in the map, using
681678
/// equivalence
682679
#[cfg(stage0)]
683-
fn find_equiv<Q:Hash + IterBytes + Equiv<K>>(&self, k: &Q)
684-
-> Option<&'self V> {
680+
fn find_equiv<Q:Hash + Equiv<K>>(&self, k: &Q) -> Option<&'self V> {
685681
match self.bucket_for_key_equiv(k) {
686682
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
687683
TableFull | FoundHole(_) => None,
@@ -693,17 +689,15 @@ pub impl<K: Hash + IterBytes + Eq, V> HashMap<K, V> {
693689
#[cfg(stage1)]
694690
#[cfg(stage2)]
695691
#[cfg(stage3)]
696-
fn find_equiv<'a, Q:Hash + IterBytes + Equiv<K>>(
697-
&'a self, k: &Q) -> Option<&'a V>
698-
{
692+
fn find_equiv<'a, Q:Hash + Equiv<K>>(&'a self, k: &Q) -> Option<&'a V> {
699693
match self.bucket_for_key_equiv(k) {
700694
FoundEntry(idx) => Some(self.value_for_bucket(idx)),
701695
TableFull | FoundHole(_) => None,
702696
}
703697
}
704698
}
705699

706-
impl<K:Hash + IterBytes + Eq,V:Eq> Eq for HashMap<K, V> {
700+
impl<K:Hash + Eq,V:Eq> Eq for HashMap<K, V> {
707701
fn eq(&self, other: &HashMap<K, V>) -> bool {
708702
if self.len() != other.len() { return false; }
709703

@@ -724,31 +718,31 @@ pub struct HashSet<T> {
724718
priv map: HashMap<T, ()>
725719
}
726720

727-
impl<T:Hash + IterBytes + Eq> BaseIter<T> for HashSet<T> {
721+
impl<T:Hash + Eq> BaseIter<T> for HashSet<T> {
728722
/// Visit all values in order
729723
fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) }
730724
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
731725
}
732726

733-
impl<T:Hash + IterBytes + Eq> Eq for HashSet<T> {
727+
impl<T:Hash + Eq> Eq for HashSet<T> {
734728
fn eq(&self, other: &HashSet<T>) -> bool { self.map == other.map }
735729
fn ne(&self, other: &HashSet<T>) -> bool { self.map != other.map }
736730
}
737731

738-
impl<T:Hash + IterBytes + Eq> Container for HashSet<T> {
732+
impl<T:Hash + Eq> Container for HashSet<T> {
739733
/// Return the number of elements in the set
740734
fn len(&const self) -> uint { self.map.len() }
741735

742736
/// Return true if the set contains no elements
743737
fn is_empty(&const self) -> bool { self.map.is_empty() }
744738
}
745739

746-
impl<T:Hash + IterBytes + Eq> Mutable for HashSet<T> {
740+
impl<T:Hash + Eq> Mutable for HashSet<T> {
747741
/// Clear the set, removing all values.
748742
fn clear(&mut self) { self.map.clear() }
749743
}
750744

751-
impl<T:Hash + IterBytes + Eq> Set<T> for HashSet<T> {
745+
impl<T:Hash + Eq> Set<T> for HashSet<T> {
752746
/// Return true if the set contains a value
753747
fn contains(&self, value: &T) -> bool { self.map.contains_key(value) }
754748

@@ -816,7 +810,7 @@ impl<T:Hash + IterBytes + Eq> Set<T> for HashSet<T> {
816810
}
817811
}
818812

819-
pub impl <T:Hash + IterBytes + Eq> HashSet<T> {
813+
pub impl <T:Hash + Eq> HashSet<T> {
820814
/// Create an empty HashSet
821815
fn new() -> HashSet<T> {
822816
HashSet::with_capacity(INITIAL_CAPACITY)

branches/dist-snap/src/libcore/iter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ pub trait ExtendedIter<A> {
4545
fn flat_map_to_vec<B,IB: BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B];
4646
}
4747

48+
pub trait ExtendedMutableIter<A> {
49+
fn eachi_mut(&mut self, blk: &fn(uint, &mut A) -> bool);
50+
}
51+
4852
pub trait EqIter<A:Eq> {
4953
fn contains(&self, x: &A) -> bool;
5054
fn count(&self, x: &A) -> uint;

branches/dist-snap/src/libcore/iterator.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub trait IteratorUtil<A> {
3939
fn take_while<'r>(self, predicate: &'r fn(&A) -> bool) -> TakeWhileIterator<'r, A, Self>;
4040
fn skip(self, n: uint) -> SkipIterator<Self>;
4141
fn take(self, n: uint) -> TakeIterator<Self>;
42+
fn scan<'r, St, B>(self, initial_state: St, f: &'r fn(&mut St, A) -> Option<B>)
43+
-> ScanIterator<'r, A, B, Self, St>;
4244
fn advance(&mut self, f: &fn(A) -> bool);
4345
}
4446

@@ -93,6 +95,12 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
9395
TakeIterator{iter: self, n: n}
9496
}
9597

98+
#[inline(always)]
99+
fn scan<'r, St, B>(self, initial_state: St, f: &'r fn(&mut St, A) -> Option<B>)
100+
-> ScanIterator<'r, A, B, T, St> {
101+
ScanIterator{iter: self, f: f, state: initial_state}
102+
}
103+
96104
/// A shim implementing the `for` loop iteration protocol for iterator objects
97105
#[inline]
98106
fn advance(&mut self, f: &fn(A) -> bool) {
@@ -306,12 +314,13 @@ impl<A, T: Iterator<A>> Iterator<A> for TakeIterator<T> {
306314

307315
pub struct UnfoldrIterator<'self, A, St> {
308316
priv f: &'self fn(&mut St) -> Option<A>,
309-
priv state: St
317+
state: St
310318
}
311319

312320
pub impl<'self, A, St> UnfoldrIterator<'self, A, St> {
313321
#[inline]
314-
fn new(f: &'self fn(&mut St) -> Option<A>, initial_state: St) -> UnfoldrIterator<'self, A, St> {
322+
fn new(f: &'self fn(&mut St) -> Option<A>, initial_state: St)
323+
-> UnfoldrIterator<'self, A, St> {
315324
UnfoldrIterator {
316325
f: f,
317326
state: initial_state
@@ -326,6 +335,19 @@ impl<'self, A, St> Iterator<A> for UnfoldrIterator<'self, A, St> {
326335
}
327336
}
328337

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
342+
}
343+
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))
348+
}
349+
}
350+
329351
#[cfg(test)]
330352
mod tests {
331353
use super::*;
@@ -406,6 +428,25 @@ mod tests {
406428
assert_eq!(i, ys.len());
407429
}
408430

431+
#[test]
432+
fn test_iterator_scan() {
433+
// test the type inference
434+
fn add(old: &mut int, new: &uint) -> Option<float> {
435+
*old += *new as int;
436+
Some(*old as float)
437+
}
438+
let xs = [0u, 1, 2, 3, 4];
439+
let ys = [0f, 1f, 3f, 6f, 10f];
440+
441+
let mut it = xs.iter().scan(0, add);
442+
let mut i = 0;
443+
for it.advance |x| {
444+
assert_eq!(x, ys[i]);
445+
i += 1;
446+
}
447+
assert_eq!(i, ys.len());
448+
}
449+
409450
#[test]
410451
fn test_unfoldr() {
411452
fn count(st: &mut uint) -> Option<uint> {

0 commit comments

Comments
 (0)