Make more moves explicit in libcore

This commit is contained in:
Tim Chevalier 2012-09-10 12:14:14 -07:00
parent 1ff268e2d5
commit e666fe89dd
15 changed files with 77 additions and 77 deletions

View File

@ -50,7 +50,7 @@ pure fn capacity<T>(&&v: @[const T]) -> uint {
pure fn build_sized<A>(size: uint, builder: fn(push: pure fn(+A))) -> @[A] {
let mut vec = @[];
unsafe { unsafe::reserve(vec, size); }
builder(|+x| unsafe { unsafe::push(vec, x) });
builder(|+x| unsafe { unsafe::push(vec, move x) });
return vec;
}
@ -163,10 +163,10 @@ mod unsafe {
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
let fill = (**repr).fill;
if (**repr).alloc > fill {
push_fast(v, initval);
push_fast(v, move initval);
}
else {
push_slow(v, initval);
push_slow(v, move initval);
}
}
// This doesn't bother to make sure we have space.
@ -182,7 +182,7 @@ mod unsafe {
unsafe fn push_slow<T>(&v: @[const T], +initval: T) {
reserve_at_least(v, v.len() + 1u);
push_fast(v, initval);
push_fast(v, move initval);
}
/**

View File

@ -76,7 +76,7 @@ fn Port<T: Send>() -> Port<T> {
impl<T: Send> Port<T> {
fn chan() -> Chan<T> { Chan(self) }
fn send(+v: T) { self.chan().send(v) }
fn send(+v: T) { self.chan().send(move v) }
fn recv() -> T { recv(self) }
fn peek() -> bool { peek(self) }
@ -85,7 +85,7 @@ impl<T: Send> Port<T> {
impl<T: Send> Chan<T> {
fn chan() -> Chan<T> { self }
fn send(+v: T) { send(self, v) }
fn send(+v: T) { send(self, move v) }
fn recv() -> T { recv_chan(self) }
fn peek() -> bool { peek_chan(self) }
@ -103,17 +103,17 @@ struct PortPtr<T:Send> {
do task::unkillable {
// Once the port is detached it's guaranteed not to receive further
// messages
let yield = 0u;
let yield = 0;
let yieldp = ptr::addr_of(yield);
rustrt::rust_port_begin_detach(self.po, yieldp);
if yield != 0u {
if yield != 0 {
// Need to wait for the port to be detached
task::yield();
}
rustrt::rust_port_end_detach(self.po);
// Drain the port so that all the still-enqueued items get dropped
while rustrt::rust_port_size(self.po) > 0u as size_t {
while rustrt::rust_port_size(self.po) > 0 as size_t {
recv_::<T>(self.po);
}
rustrt::del_port(self.po);
@ -179,7 +179,7 @@ fn send<T: Send>(ch: Chan<T>, +data: T) {
let Chan_(p) = ch;
let data_ptr = ptr::addr_of(data) as *();
let res = rustrt::rust_port_id_send(p, data_ptr);
if res != 0u unsafe {
if res != 0 unsafe {
// Data sent successfully
unsafe::forget(data);
}
@ -206,13 +206,13 @@ fn peek_chan<T: Send>(ch: comm::Chan<T>) -> bool {
/// Receive on a raw port pointer
fn recv_<T: Send>(p: *rust_port) -> T {
let yield = 0u;
let yield = 0;
let yieldp = ptr::addr_of(yield);
let mut res;
res = rusti::init::<T>();
rustrt::port_recv(ptr::addr_of(res) as *uint, p, yieldp);
if yield != 0u {
if yield != 0 {
// Data isn't available yet, so res has not been initialized.
task::yield();
} else {
@ -220,21 +220,21 @@ fn recv_<T: Send>(p: *rust_port) -> T {
// this is a good place to yield
task::yield();
}
return res;
move res
}
fn peek_(p: *rust_port) -> bool {
// Yield here before we check to see if someone sent us a message
// FIXME #524, if the compilergenerates yields, we don't need this
// FIXME #524, if the compiler generates yields, we don't need this
task::yield();
rustrt::rust_port_size(p) != 0u as libc::size_t
rustrt::rust_port_size(p) != 0 as libc::size_t
}
/// Receive on one of two ports
fn select2<A: Send, B: Send>(p_a: Port<A>, p_b: Port<B>)
-> Either<A, B> {
let ports = ~[(**p_a).po, (**p_b).po];
let yield = 0u, yieldp = ptr::addr_of(yield);
let yield = 0, yieldp = ptr::addr_of(yield);
let mut resport: *rust_port;
resport = rusti::init::<*rust_port>();
@ -243,7 +243,7 @@ fn select2<A: Send, B: Send>(p_a: Port<A>, p_b: Port<B>)
n_ports as size_t, yieldp);
}
if yield != 0u {
if yield != 0 {
// Wait for data
task::yield();
} else {
@ -380,16 +380,16 @@ fn test_select2_rendezvous() {
let ch_a = Chan(po_a);
let ch_b = Chan(po_b);
for iter::repeat(10u) {
for iter::repeat(10) {
do task::spawn {
for iter::repeat(10u) { task::yield() }
for iter::repeat(10) { task::yield() }
send(ch_a, ~"a");
};
assert select2(po_a, po_b) == either::Left(~"a");
do task::spawn {
for iter::repeat(10u) { task::yield() }
for iter::repeat(10) { task::yield() }
send(ch_b, ~"b");
};
@ -404,7 +404,7 @@ fn test_select2_stress() {
let ch_a = Chan(po_a);
let ch_b = Chan(po_b);
let msgs = 100u;
let msgs = 100;
let times = 4u;
for iter::repeat(times) {
@ -490,7 +490,7 @@ fn test_listen() {
#[test]
#[ignore(cfg(windows))]
fn test_port_detach_fail() {
for iter::repeat(100u) {
for iter::repeat(100) {
do task::spawn_unlinked {
let po = Port();
let ch = po.chan();

View File

@ -80,7 +80,7 @@ impl<T> DListNode<T> {
/// Creates a new dlist node with the given data.
pure fn new_dlist_node<T>(+data: T) -> DListNode<T> {
DListNode(@{data: data, mut linked: false,
DListNode(@{data: move data, mut linked: false,
mut prev: None, mut next: None})
}
@ -92,7 +92,7 @@ pure fn DList<T>() -> DList<T> {
/// Creates a new dlist with a single element
pure fn from_elem<T>(+data: T) -> DList<T> {
let list = DList();
unchecked { list.push(data); }
unchecked { list.push(move data); }
list
}
@ -115,7 +115,7 @@ fn concat<T>(lists: DList<DList<T>>) -> DList<T> {
priv impl<T> DList<T> {
pure fn new_link(-data: T) -> DListLink<T> {
Some(DListNode(@{data: data, mut linked: true,
Some(DListNode(@{data: move data, mut linked: true,
mut prev: None, mut next: None}))
}
pure fn assert_mine(nobe: DListNode<T>) {
@ -442,7 +442,7 @@ impl<T: Copy> DList<T> {
v[index] = data;
}
}
v
move v
}
}

View File

@ -64,18 +64,18 @@ fn DVec<A>() -> DVec<A> {
/// Creates a new dvec with a single element
fn from_elem<A>(+e: A) -> DVec<A> {
DVec_({mut data: ~[mut e]})
DVec_({mut data: ~[mut move e]})
}
/// Creates a new dvec with the contents of a vector
fn from_vec<A>(+v: ~[mut A]) -> DVec<A> {
DVec_({mut data: v})
DVec_({mut data: move v})
}
/// Consumes the vector and returns its contents
fn unwrap<A>(+d: DVec<A>) -> ~[mut A] {
let DVec_({data: v}) <- d;
return v;
move v
}
priv impl<A> DVec<A> {
@ -149,7 +149,7 @@ impl<A> DVec<A> {
let mut v <- v;
let result = vec::pop(v);
self.give_back(v);
result
move result
}
}
@ -161,7 +161,7 @@ impl<A> DVec<A> {
let data_ptr: *() = unsafe::reinterpret_cast(&data);
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
log(error, ~"a");
self.data <- ~[mut t];
self.data <- ~[mut move t];
vec::push_all_move(self.data, data);
log(error, ~"b");
}
@ -170,16 +170,16 @@ impl<A> DVec<A> {
/// Append a single item to the end of the list
fn push(+t: A) {
self.check_not_borrowed();
vec::push(self.data, t);
vec::push(self.data, move t);
}
/// Remove and return the first element
fn shift() -> A {
do self.check_out |v| {
let mut v = vec::from_mut(v);
let mut v = vec::from_mut(move v);
let result = vec::shift(v);
self.give_back(vec::to_mut(v));
result
self.give_back(vec::to_mut(move v));
move result
}
}
@ -196,7 +196,7 @@ impl<A> DVec<A> {
do self.check_out |v| {
let result = op(v);
self.give_back(v);
result
move result
}
}
@ -205,7 +205,7 @@ impl<A> DVec<A> {
do self.check_out |v| {
let result = op(v);
self.give_back(v);
result
move result
}
}
}
@ -231,7 +231,7 @@ impl<A: Copy> DVec<A> {
vec::push(v, ts[i]);
i += 1u;
}
v
move v
}
}
@ -270,7 +270,7 @@ impl<A: Copy> DVec<A> {
do self.check_out |v| {
let w = vec::from_mut(copy v);
self.give_back(v);
w
move w
}
}
}
@ -297,7 +297,7 @@ impl<A: Copy> DVec<A> {
do self.swap |v| {
let mut v <- v;
vec::grow_set(v, idx, initval, val);
v
move v
}
}
@ -317,13 +317,13 @@ impl<A: Copy> DVec<A> {
/// Iterates over the elements in reverse order
#[inline(always)]
fn reach(f: fn(A) -> bool) {
do self.swap |v| { vec::reach(v, f); v }
do self.swap |v| { vec::reach(v, f); move v }
}
/// Iterates over the elements and indices in reverse order
#[inline(always)]
fn reachi(f: fn(uint, A) -> bool) {
do self.swap |v| { vec::reachi(v, f); v }
do self.swap |v| { vec::reachi(v, f); move v }
}
}

View File

@ -39,7 +39,7 @@ fn lefts<T: Copy, U>(eithers: &[Either<T, U>]) -> ~[T] {
_ => { /* fallthrough */ }
}
}
return result;
move result
}
fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
@ -52,7 +52,7 @@ fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
_ => { /* fallthrough */ }
}
}
return result;
move result
}
fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
@ -72,7 +72,7 @@ fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
Right(r) => vec::push(rights, r)
}
}
return {lefts: lefts, rights: rights};
return {lefts: move lefts, rights: move rights};
}
pure fn flip<T: Copy, U: Copy>(eith: &Either<T, U>) -> Either<U, T> {
@ -114,7 +114,7 @@ pure fn unwrap_left<T,U>(+eith: Either<T,U>) -> T {
//! Retrieves the value in the left branch. Fails if the either is Right.
match move eith {
Left(move x) => x, Right(_) => fail ~"either::unwrap_left Right"
Left(move x) => move x, Right(_) => fail ~"either::unwrap_left Right"
}
}
@ -122,7 +122,7 @@ pure fn unwrap_right<T,U>(+eith: Either<T,U>) -> U {
//! Retrieves the value in the right branch. Fails if the either is Left.
match move eith {
Right(move x) => x, Left(_) => fail ~"either::unwrap_right Left"
Right(move x) => move x, Left(_) => fail ~"either::unwrap_right Left"
}
}

View File

@ -201,7 +201,7 @@ fn SipState(key0: u64, key1: u64) -> SipState {
mut ntail : 0u,
};
(&state).reset();
return state;
move state
}
@ -368,7 +368,7 @@ impl &SipState : Streaming {
let r = self.result_bytes();
let mut s = ~"";
for vec::each(r) |b| { s += uint::to_str(b as uint, 16u); }
return s;
move s
}
#[inline(always)]

