diff --git a/src/libcore/future.rs b/src/libcore/future.rs index b1d73dd9f5a3..a903a828326a 100644 --- a/src/libcore/future.rs +++ b/src/libcore/future.rs @@ -75,7 +75,7 @@ fn from_value(+val: A) -> Future { * not block. */ - Future {state: Forced(~val)} + Future {state: Forced(~(move val))} } fn from_port(+port: future_pipe::client::waiting) -> Future { @@ -86,13 +86,13 @@ fn from_port(+port: future_pipe::client::waiting) -> Future { * waiting for the result to be received on the port. */ - let port = ~mut Some(port); + let port = ~mut Some(move port); do from_fn |move port| { let mut port_ = None; port_ <-> *port; let port = option::unwrap(port_); - match recv(port) { - future_pipe::completed(move data) => data + match recv(move port) { + future_pipe::completed(move data) => move data } } } @@ -106,7 +106,7 @@ fn from_fn(+f: ~fn() -> A) -> Future { * function. It is not spawned into another task. */ - Future {state: Pending(f)} + Future {state: Pending(move f)} } fn spawn(+blk: fn~() -> A) -> Future { @@ -117,8 +117,8 @@ fn spawn(+blk: fn~() -> A) -> Future { * value of the future. */ - from_port(pipes::spawn_service_recv(future_pipe::init, |ch| { - future_pipe::server::completed(ch, blk()); + from_port(pipes::spawn_service_recv(future_pipe::init, |move blk, ch| { + future_pipe::server::completed(move ch, blk()); })) } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 27baf3d931e9..75716e642df4 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -113,7 +113,7 @@ export send_packet, recv_packet, buffer_header; const SPIN_COUNT: uint = 0; macro_rules! move_it ( - { $x:expr } => { unsafe { let y <- *ptr::addr_of($x); y } } + { $x:expr } => { unsafe { let y <- *ptr::addr_of($x); move y } } ) #[doc(hidden)] @@ -262,8 +262,7 @@ fn unibuffer() -> ~Buffer> { unsafe { b.data.header.buffer = reinterpret_cast(&b); } - - b + move b } #[doc(hidden)] @@ -411,7 +410,7 @@ fn send(+p: SendPacketBuffered, let p = unsafe { &*p_ }; assert ptr::addr_of(p.header) == header; assert p.payload.is_none(); - p.payload <- Some(payload); + p.payload <- Some(move payload); let old_state = swap_state_rel(&mut p.header.state, Full); match old_state { Empty => { @@ -449,7 +448,7 @@ Fails if the sender closes the connection. */ fn recv(+p: RecvPacketBuffered) -> T { - option::unwrap_expect(try_recv(p), "connection closed") + option::unwrap_expect(try_recv(move p), "connection closed") } /** Attempts to receive a message from a pipe. @@ -713,8 +712,8 @@ fn select2( let i = wait_many([a.header(), b.header()]/_); match i { - 0 => Left((try_recv(a), b)), - 1 => Right((a, try_recv(b))), + 0 => Left((try_recv(move a), move b)), + 1 => Right((move a, try_recv(move b))), _ => fail ~"select2 return an invalid packet" } } @@ -750,10 +749,10 @@ fn select(+endpoints: ~[RecvPacketBuffered]) -> (uint, Option, ~[RecvPacketBuffered]) { let ready = wait_many(endpoints.map(|p| p.header())); - let mut remaining = endpoints; + let mut remaining <- endpoints; let port = vec::swap_remove(remaining, ready); - let result = try_recv(port); - (ready, result, remaining) + let result = try_recv(move port); + (ready, move result, move remaining) } /** The sending end of a pipe. It can be used to send exactly one @@ -943,14 +942,14 @@ fn spawn_service( // This is some nasty gymnastics required to safely move the pipe // into a new task. - let server = ~mut Some(server); - do task::spawn |move service| { + let server = ~mut Some(move server); + do task::spawn |move service, move server| { let mut server_ = None; server_ <-> *server; service(option::unwrap(server_)) } - client + move client } /** Like `spawn_service_recv`, but for protocols that start in the @@ -967,14 +966,14 @@ fn spawn_service_recv( // This is some nasty gymnastics required to safely move the pipe // into a new task. - let server = ~mut Some(server); - do task::spawn |move service| { + let server = ~mut Some(move server); + do task::spawn |move service, move server| { let mut server_ = None; server_ <-> *server; service(option::unwrap(server_)) } - client + move client } // Streams - Make pipes a little easier in general. @@ -1039,7 +1038,7 @@ These allow sending or receiving an unlimited number of messages. fn stream() -> (Chan, Port) { let (c, s) = streamp::init(); - (Chan_({ mut endp: Some(c) }), Port_({ mut endp: Some(s) })) + (Chan_({ mut endp: Some(move c) }), Port_({ mut endp: Some(move s) })) } impl Chan: Channel { @@ -1047,15 +1046,15 @@ impl Chan: Channel { let mut endp = None; endp <-> self.endp; self.endp = Some( - streamp::client::data(unwrap(endp), x)) + streamp::client::data(unwrap(endp), move x)) } fn try_send(+x: T) -> bool { let mut endp = None; endp <-> self.endp; - match move streamp::client::try_data(unwrap(endp), x) { + match move streamp::client::try_data(unwrap(endp), move x) { Some(move next) => { - self.endp = Some(next); + self.endp = Some(move next); true } None => false @@ -1068,8 +1067,8 @@ impl Port: Recv { let mut endp = None; endp <-> self.endp; let streamp::data(x, endp) = pipes::recv(unwrap(endp)); - self.endp = Some(endp); - x + self.endp = Some(move endp); + move x } fn try_recv() -> Option { @@ -1077,8 +1076,8 @@ impl Port: Recv { endp <-> self.endp; match move pipes::try_recv(unwrap(endp)) { Some(streamp::data(move x, move endp)) => { - self.endp = Some(endp); - Some(x) + self.endp = Some(move endp); + Some(move x) } None => None } @@ -1101,13 +1100,13 @@ struct PortSet : Recv { mut ports: ~[pipes::Port], fn add(+port: pipes::Port) { - vec::push(self.ports, port) + vec::push(self.ports, move port) } fn chan() -> Chan { let (ch, po) = stream(); - self.add(po); - ch + self.add(move po); + move ch } fn try_recv() -> Option { @@ -1120,7 +1119,7 @@ struct PortSet : Recv { let i = wait_many(ports); match move ports[i].try_recv() { Some(move m) => { - result = Some(m); + result = Some(move m); } None => { // Remove this port. @@ -1129,7 +1128,7 @@ struct PortSet : Recv { } } ports <-> self.ports; - result + move result } fn recv() -> T { @@ -1166,7 +1165,7 @@ type SharedChan = unsafe::Exclusive>; impl SharedChan: Channel { fn send(+x: T) { - let mut xx = Some(x); + let mut xx = Some(move x); do self.with |chan| { let mut x = None; x <-> xx; @@ -1175,7 +1174,7 @@ impl SharedChan: Channel { } fn try_send(+x: T) -> bool { - let mut xx = Some(x); + let mut xx = Some(move x); do self.with |chan| { let mut x = None; x <-> xx; @@ -1186,7 +1185,7 @@ impl SharedChan: Channel { /// Converts a `chan` into a `shared_chan`. fn SharedChan(+c: Chan) -> SharedChan { - unsafe::exclusive(c) + unsafe::exclusive(move c) } /// Receive a message from one of two endpoints. @@ -1240,24 +1239,24 @@ fn oneshot() -> (ChanOne, PortOne) { * closed. */ fn recv_one(+port: PortOne) -> T { - let oneshot::send(message) = recv(port); - message + let oneshot::send(message) = recv(move port); + move message } /// Receive a message from a oneshot pipe unless the connection was closed. fn try_recv_one (+port: PortOne) -> Option { - let message = try_recv(port); + let message = try_recv(move port); if message.is_none() { None } else { let oneshot::send(message) = option::unwrap(message); - Some(message) + Some(move message) } } /// Send a message on a oneshot pipe, failing if the connection was closed. fn send_one(+chan: ChanOne, +data: T) { - oneshot::client::send(chan, data); + oneshot::client::send(move chan, move data); } /** @@ -1266,13 +1265,13 @@ fn send_one(+chan: ChanOne, +data: T) { */ fn try_send_one(+chan: ChanOne, +data: T) -> bool { - oneshot::client::try_send(chan, data).is_some() + oneshot::client::try_send(move chan, move data).is_some() } mod rt { // These are used to hide the option constructors from the // compiler because their names are changing - fn make_some(+val: T) -> Option { Some(val) } + fn make_some(+val: T) -> Option { Some(move val) } fn make_none() -> Option { None } } diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 07c766792b55..123628a28a24 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -64,10 +64,10 @@ impl message: gen_send { if this.proto.is_bounded() { let (sp, rp) = match (this.dir, next.dir) { - (send, send) => (~"c", ~"s"), + (send, send) => (~"move c", ~"move s"), (send, recv) => (~"s", ~"c"), (recv, send) => (~"s", ~"c"), - (recv, recv) => (~"c", ~"s") + (recv, recv) => (~"move c", ~"move s") }; body += ~"let b = pipe.reuse_buffer();\n"; @@ -80,10 +80,10 @@ impl message: gen_send { } else { let pat = match (this.dir, next.dir) { - (send, send) => "(c, s)", + (send, send) => "(move c, move s)", (send, recv) => "(s, c)", (recv, send) => "(s, c)", - (recv, recv) => "(c, s)" + (recv, recv) => "(move c, move s)" }; body += fmt!("let %s = pipes::entangle();\n", pat); @@ -92,17 +92,17 @@ impl message: gen_send { this.proto.name, self.name(), str::connect(vec::append_one( - arg_names.map(|x| cx.str_of(x)), ~"s"), - ~", ")); + arg_names.map(|x| ~"move " + cx.str_of(x)), + ~"move s"), ~", ")); if !try { - body += fmt!("pipes::send(pipe, message);\n"); + body += fmt!("pipes::send(move pipe, move message);\n"); // return the new channel - body += ~"c }"; + body += ~"move c }"; } else { - body += fmt!("if pipes::send(pipe, message) {\n \ - pipes::rt::make_some(c) \ + body += fmt!("if pipes::send(move pipe, move message) {\n \ + pipes::rt::make_some(move c) \ } else { pipes::rt::make_none() } }"); } @@ -145,7 +145,8 @@ impl message: gen_send { ~"" } else { - ~"(" + str::connect(arg_names, ~", ") + ~")" + ~"(" + str::connect(arg_names.map(|x| ~"move " + x), + ~", ") + ~")" }; let mut body = ~"{ "; @@ -155,10 +156,10 @@ impl message: gen_send { message_args); if !try { - body += fmt!("pipes::send(pipe, message);\n"); + body += fmt!("pipes::send(move pipe, move message);\n"); body += ~" }"; } else { - body += fmt!("if pipes::send(pipe, message) { \ + body += fmt!("if pipes::send(move pipe, move message) { \ pipes::rt::make_some(()) \ } else { pipes::rt::make_none() } }"); } @@ -301,7 +302,7 @@ impl protocol: gen_init { recv => { #ast {{ let (s, c) = pipes::entangle(); - (c, s) + (move c, move s) }} } } @@ -313,7 +314,7 @@ impl protocol: gen_init { recv => { #ast {{ let (s, c) = $(body); - (c, s) + (move c, move s) }} } } @@ -356,7 +357,7 @@ impl protocol: gen_init { #ast {{ let buffer = $(buffer); - do pipes::entangle_buffer(buffer) |buffer, data| { + do pipes::entangle_buffer(move buffer) |buffer, data| { $(entangle_body) } }}