Skip to content

Commit 63ef60c

Browse files
committed
---
yaml --- r: 125950 b: refs/heads/try c: 7097283 h: refs/heads/master v: v3
1 parent 02d01e0 commit 63ef60c

File tree

221 files changed

+306
-231
lines changed

Some content is hidden

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

221 files changed

+306
-231
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: f2fa55903e378368ed9173560f03a0ef16e371c2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 9fc8394d3bce22ab483f98842434c84c396212ae
5-
refs/heads/try: 9fa4424b71c1e8a0616e82a34f406a109dffe685
5+
refs/heads/try: 70972832b34cdb3965f95ac465701d9a56151500
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/etc/licenseck.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"libsync/mpsc_intrusive.rs", # BSD
4545
"test/bench/shootout-binarytrees.rs", # BSD
4646
"test/bench/shootout-fannkuch-redux.rs", # BSD
47+
"test/bench/shootout-k-nucleotide.rs", # BSD
4748
"test/bench/shootout-mandelbrot.rs", # BSD
4849
"test/bench/shootout-meteor.rs", # BSD
4950
"test/bench/shootout-pidigits.rs", # BSD

branches/try/src/grammar/raw-string-literal-ambiguity.md

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
Rust's lexical grammar is not context-free. Raw string literals are the source
22
of the problem. Informally, a raw string literal is an `r`, followed by `N`
33
hashes (where N can be zero), a quote, any characters, then a quote followed
4-
by `N` hashes. This grammar describes this as best possible:
4+
by `N` hashes. Critically, once inside the first pair of quotes,
5+
another quote cannot be followed by `N` consecutive hashes. e.g.
6+
`r###""###"###` is invalid.
7+
8+
This grammar describes this as best possible:
59

