Skip to content

Commit 9e38b30

Browse files
committed
---
yaml --- r: 67010 b: refs/heads/master c: babf741 h: refs/heads/master v: v3
1 parent 5706ad0 commit 9e38b30

File tree

9 files changed

+160
-42
lines changed

9 files changed

+160
-42
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 7ef9e722b8a499cd0b84ab175a366cbe536a86e4
2+
refs/heads/master: babf7411777a1f0318aafa24f548f2be4a64a521
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/etc/vim/compiler/rustc.vim

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
" Vim compiler file
2+
" Compiler: Rust Compiler
3+
" Maintainer: Chris Morgan <[email protected]>
4+
" Latest Revision: 2013 Jul 12
5+
6+
if exists("current_compiler")
7+
finish
8+
endif
9+
let current_compiler = "rustc"
10+
11+
let s:cpo_save = &cpo
12+
set cpo&vim
13+
14+
if exists(":CompilerSet") != 2
15+
command -nargs=* CompilerSet setlocal <args>
16+
endif
17+
18+
if exists("g:rustc_makeprg_no_percent") && g:rustc_makeprg_no_percent == 1
19+
CompilerSet makeprg=rustc
20+
else
21+
CompilerSet makeprg=rustc\ \%
22+
endif
23+
24+
CompilerSet errorformat=
25+
\%f:%l:%c:\ %t%*[^:]:\ %m,
26+
\%f:%l:%c:\ %*\\d:%*\\d\ %t%*[^:]:\ %m,
27+
\%-G%f:%l\ %s,
28+
\%-G%*[\ ]^,
29+
\%-G%*[\ ]^%*[~],
30+
\%-G%*[\ ]...
31+
32+
let &cpo = s:cpo_save
33+
unlet s:cpo_save

