Skip to content

Commit da28054

Browse files
committed
---
yaml --- r: 125947 b: refs/heads/try c: 1cfa656 h: refs/heads/master i: 125945: 5558ccb 125943: af607ec v: v3
1 parent 19dea30 commit da28054

File tree

222 files changed

+259
-306
lines changed

Some content is hidden

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

222 files changed

+259
-306
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: 769dae0a00f04bae5ffba6c9f3c0cf2478782be1
5+
refs/heads/try: 1cfa6569f9078090ac317af432adf712407bd4f7
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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
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
4847
"test/bench/shootout-mandelbrot.rs", # BSD
4948
"test/bench/shootout-meteor.rs", # BSD
5049
"test/bench/shootout-pidigits.rs", # BSD
Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
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. 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:
4+
by `N` hashes. This grammar describes this as best possible:
95

106
R -> 'r' S
117
S -> '"' B '"'
@@ -26,39 +22,8 @@ accepted as one by the above grammar, using the derivation:
2622
(Where `T : U` means the rule `T` is applied, and `U` is the remainder of the
2723
string.) The difficulty arises from the fact that it is fundamentally
2824
context-sensitive. In particular, the context needed is the number of hashes.
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.
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!

branches/try/src/libcollections/ringbuf.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use core::cmp;
1919
use core::default::Default;
2020
use core::fmt;
2121
use core::iter::RandomAccessIterator;
22+
use std::hash::{Writer, Hash};
2223

2324
use {Deque, Collection, Mutable, MutableSeq};
2425
use vec::Vec;
@@ -450,6 +451,14 @@ impl<A: PartialEq> PartialEq for RingBuf<A> {
450451
}
451452
}
452453

454+
impl<S: Writer, A: Hash<S>> Hash<S> for RingBuf<A> {
455+
fn hash(&self, state: &mut S) {
456+
for elt in self.iter() {
457+
elt.hash(state);
458+
}
459+
}
460+
}
461+
453462
impl<A> FromIterator<A> for RingBuf<A> {
454463
fn from_iter<T: Iterator<A>>(iterator: T) -> RingBuf<A> {
455464
let (lower, _) = iterator.size_hint();
@@ -485,6 +494,7 @@ mod tests {
485494
use std::fmt::Show;
486495
use std::prelude::*;
487496
use std::gc::{GC, Gc};
497+
use std::hash;
488498
use test::Bencher;
489499
use test;
490500

@@ -912,6 +922,24 @@ mod tests {
912922
assert!(e == RingBuf::new());
913923
}
914924

925+
#[test]
926+
fn test_hash() {
927+
let mut x = RingBuf::new();
928+
let mut y = RingBuf::new();
929+
930+
x.push(1i);
931+
x.push(2);
932+
x.push(3);
933+
934+
y.push(0i);
935+
y.push(1i);
936+
y.pop_front();
937+
y.push(2);
938+
y.push(3);
939+
940+
assert!(hash::hash(&x) == hash::hash(&y));
941+
}
942+
915943
#[test]
916944
fn test_show() {
917945
let ringbuf: RingBuf<int> = range(0i, 10).collect();

branches/try/src/libcollections/smallintmap.rs

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ 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;
2927

3028
/// A map optimized for small integer keys.
3129
///
@@ -60,7 +58,6 @@ use hash::Hash;
6058
/// months.clear();
6159
/// assert!(months.is_empty());
6260
/// ```
63-
#[deriving(PartialEq, Eq)]
6461
pub struct SmallIntMap<T> {
6562
v: Vec<Option<T>>,
6663
}
@@ -154,27 +151,6 @@ impl<V> Default for SmallIntMap<V> {
154151
fn default() -> SmallIntMap<V> { SmallIntMap::new() }
155152
}
156153

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-
178154
impl<V> SmallIntMap<V> {
179155
/// Create an empty SmallIntMap.
180156
///
@@ -386,22 +362,6 @@ impl<V: fmt::Show> fmt::Show for SmallIntMap<V> {
386362
}
387363
}
388364

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-
405365
macro_rules! iterator {
406366
(impl $name:ident -> $elem:ty, $getter:ident) => {
407367
impl<'a, T> Iterator<$elem> for $name<'a, T> {
@@ -486,10 +446,8 @@ pub type Values<'a, T> =
486446
#[cfg(test)]
487447
mod test_map {
488448
use std::prelude::*;
489-
use vec::Vec;
490-
use hash;
491449

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

495453
#[test]
@@ -740,63 +698,6 @@ mod test_map {
740698
assert!(map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}");
741699
assert_eq!(format!("{}", empty), "{}".to_string());
742700
}
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-
}
800701
}
801702

802703
#[cfg(test)]

0 commit comments

Comments
 (0)