610
R -> 'r' S
711
S -> '"' B '"'
@@ -22,8 +26,39 @@ accepted as one by the above grammar, using the derivation:
2226
(Where `T : U` means the rule `T` is applied, and `U` is the remainder of the
2327
string.) The difficulty arises from the fact that it is fundamentally
2428
context-sensitive. In particular, the context needed is the number of hashes.
25-
I know of no way to resolve this, but also have not come up with a proof that
26-
it is not context sensitive. Such a proof would probably use the pumping lemma
27-
for context-free languages, but I (cmr) could not come up with a proof after
28-
spending a few hours on it, and decided my time best spent elsewhere. Pull
29-
request welcome!
29+
30+
To prove that Rust's string literals are not context-free, we will use
31+
the fact that context-free languages are closed under intersection with
32+
regular languages, and the
33+
[pumping lemma for context-free languages](https://en.wikipedia.org/wiki/Pumping_lemma_for_context-free_languages).
34+
35+
Consider the regular language `R = r#+""#*"#+`. If Rust's raw string literals are
36+
context-free, then their intersection with `R`, `R'`, should also be context-free.
37+
Therefore, to prove that raw string literals are not context-free,
38+
it is sufficient to prove that `R'` is not context-free.
39+
40+
The language `R'` is `{r#^n""#^m"#^n | m < n}`.
41+
42+
Assume `R'` *is* context-free. Then `R'` has some pumping length `p > 0` for which
43+
the pumping lemma applies. Consider the following string `s` in `R'`:
44+
45+
`r#^p""#^{p-1}"#^p`
46+
47+
e.g. for `p = 2`: `s = r##""#"##`
48+
49+
Then `s = uvwxy` for some choice of `uvwxy` such that `vx` is non-empty,
50+
`|vwx| < p+1`, and `uv^iwx^iy` is in `R'` for all `i >= 0`.
51+
52+
Neither `v` nor `x` can contain a `"` or `r`, as the number of these characters
53+
in any string in `R'` is fixed. So `v` and `x` contain only hashes.
54+
Consequently, of the three sequences of hashes, `v` and `x` combined
55+
can only pump two of them.
56+
If we ever choose the central sequence of hashes, then one of the outer sequences
57+
will not grow when we pump, leading to an imbalance between the outer sequences.
58+
Therefore, we must pump both outer sequences of hashes. However,
59+
there are `p+2` characters between these two sequences of hashes, and `|vwx|` must
60+
be less than `p+1`. Therefore we have a contradiction, and `R'` must not be
61+
context-free.
62+
63+
Since `R'` is not context-free, it follows that the Rust's raw string literals
64+
must not be context-free.

branches/try/src/libcollections/smallintmap.rs

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use core::mem::replace;
2424
use {Collection, Mutable, Map, MutableMap, MutableSeq};
2525
use {vec, slice};
2626
use vec::Vec;
27+
use hash;
28+
use hash::Hash;
2729

2830
/// A map optimized for small integer keys.
2931
///
@@ -58,6 +60,7 @@ use vec::Vec;
5860
/// months.clear();
5961
/// assert!(months.is_empty());
6062
/// ```
63+
#[deriving(PartialEq, Eq)]
6164
pub struct SmallIntMap<T> {
6265
v: Vec<Option<T>>,
6366
}
@@ -151,6 +154,27 @@ impl<V> Default for SmallIntMap<V> {
151154
fn default() -> SmallIntMap<V> { SmallIntMap::new() }
152155
}
153156

157+
impl<V:Clone> Clone for SmallIntMap<V> {
158+
#[inline]
159+
fn clone(&self) -> SmallIntMap<V> {
160+
SmallIntMap { v: self.v.clone() }
161+
}
162+
163+
#[inline]
164+
fn clone_from(&mut self, source: &SmallIntMap<V>) {
165+
self.v.reserve(source.v.len());
166+
for (i, w) in self.v.mut_iter().enumerate() {
167+
*w = source.v[i].clone();
168+
}
169+
}
170+
}
171+
172+
impl <S: hash::Writer, T: Hash<S>> Hash<S> for SmallIntMap<T> {
173+
fn hash(&self, state: &mut S) {
174+
self.v.hash(state)
175+
}
176+
}
177+
154178
impl<V> SmallIntMap<V> {
155179
/// Create an empty SmallIntMap.
156180
///
@@ -362,6 +386,22 @@ impl<V: fmt::Show> fmt::Show for SmallIntMap<V> {
362386
}
363387
}
364388

389+
impl<V> FromIterator<(uint, V)> for SmallIntMap<V> {
390+
fn from_iter<Iter: Iterator<(uint, V)>>(iter: Iter) -> SmallIntMap<V> {
391+
let mut map = SmallIntMap::new();
392+
map.extend(iter);
393+
map
394+
}
395+
}
396+
397+
impl<V> Extendable<(uint, V)> for SmallIntMap<V> {
398+
fn extend<Iter: Iterator<(uint, V)>>(&mut self, mut iter: Iter) {
399+
for (k, v) in iter {
400+
self.insert(k, v);
401+
}
402+
}
403+
}
404+
365405
macro_rules! iterator {
366406
(impl $name:ident -> $elem:ty, $getter:ident) => {
367407
impl<'a, T> Iterator<$elem> for $name<'a, T> {
@@ -446,8 +486,10 @@ pub type Values<'a, T> =
446486
#[cfg(test)]
447487
mod test_map {
448488
use std::prelude::*;
489+
use vec::Vec;
490+
use hash;
449491

450-
use {Map, MutableMap, Mutable};
492+
use {Map, MutableMap, Mutable, MutableSeq};
451493
use super::SmallIntMap;
452494

453495
#[test]
@@ -698,6 +740,63 @@ mod test_map {
698740
assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}");
699741
assert_eq!(format!("{}", empty), "{}".to_string());
700742
}
743+
744+
#[test]
745+
fn test_clone() {
746+
let mut a = SmallIntMap::new();
747+
748+
a.insert(1, 'x');
749+
a.insert(4, 'y');
750+
a.insert(6, 'z');
751+
752+
assert!(a.clone() == a);
753+
}
754+
755+
#[test]
756+
fn test_eq() {
757+
let mut a = SmallIntMap::new();
758+
let mut b = SmallIntMap::new();
759+
760+
assert!(a == b);
761+
assert!(a.insert(0, 5i));
762+
assert!(a != b);
763+
assert!(b.insert(0, 4i));
764+
assert!(a != b);
765+
assert!(a.insert(5, 19));
766+
assert!(a != b);
767+
assert!(!b.insert(0, 5));
768+
assert!(a != b);
769+
assert!(b.insert(5, 19));
770+
assert!(a == b);
771+
}
772+
773+
#[test]
774+
fn test_hash() {
775+
let mut x = SmallIntMap::new();
776+
let mut y = SmallIntMap::new();
777+
778+
assert!(hash::hash(&x) == hash::hash(&y));
779+
x.insert(1, 'a');
780+
x.insert(2, 'b');
781+
x.insert(3, 'c');
782+
783+
y.insert(3, 'c');
784+
y.insert(2, 'b');
785+
y.insert(1, 'a');
786+
787+
assert!(hash::hash(&x) == hash::hash(&y));
788+
}
789+
790+
#[test]
791+
fn test_from_iter() {
792+
let xs: Vec<(uint, char)> = vec![(1u, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')];
793+
794+
let map: SmallIntMap<char> = xs.iter().map(|&x| x).collect();
795+
796+
for &(k, v) in xs.iter() {
797+
assert_eq!(map.find(&k), Some(&v));
798+
}
799+
}
701800
}
702801

703802
#[cfg(test)]

branches/try/src/libcollections/trie.rs

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use core::prelude::*;
1515

1616
use alloc::boxed::Box;
1717
use core::default::Default;
18+
use core::fmt;
19+
use core::fmt::Show;
1820
use core::mem::zeroed;
1921
use core::mem;
2022
use core::uint;
@@ -31,6 +33,7 @@ static SIZE: uint = 1 << SHIFT;
3133
static MASK: uint = SIZE - 1;
3234
static NUM_CHUNKS: uint = uint::BITS / SHIFT;
3335

36+
#[deriving(Clone)]
3437
enum Child<T> {
3538
Internal(Box<TrieNode<T>>),
3639
External(uint, T),
@@ -75,6 +78,7 @@ enum Child<T> {
7578
/// map.clear();
7679
/// assert!(map.is_empty());
7780
/// ```
81+
#[deriving(Clone)]
7882
pub struct TrieMap<T> {
7983
root: TrieNode<T>,
8084
length: uint
@@ -89,6 +93,19 @@ impl<T: PartialEq> PartialEq for TrieMap<T> {
8993

9094
impl<T: Eq> Eq for TrieMap<T> {}
9195

96+
impl<T: Show> Show for TrieMap<T> {
97+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
98+
try!(write!(f, "{{"));
99+
100+
for (i, (k, v)) in self.iter().enumerate() {
101+
if i != 0 { try!(write!(f, ", ")); }
102+
try!(write!(f, "{}: {}", k, *v));
103+
}
104+
105+
write!(f, "}}")
106+
}
107+
}
108+
92109
impl<T> Collection for TrieMap<T> {
93110
/// Return the number of elements in the map.
94111
#[inline]
@@ -500,11 +517,24 @@ impl<S: Writer, T: Hash<S>> Hash<S> for TrieMap<T> {
500517
/// set.clear();
501518
/// assert!(set.is_empty());
502519
/// ```
503-
#[deriving(Hash, PartialEq, Eq)]
520+
#[deriving(Clone, Hash, PartialEq, Eq)]
504521
pub struct TrieSet {
505522
map: TrieMap<()>
506523
}
507524

525+
impl Show for TrieSet {
526+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
527+
try!(write!(f, "{{"));
528+
529+
for (i, x) in self.iter().enumerate() {
530+
if i != 0 { try!(write!(f, ", ")); }
531+
try!(write!(f, "{}", x));
532+
}
533+
534+
write!(f, "}}")
535+
}
536+
}
537+
508538
impl Collection for TrieSet {
509539
/// Return the number of elements in the set.
510540
#[inline]
@@ -673,6 +703,19 @@ struct TrieNode<T> {
673703
children: [Child<T>, ..SIZE]
674704
}
675705

706+
impl<T:Clone> Clone for TrieNode<T> {
707+
#[inline]
708+
fn clone(&self) -> TrieNode<T> {
709+
let ch = &self.children;
710+
TrieNode {
711+
count: self.count,
712+
children: [ch[0].clone(), ch[1].clone(), ch[2].clone(), ch[3].clone(),
713+
ch[4].clone(), ch[5].clone(), ch[6].clone(), ch[7].clone(),
714+
ch[8].clone(), ch[9].clone(), ch[10].clone(), ch[11].clone(),
715+
ch[12].clone(), ch[13].clone(), ch[14].clone(), ch[15].clone()]}
716+
}
717+
}
718+
676719
impl<T> TrieNode<T> {
677720
#[inline]
678721
fn new() -> TrieNode<T> {
@@ -1237,6 +1280,17 @@ mod test_map {
12371280
assert!(m_upper.iter().all(|(_, &x)| x == 0));
12381281
}
12391282

1283+
#[test]
1284+
fn test_clone() {
1285+
let mut a = TrieMap::new();
1286+
1287+
a.insert(1, 'a');
1288+
a.insert(2, 'b');
1289+
a.insert(3, 'c');
1290+
1291+
assert!(a.clone() == a);
1292+
}
1293+
12401294
#[test]
12411295
fn test_eq() {
12421296
let mut a = TrieMap::new();
@@ -1271,6 +1325,20 @@ mod test_map {
12711325

12721326
assert!(hash::hash(&x) == hash::hash(&y));
12731327
}
1328+
1329+
#[test]
1330+
fn test_show() {
1331+
let mut map = TrieMap::new();
1332+
let empty: TrieMap<uint> = TrieMap::new();
1333+
1334+
map.insert(1, 'a');
1335+
map.insert(2, 'b');
1336+
1337+
let map_str = format!("{}", map);
1338+
1339+
assert!(map_str == "{1: a, 2: b}".to_string());
1340+
assert_eq!(format!("{}", empty), "{}".to_string());
1341+
}
12741342
}
12751343

12761344
#[cfg(test)]
@@ -1420,4 +1488,29 @@ mod test_set {
14201488
assert!(set.contains(x));
14211489
}
14221490
}
1491+
1492+
#[test]
1493+
fn test_show() {
1494+
let mut set = TrieSet::new();
1495+
let empty = TrieSet::new();
1496+
1497+
set.insert(1);
1498+
set.insert(2);
1499+
1500+
let set_str = format!("{}", set);
1501+
1502+
assert!(set_str == "{1, 2}".to_string());
1503+
assert_eq!(format!("{}", empty), "{}".to_string());
1504+
}
1505+
1506+
#[test]
1507+
fn test_clone() {
1508+
let mut a = TrieSet::new();
1509+
1510+
a.insert(1);
1511+
a.insert(2);
1512+
a.insert(3);
1513+
1514+
assert!(a.clone() == a);
1515+
}
14231516
}

branches/try/src/librustdoc/html/render.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,12 @@ impl DocFolder for Cache {
845845
}
846846
_ => (None, Some(self.stack.as_slice()))
847847
};
848+
let hidden_field = match item.inner {
849+
clean::StructFieldItem(clean::HiddenStructField) => true,
850+
_ => false
851+
};
848852
match parent {
849-
(parent, Some(path)) if !self.privmod => {
853+
(parent, Some(path)) if !self.privmod && !hidden_field => {
850854
self.search_index.push(IndexItem {
851855
ty: shortty(&item),
852856
name: s.to_string(),

0 commit comments

Comments
 (0)