trunk/src/libextra/json.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,9 @@ impl serialize::Decoder for Decoder {
10861086
debug!("read_map()");
10871087
let len = match self.stack.pop() {
10881088
Object(obj) => {
1089+
let mut obj = obj;
10891090
let len = obj.len();
1090-
for obj.consume().advance |(key, value)| {
1091+
do obj.consume |key, value| {
10911092
self.stack.push(value);
10921093
self.stack.push(String(key));
10931094
}

trunk/src/libextra/test.rs

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818

1919
use getopts;
20+
use getopts::groups;
2021
use json::ToJson;
2122
use json;
2223
use serialize::Decodable;
@@ -29,6 +30,7 @@ use treemap::TreeMap;
2930

3031
use std::clone::Clone;
3132
use std::comm::{stream, SharedChan};
33+
use std::libc;
3234
use std::either;
3335
use std::io;
3436
use std::result;
@@ -169,22 +171,64 @@ pub struct TestOpts {
169171

170172
type OptRes = Either<TestOpts, ~str>;
171173

174+
fn optgroups() -> ~[getopts::groups::OptGroup] {
175+
~[groups::optflag("", "ignored", "Run ignored tests"),
176+
groups::optflag("", "test", "Run tests and not benchmarks"),
177+
groups::optflag("", "bench", "Run benchmarks instead of tests"),
178+
groups::optflag("h", "help", "Display this message (longer with --help)"),
179+
groups::optopt("", "save-metrics", "Location to save bench metrics",
180+
"PATH"),
181+
groups::optopt("", "ratchet-metrics",
182+
"Location to load and save metrics from. The metrics \
183+
loaded are cause benchmarks to fail if they run too \
184+
slowly", "PATH"),
185+
groups::optopt("", "ratchet-noise-percent",
186+
"Tests within N% of the recorded metrics will be \
187+
considered as passing", "PERCENTAGE"),
188+
groups::optopt("", "logfile", "Write logs to the specified file instead \
189+
of stdout", "PATH")]
190+
}
191+
192+
fn usage(binary: &str, helpstr: &str) -> ! {
193+
let message = fmt!("Usage: %s [OPTIONS] [FILTER]", binary);
194+
println(groups::usage(message, optgroups()));
195+
if helpstr == "help" {
196+
println("\
197+
The FILTER is matched against the name of all tests to run, and if any tests
198+
have a substring match, only those tests are run.
199+
200+
By default, all tests are run in parallel. This can be altered with the
201+
RUST_THREADS environment variable when running tests (set it to 1).
202+
203+
Test Attributes:
204+
205+
#[test] - Indicates a function is a test to be run. This function
206+
takes no arguments.
207+
#[bench] - Indicates a function is a benchmark to be run. This
208+
function takes one argument (extra::test::BenchHarness).
209+
#[should_fail] - This function (also labeled with #[test]) will only pass if
210+
the code causes a failure (an assertion failure or fail!)
211+
#[ignore] - When applied to a function which is already attributed as a
212+
test, then the test runner will ignore these tests during
213+
normal test runs. Running with --ignored will run these
214+
tests. This may also be written as #[ignore(cfg(...))] to
215+
ignore the test on certain configurations.");
216+
}
217+
unsafe { libc::exit(0) }
218+
}
219+
172220
// Parses command line arguments into test options
173221
pub fn parse_opts(args: &[~str]) -> OptRes {
174222
let args_ = args.tail();
175-
let opts = ~[getopts::optflag("ignored"),
176-
getopts::optflag("test"),
177-
getopts::optflag("bench"),
178-
getopts::optopt("save-metrics"),
179-
getopts::optopt("ratchet-metrics"),
180-
getopts::optopt("ratchet-noise-percent"),
181-
getopts::optopt("logfile")];
182223
let matches =
183-
match getopts::getopts(args_, opts) {
224+
match groups::getopts(args_, optgroups()) {
184225
Ok(m) => m,
185226
Err(f) => return either::Right(getopts::fail_str(f))
186227
};
187228

229+
if getopts::opt_present(&matches, "h") { usage(args[0], "h"); }
230+
if getopts::opt_present(&matches, "help") { usage(args[0], "help"); }
231+
188232
let filter =
189233
if matches.free.len() > 0 {
190234
Some((matches).free[0].clone())

trunk/src/librustc/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Available lint options:
154154
"));
155155

156156
let lint_dict = lint::get_lint_dict();
157-
let mut lint_dict = lint_dict.consume()
157+
let mut lint_dict = lint_dict.consume_iter()
158158
.transform(|(k, v)| (v, k))
159159
.collect::<~[(lint::LintSpec, &'static str)]>();
160160
lint_dict.qsort();

trunk/src/librusti/program.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use std::cast;
12-
use std::util;
1312
use std::hashmap::HashMap;
1413
use std::local_data;
1514

@@ -166,8 +165,7 @@ impl Program {
166165
None => {}
167166
}
168167

169-
let newvars = util::replace(&mut self.newvars, HashMap::new());
170-
for newvars.consume().advance |(name, var)| {
168+
do self.newvars.consume |name, var| {
171169
self.local_vars.insert(name, var);
172170
}
173171

@@ -232,8 +230,7 @@ impl Program {
232230
/// it updates this cache with the new values of each local variable.
233231
pub fn consume_cache(&mut self) {
234232
let map = local_data::pop(tls_key).expect("tls is empty");
235-
let cons_map = util::replace(map, HashMap::new());
236-
for cons_map.consume().advance |(name, value)| {
233+
do map.consume |name, value| {
237234
match self.local_vars.find_mut(&name) {
238235
Some(v) => { v.data = (*value).clone(); }
239236
None => { fail!("unknown variable %s", name) }
@@ -344,8 +341,7 @@ impl Program {
344341
}
345342

346343
// I'm not an @ pointer, so this has to be done outside.
347-
let cons_newvars = util::replace(newvars, HashMap::new());
348-
for cons_newvars.consume().advance |(k, v)| {
344+
do newvars.consume |k, v| {
349345
self.newvars.insert(k, v);
350346
}
351347

trunk/src/libstd/hashmap.rs

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,31 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
438438
self.mangle(k, v, |_k,a| a, |k,v,_a| f(k,v))
439439
}
440440

441+
/// Calls a function on each element of a hash map, destroying the hash
442+
/// map in the process.
443+
pub fn consume(&mut self, f: &fn(K, V)) {
444+
let buckets = replace(&mut self.buckets,
445+
vec::from_fn(INITIAL_CAPACITY, |_| None));
446+
self.size = 0;
447+
448+
for buckets.consume_iter().advance |bucket| {
449+
match bucket {
450+
None => {},
451+
Some(Bucket{key, value, _}) => {
452+
f(key, value)
453+
}
454+
}
455+
}
456+
}
457+
458+
/// Creates a consuming iterator, that is, one that moves each key-value
459+
/// pair out of the map in arbitrary order. The map cannot be used after
460+
/// calling this.
461+
pub fn consume_iter(self) -> HashMapConsumeIterator<K, V> {
462+
// `consume_rev_iter` is more efficient than `consume_iter` for vectors
463+
HashMapConsumeIterator {iter: self.buckets.consume_rev_iter()}
464+
}
465+
441466
/// Retrieves a value for the given key, failing if the key is not
442467
/// present.
443468
pub fn get<'a>(&'a self, k: &K) -> &'a V {
@@ -497,15 +522,6 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
497522
pub fn mut_iter<'a>(&'a mut self) -> HashMapMutIterator<'a, K, V> {
498523
HashMapMutIterator { iter: self.buckets.mut_iter() }
499524
}
500-
501-
/// Creates a consuming iterator, that is, one that moves each key-value
502-
/// pair out of the map in arbitrary order. The map cannot be used after
503-
/// calling this.
504-
pub fn consume(self) -> HashMapConsumeIterator<K, V> {
505-
// `consume_rev_iter` is more efficient than `consume_iter` for vectors
506-
HashMapConsumeIterator {iter: self.buckets.consume_rev_iter()}
507-
}
508-
509525
}
510526

511527
impl<K: Hash + Eq, V: Clone> HashMap<K, V> {
@@ -745,6 +761,19 @@ impl<T:Hash + Eq> HashSet<T> {
745761
self.map.reserve_at_least(n)
746762
}
747763

764+
/// Consumes all of the elements in the set, emptying it out
765+
pub fn consume(&mut self, f: &fn(T)) {
766+
self.map.consume(|k, _| f(k))
767+
}
768+
769+
/// Creates a consuming iterator, that is, one that moves each value out
770+
/// of the set in arbitrary order. The set cannot be used after calling
771+
/// this.
772+
pub fn consume_iter(self) -> HashSetConsumeIterator<T> {
773+
// `consume_rev_iter` is more efficient than `consume_iter` for vectors
774+
HashSetConsumeIterator {iter: self.map.buckets.consume_rev_iter()}
775+
}
776+
748777
/// Returns true if the hash set contains a value equivalent to the
749778
/// given query value.
750779
pub fn contains_equiv<Q:Hash + Equiv<T>>(&self, value: &Q) -> bool {
@@ -757,14 +786,6 @@ impl<T:Hash + Eq> HashSet<T> {
757786
HashSetIterator { iter: self.map.buckets.iter() }
758787
}
759788

760-
/// Creates a consuming iterator, that is, one that moves each value out
761-
/// of the set in arbitrary order. The set cannot be used after calling
762-
/// this.
763-
pub fn consume(self) -> HashSetConsumeIterator<T> {
764-
// `consume_rev_iter` is more efficient than `consume_iter` for vectors
765-
HashSetConsumeIterator {iter: self.map.buckets.consume_rev_iter()}
766-
}
767-
768789
/// Visit the values representing the difference
769790
pub fn difference_iter<'a>(&'a self, other: &'a HashSet<T>)
770791
-> SetAlgebraIter<'a, T> {
@@ -954,6 +975,29 @@ mod test_map {
954975

955976
#[test]
956977
fn test_consume() {
978+
let mut m = HashMap::new();
979+
assert!(m.insert(1, 2));
980+
assert!(m.insert(2, 3));
981+
let mut m2 = HashMap::new();
982+
do m.consume |k, v| {
983+
m2.insert(k, v);
984+
}
985+
assert_eq!(m.len(), 0);
986+
assert_eq!(m2.len(), 2);
987+
assert_eq!(m2.get(&1), &2);
988+
assert_eq!(m2.get(&2), &3);
989+
}
990+
991+
#[test]
992+
fn test_consume_still_usable() {
993+
let mut m = HashMap::new();
994+
assert!(m.insert(1, 2));
995+
do m.consume |_, _| {}
996+
assert!(m.insert(1, 2));
997+
}
998+
999+
#[test]
1000+
fn test_consume_iter() {
9571001
let hm = {
9581002
let mut hm = HashMap::new();
9591003

@@ -963,7 +1007,7 @@ mod test_map {
9631007
hm
9641008
};
9651009

966-
let v = hm.consume().collect::<~[(char, int)]>();
1010+
let v = hm.consume_iter().collect::<~[(char, int)]>();
9671011
assert!([('a', 1), ('b', 2)] == v || [('b', 2), ('a', 1)] == v);
9681012
}
9691013

@@ -1249,7 +1293,7 @@ mod test_set {
12491293
}
12501294

12511295
#[test]
1252-
fn test_consume() {
1296+
fn test_consume_iter() {
12531297
let hs = {
12541298
let mut hs = HashSet::new();
12551299

@@ -1259,7 +1303,7 @@ mod test_set {
12591303
hs
12601304
};
12611305

1262-
let v = hs.consume().collect::<~[char]>();
1306+
let v = hs.consume_iter().collect::<~[char]>();
12631307
assert!(['a', 'b'] == v || ['b', 'a'] == v);
12641308
}
12651309
}

trunk/src/libstd/unstable/weak_task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn run_weak_task_service(port: Port<ServiceMsg>) {
122122
}
123123
}
124124

125-
for shutdown_map.consume().advance |(_, shutdown_chan)| {
125+
do shutdown_map.consume |_, shutdown_chan| {
126126
// Weak task may have already exited
127127
shutdown_chan.send(());
128128
}

trunk/src/test/bench/graph500-bfs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph {
9696
}
9797
}
9898

99-
do graph.consume_iter().transform |v| {
99+
do graph.consume_iter().transform |mut v| {
100100
let mut vec = ~[];
101-
for v.consume().advance |i| {
101+
do v.consume |i| {
102102
vec.push(i);
103103
}
104104
vec
@@ -119,7 +119,7 @@ fn gen_search_keys(graph: &[~[node_id]], n: uint) -> ~[node_id] {
119119
}
120120
}
121121
let mut vec = ~[];
122-
for keys.consume().advance |i| {
122+
do keys.consume |i| {
123123
vec.push(i);
124124
}
125125
return vec;

0 commit comments

Comments
 (0)