Skip to content

Commit

Permalink
tests/tutorials: Get rid of move.
Browse files Browse the repository at this point in the history
  • Loading branch information
luqmana committed Feb 15, 2013
1 parent e244f10 commit 178882c
Show file tree
Hide file tree
Showing 150 changed files with 409 additions and 411 deletions.
2 changes: 1 addition & 1 deletion doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ else enum extern
false fn for
if impl
let log loop
match mod move mut
match mod mut
priv pub pure
ref return
self static struct super
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial-borrowed-ptr.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ fn example5c(x: @S) -> int {
let y = &v.g;
...
}
x.f = move v; // Replace x.f
x.f = v; // Replace x.f
...
# return 0;
}
Expand Down
20 changes: 10 additions & 10 deletions doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ use pipes::{stream, Port, Chan};
let (port, chan): (Port<int>, Chan<int>) = stream();
do spawn |move chan| {
do spawn || {
let result = some_expensive_computation();
chan.send(result);
}
Expand Down Expand Up @@ -192,7 +192,7 @@ spawns the child task.
# use pipes::{stream, Port, Chan};
# fn some_expensive_computation() -> int { 42 }
# let (port, chan) = stream();
do spawn |move chan| {
do spawn || {
let result = some_expensive_computation();
chan.send(result);
}
Expand Down Expand Up @@ -229,7 +229,7 @@ following program is ill-typed:
# fn some_expensive_computation() -> int { 42 }
let (port, chan) = stream();
do spawn |move chan| {
do spawn {
chan.send(some_expensive_computation());
}
Expand All @@ -248,12 +248,12 @@ Instead we can use a `SharedChan`, a type that allows a single
use pipes::{stream, SharedChan};
let (port, chan) = stream();
let chan = SharedChan(move chan);
let chan = SharedChan(chan);
for uint::range(0, 3) |init_val| {
// Create a new channel handle to distribute to the child task
let child_chan = chan.clone();
do spawn |move child_chan| {
do spawn {
child_chan.send(some_expensive_computation(init_val));
}
}
Expand Down Expand Up @@ -283,10 +283,10 @@ might look like the example below.
// Create a vector of ports, one for each child task
let ports = do vec::from_fn(3) |init_val| {
let (port, chan) = stream();
do spawn |move chan| {
do spawn {
chan.send(some_expensive_computation(init_val));
}
move port
port
};
// Wait on each port, accumulating the results
Expand Down Expand Up @@ -398,13 +398,13 @@ before returning. Hence:
# fn sleep_forever() { loop { task::yield() } }
# do task::try {
let (receiver, sender): (Port<int>, Chan<int>) = stream();
do spawn |move receiver| { // Bidirectionally linked
do spawn { // Bidirectionally linked
// Wait for the supervised child task to exist.
let message = receiver.recv();
// Kill both it and the parent task.
assert message != 42;
}
do try |move sender| { // Unidirectionally linked
do try { // Unidirectionally linked
sender.send(42);
sleep_forever(); // Will get woken up by force
}
Expand Down Expand Up @@ -505,7 +505,7 @@ Here is the code for the parent task:
let (from_child, to_child) = DuplexStream();
do spawn |move to_child| {
do spawn {
stringifier(&to_child);
};
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ Moving it into a mutable slot makes the elements assignable.
let crayons: ~[Crayon] = ~[BananaMania, Beaver, Bittersweet];
// Put the vector into a mutable slot
let mut mutable_crayons = move crayons;
let mut mutable_crayons = crayons;
// Now it's mutable to the bone
mutable_crayons[0] = Apricot;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ pub fn encode_metadata(parms: encode_parms, crate: &crate) -> ~[u8] {
let ecx: @encode_ctxt = @encode_ctxt({
diag: parms.diag,
tcx: parms.tcx,
stats: @mut move stats,
stats: @mut stats,
reachable: parms.reachable,
reexports2: parms.reexports2,
item_symbols: parms.item_symbols,
Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/cci_class_6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub mod kitties {
cat {
meows: in_x,
how_hungry: in_y,
info: move in_info
info: in_info
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/core-vec-append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn collect_dvec(num: uint) -> ~[uint] {
for uint::range(0u, num) |i| {
result.push(i);
}
return dvec::unwrap(move result);
return dvec::unwrap(result);
}

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions src/test/bench/graph500-bfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn bfs(graph: graph, key: node_id) -> bfs_result {
};
}

move marks
marks
}

/**
Expand Down Expand Up @@ -260,7 +260,7 @@ fn pbfs(&&graph: arc::ARC<graph>, key: node_id) -> bfs_result {
i += 1;
let old_len = colors.len();

let color = arc::ARC(move colors);
let color = arc::ARC(colors);

let color_vec = arc::get(&color); // FIXME #3387 requires this temp
colors = do par::mapi(*color_vec) {
Expand Down
10 changes: 5 additions & 5 deletions src/test/bench/msgsend-pipes-shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use io::WriterUtil;
use pipes::{Port, Chan, SharedChan};

macro_rules! move_out (
{ $x:expr } => { unsafe { let y = move *ptr::addr_of(&($x)); move y } }
{ $x:expr } => { unsafe { let y = *ptr::addr_of(&($x)); y } }
)

enum request {
Expand Down Expand Up @@ -58,7 +58,7 @@ fn run(args: &[~str]) {
let (from_child, to_parent) = pipes::stream();
let (from_parent, to_child) = pipes::stream();

let to_child = SharedChan(move to_child);
let to_child = SharedChan(to_child);

let size = uint::from_str(args[1]).get();
let workers = uint::from_str(args[2]).get();
Expand All @@ -68,16 +68,16 @@ fn run(args: &[~str]) {
for uint::range(0, workers) |_i| {
let to_child = to_child.clone();
do task::task().future_result(|+r| {
worker_results.push(move r);
}).spawn |move to_child| {
worker_results.push(r);
}).spawn || {
for uint::range(0, size / workers) |_i| {
//error!("worker %?: sending %? bytes", i, num_bytes);
to_child.send(bytes(num_bytes));
}
//error!("worker %? exiting", i);
};
}
do task::spawn |move from_parent, move to_parent| {
do task::spawn || {
server(from_parent, to_parent);
}

Expand Down
12 changes: 6 additions & 6 deletions src/test/bench/msgsend-pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use io::WriterUtil;
use pipes::{Port, PortSet, Chan};

macro_rules! move_out (
{ $x:expr } => { unsafe { let y = move *ptr::addr_of(&($x)); move y } }
{ $x:expr } => { unsafe { let y = *ptr::addr_of(&($x)); y } }
)

enum request {
Expand Down Expand Up @@ -54,7 +54,7 @@ fn run(args: &[~str]) {
let (from_child, to_parent) = pipes::stream();
let (from_parent_, to_child) = pipes::stream();
let from_parent = PortSet();
from_parent.add(move from_parent_);
from_parent.add(from_parent_);

let size = uint::from_str(args[1]).get();
let workers = uint::from_str(args[2]).get();
Expand All @@ -63,18 +63,18 @@ fn run(args: &[~str]) {
let mut worker_results = ~[];
for uint::range(0, workers) |_i| {
let (from_parent_, to_child) = pipes::stream();
from_parent.add(move from_parent_);
from_parent.add(from_parent_);
do task::task().future_result(|+r| {
worker_results.push(move r);
}).spawn |move to_child| {
worker_results.push(r);
}).spawn || {
for uint::range(0, size / workers) |_i| {
//error!("worker %?: sending %? bytes", i, num_bytes);
to_child.send(bytes(num_bytes));
}
//error!("worker %? exiting", i);
};
}
do task::spawn |move from_parent, move to_parent| {
do task::spawn || {
server(from_parent, to_parent);
}

Expand Down
28 changes: 14 additions & 14 deletions src/test/bench/msgsend-ring-mutex-arcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@ fn recv(p: &pipe) -> uint {

fn init() -> (pipe,pipe) {
let m = arc::MutexARC(~[]);
((&m).clone(), move m)
((&m).clone(), m)
}


fn thread_ring(i: uint,
count: uint,
+num_chan: pipe,
+num_port: pipe) {
let mut num_chan = move Some(move num_chan);
let mut num_port = move Some(move num_port);
let mut num_chan = Some(num_chan);
let mut num_port = Some(num_port);
// Send/Receive lots of messages.
for uint::range(0u, count) |j| {
//error!("task %?, iter %?", i, j);
let mut num_chan2 = option::swap_unwrap(&mut num_chan);
let mut num_port2 = option::swap_unwrap(&mut num_port);
send(&num_chan2, i * j);
num_chan = Some(move num_chan2);
num_chan = Some(num_chan2);
let _n = recv(&num_port2);
//log(error, _n);
num_port = Some(move num_port2);
num_port = Some(num_port2);
};
}

Expand All @@ -77,7 +77,7 @@ fn main() {
let msg_per_task = uint::from_str(args[2]).get();

let (num_chan, num_port) = init();
let mut num_chan = Some(move num_chan);
let mut num_chan = Some(num_chan);

let start = time::precise_time_s();

Expand All @@ -89,22 +89,22 @@ fn main() {
let (new_chan, num_port) = init();
let num_chan2 = ~mut None;
*num_chan2 <-> num_chan;
let num_port = ~mut Some(move num_port);
let new_future = future::spawn(|move num_chan2, move num_port| {
let num_port = ~mut Some(num_port);
let new_future = do future::spawn() || {
let mut num_chan = None;
num_chan <-> *num_chan2;
let mut num_port1 = None;
num_port1 <-> *num_port;
thread_ring(i, msg_per_task,
option::unwrap(move num_chan),
option::unwrap(move num_port1))
});
futures.push(move new_future);
num_chan = Some(move new_chan);
option::unwrap(num_chan),
option::unwrap(num_port1))
};
futures.push(new_future);
num_chan = Some(new_chan);
};

// do our iteration
thread_ring(0, msg_per_task, option::unwrap(move num_chan), move num_port);
thread_ring(0, msg_per_task, option::unwrap(num_chan), num_port);

// synchronize
for futures.each |f| { f.get() };
Expand Down
29 changes: 14 additions & 15 deletions src/test/bench/msgsend-ring-pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ proto! ring (
)

macro_rules! move_out (
($x:expr) => { unsafe { let y = move *ptr::addr_of(&$x); move y } }
($x:expr) => { unsafe { let y = *ptr::addr_of(&$x); y } }
)

fn thread_ring(i: uint,
count: uint,
+num_chan: ring::client::num,
+num_port: ring::server::num) {
let mut num_chan = move Some(move num_chan);
let mut num_port = move Some(move num_port);
let mut num_chan = Some(num_chan);
let mut num_port = Some(num_port);
// Send/Receive lots of messages.
for uint::range(0, count) |j| {
//error!("task %?, iter %?", i, j);
let mut num_chan2 = None;
let mut num_port2 = None;
num_chan2 <-> num_chan;
num_port2 <-> num_port;
num_chan = Some(ring::client::num(option::unwrap(move num_chan2), i * j));
let port = option::unwrap(move num_port2);
match recv(move port) {
num_chan = Some(ring::client::num(option::unwrap(num_chan2), i * j));
let port = option::unwrap(num_port2);
match recv(port) {
ring::num(_n, p) => {
//log(error, _n);
num_port = Some(move_out!(p));
Expand All @@ -70,7 +70,7 @@ fn main() {
let msg_per_task = uint::from_str(args[2]).get();

let (num_chan, num_port) = ring::init();
let mut num_chan = Some(move num_chan);
let mut num_chan = Some(num_chan);

let start = time::precise_time_s();

Expand All @@ -82,23 +82,22 @@ fn main() {
let (new_chan, num_port) = ring::init();
let num_chan2 = ~mut None;
*num_chan2 <-> num_chan;
let num_port = ~mut Some(move num_port);
let new_future = do future::spawn
|move num_chan2, move num_port| {
let num_port = ~mut Some(num_port);
let new_future = do future::spawn || {
let mut num_chan = None;
num_chan <-> *num_chan2;
let mut num_port1 = None;
num_port1 <-> *num_port;
thread_ring(i, msg_per_task,
option::unwrap(move num_chan),
option::unwrap(move num_port1))
option::unwrap(num_chan),
option::unwrap(num_port1))
};
futures.push(move new_future);
num_chan = Some(move new_chan);
futures.push(new_future);
num_chan = Some(new_chan);
};

// do our iteration
thread_ring(0, msg_per_task, option::unwrap(move num_chan), move num_port);
thread_ring(0, msg_per_task, option::unwrap(num_chan), num_port);

// synchronize
for futures.each |f| { f.get() };
Expand Down
Loading

0 comments on commit 178882c

Please sign in to comment.