View File

@ -16,7 +16,7 @@ impl<A> IMPL_T<A>: iter::ExtendedIter<A> {
pure fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) }
pure fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) }
pure fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B {
iter::foldl(self, b0, blk)
iter::foldl(self, move b0, blk)
}
}

View File

@ -7,7 +7,7 @@ type IMPL_T<A> = dvec::DVec<A>;
* Attempts to access this dvec during iteration will fail.
*/
pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
unsafe { self.swap(|v| { vec::each(v, f); v }) }
unsafe { self.swap(|v| { vec::each(v, f); move v }) }
}
pure fn SIZE_HINT<A>(self: IMPL_T<A>) -> Option<uint> {

View File

@ -117,7 +117,7 @@ pure fn foldl<A,B,IA:BaseIter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B {
for self.each |a| {
b = blk(b, a);
}
return b;
move b
}
pure fn to_vec<A:Copy,IA:BaseIter<A>>(self: IA) -> ~[A] {

View File

@ -74,7 +74,7 @@ pure fn map_consume<T, U>(+opt: Option<T>, f: fn(+T) -> U) -> Option<U> {
* As `map`, but consumes the option and gives `f` ownership to avoid
* copying.
*/
if opt.is_some() { Some(f(option::unwrap(opt))) } else { None }
if opt.is_some() { Some(f(option::unwrap(move opt))) } else { None }
}
pure fn chain<T, U>(opt: Option<T>, f: fn(T) -> Option<U>) -> Option<U> {
@ -101,8 +101,8 @@ pure fn or<T>(+opta: Option<T>, +optb: Option<T>) -> Option<T> {
* Returns the leftmost some() value, or none if both are none.
*/
match opta {
Some(_) => opta,
_ => optb
Some(_) => move opta,
_ => move optb
}
}
@ -112,7 +112,7 @@ pure fn while_some<T>(+x: Option<T>, blk: fn(+T) -> Option<T>) {
let mut opt <- x;
while opt.is_some() {
opt = blk(unwrap(opt));
opt = blk(unwrap(move opt));
}
}
@ -137,7 +137,7 @@ pure fn get_default<T: Copy>(opt: Option<T>, def: T) -> T {
pure fn map_default<T, U>(opt: Option<T>, +def: U, f: fn(T) -> U) -> U {
//! Applies a function to the contained value or returns a default
match opt { None => def, Some(t) => f(t) }
match opt { None => move def, Some(t) => f(t) }
}
// This should replace map_default.
@ -145,7 +145,7 @@ pure fn map_default_ref<T, U>(opt: &Option<T>, +def: U,
f: fn(x: &T) -> U) -> U {
//! Applies a function to the contained value or returns a default
match *opt { None => def, Some(ref t) => f(t) }
match *opt { None => move def, Some(ref t) => f(t) }
}
// This should change to by-copy mode; use iter_ref below for by reference
@ -169,7 +169,7 @@ pure fn unwrap<T>(+opt: Option<T>) -> T {
* of option types without copying them.
*/
match move opt {
Some(move x) => x,
Some(move x) => move x,
None => fail ~"option::unwrap none"
}
}
@ -184,7 +184,7 @@ fn swap_unwrap<T>(opt: &mut Option<T>) -> T {
pure fn unwrap_expect<T>(+opt: Option<T>, reason: &str) -> T {
//! As unwrap, but with a specified failure message.
if opt.is_none() { fail reason.to_unique(); }
unwrap(opt)
unwrap(move opt)
}
// Some of these should change to be &Option<T>, some should not. See below.
@ -196,7 +196,7 @@ impl<T> Option<T> {
pure fn chain<U>(f: fn(T) -> Option<U>) -> Option<U> { chain(self, f) }
/// Applies a function to the contained value or returns a default
pure fn map_default<U>(+def: U, f: fn(T) -> U) -> U
{ map_default(self, def, f) }
{ map_default(self, move def, f) }
/// Performs an operation on the contained value or does nothing
pure fn iter(f: fn(T)) { iter(self, f) }
/// Returns true if the option equals `none`
@ -217,7 +217,7 @@ impl<T> &Option<T> {
}
/// Applies a function to the contained value or returns a default
pure fn map_default_ref<U>(+def: U, f: fn(x: &T) -> U) -> U
{ map_default_ref(self, def, f) }
{ map_default_ref(self, move def, f) }
/// Performs an operation on the contained value by reference
pure fn iter_ref(f: fn(x: &T)) { iter_ref(self, f) }
/// Maps a `some` value from one type to another by reference

View File

@ -277,7 +277,7 @@ fn map_vec<T,U:Copy,V:Copy>(
Err(u) => return Err(u)
}
}
return Ok(vs);
return Ok(move vs);
}
fn map_opt<T,U:Copy,V:Copy>(
@ -316,7 +316,7 @@ fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
}
i += 1u;
}
return Ok(vs);
return Ok(move vs);
}
/**
@ -343,7 +343,7 @@ fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
/// Unwraps a result, assuming it is an `ok(T)`
fn unwrap<T, U>(+res: Result<T, U>) -> T {
match move res {
Ok(move t) => t,
Ok(move t) => move t,
Err(_) => fail ~"unwrap called on an err result"
}
}
@ -351,7 +351,7 @@ fn unwrap<T, U>(+res: Result<T, U>) -> T {
/// Unwraps a result, assuming it is an `err(U)`
fn unwrap_err<T, U>(+res: Result<T, U>) -> U {
match move res {
Err(move u) => u,
Err(move u) => move u,
Ok(_) => fail ~"unwrap called on an ok result"
}
}

View File

@ -152,7 +152,7 @@ mod linear {
for uint::range(0, old_capacity) |i| {
let mut bucket = None;
bucket <-> old_buckets[i];
self.insert_opt_bucket(bucket);
self.insert_opt_bucket(move bucket);
}
}
@ -161,7 +161,7 @@ mod linear {
Some(Bucket {hash: move hash,
key: move key,
value: move value}) => {
self.insert_internal(hash, key, value);
self.insert_internal(hash, move key, move value);
}
None => {}
}
@ -213,7 +213,7 @@ mod linear {
}
let hash = k.hash_keyed(self.k0, self.k1) as uint;
self.insert_internal(hash, k, v)
self.insert_internal(hash, move k, move v)
}
fn remove(&mut self, k: &K) -> bool {
@ -247,7 +247,7 @@ mod linear {
while self.buckets[idx].is_some() {
let mut bucket = None;
bucket <-> self.buckets[idx];
self.insert_opt_bucket(bucket);
self.insert_opt_bucket(move bucket);
idx = self.next_bucket(idx, len_buckets);
}
self.size -= 1;

View File

@ -72,7 +72,7 @@ impl<A: ToStr> ~[A]: ToStr {
str::push_str(acc, elt.to_str());
}
str::push_char(acc, ']');
acc
move acc
}
}

View File

@ -55,13 +55,13 @@ impl<A: Copy, B: Copy> (&[A], &[B]): ExtendedTupleOps<A,B> {
impl<A: Copy, B: Copy> (~[A], ~[B]): ExtendedTupleOps<A,B> {
fn zip() -> ~[(A, B)] {
// XXX: Bad copy
// FIXME #2543: Bad copy
let (a, b) = copy self;
vec::zip(a, b)
vec::zip(move a, move b)
}
fn map<C>(f: fn(A, B) -> C) -> ~[C] {
// XXX: Bad copy
// FIXME #2543: Bad copy
let (a, b) = copy self;
vec::map2(a, b, f)
}

View File

@ -9,7 +9,7 @@ use cmp::Eq;
*/
/// The identity function.
pure fn id<T>(+x: T) -> T { x }
pure fn id<T>(+x: T) -> T { move x }
/// Ignores a value.
pure fn ignore<T>(+_x: T) { }
@ -47,9 +47,9 @@ fn swap<T>(x: &mut T, y: &mut T) {
*/
#[inline(always)]
fn replace<T>(dest: &mut T, +src: T) -> T {
let mut tmp = src;
let mut tmp <- src;
swap(dest, &mut tmp);
tmp
move tmp
}
/// A non-copyable dummy type.