Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove uses of last-use analysis #3754

Merged
merged 18 commits into from
Oct 13, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 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 (chan, port): (Chan<int>, Port<int>) = stream();

do spawn {
do spawn |move chan| {
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 (chan, port) = stream();
do spawn {
do spawn |move chan| {
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 (chan, port) = stream();

do spawn {
do spawn |move chan| {
chan.send(some_expensive_computation());
}

Expand All @@ -253,7 +253,7 @@ let chan = SharedChan(move 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 {
do spawn |move child_chan| {
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 (chan, port) = stream();
do spawn {
do spawn |move chan| {
chan.send(some_expensive_computation(init_val));
}
port
move 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 (sender, receiver): (Chan<int>, Port<int>) = stream();
do spawn { // Bidirectionally linked
do spawn |move receiver| { // 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 { // Unidirectionally linked
do try |move sender| { // 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 || {
do spawn |move to_child| {
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 @@ -1827,7 +1827,7 @@ fn map<T, U>(vector: &[T], function: fn(v: &T) -> U) -> ~[U] {
for vec::each(vector) |element| {
accumulator.push(function(element));
}
return accumulator;
return (move accumulator);
}
~~~~

Expand Down
6 changes: 3 additions & 3 deletions src/cargo/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ fn configure(opts: Options) -> Cargo {
~" or package manager to get it to work correctly");
}

c
move c
}

fn for_each_package(c: &Cargo, b: fn(s: @Source, p: &Package)) {
Expand Down Expand Up @@ -1615,10 +1615,10 @@ fn dump_sources(c: &Cargo) {
_ => ()
}

hash.insert(copy k, json::Object(chash));
hash.insert(copy k, json::Object(move chash));
}

json::to_writer(writer, &json::Object(hash))
json::to_writer(writer, &json::Object(move hash))
}
result::Err(e) => {
error(fmt!("could not dump sources: %s", e));
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn make_tests(config: config) -> ~[test::TestDesc] {
tests.push(make_test(config, file))
}
}
return tests;
move tests
}

fn is_test(config: config, testfile: &Path) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ fn run(lib_path: ~str,
writeclose(pipe_in.out, input);
let p = pipes::PortSet();
let ch = p.chan();
do task::spawn_sched(task::SingleThreaded) {
do task::spawn_sched(task::SingleThreaded) |move ch| {
let errput = readclose(pipe_err.in);
ch.send((2, errput));
}
let ch = p.chan();
do task::spawn_sched(task::SingleThreaded) {
do task::spawn_sched(task::SingleThreaded) |move ch| {
let output = readclose(pipe_out.in);
ch.send((1, output));
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ pub mod tests {
pub fn test_transmute() {
unsafe {
let x = @1;
let x: *int = transmute(x);
let x: *int = transmute(move x);
assert *x == 1;
let _x: @int = transmute(x);
let _x: @int = transmute(move x);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub unsafe fn annihilate() {
assert (*box).header.prev == null();

debug!("freeing box: %x", box as uint);
rt_free(transmute(box));
rt_free(transmute(move box));
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/libcore/extfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ pub mod rt {
unsafe { str::unshift_char(&mut s, ' ') };
}
}
return unsafe { pad(cv, s, PadSigned) };
return unsafe { pad(cv, move s, PadSigned) };
}
pub pure fn conv_uint(cv: Conv, u: uint) -> ~str {
let prec = get_int_precision(cv);
Expand All @@ -313,7 +313,7 @@ pub mod rt {
TyBits => uint_to_str_prec(u, 2u, prec),
TyOctal => uint_to_str_prec(u, 8u, prec)
};
return unsafe { pad(cv, rs, PadUnsigned) };
return unsafe { pad(cv, move rs, PadUnsigned) };
}
pub pure fn conv_bool(cv: Conv, b: bool) -> ~str {
let s = if b { ~"true" } else { ~"false" };
Expand All @@ -323,7 +323,7 @@ pub mod rt {
}
pub pure fn conv_char(cv: Conv, c: char) -> ~str {
let mut s = str::from_char(c);
return unsafe { pad(cv, s, PadNozero) };
return unsafe { pad(cv, move s, PadNozero) };
}
pub pure fn conv_str(cv: Conv, s: &str) -> ~str {
// For strings, precision is the maximum characters
Expand All @@ -336,7 +336,7 @@ pub mod rt {
s.to_unique()
}
};
return unsafe { pad(cv, unpadded, PadNozero) };
return unsafe { pad(cv, move unpadded, PadNozero) };
}
pub pure fn conv_float(cv: Conv, f: float) -> ~str {
let (to_str, digits) = match cv.precision {
Expand All @@ -351,7 +351,7 @@ pub mod rt {
s = ~" " + s;
}
}
return unsafe { pad(cv, s, PadFloat) };
return unsafe { pad(cv, move s, PadFloat) };
}
pub pure fn conv_poly<T>(cv: Conv, v: &T) -> ~str {
let s = sys::log_str(v);
Expand Down Expand Up @@ -411,14 +411,14 @@ pub mod rt {
pub fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {
let mut s = move s; // sadtimes
let uwidth : uint = match cv.width {
CountImplied => return s,
CountImplied => return (move s),
CountIs(width) => {
// FIXME: width should probably be uint (see Issue #1996)
width as uint
}
};
let strlen = str::char_len(s);
if uwidth <= strlen { return s; }
if uwidth <= strlen { return (move s); }
let mut padchar = ' ';
let diff = uwidth - strlen;
if have_flag(cv.flags, flag_left_justify) {
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ pub mod test {
#[test]
pub fn test_from_port() {
let (po, ch) = future_pipe::init();
future_pipe::server::completed(ch, ~"whale");
let f = from_port(po);
future_pipe::server::completed(move ch, ~"whale");
let f = from_port(move po);
assert get(&f) == ~"whale";
}

Expand Down Expand Up @@ -238,7 +238,7 @@ pub mod test {
pub fn test_sendable_future() {
let expected = ~"schlorf";
let f = do spawn |copy expected| { copy expected };
do task::spawn {
do task::spawn |move f, move expected| {
let actual = get(&f);
assert actual == expected;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ pub fn test_siphash() {
for vec::each(*r) |b| {
s += uint::to_str(*b as uint, 16u);
}
return s;
move s
}

while t < 64 {
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ pub fn BytesWriter() -> BytesWriter {
pub fn with_bytes_writer(f: fn(Writer)) -> ~[u8] {
let wr = @BytesWriter();
f(wr as Writer);
wr.buf.check_out(|buf| buf)
wr.buf.check_out(|buf| move buf)
}

pub fn with_str_writer(f: fn(Writer)) -> ~str {
Expand All @@ -747,7 +747,7 @@ pub fn with_str_writer(f: fn(Writer)) -> ~str {
v.push(0);
assert str::is_utf8(v);

unsafe { move ::cast::transmute(v) }
unsafe { move ::cast::transmute(move v) }
}

// Utility functions
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ struct Data<T> {
pub type Mut<T> = Data<T>;

pub fn Mut<T>(t: T) -> Mut<T> {
Data {value: t, mode: ReadOnly}
Data {value: move t, mode: ReadOnly}
}

pub fn unwrap<T>(m: Mut<T>) -> T {
// Borrowck should prevent us from calling unwrap while the value
// is in use, as that would be a move from a borrowed value.
assert (m.mode as uint) == (ReadOnly as uint);
let Data {value: move value, mode: _} = move m;
return value;
move value
}

impl<T> Data<T> {
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub pure fn chain<T, U>(opt: Option<T>,
*/

match move opt {
Some(move t) => f(t),
Some(move t) => f(move t),
None => None
}
}
Expand Down Expand Up @@ -294,7 +294,7 @@ impl<T: Copy> Option<T> {
*
* Fails if the value equals `none`
*/
pure fn expect(reason: ~str) -> T { expect(&self, reason) }
pure fn expect(reason: ~str) -> T { expect(&self, move reason) }
/// Applies a function zero or more times until the result is none.
pure fn while_some(blk: fn(v: T) -> Option<T>) { while_some(self, blk) }
}
Expand Down Expand Up @@ -324,8 +324,8 @@ impl<T: Eq> Option<T> : Eq {
fn test_unwrap_ptr() {
let x = ~0;
let addr_x = ptr::addr_of(&(*x));
let opt = Some(x);
let y = unwrap(opt);
let opt = Some(move x);
let y = unwrap(move opt);
let addr_y = ptr::addr_of(&(*y));
assert addr_x == addr_y;
}
Expand Down Expand Up @@ -356,8 +356,8 @@ fn test_unwrap_resource() {
let i = @mut 0;
{
let x = R(i);
let opt = Some(x);
let _y = unwrap(opt);
let opt = Some(move x);
let _y = unwrap(move opt);
}
assert *i == 1;
}
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ unsafe fn load_argc_and_argv(argc: c_int, argv: **c_char) -> ~[~str] {
for uint::range(0, argc as uint) |i| {
vec::push(&mut args, str::raw::from_c_str(*argv.offset(i)));
}
return args;
move args
}

/**
Expand Down Expand Up @@ -903,7 +903,7 @@ mod tests {
let rng: rand::Rng = rand::Rng();
let n = ~"TEST" + rng.gen_str(10u);
assert getenv(n).is_none();
n
move n
}

#[test]
Expand Down Expand Up @@ -937,7 +937,7 @@ mod tests {
let n = make_rand_name();
setenv(n, s);
log(debug, s);
assert getenv(n) == option::Some(s);
assert getenv(n) == option::Some(move s);
}

#[test]
Expand All @@ -963,7 +963,7 @@ mod tests {
// MingW seems to set some funky environment variables like
// "=C:=C:\MinGW\msys\1.0\bin" and "!::=::\" that are returned
// from env() but not visible from getenv().
assert v2.is_none() || v2 == option::Some(v);
assert v2.is_none() || v2 == option::Some(move v);
}
}

Expand All @@ -976,7 +976,7 @@ mod tests {
assert !vec::contains(e, &(copy n, ~"VALUE"));

e = env();
assert vec::contains(e, &(n, ~"VALUE"));
assert vec::contains(e, &(move n, ~"VALUE"));
}

#[test]
Expand Down
Loading