From da2ac908126ec52e60e621416ce84284e7b77e51 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 2 May 2013 22:37:22 -0700 Subject: [PATCH 01/25] libstd: Remove mutable fields from fileinput and net_tcp --- src/libstd/fileinput.rs | 4 ++-- src/libstd/net_tcp.rs | 40 +++++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/libstd/fileinput.rs b/src/libstd/fileinput.rs index a24b11d71c68d..90774d19595ab 100644 --- a/src/libstd/fileinput.rs +++ b/src/libstd/fileinput.rs @@ -145,7 +145,7 @@ struct FileInput_ { // "self.fi." -> "self." and renaming FileInput_. Documentation above // will likely have to be updated to use `let mut in = ...`. pub struct FileInput { - priv mut fi: FileInput_ + priv fi: @mut FileInput_ } impl FileInput { @@ -170,7 +170,7 @@ impl FileInput { pub fn from_vec_raw(files: ~[Option]) -> FileInput { FileInput{ - fi: FileInput_ { + fi: @mut FileInput_ { files: files, current_reader: None, state: FileInputState { diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 53eb6c5561b68..e8c38be74c7d2 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -71,14 +71,14 @@ pub fn TcpSocket(socket_data: @TcpSocketData) -> TcpSocket { * satisfy both the `io::Reader` and `io::Writer` traits. */ pub struct TcpSocketBuf { - data: @TcpBufferedSocketData, - mut end_of_stream: bool + data: @mut TcpBufferedSocketData, + end_of_stream: @mut bool } -pub fn TcpSocketBuf(data: @TcpBufferedSocketData) -> TcpSocketBuf { +pub fn TcpSocketBuf(data: @mut TcpBufferedSocketData) -> TcpSocketBuf { TcpSocketBuf { data: data, - end_of_stream: false + end_of_stream: @mut false } } @@ -670,7 +670,7 @@ fn listen_common(host_ip: ip::IpAddr, &ip::Ipv4(_) => { false } &ip::Ipv6(_) => { true } }, - mut active: true + active: @mut true }; let server_data_ptr: *TcpListenFcData = &server_data; @@ -751,7 +751,7 @@ fn listen_common(host_ip: ip::IpAddr, debug!( "tcp::listen post-kill recv hl interact %?", loop_ptr); - (*server_data_ptr).active = false; + *(*server_data_ptr).active = false; uv::ll::close(server_stream_ptr, tcp_lfc_close_cb); } }; @@ -782,7 +782,7 @@ fn listen_common(host_ip: ip::IpAddr, debug!( "tcp::listen post-kill recv hl interact %?", loop_ptr); - (*server_data_ptr).active = false; + *(*server_data_ptr).active = false; uv::ll::close(server_stream_ptr, tcp_lfc_close_cb); } }; @@ -816,8 +816,8 @@ fn listen_common(host_ip: ip::IpAddr, * A buffered wrapper that you can cast as an `io::Reader` or `io::Writer` */ pub fn socket_buf(sock: TcpSocket) -> TcpSocketBuf { - TcpSocketBuf(@TcpBufferedSocketData { - sock: sock, mut buf: ~[], buf_off: 0 + TcpSocketBuf(@mut TcpBufferedSocketData { + sock: sock, buf: ~[], buf_off: 0 }) } @@ -902,12 +902,13 @@ impl io::Reader for TcpSocketBuf { // need to read in data from the socket. Note that the internal // buffer is of no use anymore as we read all bytes from it, // so we can throw it away. - let read_result = read(&self.data.sock, 0u); + let data = &*self.data; + let read_result = read(&data.sock, 0u); if read_result.is_err() { let err_data = read_result.get_err(); if err_data.err_name == ~"EOF" { - self.end_of_stream = true; + *self.end_of_stream = true; break; } else { debug!("ERROR sock_buf as io::reader.read err %? %?", @@ -934,12 +935,13 @@ impl io::Reader for TcpSocketBuf { return c as int } - let read_result = read(&self.data.sock, 0u); + let data = &*self.data; + let read_result = read(&data.sock, 0u); if read_result.is_err() { let err_data = read_result.get_err(); if err_data.err_name == ~"EOF" { - self.end_of_stream = true; + *self.end_of_stream = true; return -1 } else { debug!("ERROR sock_buf as io::reader.read err %? %?", @@ -954,7 +956,7 @@ impl io::Reader for TcpSocketBuf { } } fn eof(&self) -> bool { - self.end_of_stream + *self.end_of_stream } fn seek(&self, dist: int, seek: io::SeekStyle) { debug!("tcp_socket_buf seek stub %? %?", dist, seek); @@ -1204,7 +1206,7 @@ struct TcpListenFcData { on_connect_cb: ~fn(*uv::ll::uv_tcp_t), iotask: IoTask, ipv6: bool, - mut active: bool, + active: @mut bool, } extern fn tcp_lfc_close_cb(handle: *uv::ll::uv_tcp_t) { @@ -1222,7 +1224,7 @@ extern fn tcp_lfc_on_connection_cb(handle: *uv::ll::uv_tcp_t, let server_data_ptr = uv::ll::get_data_for_uv_handle(handle) as *TcpListenFcData; let kill_ch = (*server_data_ptr).kill_ch.clone(); - if (*server_data_ptr).active { + if *(*server_data_ptr).active { match status { 0i32 => ((*server_data_ptr).on_connect_cb)(handle), _ => { @@ -1230,7 +1232,7 @@ extern fn tcp_lfc_on_connection_cb(handle: *uv::ll::uv_tcp_t, kill_ch.send( Some(uv::ll::get_last_err_data(loop_ptr) .to_tcp_err())); - (*server_data_ptr).active = false; + *(*server_data_ptr).active = false; } } } @@ -1430,8 +1432,8 @@ struct TcpSocketData { struct TcpBufferedSocketData { sock: TcpSocket, - mut buf: ~[u8], - mut buf_off: uint + buf: ~[u8], + buf_off: uint } #[cfg(test)] From 92d2ec4d32c7f7722569b1463cba31c6402f7513 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 2 May 2013 22:44:03 -0700 Subject: [PATCH 02/25] libstd: Remove mutable fields from flatpipes and io_util --- src/libstd/flatpipes.rs | 20 +++++++++++--------- src/libstd/io_util.rs | 8 ++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs index 88de53f360519..b091a951af178 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -558,9 +558,11 @@ pub mod bytepipes { } } + // XXX: Remove `@mut` when this module is ported to the new I/O traits, + // which use `&mut self` properly. pub struct PipeBytePort { port: comm::Port<~[u8]>, - mut buf: ~[u8] + buf: @mut ~[u8] } pub struct PipeByteChan { @@ -569,13 +571,13 @@ pub mod bytepipes { impl BytePort for PipeBytePort { fn try_recv(&self, count: uint) -> Option<~[u8]> { - if vec::uniq_len(&const self.buf) >= count { - let mut bytes = ::core::util::replace(&mut self.buf, ~[]); - self.buf = bytes.slice(count, bytes.len()).to_owned(); + if vec::uniq_len(&const *self.buf) >= count { + let mut bytes = ::core::util::replace(&mut *self.buf, ~[]); + *self.buf = bytes.slice(count, bytes.len()).to_owned(); bytes.truncate(count); return Some(bytes); - } else if vec::uniq_len(&const self.buf) > 0 { - let mut bytes = ::core::util::replace(&mut self.buf, ~[]); + } else if vec::uniq_len(&const *self.buf) > 0 { + let mut bytes = ::core::util::replace(&mut *self.buf, ~[]); assert!(count > bytes.len()); match self.try_recv(count - bytes.len()) { Some(rest) => { @@ -584,11 +586,11 @@ pub mod bytepipes { } None => return None } - } else if vec::uniq_len(&const self.buf) == 0 { + } else if vec::uniq_len(&const *self.buf) == 0 { match self.port.try_recv() { Some(buf) => { assert!(!buf.is_empty()); - self.buf = buf; + *self.buf = buf; return self.try_recv(count); } None => return None @@ -609,7 +611,7 @@ pub mod bytepipes { fn new(p: Port<~[u8]>) -> PipeBytePort { PipeBytePort { port: p, - buf: ~[] + buf: @mut ~[] } } } diff --git a/src/libstd/io_util.rs b/src/libstd/io_util.rs index 50d2eb6a78521..6ed626202b7e2 100644 --- a/src/libstd/io_util.rs +++ b/src/libstd/io_util.rs @@ -13,14 +13,14 @@ use core::io; pub struct BufReader { buf: ~[u8], - mut pos: uint + pos: @mut uint } pub impl BufReader { pub fn new(v: ~[u8]) -> BufReader { BufReader { buf: v, - pos: 0 + pos: @mut 0 } } @@ -29,13 +29,13 @@ pub impl BufReader { // I can't get the borrowing to work correctly let bytes_reader = BytesReader { bytes: ::core::util::id::<&[u8]>(self.buf), - pos: self.pos + pos: *self.pos }; let res = f(&bytes_reader); // FIXME #4429: This isn't correct if f fails - self.pos = bytes_reader.pos; + *self.pos = bytes_reader.pos; return res; } From bba0680cb0801bc52d2abfc87bbf0885dc0355f8 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 2 May 2013 22:51:12 -0700 Subject: [PATCH 03/25] libstd: Remove mutable fields from future and par --- src/libstd/future.rs | 77 ++++++++++++++++++++++++++++++++------------ src/libstd/par.rs | 4 +-- 2 files changed, 58 insertions(+), 23 deletions(-) diff --git a/src/libstd/future.rs b/src/libstd/future.rs index 5e3e64b2f1cfa..209859e30961e 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -29,7 +29,7 @@ use core::task; #[doc = "The future type"] pub struct Future { - priv mut state: FutureState, + priv state: FutureState, } // FIXME(#2829) -- futures should not be copyable, because they close @@ -47,13 +47,14 @@ priv enum FutureState { /// Methods on the `future` type pub impl Future { - fn get(&self) -> A { + fn get(&mut self) -> A { //! Get the value of the future *(self.get_ref()) } } pub impl Future { + #[cfg(stage0)] fn get_ref<'a>(&'a self) -> &'a A { /*! * Executes the future's closure and then returns a borrowed @@ -61,19 +62,53 @@ pub impl Future { * the future. */ unsafe { - match self.state { - Forced(ref mut v) => { return cast::transmute(v); } - Evaluating => fail!(~"Recursive forcing of future!"), - Pending(_) => {} + { + match self.state { + Forced(ref mut v) => { return cast::transmute(v); } + Evaluating => fail!(~"Recursive forcing of future!"), + Pending(_) => {} + } + } + { + let mut state = Evaluating; + self.state <-> state; + match state { + Forced(_) | Evaluating => fail!(~"Logic error."), + Pending(f) => { + self.state = Forced(f()); + cast::transmute(self.get_ref()) + } + } } + } + } - let mut state = Evaluating; - self.state <-> state; - match state { - Forced(_) | Evaluating => fail!(~"Logic error."), - Pending(f) => { - self.state = Forced(f()); - self.get_ref() + #[cfg(stage1)] + #[cfg(stage2)] + #[cfg(stage3)] + fn get_ref<'a>(&'a mut self) -> &'a A { + /*! + * Executes the future's closure and then returns a borrowed + * pointer to the result. The borrowed pointer lasts as long as + * the future. + */ + unsafe { + { + match self.state { + Forced(ref mut v) => { return cast::transmute(v); } + Evaluating => fail!(~"Recursive forcing of future!"), + Pending(_) => {} + } + } + { + let mut state = Evaluating; + self.state <-> state; + match state { + Forced(_) | Evaluating => fail!(~"Logic error."), + Pending(f) => { + self.state = Forced(f()); + cast::transmute(self.get_ref()) + } } } } @@ -150,7 +185,7 @@ mod test { #[test] fn test_from_value() { - let f = from_value(~"snail"); + let mut f = from_value(~"snail"); assert!(f.get() == ~"snail"); } @@ -158,31 +193,31 @@ mod test { fn test_from_port() { let (po, ch) = oneshot(); send_one(ch, ~"whale"); - let f = from_port(po); + let mut f = from_port(po); assert!(f.get() == ~"whale"); } #[test] fn test_from_fn() { - let f = from_fn(|| ~"brail"); + let mut f = from_fn(|| ~"brail"); assert!(f.get() == ~"brail"); } #[test] fn test_interface_get() { - let f = from_value(~"fail"); + let mut f = from_value(~"fail"); assert!(f.get() == ~"fail"); } #[test] fn test_get_ref_method() { - let f = from_value(22); + let mut f = from_value(22); assert!(*f.get_ref() == 22); } #[test] fn test_spawn() { - let f = spawn(|| ~"bale"); + let mut f = spawn(|| ~"bale"); assert!(f.get() == ~"bale"); } @@ -190,14 +225,14 @@ mod test { #[should_fail] #[ignore(cfg(target_os = "win32"))] fn test_futurefail() { - let f = spawn(|| fail!()); + let mut f = spawn(|| fail!()); let _x: ~str = f.get(); } #[test] fn test_sendable_future() { let expected = ~"schlorf"; - let f = do spawn { copy expected }; + let mut f = do spawn { copy expected }; do task::spawn || { let actual = f.get(); assert!(actual == expected); diff --git a/src/libstd/par.rs b/src/libstd/par.rs index cfedbb66caac5..cf0eba9d30cea 100644 --- a/src/libstd/par.rs +++ b/src/libstd/par.rs @@ -73,10 +73,10 @@ fn map_slices( info!("num_tasks: %?", (num_tasks, futures.len())); assert!((num_tasks == futures.len())); - let r = do futures.map() |ys| { + let r = do vec::map_consume(futures) |ys| { + let mut ys = ys; ys.get() }; - assert!((r.len() == futures.len())); r } } From ee78d811e488e2f279cfda454f8f909477dc3d6b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 2 May 2013 22:52:19 -0700 Subject: [PATCH 04/25] libstd: Start warning about mutable fields, now that they only exist in stage0 --- src/libstd/std.rc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 51e11669f449d..931974d245485 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -28,7 +28,9 @@ not required in or otherwise suitable for the core library. #[allow(vecs_implicitly_copyable)]; #[deny(non_camel_case_types)]; -#[allow(deprecated_mutable_fields)]; + +// Allow mutable fields only in stage0. +#[warn(deprecated_mutable_fields)]; pub mod uv_ll; From b2d1ac100fb7c7ea8716b17b8df64e43aef41f9e Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 2 May 2013 23:09:50 -0700 Subject: [PATCH 05/25] libcore: Remove mutable fields from rand. --- src/libcore/hashmap.rs | 2 +- src/libcore/rand.rs | 176 ++++++++++++++++-------------- src/libcore/rand/distributions.rs | 12 +- src/libcore/unstable/at_exit.rs | 3 +- src/libstd/tempfile.rs | 2 +- src/libstd/test.rs | 2 +- 6 files changed, 107 insertions(+), 90 deletions(-) diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs index b764fccf64cff..8e0a185248e61 100644 --- a/src/libcore/hashmap.rs +++ b/src/libcore/hashmap.rs @@ -56,7 +56,7 @@ fn resize_at(capacity: uint) -> uint { pub fn linear_map_with_capacity( initial_capacity: uint) -> HashMap { - let r = rand::task_rng(); + let mut r = rand::task_rng(); linear_map_with_capacity_and_keys(r.gen(), r.gen(), initial_capacity) } diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index 80f69f067eb54..cb212efa363e2 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -55,12 +55,12 @@ pub mod distributions; /// A type that can be randomly generated using an Rng pub trait Rand { - fn rand(rng: &R) -> Self; + fn rand(rng: &mut R) -> Self; } impl Rand for int { #[inline] - fn rand(rng: &R) -> int { + fn rand(rng: &mut R) -> int { if int::bits == 32 { rng.next() as int } else { @@ -71,35 +71,35 @@ impl Rand for int { impl Rand for i8 { #[inline] - fn rand(rng: &R) -> i8 { + fn rand(rng: &mut R) -> i8 { rng.next() as i8 } } impl Rand for i16 { #[inline] - fn rand(rng: &R) -> i16 { + fn rand(rng: &mut R) -> i16 { rng.next() as i16 } } impl Rand for i32 { #[inline] - fn rand(rng: &R) -> i32 { + fn rand(rng: &mut R) -> i32 { rng.next() as i32 } } impl Rand for i64 { #[inline] - fn rand(rng: &R) -> i64 { + fn rand(rng: &mut R) -> i64 { (rng.next() as i64 << 32) | rng.next() as i64 } } impl Rand for uint { #[inline] - fn rand(rng: &R) -> uint { + fn rand(rng: &mut R) -> uint { if uint::bits == 32 { rng.next() as uint } else { @@ -110,42 +110,42 @@ impl Rand for uint { impl Rand for u8 { #[inline] - fn rand(rng: &R) -> u8 { + fn rand(rng: &mut R) -> u8 { rng.next() as u8 } } impl Rand for u16 { #[inline] - fn rand(rng: &R) -> u16 { + fn rand(rng: &mut R) -> u16 { rng.next() as u16 } } impl Rand for u32 { #[inline] - fn rand(rng: &R) -> u32 { + fn rand(rng: &mut R) -> u32 { rng.next() } } impl Rand for u64 { #[inline] - fn rand(rng: &R) -> u64 { + fn rand(rng: &mut R) -> u64 { (rng.next() as u64 << 32) | rng.next() as u64 } } impl Rand for float { #[inline] - fn rand(rng: &R) -> float { + fn rand(rng: &mut R) -> float { rng.gen::() as float } } impl Rand for f32 { #[inline] - fn rand(rng: &R) -> f32 { + fn rand(rng: &mut R) -> f32 { rng.gen::() as f32 } } @@ -153,7 +153,7 @@ impl Rand for f32 { static scale : f64 = (u32::max_value as f64) + 1.0f64; impl Rand for f64 { #[inline] - fn rand(rng: &R) -> f64 { + fn rand(rng: &mut R) -> f64 { let u1 = rng.next() as f64; let u2 = rng.next() as f64; let u3 = rng.next() as f64; @@ -164,14 +164,14 @@ impl Rand for f64 { impl Rand for char { #[inline] - fn rand(rng: &R) -> char { + fn rand(rng: &mut R) -> char { rng.next() as char } } impl Rand for bool { #[inline] - fn rand(rng: &R) -> bool { + fn rand(rng: &mut R) -> bool { rng.next() & 1u32 == 1u32 } } @@ -185,7 +185,7 @@ macro_rules! tuple_impl { > Rand for ( $( $tyvar ),* , ) { #[inline] - fn rand(_rng: &R) -> ( $( $tyvar ),* , ) { + fn rand(_rng: &mut R) -> ( $( $tyvar ),* , ) { ( // use the $tyvar's to get the appropriate number of // repeats (they're not actually needed) @@ -201,7 +201,7 @@ macro_rules! tuple_impl { impl Rand for () { #[inline] - fn rand(_: &R) -> () { () } + fn rand(_: &mut R) -> () { () } } tuple_impl!{A} tuple_impl!{A, B} @@ -216,7 +216,7 @@ tuple_impl!{A, B, C, D, E, F, G, H, I, J} impl Rand for Option { #[inline] - fn rand(rng: &R) -> Option { + fn rand(rng: &mut R) -> Option { if rng.gen() { Some(rng.gen()) } else { @@ -227,12 +227,12 @@ impl Rand for Option { impl Rand for ~T { #[inline] - fn rand(rng: &R) -> ~T { ~rng.gen() } + fn rand(rng: &mut R) -> ~T { ~rng.gen() } } impl Rand for @T { #[inline] - fn rand(rng: &R) -> @T { @rng.gen() } + fn rand(rng: &mut R) -> @T { @rng.gen() } } #[abi = "cdecl"] @@ -248,7 +248,7 @@ pub mod rustrt { /// A random number generator pub trait Rng { /// Return the next random integer - pub fn next(&self) -> u32; + pub fn next(&mut self) -> u32; } /// A value with a particular weight compared to other values @@ -259,21 +259,21 @@ pub struct Weighted { pub trait RngUtil { /// Return a random value of a Rand type - fn gen(&self) -> T; + fn gen(&mut self) -> T; /** * Return a int randomly chosen from the range [start, end), * failing if start >= end */ - fn gen_int_range(&self, start: int, end: int) -> int; + fn gen_int_range(&mut self, start: int, end: int) -> int; /** * Return a uint randomly chosen from the range [start, end), * failing if start >= end */ - fn gen_uint_range(&self, start: uint, end: uint) -> uint; + fn gen_uint_range(&mut self, start: uint, end: uint) -> uint; /** * Return a char randomly chosen from chars, failing if chars is empty */ - fn gen_char_from(&self, chars: &str) -> char; + fn gen_char_from(&mut self, chars: &str) -> char; /** * Return a bool with a 1 in n chance of true * @@ -289,7 +289,7 @@ pub trait RngUtil { * } * ~~~ */ - fn gen_weighted_bool(&self, n: uint) -> bool; + fn gen_weighted_bool(&mut self, n: uint) -> bool; /** * Return a random string of the specified length composed of A-Z,a-z,0-9 * @@ -305,7 +305,7 @@ pub trait RngUtil { * } * ~~~ */ - fn gen_str(&self, len: uint) -> ~str; + fn gen_str(&mut self, len: uint) -> ~str; /** * Return a random byte string of the specified length * @@ -321,7 +321,7 @@ pub trait RngUtil { * } * ~~~ */ - fn gen_bytes(&self, len: uint) -> ~[u8]; + fn gen_bytes(&mut self, len: uint) -> ~[u8]; /** * Choose an item randomly, failing if values is empty * @@ -337,9 +337,9 @@ pub trait RngUtil { * } * ~~~ */ - fn choose(&self, values: &[T]) -> T; + fn choose(&mut self, values: &[T]) -> T; /// Choose Some(item) randomly, returning None if values is empty - fn choose_option(&self, values: &[T]) -> Option; + fn choose_option(&mut self, values: &[T]) -> Option; /** * Choose an item respecting the relative weights, failing if the sum of * the weights is 0 @@ -359,7 +359,7 @@ pub trait RngUtil { * } * ~~~ */ - fn choose_weighted(&self, v : &[Weighted]) -> T; + fn choose_weighted(&mut self, v : &[Weighted]) -> T; /** * Choose Some(item) respecting the relative weights, returning none if * the sum of the weights is 0 @@ -379,7 +379,8 @@ pub trait RngUtil { * } * ~~~ */ - fn choose_weighted_option(&self, v: &[Weighted]) -> Option; + fn choose_weighted_option(&mut self, v: &[Weighted]) + -> Option; /** * Return a vec containing copies of the items, in order, where * the weight of the item determines how many copies there are @@ -399,7 +400,7 @@ pub trait RngUtil { * } * ~~~ */ - fn weighted_vec(&self, v: &[Weighted]) -> ~[T]; + fn weighted_vec(&mut self, v: &[Weighted]) -> ~[T]; /** * Shuffle a vec * @@ -415,7 +416,7 @@ pub trait RngUtil { * } * ~~~ */ - fn shuffle(&self, values: &[T]) -> ~[T]; + fn shuffle(&mut self, values: &[T]) -> ~[T]; /** * Shuffle a mutable vec in place * @@ -435,14 +436,14 @@ pub trait RngUtil { * } * ~~~ */ - fn shuffle_mut(&self, values: &mut [T]); + fn shuffle_mut(&mut self, values: &mut [T]); } /// Extension methods for random number generators impl RngUtil for R { /// Return a random value for a Rand type #[inline(always)] - fn gen(&self) -> T { + fn gen(&mut self) -> T { Rand::rand(self) } @@ -450,7 +451,7 @@ impl RngUtil for R { * Return an int randomly chosen from the range [start, end), * failing if start >= end */ - fn gen_int_range(&self, start: int, end: int) -> int { + fn gen_int_range(&mut self, start: int, end: int) -> int { assert!(start < end); start + int::abs(self.gen::() % (end - start)) } @@ -459,7 +460,7 @@ impl RngUtil for R { * Return a uint randomly chosen from the range [start, end), * failing if start >= end */ - fn gen_uint_range(&self, start: uint, end: uint) -> uint { + fn gen_uint_range(&mut self, start: uint, end: uint) -> uint { assert!(start < end); start + (self.gen::() % (end - start)) } @@ -467,7 +468,7 @@ impl RngUtil for R { /** * Return a char randomly chosen from chars, failing if chars is empty */ - fn gen_char_from(&self, chars: &str) -> char { + fn gen_char_from(&mut self, chars: &str) -> char { assert!(!chars.is_empty()); let mut cs = ~[]; for str::each_char(chars) |c| { cs.push(c) } @@ -475,7 +476,7 @@ impl RngUtil for R { } /// Return a bool with a 1-in-n chance of true - fn gen_weighted_bool(&self, n: uint) -> bool { + fn gen_weighted_bool(&mut self, n: uint) -> bool { if n == 0u { true } else { @@ -486,7 +487,7 @@ impl RngUtil for R { /** * Return a random string of the specified length composed of A-Z,a-z,0-9 */ - fn gen_str(&self, len: uint) -> ~str { + fn gen_str(&mut self, len: uint) -> ~str { let charset = ~"ABCDEFGHIJKLMNOPQRSTUVWXYZ\ abcdefghijklmnopqrstuvwxyz\ 0123456789"; @@ -500,19 +501,19 @@ impl RngUtil for R { } /// Return a random byte string of the specified length - fn gen_bytes(&self, len: uint) -> ~[u8] { + fn gen_bytes(&mut self, len: uint) -> ~[u8] { do vec::from_fn(len) |_i| { self.gen() } } /// Choose an item randomly, failing if values is empty - fn choose(&self, values: &[T]) -> T { + fn choose(&mut self, values: &[T]) -> T { self.choose_option(values).get() } /// Choose Some(item) randomly, returning None if values is empty - fn choose_option(&self, values: &[T]) -> Option { + fn choose_option(&mut self, values: &[T]) -> Option { if values.is_empty() { None } else { @@ -523,7 +524,7 @@ impl RngUtil for R { * Choose an item respecting the relative weights, failing if the sum of * the weights is 0 */ - fn choose_weighted(&self, v : &[Weighted]) -> T { + fn choose_weighted(&mut self, v: &[Weighted]) -> T { self.choose_weighted_option(v).get() } @@ -531,7 +532,8 @@ impl RngUtil for R { * Choose Some(item) respecting the relative weights, returning none if * the sum of the weights is 0 */ - fn choose_weighted_option(&self, v: &[Weighted]) -> Option { + fn choose_weighted_option(&mut self, v: &[Weighted]) + -> Option { let mut total = 0u; for v.each |item| { total += item.weight; @@ -554,7 +556,7 @@ impl RngUtil for R { * Return a vec containing copies of the items, in order, where * the weight of the item determines how many copies there are */ - fn weighted_vec(&self, v: &[Weighted]) -> ~[T] { + fn weighted_vec(&mut self, v: &[Weighted]) -> ~[T] { let mut r = ~[]; for v.each |item| { for uint::range(0u, item.weight) |_i| { @@ -565,14 +567,14 @@ impl RngUtil for R { } /// Shuffle a vec - fn shuffle(&self, values: &[T]) -> ~[T] { + fn shuffle(&mut self, values: &[T]) -> ~[T] { let mut m = vec::from_slice(values); self.shuffle_mut(m); m } /// Shuffle a mutable vec in place - fn shuffle_mut(&self, values: &mut [T]) { + fn shuffle_mut(&mut self, values: &mut [T]) { let mut i = values.len(); while i >= 2u { // invariant: elements with index >= i have been locked in place. @@ -594,12 +596,12 @@ static RAND_SIZE: u32 = 1 << RAND_SIZE_LEN; /// A random number generator that uses the [ISAAC /// algorithm](http://en.wikipedia.org/wiki/ISAAC_%28cipher%29). pub struct IsaacRng { - priv mut cnt: u32, - priv mut rsl: [u32, .. RAND_SIZE], - priv mut mem: [u32, .. RAND_SIZE], - priv mut a: u32, - priv mut b: u32, - priv mut c: u32 + priv cnt: u32, + priv rsl: [u32, .. RAND_SIZE], + priv mem: [u32, .. RAND_SIZE], + priv a: u32, + priv b: u32, + priv c: u32 } pub impl IsaacRng { @@ -647,7 +649,7 @@ pub impl IsaacRng { /// Initialises `self`. If `use_rsl` is true, then use the current value /// of `rsl` as a seed, otherwise construct one algorithmically (not /// randomly). - priv fn init(&self, use_rsl: bool) { + priv fn init(&mut self, use_rsl: bool) { macro_rules! init_mut_many ( ($( $var:ident ),* = $val:expr ) => { let mut $( $var = $val ),*; @@ -705,16 +707,16 @@ pub impl IsaacRng { /// Refills the output buffer (`self.rsl`) #[inline] - priv fn isaac(&self) { + priv fn isaac(&mut self) { self.c += 1; // abbreviations let mut a = self.a, b = self.b + self.c; - let mem = &mut self.mem; - let rsl = &mut self.rsl; static midpoint: uint = RAND_SIZE as uint / 2; - macro_rules! ind (($x:expr) => { mem[($x >> 2) & (RAND_SIZE - 1)] }); + macro_rules! ind (($x:expr) => { + self.mem[($x >> 2) & (RAND_SIZE - 1)] + }); macro_rules! rngstep( ($j:expr, $shift:expr) => {{ let base = base + $j; @@ -724,13 +726,13 @@ pub impl IsaacRng { a << $shift as uint }; - let x = mem[base + mr_offset]; - a = (a ^ mix) + mem[base + m2_offset]; + let x = self.mem[base + mr_offset]; + a = (a ^ mix) + self.mem[base + m2_offset]; let y = ind!(x) + a + b; - mem[base + mr_offset] = y; + self.mem[base + mr_offset] = y; b = ind!(y >> RAND_SIZE_LEN) + x; - rsl[base + mr_offset] = b; + self.rsl[base + mr_offset] = b; }} ); @@ -751,7 +753,7 @@ pub impl IsaacRng { impl Rng for IsaacRng { #[inline(always)] - fn next(&self) -> u32 { + fn next(&mut self) -> u32 { if self.cnt == 0 { // make some more numbers self.isaac(); @@ -765,15 +767,15 @@ impl Rng for IsaacRng { /// generator](http://en.wikipedia.org/wiki/Xorshift). Not suitable for /// cryptographic purposes. pub struct XorShiftRng { - priv mut x: u32, - priv mut y: u32, - priv mut z: u32, - priv mut w: u32, + priv x: u32, + priv y: u32, + priv z: u32, + priv w: u32, } impl Rng for XorShiftRng { #[inline] - pub fn next(&self) -> u32 { + pub fn next(&mut self) -> u32 { let x = self.x; let t = x ^ (x << 11); self.x = self.y; @@ -789,7 +791,10 @@ pub impl XorShiftRng { /// Create an xor shift random number generator with a default seed. fn new() -> XorShiftRng { // constants taken from http://en.wikipedia.org/wiki/Xorshift - XorShiftRng::new_seeded(123456789u32, 362436069u32, 521288629u32, 88675123u32) + XorShiftRng::new_seeded(123456789u32, + 362436069u32, + 521288629u32, + 88675123u32) } /** @@ -798,7 +803,12 @@ pub impl XorShiftRng { * all other generators constructed with the same seed. */ fn new_seeded(x: u32, y: u32, z: u32, w: u32) -> XorShiftRng { - XorShiftRng { x: x, y: y, z: z, w: w } + XorShiftRng { + x: x, + y: y, + z: z, + w: w, + } } } @@ -815,7 +825,7 @@ pub fn seed() -> ~[u8] { } // used to make space in TLS for a random number generator -fn tls_rng_state(_v: @IsaacRng) {} +fn tls_rng_state(_v: @@mut IsaacRng) {} /** * Gives back a lazily initialized task-local random number generator, @@ -823,15 +833,15 @@ fn tls_rng_state(_v: @IsaacRng) {} * `task_rng().gen::()`. */ #[inline] -pub fn task_rng() -> @IsaacRng { - let r : Option<@IsaacRng>; +pub fn task_rng() -> @@mut IsaacRng { + let r : Option<@@mut IsaacRng>; unsafe { r = task::local_data::local_data_get(tls_rng_state); } match r { None => { unsafe { - let rng = @IsaacRng::new_seeded(seed()); + let rng = @@mut IsaacRng::new_seeded(seed()); task::local_data::local_data_set(tls_rng_state, rng); rng } @@ -841,9 +851,13 @@ pub fn task_rng() -> @IsaacRng { } // Allow direct chaining with `task_rng` -impl Rng for @R { +impl Rng for @@mut R { #[inline(always)] - fn next(&self) -> u32 { (**self).next() } + fn next(&mut self) -> u32 { + match *self { + @@ref mut r => r.next() + } + } } /** @@ -852,7 +866,9 @@ impl Rng for @R { */ #[inline] pub fn random() -> T { - (*task_rng()).gen() + match *task_rng() { + @ref mut r => r.gen() + } } #[cfg(test)] diff --git a/src/libcore/rand/distributions.rs b/src/libcore/rand/distributions.rs index a644f60db69fb..72cff5111e762 100644 --- a/src/libcore/rand/distributions.rs +++ b/src/libcore/rand/distributions.rs @@ -27,13 +27,13 @@ mod ziggurat_tables; // inlining should mean there is no performance penalty for this #[inline(always)] -fn ziggurat(rng: &R, +fn ziggurat(rng: &mut R, center_u: bool, X: ziggurat_tables::ZigTable, F: ziggurat_tables::ZigTable, F_DIFF: ziggurat_tables::ZigTable, pdf: &'static fn(f64) -> f64, // probability density function - zero_case: &'static fn(&R, f64) -> f64) -> f64 { + zero_case: &'static fn(&mut R, f64) -> f64) -> f64 { loop { let u = if center_u {2.0 * rng.gen() - 1.0} else {rng.gen()}; let i: uint = rng.gen::() & 0xff; @@ -76,13 +76,13 @@ fn ziggurat(rng: &R, pub struct StandardNormal(f64); impl Rand for StandardNormal { - fn rand(rng: &R) -> StandardNormal { + fn rand(rng: &mut R) -> StandardNormal { #[inline(always)] fn pdf(x: f64) -> f64 { f64::exp((-x*x/2.0) as f64) as f64 } #[inline(always)] - fn zero_case(rng: &R, u: f64) -> f64 { + fn zero_case(rng: &mut R, u: f64) -> f64 { // compute a random number in the tail by hand // strange initial conditions, because the loop is not @@ -130,13 +130,13 @@ pub struct Exp1(f64); // This could be done via `-f64::ln(rng.gen::())` but that is slower. impl Rand for Exp1 { #[inline] - fn rand(rng: &R) -> Exp1 { + fn rand(rng: &mut R) -> Exp1 { #[inline(always)] fn pdf(x: f64) -> f64 { f64::exp(-x) } #[inline(always)] - fn zero_case(rng: &R, _u: f64) -> f64 { + fn zero_case(rng: &mut R, _u: f64) -> f64 { ziggurat_tables::ZIG_EXP_R - f64::ln(rng.gen()) } diff --git a/src/libcore/unstable/at_exit.rs b/src/libcore/unstable/at_exit.rs index bc4ec620aa86a..c9cd2f61e5c8a 100644 --- a/src/libcore/unstable/at_exit.rs +++ b/src/libcore/unstable/at_exit.rs @@ -62,7 +62,8 @@ fn exit_runner(exit_fns: *ExitFunctions) { // give us ownership of the array of functions let mut exit_fns_vec = unsafe { vec::from_buf(start, count as uint) }; // Let's not make any promises about execution order - rand::rng().shuffle_mut(exit_fns_vec); + let mut rng = rand::rng(); + rng.shuffle_mut(exit_fns_vec); debug!("running %u exit functions", exit_fns_vec.len()); diff --git a/src/libstd/tempfile.rs b/src/libstd/tempfile.rs index 10645e947e2d9..e02a7a337334e 100644 --- a/src/libstd/tempfile.rs +++ b/src/libstd/tempfile.rs @@ -13,7 +13,7 @@ use core::rand::RngUtil; pub fn mkdtemp(tmpdir: &Path, suffix: &str) -> Option { - let r = rand::rng(); + let mut r = rand::rng(); for 1000.times { let p = tmpdir.push(r.gen_str(16) + suffix); if os::make_dir(&p, 0x1c0) { // 700 diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 65fb0c7426a4e..7c0673a280bd8 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -688,7 +688,7 @@ pub mod bench { // not met, it may run as long as the Go algorithm. pub fn auto_bench(&mut self, f: &fn(&mut BenchHarness)) -> ~[f64] { - let rng = rand::rng(); + let mut rng = rand::rng(); let mut magnitude = 10; let mut prev_madp = 0.0; From 2961997f169a526ccf5a3bafd95db3e12f7e0283 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 2 May 2013 23:12:43 -0700 Subject: [PATCH 06/25] libcore: Remove mutable fields from os and ptr --- src/libcore/os.rs | 5 ++++- src/libcore/ptr.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 42c77a687e5fd..5a7f01706b4f4 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -352,7 +352,10 @@ pub fn fsync_fd(fd: c_int, _l: io::fsync::Level) -> c_int { } } -pub struct Pipe { in: c_int, out: c_int } +pub struct Pipe { + in: c_int, + out: c_int +} #[cfg(unix)] pub fn pipe() -> Pipe { diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 85e46a0feff6b..1a5ff39b30565 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -336,7 +336,10 @@ pub mod ptr_tests { #[test] fn test() { unsafe { - struct Pair {mut fst: int, mut snd: int}; + struct Pair { + fst: int, + snd: int + }; let mut p = Pair {fst: 10, snd: 20}; let pptr: *mut Pair = &mut p; let iptr: *mut int = cast::transmute(pptr); From 4dc1c2976d03b6e0fc114019341be51593ef49b2 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 3 May 2013 11:30:30 -0700 Subject: [PATCH 07/25] libcore: Remove mutable fields from hash --- src/libcore/hash.rs | 208 ++++++++++++++++------------ src/librustc/back/link.rs | 48 ++++--- src/librustc/middle/trans/base.rs | 5 +- src/librustc/middle/trans/common.rs | 2 +- src/librustdoc/markdown_writer.rs | 1 + src/librustpkg/util.rs | 7 +- 6 files changed, 160 insertions(+), 111 deletions(-) diff --git a/src/libcore/hash.rs b/src/libcore/hash.rs index ba1f8cebdb01c..486f0e096e8ac 100644 --- a/src/libcore/hash.rs +++ b/src/libcore/hash.rs @@ -19,12 +19,16 @@ * CPRNG like rand::rng. */ -use io; -use io::Writer; +#[cfg(stage0)] +use cast; +use rt::io::Writer; use to_bytes::IterBytes; use uint; use vec; +// Alias `SipState` to `State`. +pub use State = hash::SipState; + /** * Types that can meaningfully be hashed should implement this. * @@ -65,20 +69,32 @@ impl HashUtil for A { /// Streaming hash-functions should implement this. pub trait Streaming { - fn input(&self, (&const [u8])); + fn input(&mut self, &[u8]); // These can be refactored some when we have default methods. - fn result_bytes(&self) -> ~[u8]; - fn result_str(&self) -> ~str; - fn result_u64(&self) -> u64; - fn reset(&self); + fn result_bytes(&mut self) -> ~[u8]; + fn result_str(&mut self) -> ~str; + fn result_u64(&mut self) -> u64; + fn reset(&mut self); +} + +// XXX: Ugly workaround for bootstrapping. +#[cfg(stage0)] +fn transmute_for_stage0<'a>(bytes: &'a [const u8]) -> &'a [u8] { + unsafe { + cast::transmute(bytes) + } +} +#[cfg(not(stage0))] +fn transmute_for_stage0<'a>(bytes: &'a [u8]) -> &'a [u8] { + bytes } impl Hash for A { #[inline(always)] fn hash_keyed(&self, k0: u64, k1: u64) -> u64 { - let s = &State(k0, k1); + let mut s = State::new(k0, k1); for self.iter_bytes(true) |bytes| { - s.input(bytes); + s.input(transmute_for_stage0(bytes)); } s.result_u64() } @@ -86,32 +102,56 @@ impl Hash for A { fn hash_keyed_2(a: &A, b: &B, k0: u64, k1: u64) -> u64 { - let s = &State(k0, k1); - for a.iter_bytes(true) |bytes| { s.input(bytes); } - for b.iter_bytes(true) |bytes| { s.input(bytes); } + let mut s = State::new(k0, k1); + for a.iter_bytes(true) |bytes| { + s.input(transmute_for_stage0(bytes)); + } + for b.iter_bytes(true) |bytes| { + s.input(transmute_for_stage0(bytes)); + } s.result_u64() } fn hash_keyed_3(a: &A, b: &B, c: &C, k0: u64, k1: u64) -> u64 { - let s = &State(k0, k1); - for a.iter_bytes(true) |bytes| { s.input(bytes); } - for b.iter_bytes(true) |bytes| { s.input(bytes); } - for c.iter_bytes(true) |bytes| { s.input(bytes); } + let mut s = State::new(k0, k1); + for a.iter_bytes(true) |bytes| { + s.input(transmute_for_stage0(bytes)); + } + for b.iter_bytes(true) |bytes| { + s.input(transmute_for_stage0(bytes)); + } + for c.iter_bytes(true) |bytes| { + s.input(transmute_for_stage0(bytes)); + } s.result_u64() } fn hash_keyed_4(a: &A, b: &B, c: &C, d: &D, k0: u64, k1: u64) - -> u64 { - let s = &State(k0, k1); - for a.iter_bytes(true) |bytes| { s.input(bytes); } - for b.iter_bytes(true) |bytes| { s.input(bytes); } - for c.iter_bytes(true) |bytes| { s.input(bytes); } - for d.iter_bytes(true) |bytes| { s.input(bytes); } + D: IterBytes>( + a: &A, + b: &B, + c: &C, + d: &D, + k0: u64, + k1: u64) + -> u64 { + let mut s = State::new(k0, k1); + for a.iter_bytes(true) |bytes| { + s.input(transmute_for_stage0(bytes)); + } + for b.iter_bytes(true) |bytes| { + s.input(transmute_for_stage0(bytes)); + } + for c.iter_bytes(true) |bytes| { + s.input(transmute_for_stage0(bytes)); + } + for d.iter_bytes(true) |bytes| { + s.input(transmute_for_stage0(bytes)); + } s.result_u64() } @@ -119,58 +159,68 @@ fn hash_keyed_5(a: &A, b: &B, c: &C, d: &D, e: &E, - k0: u64, k1: u64) -> u64 { - let s = &State(k0, k1); - for a.iter_bytes(true) |bytes| { s.input(bytes); } - for b.iter_bytes(true) |bytes| { s.input(bytes); } - for c.iter_bytes(true) |bytes| { s.input(bytes); } - for d.iter_bytes(true) |bytes| { s.input(bytes); } - for e.iter_bytes(true) |bytes| { s.input(bytes); } + E: IterBytes>( + a: &A, + b: &B, + c: &C, + d: &D, + e: &E, + k0: u64, + k1: u64) + -> u64 { + let mut s = State::new(k0, k1); + for a.iter_bytes(true) |bytes| { + s.input(transmute_for_stage0(bytes)); + } + for b.iter_bytes(true) |bytes| { + s.input(transmute_for_stage0(bytes)); + } + for c.iter_bytes(true) |bytes| { + s.input(transmute_for_stage0(bytes)); + } + for d.iter_bytes(true) |bytes| { + s.input(transmute_for_stage0(bytes)); + } + for e.iter_bytes(true) |bytes| { + s.input(transmute_for_stage0(bytes)); + } s.result_u64() } -// Implement State as SipState - -pub type State = SipState; - -#[inline(always)] -pub fn State(k0: u64, k1: u64) -> State { - SipState(k0, k1) -} - #[inline(always)] pub fn default_state() -> State { - State(0,0) + State::new(0, 0) } struct SipState { k0: u64, k1: u64, - mut length: uint, // how many bytes we've processed - mut v0: u64, // hash state - mut v1: u64, - mut v2: u64, - mut v3: u64, - mut tail: [u8, ..8], // unprocessed bytes - mut ntail: uint, // how many bytes in tail are valid + length: uint, // how many bytes we've processed + v0: u64, // hash state + v1: u64, + v2: u64, + v3: u64, + tail: [u8, ..8], // unprocessed bytes + ntail: uint, // how many bytes in tail are valid } -#[inline(always)] -fn SipState(key0: u64, key1: u64) -> SipState { - let state = SipState { - k0 : key0, - k1 : key1, - mut length : 0u, - mut v0 : 0u64, - mut v1 : 0u64, - mut v2 : 0u64, - mut v3 : 0u64, - mut tail : [0u8,0,0,0,0,0,0,0], - mut ntail : 0u, - }; - (&state).reset(); - state +impl SipState { + #[inline(always)] + fn new(key0: u64, key1: u64) -> SipState { + let mut state = SipState { + k0: key0, + k1: key1, + length: 0, + v0: 0, + v1: 0, + v2: 0, + v3: 0, + tail: [ 0, 0, 0, 0, 0, 0, 0, 0 ], + ntail: 0, + }; + state.reset(); + state + } } // sadly, these macro definitions can't appear later, @@ -207,12 +257,10 @@ macro_rules! compress ( ) -impl io::Writer for SipState { - +impl Writer for SipState { // Methods for io::writer #[inline(always)] - fn write(&self, msg: &const [u8]) { - + fn write(&mut self, msg: &[u8]) { let length = msg.len(); self.length += length; @@ -272,29 +320,19 @@ impl io::Writer for SipState { self.ntail = left; } - fn seek(&self, _x: int, _s: io::SeekStyle) { - fail!(); - } - fn tell(&self) -> uint { - self.length - } - fn flush(&self) -> int { - 0 - } - fn get_type(&self) -> io::WriterType { - io::File + fn flush(&mut self) { + // No-op } } impl Streaming for SipState { - #[inline(always)] - fn input(&self, buf: &const [u8]) { + fn input(&mut self, buf: &[u8]) { self.write(buf); } #[inline(always)] - fn result_u64(&self) -> u64 { + fn result_u64(&mut self) -> u64 { let mut v0 = self.v0; let mut v1 = self.v1; let mut v2 = self.v2; @@ -324,7 +362,7 @@ impl Streaming for SipState { return (v0 ^ v1 ^ v2 ^ v3); } - fn result_bytes(&self) -> ~[u8] { + fn result_bytes(&mut self) -> ~[u8] { let h = self.result_u64(); ~[(h >> 0) as u8, (h >> 8) as u8, @@ -337,7 +375,7 @@ impl Streaming for SipState { ] } - fn result_str(&self) -> ~str { + fn result_str(&mut self) -> ~str { let r = self.result_bytes(); let mut s = ~""; for vec::each(r) |b| { @@ -347,7 +385,7 @@ impl Streaming for SipState { } #[inline(always)] - fn reset(&self) { + fn reset(&mut self) { self.length = 0; self.v0 = self.k0 ^ 0x736f6d6570736575; self.v1 = self.k1 ^ 0x646f72616e646f6d; @@ -529,4 +567,4 @@ mod tests { val & !(0xff << (byte * 8)) } } -} \ No newline at end of file +} diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index c34c7fe303ee2..3b5c90ec1f964 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -22,9 +22,9 @@ use util::ppaux; use core::hash::Streaming; use core::hash; -use core::io::WriterUtil; use core::libc::{c_int, c_uint}; use core::os::consts::{macos, freebsd, linux, android, win32}; +use core::rt::io::Writer; use core::run; use syntax::ast; use syntax::ast_map::{path, path_mod, path_name}; @@ -41,6 +41,11 @@ pub enum output_type { output_type_exe, } +fn write_string(writer: &mut W, string: &str) { + let buffer = str::as_bytes_slice(string); + writer.write(buffer); +} + pub fn llvm_err(sess: Session, msg: ~str) -> ! { unsafe { let cstr = llvm::LLVMRustGetLastError(); @@ -458,9 +463,11 @@ pub mod write { * */ -pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path, - symbol_hasher: &hash::State) -> LinkMeta { - +pub fn build_link_meta(sess: Session, + c: &ast::crate, + output: &Path, + symbol_hasher: &mut hash::State) + -> LinkMeta { struct ProvidedMetas { name: Option<@str>, vers: Option<@str>, @@ -498,7 +505,7 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path, } // This calculates CMH as defined above - fn crate_meta_extras_hash(symbol_hasher: &hash::State, + fn crate_meta_extras_hash(symbol_hasher: &mut hash::State, cmh_items: ~[@ast::meta_item], dep_hashes: ~[~str]) -> @str { fn len_and_str(s: &str) -> ~str { @@ -511,17 +518,17 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path, let cmh_items = attr::sort_meta_items(cmh_items); - fn hash(symbol_hasher: &hash::State, m: &@ast::meta_item) { + fn hash(symbol_hasher: &mut hash::State, m: &@ast::meta_item) { match m.node { ast::meta_name_value(key, value) => { - symbol_hasher.write_str(len_and_str(*key)); - symbol_hasher.write_str(len_and_str_lit(value)); + write_string(symbol_hasher, len_and_str(*key)); + write_string(symbol_hasher, len_and_str_lit(value)); } ast::meta_word(name) => { - symbol_hasher.write_str(len_and_str(*name)); + write_string(symbol_hasher, len_and_str(*name)); } ast::meta_list(name, ref mis) => { - symbol_hasher.write_str(len_and_str(*name)); + write_string(symbol_hasher, len_and_str(*name)); for mis.each |m_| { hash(symbol_hasher, m_); } @@ -535,7 +542,7 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path, } for dep_hashes.each |dh| { - symbol_hasher.write_str(len_and_str(*dh)); + write_string(symbol_hasher, len_and_str(*dh)); } // tjc: allocation is unfortunate; need to change core::hash @@ -596,23 +603,26 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path, } } -pub fn truncated_hash_result(symbol_hasher: &hash::State) -> ~str { +pub fn truncated_hash_result(symbol_hasher: &mut hash::State) -> ~str { symbol_hasher.result_str() } // This calculates STH for a symbol, as defined above -pub fn symbol_hash(tcx: ty::ctxt, symbol_hasher: &hash::State, t: ty::t, - link_meta: LinkMeta) -> @str { +pub fn symbol_hash(tcx: ty::ctxt, + symbol_hasher: &mut hash::State, + t: ty::t, + link_meta: LinkMeta) + -> @str { // NB: do *not* use abbrevs here as we want the symbol names // to be independent of one another in the crate. symbol_hasher.reset(); - symbol_hasher.write_str(link_meta.name); - symbol_hasher.write_str(~"-"); - symbol_hasher.write_str(link_meta.extras_hash); - symbol_hasher.write_str(~"-"); - symbol_hasher.write_str(encoder::encoded_ty(tcx, t)); + write_string(symbol_hasher, link_meta.name); + write_string(symbol_hasher, ~"-"); + write_string(symbol_hasher, link_meta.extras_hash); + write_string(symbol_hasher, ~"-"); + write_string(symbol_hasher, encoder::encoded_ty(tcx, t)); let mut hash = truncated_hash_result(symbol_hasher); // Prefix with _ so that it never blends into adjacent digits str::unshift_char(&mut hash, '_'); diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 34f798ec7a631..76ad7d7405365 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2987,9 +2987,8 @@ pub fn trans_crate(sess: session::Session, emap2: resolve::ExportMap2, maps: astencode::Maps) -> (ModuleRef, LinkMeta) { - let symbol_hasher = @hash::default_state(); - let link_meta = - link::build_link_meta(sess, crate, output, symbol_hasher); + let symbol_hasher = @mut hash::default_state(); + let link_meta = link::build_link_meta(sess, crate, output, symbol_hasher); let reachable = reachable::find_reachable( &crate.node.module, emap2, diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index b004ba9d41f34..c1309b422880a 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -207,7 +207,7 @@ pub struct CrateContext { adt_reprs: @mut HashMap, names: namegen, next_addrspace: addrspace_gen, - symbol_hasher: @hash::State, + symbol_hasher: @mut hash::State, type_hashcodes: @mut HashMap, type_short_names: @mut HashMap, all_llvm_symbols: @mut HashSet<@~str>, diff --git a/src/librustdoc/markdown_writer.rs b/src/librustdoc/markdown_writer.rs index b9a2ee7ccb7c9..fc5a9a60df290 100644 --- a/src/librustdoc/markdown_writer.rs +++ b/src/librustdoc/markdown_writer.rs @@ -230,6 +230,7 @@ pub fn future_writer_factory( let markdown_ch = markdown_ch.clone(); do task::spawn || { let (writer, future) = future_writer(); + let mut future = future; writer_ch.send(writer); let s = future.get(); markdown_ch.send((copy page, s)); diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 0762fa4ad7fd3..5e43cb4396075 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -11,6 +11,7 @@ use core::*; use core::cmp::Ord; use core::hash::Streaming; +use core::rt::io::Writer; use rustc::driver::{driver, session}; use rustc::driver::session::{lib_crate, unknown_crate}; use rustc::metadata::filesearch; @@ -367,9 +368,9 @@ pub fn error(msg: ~str) { } pub fn hash(data: ~str) -> ~str { - let hasher = &hash::default_state(); - - hasher.write_str(data); + let mut hasher = hash::default_state(); + let buffer = str::as_bytes_slice(data); + hasher.write(buffer); hasher.result_str() } From 226ee7d86f2d8eab17537b5ba3a393dfae1cf14e Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 3 May 2013 12:46:35 -0700 Subject: [PATCH 08/25] libcore: Remove mutable fields from task::spawn --- src/libcore/task/spawn.rs | 110 +++++++++++++++++++++++--------------- src/libcore/unstable.rs | 21 ++++++-- 2 files changed, 85 insertions(+), 46 deletions(-) diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 267250b3642a0..63959edb42761 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -72,6 +72,7 @@ #[doc(hidden)]; // FIXME #3538 +use cast::transmute; use cast; use cell::Cell; use container::Map; @@ -117,10 +118,10 @@ pub fn taskset_each(tasks: &TaskSet, blk: &fn(v: *rust_task) -> bool) { struct TaskGroupData { // All tasks which might kill this group. When this is empty, the group // can be "GC"ed (i.e., its link in the ancestor list can be removed). - mut members: TaskSet, + members: TaskSet, // All tasks unidirectionally supervised by (directly or transitively) // tasks in this group. - mut descendants: TaskSet, + descendants: TaskSet, } type TaskGroupArc = unstable::Exclusive>; @@ -145,11 +146,11 @@ struct AncestorNode { // Hence we assert that this counter monotonically decreases as we // approach the tail of the list. // FIXME(#3068): Make the generation counter togglable with #[cfg(debug)]. - generation: uint, - // Should really be an immutable non-option. This way appeases borrowck. - mut parent_group: Option, + generation: uint, + // Should really be a non-option. This way appeases borrowck. + parent_group: Option, // Recursive rest of the list. - mut ancestors: AncestorList, + ancestors: AncestorList, } struct AncestorList(Option>); @@ -301,22 +302,26 @@ fn each_ancestor(list: &mut AncestorList, // One of these per task. struct TCB { - me: *rust_task, + me: *rust_task, // List of tasks with whose fates this one's is intertwined. - tasks: TaskGroupArc, // 'none' means the group has failed. + tasks: TaskGroupArc, // 'none' means the group has failed. // Lists of tasks who will kill us if they fail, but whom we won't kill. - mut ancestors: AncestorList, - is_main: bool, - notifier: Option, + ancestors: AncestorList, + is_main: bool, + notifier: Option, } impl Drop for TCB { // Runs on task exit. fn finalize(&self) { unsafe { + let this: &mut TCB = transmute(self); + // If we are failing, the whole taskgroup needs to die. if rt::rust_task_is_unwinding(self.me) { - for self.notifier.each |x| { x.failed = true; } + for this.notifier.each_mut |x| { + x.failed = true; + } // Take everybody down with us. do access_group(&self.tasks) |tg| { kill_taskgroup(tg, self.me, self.is_main); @@ -331,16 +336,21 @@ impl Drop for TCB { // with our own taskgroup, so long as both happen before we die. // We remove ourself from every ancestor we can, so no cleanup; no // break. - for each_ancestor(&mut self.ancestors, None) |ancestor_group| { + for each_ancestor(&mut this.ancestors, None) |ancestor_group| { leave_taskgroup(ancestor_group, self.me, false); }; } } } -fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, - is_main: bool, notifier: Option) -> TCB { - for notifier.each |x| { x.failed = false; } +fn TCB(me: *rust_task, + tasks: TaskGroupArc, + ancestors: AncestorList, + is_main: bool, + mut notifier: Option) -> TCB { + for notifier.each_mut |x| { + x.failed = false; + } TCB { me: me, @@ -353,7 +363,7 @@ fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, struct AutoNotify { notify_chan: Chan, - mut failed: bool, + failed: bool, } impl Drop for AutoNotify { @@ -375,9 +385,12 @@ fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task, let newstate = util::replace(&mut *state, None); // If 'None', the group was failing. Can't enlist. if newstate.is_some() { - let group = newstate.unwrap(); - taskset_insert(if is_member { &mut group.members } - else { &mut group.descendants }, me); + let mut group = newstate.unwrap(); + taskset_insert(if is_member { + &mut group.members + } else { + &mut group.descendants + }, me); *state = Some(group); true } else { @@ -391,9 +404,12 @@ fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, let newstate = util::replace(&mut *state, None); // If 'None', already failing and we've already gotten a kill signal. if newstate.is_some() { - let group = newstate.unwrap(); - taskset_remove(if is_member { &mut group.members } - else { &mut group.descendants }, me); + let mut group = newstate.unwrap(); + taskset_remove(if is_member { + &mut group.members + } else { + &mut group.descendants + }, me); *state = Some(group); } } @@ -451,23 +467,30 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) /*##################################################################* * Step 1. Get spawner's taskgroup info. *##################################################################*/ - let spawner_group = match local_get(OldHandle(spawner), taskgroup_key!()) { - None => { - // Main task, doing first spawn ever. Lazily initialise here. - let mut members = new_taskset(); - taskset_insert(&mut members, spawner); - let tasks = unstable::exclusive(Some(TaskGroupData { - members: members, - descendants: new_taskset(), - })); - // Main task/group has no ancestors, no notifier, etc. - let group = - @TCB(spawner, tasks, AncestorList(None), true, None); - local_set(OldHandle(spawner), taskgroup_key!(), group); - group - } - Some(group) => group - }; + let mut spawner_group: @@mut TCB = + match local_get(OldHandle(spawner), taskgroup_key!()) { + None => { + // Main task, doing first spawn ever. Lazily initialise + // here. + let mut members = new_taskset(); + taskset_insert(&mut members, spawner); + let tasks = unstable::exclusive(Some(TaskGroupData { + members: members, + descendants: new_taskset(), + })); + // Main task/group has no ancestors, no notifier, etc. + let group = @@mut TCB(spawner, + tasks, + AncestorList(None), + true, + None); + local_set(OldHandle(spawner), taskgroup_key!(), group); + group + } + Some(group) => group + }; + let spawner_group: &mut TCB = *spawner_group; + /*##################################################################* * Step 2. Process spawn options for child. *##################################################################*/ @@ -624,8 +647,11 @@ fn spawn_raw_oldsched(opts: TaskOpts, f: ~fn()) { }; if enlist_many(child, &child_arc, &mut ancestors) { - let group = @TCB(child, child_arc, ancestors, - is_main, notifier); + let group = @@mut TCB(child, + child_arc, + ancestors, + is_main, + notifier); unsafe { local_set(OldHandle(child), taskgroup_key!(), group); } diff --git a/src/libcore/unstable.rs b/src/libcore/unstable.rs index 0b96e649178a1..7f42507bfd5f4 100644 --- a/src/libcore/unstable.rs +++ b/src/libcore/unstable.rs @@ -235,17 +235,30 @@ pub impl LittleLock { } } -struct ExData { lock: LittleLock, failed: bool, data: T, } +struct ExData { + lock: LittleLock, + failed: bool, + data: T, +} + /** * An arc over mutable data that is protected by a lock. For library use only. */ -pub struct Exclusive { x: SharedMutableState> } +pub struct Exclusive { + x: SharedMutableState> +} pub fn exclusive(user_data: T) -> Exclusive { let data = ExData { - lock: LittleLock(), failed: false, data: user_data + lock: LittleLock(), + failed: false, + data: user_data }; - Exclusive { x: unsafe { shared_mutable_state(data) } } + Exclusive { + x: unsafe { + shared_mutable_state(data) + } + } } impl Clone for Exclusive { From 803a4f45fa5b581155e638143afb97195cfa9f2e Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 3 May 2013 13:21:33 -0700 Subject: [PATCH 09/25] libcore: Remove mutable fields from the task builder API --- src/libcore/task/mod.rs | 178 ++++++++++-------------------- src/libcore/task/spawn.rs | 2 +- src/libcore/unstable/at_exit.rs | 4 +- src/libcore/unstable/weak_task.rs | 4 +- src/libstd/task_pool.rs | 4 +- src/libstd/test.rs | 9 +- src/libstd/uv_global_loop.rs | 11 +- src/libstd/uv_iotask.rs | 6 +- 8 files changed, 87 insertions(+), 131 deletions(-) diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs index fd695c16ea7cb..248898001750f 100644 --- a/src/libcore/task/mod.rs +++ b/src/libcore/task/mod.rs @@ -156,7 +156,7 @@ pub struct SchedOpts { pub struct TaskOpts { linked: bool, supervised: bool, - mut notify_chan: Option>, + notify_chan: Option>, sched: SchedOpts } @@ -176,9 +176,9 @@ pub struct TaskOpts { // FIXME (#3724): Replace the 'consumed' bit with move mode on self pub struct TaskBuilder { opts: TaskOpts, - mut gen_body: Option<~fn(v: ~fn()) -> ~fn()>, + gen_body: Option<~fn(v: ~fn()) -> ~fn()>, can_not_copy: Option, - mut consumed: bool, + consumed: bool, } /** @@ -191,13 +191,13 @@ pub fn task() -> TaskBuilder { opts: default_task_opts(), gen_body: None, can_not_copy: None, - mut consumed: false, + consumed: false, } } #[doc(hidden)] // FIXME #3538 priv impl TaskBuilder { - fn consume(&self) -> TaskBuilder { + fn consume(&mut self) -> TaskBuilder { if self.consumed { fail!(~"Cannot copy a task_builder"); // Fake move mode on self } @@ -219,57 +219,23 @@ priv impl TaskBuilder { } pub impl TaskBuilder { - /** - * Decouple the child task's failure from the parent's. If either fails, - * the other will not be killed. - */ - fn unlinked(&self) -> TaskBuilder { - let notify_chan = replace(&mut self.opts.notify_chan, None); - TaskBuilder { - opts: TaskOpts { - linked: false, - supervised: self.opts.supervised, - notify_chan: notify_chan, - sched: self.opts.sched - }, - can_not_copy: None, - .. self.consume() - } + /// Decouple the child task's failure from the parent's. If either fails, + /// the other will not be killed. + fn unlinked(&mut self) { + self.opts.linked = false; } - /** - * Unidirectionally link the child task's failure with the parent's. The - * child's failure will not kill the parent, but the parent's will kill - * the child. - */ - fn supervised(&self) -> TaskBuilder { - let notify_chan = replace(&mut self.opts.notify_chan, None); - TaskBuilder { - opts: TaskOpts { - linked: false, - supervised: true, - notify_chan: notify_chan, - sched: self.opts.sched - }, - can_not_copy: None, - .. self.consume() - } + + /// Unidirectionally link the child task's failure with the parent's. The + /// child's failure will not kill the parent, but the parent's will kill + /// the child. + fn supervised(&mut self) { + self.opts.supervised = true; } - /** - * Link the child task's and parent task's failures. If either fails, the - * other will be killed. - */ - fn linked(&self) -> TaskBuilder { - let notify_chan = replace(&mut self.opts.notify_chan, None); - TaskBuilder { - opts: TaskOpts { - linked: true, - supervised: false, - notify_chan: notify_chan, - sched: self.opts.sched - }, - can_not_copy: None, - .. self.consume() - } + + /// Link the child task's and parent task's failures. If either fails, the + /// other will be killed. + fn linked(&mut self) { + self.opts.linked = true; } /** @@ -289,7 +255,7 @@ pub impl TaskBuilder { * # Failure * Fails if a future_result was already set for this task. */ - fn future_result(&self, blk: &fn(v: Port)) -> TaskBuilder { + fn future_result(&mut self, blk: &fn(v: Port)) { // FIXME (#3725): Once linked failure and notification are // handled in the library, I can imagine implementing this by just // registering an arbitrary number of task::on_exit handlers and @@ -305,30 +271,12 @@ pub impl TaskBuilder { blk(notify_pipe_po); // Reconfigure self to use a notify channel. - TaskBuilder { - opts: TaskOpts { - linked: self.opts.linked, - supervised: self.opts.supervised, - notify_chan: Some(notify_pipe_ch), - sched: self.opts.sched - }, - can_not_copy: None, - .. self.consume() - } + self.opts.notify_chan = Some(notify_pipe_ch); } + /// Configure a custom scheduler mode for the task. - fn sched_mode(&self, mode: SchedMode) -> TaskBuilder { - let notify_chan = replace(&mut self.opts.notify_chan, None); - TaskBuilder { - opts: TaskOpts { - linked: self.opts.linked, - supervised: self.opts.supervised, - notify_chan: notify_chan, - sched: SchedOpts { mode: mode, foreign_stack_size: None} - }, - can_not_copy: None, - .. self.consume() - } + fn sched_mode(&mut self, mode: SchedMode) { + self.opts.sched.mode = mode; } /** @@ -343,7 +291,7 @@ pub impl TaskBuilder { * generator by applying the task body which results from the * existing body generator to the new body generator. */ - fn add_wrapper(&self, wrapper: ~fn(v: ~fn()) -> ~fn()) -> TaskBuilder { + fn add_wrapper(&mut self, wrapper: ~fn(v: ~fn()) -> ~fn()) { let prev_gen_body = replace(&mut self.gen_body, None); let prev_gen_body = match prev_gen_body { Some(gen) => gen, @@ -360,18 +308,7 @@ pub impl TaskBuilder { }; f }; - let notify_chan = replace(&mut self.opts.notify_chan, None); - TaskBuilder { - opts: TaskOpts { - linked: self.opts.linked, - supervised: self.opts.supervised, - notify_chan: notify_chan, - sched: self.opts.sched - }, - gen_body: Some(next_gen_body), - can_not_copy: None, - .. self.consume() - } + self.gen_body = Some(next_gen_body); } /** @@ -386,7 +323,7 @@ pub impl TaskBuilder { * When spawning into a new scheduler, the number of threads requested * must be greater than zero. */ - fn spawn(&self, f: ~fn()) { + fn spawn(&mut self, f: ~fn()) { let gen_body = replace(&mut self.gen_body, None); let notify_chan = replace(&mut self.opts.notify_chan, None); let x = self.consume(); @@ -406,8 +343,9 @@ pub impl TaskBuilder { }; spawn::spawn_raw(opts, f); } + /// Runs a task, while transfering ownership of one argument to the child. - fn spawn_with(&self, arg: A, f: ~fn(v: A)) { + fn spawn_with(&mut self, arg: A, f: ~fn(v: A)) { let arg = Cell(arg); do self.spawn { f(arg.take()); @@ -427,16 +365,16 @@ pub impl TaskBuilder { * # Failure * Fails if a future_result was already set for this task. */ - fn try(&self, f: ~fn() -> T) -> Result { + fn try(&mut self, f: ~fn() -> T) -> Result { let (po, ch) = stream::(); let mut result = None; - let fr_task_builder = self.future_result(|+r| { - result = Some(r); - }); - do fr_task_builder.spawn || { + self.future_result(|+r| { result = Some(r); }); + + do self.spawn { ch.send(f()); } + match result.unwrap().recv() { Success => result::Ok(po.recv()), Failure => result::Err(()) @@ -468,26 +406,23 @@ pub fn default_task_opts() -> TaskOpts { /* Spawn convenience functions */ +/// Creates and executes a new child task +/// +/// Sets up a new task with its own call stack and schedules it to run +/// the provided unique closure. +/// +/// This function is equivalent to `task().spawn(f)`. pub fn spawn(f: ~fn()) { - /*! - * Creates and executes a new child task - * - * Sets up a new task with its own call stack and schedules it to run - * the provided unique closure. - * - * This function is equivalent to `task().spawn(f)`. - */ - - task().spawn(f) + let mut task = task(); + task.spawn(f) } +/// Creates a child task unlinked from the current one. If either this +/// task or the child task fails, the other will not be killed. pub fn spawn_unlinked(f: ~fn()) { - /*! - * Creates a child task unlinked from the current one. If either this - * task or the child task fails, the other will not be killed. - */ - - task().unlinked().spawn(f) + let mut task = task(); + task.unlinked(); + task.spawn(f) } pub fn spawn_supervised(f: ~fn()) { @@ -497,7 +432,9 @@ pub fn spawn_supervised(f: ~fn()) { * the child will be killed. */ - task().supervised().spawn(f) + let mut task = task(); + task.supervised(); + task.spawn(f) } pub fn spawn_with(arg: A, f: ~fn(v: A)) { @@ -511,7 +448,8 @@ pub fn spawn_with(arg: A, f: ~fn(v: A)) { * This function is equivalent to `task().spawn_with(arg, f)`. */ - task().spawn_with(arg, f) + let mut task = task(); + task.spawn_with(arg, f) } pub fn spawn_sched(mode: SchedMode, f: ~fn()) { @@ -527,7 +465,9 @@ pub fn spawn_sched(mode: SchedMode, f: ~fn()) { * greater than zero. */ - task().sched_mode(mode).spawn(f) + let mut task = task(); + task.sched_mode(mode); + task.spawn(f) } pub fn try(f: ~fn() -> T) -> Result { @@ -538,7 +478,9 @@ pub fn try(f: ~fn() -> T) -> Result { * This is equivalent to task().supervised().try. */ - task().supervised().try(f) + let mut task = task(); + task.supervised(); + task.try(f) } @@ -822,7 +764,7 @@ fn test_run_basic() { #[cfg(test)] struct Wrapper { - mut f: Option> + f: Option> } #[test] diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 63959edb42761..19c417dfdfc95 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -580,7 +580,7 @@ fn spawn_raw_newsched(_opts: TaskOpts, f: ~fn()) { sched.schedule_new_task(task); } -fn spawn_raw_oldsched(opts: TaskOpts, f: ~fn()) { +fn spawn_raw_oldsched(mut opts: TaskOpts, f: ~fn()) { let (child_tg, ancestors, is_main) = gen_child_taskgroup(opts.linked, opts.supervised); diff --git a/src/libcore/unstable/at_exit.rs b/src/libcore/unstable/at_exit.rs index c9cd2f61e5c8a..39c930d415f1c 100644 --- a/src/libcore/unstable/at_exit.rs +++ b/src/libcore/unstable/at_exit.rs @@ -70,7 +70,9 @@ fn exit_runner(exit_fns: *ExitFunctions) { while !exit_fns_vec.is_empty() { match exit_fns_vec.pop() { ~f => { - task::task().supervised().spawn(f); + let mut task = task::task(); + task.supervised(); + task.spawn(f); } } } diff --git a/src/libcore/unstable/weak_task.rs b/src/libcore/unstable/weak_task.rs index 6edbdcb51b0cb..381083e6031b4 100644 --- a/src/libcore/unstable/weak_task.rs +++ b/src/libcore/unstable/weak_task.rs @@ -72,7 +72,9 @@ fn create_global_service() -> ~WeakTaskService { let chan = SharedChan::new(chan); let chan_clone = chan.clone(); - do task().unlinked().spawn { + let mut task = task(); + task.unlinked(); + do task.spawn { debug!("running global weak task service"); let port = Cell(port.take()); do (|| { diff --git a/src/libstd/task_pool.rs b/src/libstd/task_pool.rs index 661247df1c144..0c52e1ff80e21 100644 --- a/src/libstd/task_pool.rs +++ b/src/libstd/task_pool.rs @@ -70,7 +70,9 @@ pub impl TaskPool { task::spawn(task_body); } Some(sched_mode) => { - task::task().sched_mode(sched_mode).spawn(task_body); + let mut task = task::task(); + task.sched_mode(sched_mode); + task.spawn(task_body); } } diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 7c0673a280bd8..b3523b8ad8019 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -556,9 +556,12 @@ pub fn run_test(force_ignore: bool, let testfn_cell = ::core::cell::Cell(testfn); do task::spawn { let mut result_future = None; // task::future_result(builder); - task::task().unlinked().future_result(|+r| { - result_future = Some(r); - }).spawn(testfn_cell.take()); + + let mut task = task::task(); + task.unlinked(); + task.future_result(|+r| { result_future = Some(r) }); + task.spawn(testfn_cell.take()); + let task_result = result_future.unwrap().recv(); let test_result = calc_result(&desc, task_result == task::Success); diff --git a/src/libstd/uv_global_loop.rs b/src/libstd/uv_global_loop.rs index e49cee434f81f..e1b7eb6150525 100644 --- a/src/libstd/uv_global_loop.rs +++ b/src/libstd/uv_global_loop.rs @@ -62,7 +62,9 @@ fn get_monitor_task_gl() -> IoTask { } }; if installed { - do task().unlinked().spawn() { + let mut task = task(); + task.unlinked(); + do task.spawn { unsafe { debug!("global monitor task starting"); // As a weak task the runtime will notify us @@ -88,7 +90,9 @@ fn get_monitor_task_gl() -> IoTask { } fn spawn_loop() -> IoTask { - let builder = do task().add_wrapper |task_body| { + let mut builder = task(); + + do builder.add_wrapper |task_body| { let result: ~fn() = || { // The I/O loop task also needs to be weak so it doesn't keep // the runtime alive @@ -107,7 +111,8 @@ fn spawn_loop() -> IoTask { }; result }; - let builder = builder.unlinked(); + + builder.unlinked(); spawn_iotask(builder) } diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index e19010e8552a2..83e95a6e1993a 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -36,11 +36,11 @@ impl Clone for IoTask { } } -pub fn spawn_iotask(task: task::TaskBuilder) -> IoTask { - +pub fn spawn_iotask(mut task: task::TaskBuilder) -> IoTask { let (iotask_port, iotask_chan) = stream(); - do task.sched_mode(task::SingleThreaded).spawn { + task.sched_mode(task::SingleThreaded); + do task.spawn { debug!("entering libuv task"); run_loop(&iotask_chan); debug!("libuv task exiting"); From 6a44482b175a5486039fd5f2fd32f1051ce80e50 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 3 May 2013 14:20:34 -0700 Subject: [PATCH 10/25] libcore: Remove mutable fields from pipes --- src/libcore/comm.rs | 94 +++++++------ src/libcore/pipes.rs | 317 +++++++++++++++++++++++-------------------- src/libstd/comm.rs | 2 +- src/libstd/timer.rs | 35 +++-- 4 files changed, 246 insertions(+), 202 deletions(-) diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index d075ff08bb7eb..56c301cd1c75a 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -12,6 +12,7 @@ Message passing */ +use cast::transmute; use cast; use either::{Either, Left, Right}; use kinds::Owned; @@ -192,9 +193,9 @@ impl Peekable for Port { fn peek(&self) -> bool { let mut endp = None; endp <-> self.endp; - let peek = match &endp { - &Some(ref endp) => peek(endp), - &None => fail!(~"peeking empty stream") + let peek = match endp { + Some(ref mut endp) => peek(endp), + None => fail!(~"peeking empty stream") }; self.endp <-> endp; peek @@ -202,10 +203,10 @@ impl Peekable for Port { } impl Selectable for Port { - fn header(&self) -> *PacketHeader { + fn header(&mut self) -> *mut PacketHeader { unsafe { match self.endp { - Some(ref endp) => endp.header(), + Some(ref mut endp) => endp.header(), None => fail!(~"peeking empty stream") } } @@ -327,23 +328,20 @@ impl ::clone::Clone for SharedChan { #[allow(non_camel_case_types)] pub mod oneshot { priv use core::kinds::Owned; - use ptr::to_unsafe_ptr; + use ptr::to_mut_unsafe_ptr; pub fn init() -> (client::Oneshot, server::Oneshot) { pub use core::pipes::HasBuffer; - let buffer = - ~::core::pipes::Buffer{ + let mut buffer = ~::core::pipes::Buffer { header: ::core::pipes::BufferHeader(), - data: __Buffer{ + data: __Buffer { Oneshot: ::core::pipes::mk_packet::>() }, }; do ::core::pipes::entangle_buffer(buffer) |buffer, data| { - { - data.Oneshot.set_buffer(buffer); - to_unsafe_ptr(&data.Oneshot) - } + data.Oneshot.set_buffer(buffer); + to_mut_unsafe_ptr(&mut data.Oneshot) } } #[allow(non_camel_case_types)] @@ -497,48 +495,66 @@ pub fn try_send_one(chan: ChanOne, data: T) -> bool { /// Returns the index of an endpoint that is ready to receive. -pub fn selecti(endpoints: &[T]) -> uint { +pub fn selecti(endpoints: &mut [T]) -> uint { wait_many(endpoints) } /// Returns 0 or 1 depending on which endpoint is ready to receive -pub fn select2i(a: &A, b: &B) -> - Either<(), ()> { - match wait_many([a.header(), b.header()]) { - 0 => Left(()), - 1 => Right(()), - _ => fail!(~"wait returned unexpected index") +pub fn select2i(a: &mut A, b: &mut B) + -> Either<(), ()> { + let mut endpoints = [ a.header(), b.header() ]; + match wait_many(endpoints) { + 0 => Left(()), + 1 => Right(()), + _ => fail!(~"wait returned unexpected index"), } } /// Receive a message from one of two endpoints. pub trait Select2 { /// Receive a message or return `None` if a connection closes. - fn try_select(&self) -> Either, Option>; + fn try_select(&mut self) -> Either, Option>; /// Receive a message or fail if a connection closes. - fn select(&self) -> Either; + fn select(&mut self) -> Either; } -impl, - Right: Selectable + GenericPort> - Select2 for (Left, Right) { - - fn select(&self) -> Either { - match *self { - (ref lp, ref rp) => match select2i(lp, rp) { - Left(()) => Left (lp.recv()), - Right(()) => Right(rp.recv()) - } +impl, + Right:Selectable + GenericPort> + Select2 + for (Left, Right) { + fn select(&mut self) -> Either { + // XXX: Bad borrow check workaround. + unsafe { + let this: &(Left, Right) = transmute(self); + match *this { + (ref lp, ref rp) => { + let lp: &mut Left = transmute(lp); + let rp: &mut Right = transmute(rp); + match select2i(lp, rp) { + Left(()) => Left(lp.recv()), + Right(()) => Right(rp.recv()), + } + } + } } } - fn try_select(&self) -> Either, Option> { - match *self { - (ref lp, ref rp) => match select2i(lp, rp) { - Left(()) => Left (lp.try_recv()), - Right(()) => Right(rp.try_recv()) - } + fn try_select(&mut self) -> Either, Option> { + // XXX: Bad borrow check workaround. + unsafe { + let this: &(Left, Right) = transmute(self); + match *this { + (ref lp, ref rp) => { + let lp: &mut Left = transmute(lp); + let rp: &mut Right = transmute(rp); + match select2i(lp, rp) { + Left(()) => Left (lp.try_recv()), + Right(()) => Right(rp.try_recv()), + } + } + } } } } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 19674900f908e..1fda5a97a375a 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -111,7 +111,7 @@ enum State { pub struct BufferHeader { // Tracks whether this buffer needs to be freed. We can probably // get away with restricting it to 0 or 1, if we're careful. - mut ref_count: int, + ref_count: int, // We may want a drop, and to be careful about stringing this // thing along. @@ -130,12 +130,12 @@ pub struct Buffer { } pub struct PacketHeader { - mut state: State, - mut blocked_task: *rust_task, + state: State, + blocked_task: *rust_task, // This is a transmute_copy of a ~buffer, that can also be cast // to a buffer_header if need be. - mut buffer: *libc::c_void, + buffer: *libc::c_void, } pub fn PacketHeader() -> PacketHeader { @@ -148,14 +148,14 @@ pub fn PacketHeader() -> PacketHeader { pub impl PacketHeader { // Returns the old state. - unsafe fn mark_blocked(&self, this: *rust_task) -> State { + unsafe fn mark_blocked(&mut self, this: *rust_task) -> State { rustrt::rust_task_ref(this); let old_task = swap_task(&mut self.blocked_task, this); assert!(old_task.is_null()); swap_state_acq(&mut self.state, Blocked) } - unsafe fn unblock(&self) { + unsafe fn unblock(&mut self) { let old_task = swap_task(&mut self.blocked_task, ptr::null()); if !old_task.is_null() { rustrt::rust_task_deref(old_task) @@ -169,13 +169,13 @@ pub impl PacketHeader { // unsafe because this can do weird things to the space/time // continuum. It ends making multiple unique pointers to the same - // thing. You'll proobably want to forget them when you're done. - unsafe fn buf_header(&self) -> ~BufferHeader { + // thing. You'll probably want to forget them when you're done. + unsafe fn buf_header(&mut self) -> ~BufferHeader { assert!(self.buffer.is_not_null()); transmute_copy(&self.buffer) } - fn set_buffer(&self, b: ~Buffer) { + fn set_buffer(&mut self, b: ~Buffer) { unsafe { self.buffer = transmute_copy(&b); } @@ -184,15 +184,15 @@ pub impl PacketHeader { pub struct Packet { header: PacketHeader, - mut payload: Option, + payload: Option, } pub trait HasBuffer { - fn set_buffer(&self, b: *libc::c_void); + fn set_buffer(&mut self, b: *libc::c_void); } impl HasBuffer for Packet { - fn set_buffer(&self, b: *libc::c_void) { + fn set_buffer(&mut self, b: *libc::c_void) { self.header.buffer = b; } } @@ -204,7 +204,7 @@ pub fn mk_packet() -> Packet { } } fn unibuffer() -> ~Buffer> { - let b = ~Buffer { + let mut b = ~Buffer { header: BufferHeader(), data: Packet { header: PacketHeader(), @@ -218,22 +218,25 @@ fn unibuffer() -> ~Buffer> { b } -pub fn packet() -> *Packet { - let b = unibuffer(); - let p = ptr::to_unsafe_ptr(&(b.data)); +pub fn packet() -> *mut Packet { + let mut b = unibuffer(); + let p = ptr::to_mut_unsafe_ptr(&mut b.data); // We'll take over memory management from here. - unsafe { forget(b) } + unsafe { + forget(b); + } p } pub fn entangle_buffer( - buffer: ~Buffer, - init: &fn(*libc::c_void, x: &T) -> *Packet) - -> (SendPacketBuffered, RecvPacketBuffered) -{ - let p = init(unsafe { transmute_copy(&buffer) }, &buffer.data); - unsafe { forget(buffer) } - (SendPacketBuffered(p), RecvPacketBuffered(p)) + mut buffer: ~Buffer, + init: &fn(*libc::c_void, x: &mut T) -> *mut Packet) + -> (SendPacketBuffered, RecvPacketBuffered) { + unsafe { + let p = init(transmute_copy(&buffer), &mut buffer.data); + forget(buffer); + (SendPacketBuffered(p), RecvPacketBuffered(p)) + } } pub fn swap_task(dst: &mut *rust_task, src: *rust_task) -> *rust_task { @@ -292,7 +295,7 @@ fn swap_state_rel(dst: &mut State, src: State) -> State { } } -pub unsafe fn get_buffer(p: *PacketHeader) -> ~Buffer { +pub unsafe fn get_buffer(p: *mut PacketHeader) -> ~Buffer { transmute((*p).buf_header()) } @@ -306,10 +309,14 @@ struct BufferResource { impl Drop for BufferResource { fn finalize(&self) { unsafe { - let b = move_it!(self.buffer); + let this: &mut BufferResource = transmute(self); + + let mut b = move_it!(this.buffer); //let p = ptr::to_unsafe_ptr(*b); //error!("drop %?", p); - let old_count = intrinsics::atomic_xsub_rel(&mut b.header.ref_count, 1); + let old_count = intrinsics::atomic_xsub_rel( + &mut b.header.ref_count, + 1); //let old_count = atomic_xchng_rel(b.header.ref_count, 0); if old_count == 1 { // The new count is 0. @@ -323,10 +330,12 @@ impl Drop for BufferResource { } } -fn BufferResource(b: ~Buffer) -> BufferResource { +fn BufferResource(mut b: ~Buffer) -> BufferResource { //let p = ptr::to_unsafe_ptr(*b); //error!("take %?", p); - unsafe { intrinsics::atomic_xadd_acq(&mut b.header.ref_count, 1) }; + unsafe { + intrinsics::atomic_xadd_acq(&mut b.header.ref_count, 1); + } BufferResource { // tjc: ???? @@ -334,10 +343,12 @@ fn BufferResource(b: ~Buffer) -> BufferResource { } } -pub fn send(p: SendPacketBuffered, payload: T) -> bool { +pub fn send(mut p: SendPacketBuffered, + payload: T) + -> bool { let header = p.header(); - let p_ = p.unwrap(); - let p = unsafe { &*p_ }; + let mut p_ = p.unwrap(); + let p = unsafe { &mut *p_ }; assert!(ptr::to_unsafe_ptr(&(p.header)) == header); assert!(p.payload.is_none()); p.payload = Some(payload); @@ -391,11 +402,12 @@ Returns `None` if the sender has closed the connection without sending a message, or `Some(T)` if a message was received. */ -pub fn try_recv(p: RecvPacketBuffered) - -> Option -{ - let p_ = p.unwrap(); - let p = unsafe { &*p_ }; +pub fn try_recv(mut p: RecvPacketBuffered) + -> Option { + let mut p_ = p.unwrap(); + let mut p = unsafe { + &mut *p_ + }; do (|| { try_recv_(p) @@ -412,7 +424,7 @@ pub fn try_recv(p: RecvPacketBuffered) } } -fn try_recv_(p: &Packet) -> Option { +fn try_recv_(p: &mut Packet) -> Option { // optimistic path match p.header.state { Full => { @@ -498,16 +510,20 @@ fn try_recv_(p: &Packet) -> Option { } /// Returns true if messages are available. -pub fn peek(p: &RecvPacketBuffered) -> bool { - match unsafe {(*p.header()).state} { - Empty | Terminated => false, - Blocked => fail!(~"peeking on blocked packet"), - Full => true +pub fn peek(p: &mut RecvPacketBuffered) -> bool { + unsafe { + match (*p.header()).state { + Empty | Terminated => false, + Blocked => fail!(~"peeking on blocked packet"), + Full => true + } } } -fn sender_terminate(p: *Packet) { - let p = unsafe { &*p }; +fn sender_terminate(p: *mut Packet) { + let p = unsafe { + &mut *p + }; match swap_state_rel(&mut p.header.state, Terminated) { Empty => { // The receiver will eventually clean up. @@ -536,8 +552,10 @@ fn sender_terminate(p: *Packet) { } } -fn receiver_terminate(p: *Packet) { - let p = unsafe { &*p }; +fn receiver_terminate(p: *mut Packet) { + let p = unsafe { + &mut *p + }; match swap_state_rel(&mut p.header.state, Terminated) { Empty => { assert!(p.header.blocked_task.is_null()); @@ -569,8 +587,10 @@ that vector. The index points to an endpoint that has either been closed by the sender or has a message waiting to be received. */ -pub fn wait_many(pkts: &[T]) -> uint { - let this = unsafe { rustrt::rust_get_task() }; +pub fn wait_many(pkts: &mut [T]) -> uint { + let this = unsafe { + rustrt::rust_get_task() + }; unsafe { rustrt::task_clear_event_reject(this); @@ -578,19 +598,19 @@ pub fn wait_many(pkts: &[T]) -> uint { let mut data_avail = false; let mut ready_packet = pkts.len(); - for pkts.eachi |i, p| { + for vec::eachi_mut(pkts) |i, p| { unsafe { - let p = &*p.header(); + let p = &mut *p.header(); let old = p.mark_blocked(this); match old { - Full | Terminated => { - data_avail = true; - ready_packet = i; - (*p).state = old; - break; - } - Blocked => fail!(~"blocking on blocked packet"), - Empty => () + Full | Terminated => { + data_avail = true; + ready_packet = i; + (*p).state = old; + break; + } + Blocked => fail!(~"blocking on blocked packet"), + Empty => () } } } @@ -598,7 +618,14 @@ pub fn wait_many(pkts: &[T]) -> uint { while !data_avail { debug!("sleeping on %? packets", pkts.len()); let event = wait_event(this) as *PacketHeader; - let pos = vec::position(pkts, |p| p.header() == event); + + let mut pos = None; + for vec::eachi_mut(pkts) |i, p| { + if p.header() == event { + pos = Some(i); + break; + } + }; match pos { Some(i) => { @@ -609,11 +636,15 @@ pub fn wait_many(pkts: &[T]) -> uint { } } - debug!("%?", pkts[ready_packet]); + debug!("%?", &mut pkts[ready_packet]); - for pkts.each |p| { unsafe{ (*p.header()).unblock()} } + for vec::each_mut(pkts) |p| { + unsafe { + (*p.header()).unblock() + } + } - debug!("%?, %?", ready_packet, pkts[ready_packet]); + debug!("%?, %?", ready_packet, &mut pkts[ready_packet]); unsafe { assert!((*pkts[ready_packet].header()).state == Full @@ -629,65 +660,58 @@ message. */ pub type SendPacket = SendPacketBuffered>; -pub fn SendPacket(p: *Packet) -> SendPacket { +pub fn SendPacket(p: *mut Packet) -> SendPacket { SendPacketBuffered(p) } pub struct SendPacketBuffered { - mut p: Option<*Packet>, - mut buffer: Option>, + p: Option<*mut Packet>, + buffer: Option>, } #[unsafe_destructor] impl Drop for SendPacketBuffered { fn finalize(&self) { - //if self.p != none { - // debug!("drop send %?", option::get(self.p)); - //} - if self.p != None { - let mut p = None; - p <-> self.p; - sender_terminate(p.unwrap()) + unsafe { + let this: &mut SendPacketBuffered = transmute(self); + if this.p != None { + let mut p = None; + p <-> this.p; + sender_terminate(p.unwrap()) + } } - //unsafe { error!("send_drop: %?", - // if self.buffer == none { - // "none" - // } else { "some" }); } } } -pub fn SendPacketBuffered(p: *Packet) - -> SendPacketBuffered { - //debug!("take send %?", p); +pub fn SendPacketBuffered(p: *mut Packet) + -> SendPacketBuffered { SendPacketBuffered { p: Some(p), buffer: unsafe { - Some(BufferResource( - get_buffer(ptr::to_unsafe_ptr(&((*p).header))))) + Some(BufferResource(get_buffer(&mut (*p).header))) } } } pub impl SendPacketBuffered { - fn unwrap(&self) -> *Packet { + fn unwrap(&mut self) -> *mut Packet { let mut p = None; p <-> self.p; p.unwrap() } - fn header(&self) -> *PacketHeader { + fn header(&mut self) -> *mut PacketHeader { match self.p { - Some(packet) => unsafe { - let packet = &*packet; - let header = ptr::to_unsafe_ptr(&(packet.header)); - //forget(packet); - header - }, - None => fail!(~"packet already consumed") + Some(packet) => unsafe { + let packet = &mut *packet; + let header = ptr::to_mut_unsafe_ptr(&mut packet.header); + header + }, + None => fail!(~"packet already consumed") } } - fn reuse_buffer(&self) -> BufferResource { + fn reuse_buffer(&mut self) -> BufferResource { //error!("send reuse_buffer"); let mut tmp = None; tmp <-> self.buffer; @@ -699,41 +723,37 @@ pub impl SendPacketBuffered { /// message. pub type RecvPacket = RecvPacketBuffered>; -pub fn RecvPacket(p: *Packet) -> RecvPacket { +pub fn RecvPacket(p: *mut Packet) -> RecvPacket { RecvPacketBuffered(p) } + pub struct RecvPacketBuffered { - mut p: Option<*Packet>, - mut buffer: Option>, + p: Option<*mut Packet>, + buffer: Option>, } #[unsafe_destructor] impl Drop for RecvPacketBuffered { fn finalize(&self) { - //if self.p != none { - // debug!("drop recv %?", option::get(self.p)); - //} - if self.p != None { - let mut p = None; - p <-> self.p; - receiver_terminate(p.unwrap()) + unsafe { + let this: &mut RecvPacketBuffered = transmute(self); + if this.p != None { + let mut p = None; + p <-> this.p; + receiver_terminate(p.unwrap()) + } } - //unsafe { error!("recv_drop: %?", - // if self.buffer == none { - // "none" - // } else { "some" }); } } } pub impl RecvPacketBuffered { - fn unwrap(&self) -> *Packet { + fn unwrap(&mut self) -> *mut Packet { let mut p = None; p <-> self.p; p.unwrap() } - fn reuse_buffer(&self) -> BufferResource { - //error!("recv reuse_buffer"); + fn reuse_buffer(&mut self) -> BufferResource { let mut tmp = None; tmp <-> self.buffer; tmp.unwrap() @@ -741,27 +761,24 @@ pub impl RecvPacketBuffered { } impl Selectable for RecvPacketBuffered { - fn header(&self) -> *PacketHeader { + fn header(&mut self) -> *mut PacketHeader { match self.p { - Some(packet) => unsafe { - let packet = &*packet; - let header = ptr::to_unsafe_ptr(&(packet.header)); - //forget(packet); - header - }, - None => fail!(~"packet already consumed") + Some(packet) => unsafe { + let packet = &mut *packet; + let header = ptr::to_mut_unsafe_ptr(&mut packet.header); + header + }, + None => fail!(~"packet already consumed") } } } -pub fn RecvPacketBuffered(p: *Packet) - -> RecvPacketBuffered { - //debug!("take recv %?", p); +pub fn RecvPacketBuffered(p: *mut Packet) + -> RecvPacketBuffered { RecvPacketBuffered { p: Some(p), buffer: unsafe { - Some(BufferResource( - get_buffer(ptr::to_unsafe_ptr(&((*p).header))))) + Some(BufferResource(get_buffer(&mut (*p).header))) } } } @@ -800,51 +817,55 @@ this case, `select2` may return either `left` or `right`. */ pub fn select2( - a: RecvPacketBuffered, - b: RecvPacketBuffered) + mut a: RecvPacketBuffered, + mut b: RecvPacketBuffered) -> Either<(Option, RecvPacketBuffered), - (RecvPacketBuffered, Option)> -{ - let i = wait_many([a.header(), b.header()]); - + (RecvPacketBuffered, Option)> { + let mut endpoints = [ a.header(), b.header() ]; + let i = wait_many(endpoints); match i { - 0 => Left((try_recv(a), b)), - 1 => Right((a, try_recv(b))), - _ => fail!(~"select2 return an invalid packet") + 0 => Left((try_recv(a), b)), + 1 => Right((a, try_recv(b))), + _ => fail!(~"select2 return an invalid packet") } } pub trait Selectable { - fn header(&self) -> *PacketHeader; + fn header(&mut self) -> *mut PacketHeader; } -impl Selectable for *PacketHeader { - fn header(&self) -> *PacketHeader { *self } +impl Selectable for *mut PacketHeader { + fn header(&mut self) -> *mut PacketHeader { *self } } /// Returns the index of an endpoint that is ready to receive. -pub fn selecti(endpoints: &[T]) -> uint { +pub fn selecti(endpoints: &mut [T]) -> uint { wait_many(endpoints) } /// Returns 0 or 1 depending on which endpoint is ready to receive -pub fn select2i(a: &A, b: &B) -> - Either<(), ()> { - match wait_many([a.header(), b.header()]) { - 0 => Left(()), - 1 => Right(()), - _ => fail!(~"wait returned unexpected index") +pub fn select2i(a: &mut A, b: &mut B) + -> Either<(), ()> { + let mut endpoints = [ a.header(), b.header() ]; + match wait_many(endpoints) { + 0 => Left(()), + 1 => Right(()), + _ => fail!(~"wait returned unexpected index") } } -/** Waits on a set of endpoints. Returns a message, its index, and a - list of the remaining endpoints. +/// Waits on a set of endpoints. Returns a message, its index, and a +/// list of the remaining endpoints. +pub fn select(mut endpoints: ~[RecvPacketBuffered]) + -> (uint, + Option, + ~[RecvPacketBuffered]) { + let mut endpoint_headers = ~[]; + for vec::each_mut(endpoints) |endpoint| { + endpoint_headers.push(endpoint.header()); + } -*/ -pub fn select(endpoints: ~[RecvPacketBuffered]) - -> (uint, Option, ~[RecvPacketBuffered]) -{ - let ready = wait_many(endpoints.map(|p| p.header())); + let ready = wait_many(endpoint_headers); let mut remaining = endpoints; let port = remaining.swap_remove(ready); let result = try_recv(port); diff --git a/src/libstd/comm.rs b/src/libstd/comm.rs index d866ee6cedbdd..20ab2d61ecc07 100644 --- a/src/libstd/comm.rs +++ b/src/libstd/comm.rs @@ -72,7 +72,7 @@ impl Peekable for DuplexStream { } impl Selectable for DuplexStream { - fn header(&self) -> *pipes::PacketHeader { + fn header(&mut self) -> *mut pipes::PacketHeader { self.port.header() } } diff --git a/src/libstd/timer.rs b/src/libstd/timer.rs index b19b2f2889e71..76aa4d615e1dc 100644 --- a/src/libstd/timer.rs +++ b/src/libstd/timer.rs @@ -14,10 +14,11 @@ use uv; use uv::iotask; use uv::iotask::IoTask; -use core::libc; -use core::libc::c_void; use core::cast::transmute; +use core::cast; use core::comm::{stream, Chan, SharedChan, Port, select2i}; +use core::libc::c_void; +use core::libc; /** * Wait for timeout period then send provided value over a channel @@ -120,22 +121,28 @@ pub fn sleep(iotask: &IoTask, msecs: uint) { pub fn recv_timeout(iotask: &IoTask, msecs: uint, wait_po: &Port) - -> Option { - let (timeout_po, timeout_ch) = stream::<()>(); + -> Option { + let mut (timeout_po, timeout_ch) = stream::<()>(); delayed_send(iotask, msecs, &timeout_ch, ()); - // FIXME: This could be written clearer (#2618) - either::either( - |_| { - None - }, |_| { - Some(wait_po.recv()) - }, &select2i(&timeout_po, wait_po) - ) + + // XXX: Workaround due to ports and channels not being &mut. They should + // be. + unsafe { + let wait_po = cast::transmute_mut(wait_po); + + // FIXME: This could be written clearer (#2618) + either::either( + |_| { + None + }, |_| { + Some(wait_po.recv()) + }, &select2i(&mut timeout_po, wait_po) + ) + } } // INTERNAL API -extern fn delayed_send_cb(handle: *uv::ll::uv_timer_t, - status: libc::c_int) { +extern fn delayed_send_cb(handle: *uv::ll::uv_timer_t, status: libc::c_int) { unsafe { debug!( "delayed_send_cb handle %? status %?", handle, status); From 56507798d9eb7bcf95bfca15b3c6f18997adae63 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 3 May 2013 15:45:55 -0700 Subject: [PATCH 11/25] libcore: Remove mutable fields from repr --- src/libcore/repr.rs | 71 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 13 deletions(-) diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs index 3d52599325928..b75ac60ff28e2 100644 --- a/src/libcore/repr.rs +++ b/src/libcore/repr.rs @@ -144,28 +144,30 @@ enum VariantState { } pub struct ReprVisitor { - mut ptr: *c_void, - mut ptr_stk: ~[*c_void], - mut var_stk: ~[VariantState], + ptr: @mut *c_void, + ptr_stk: @mut ~[*c_void], + var_stk: @mut ~[VariantState], writer: @Writer } pub fn ReprVisitor(ptr: *c_void, writer: @Writer) -> ReprVisitor { - ReprVisitor { ptr: ptr, - ptr_stk: ~[], - var_stk: ~[], - writer: writer } + ReprVisitor { + ptr: @mut ptr, + ptr_stk: @mut ~[], + var_stk: @mut ~[], + writer: writer, + } } impl MovePtr for ReprVisitor { #[inline(always)] fn move_ptr(&self, adjustment: &fn(*c_void) -> *c_void) { - self.ptr = adjustment(self.ptr); + *self.ptr = adjustment(*self.ptr); } fn push_ptr(&self) { - self.ptr_stk.push(self.ptr); + self.ptr_stk.push(*self.ptr); } fn pop_ptr(&self) { - self.ptr = self.ptr_stk.pop(); + *self.ptr = self.ptr_stk.pop(); } } @@ -176,14 +178,14 @@ pub impl ReprVisitor { #[inline(always)] fn get(&self, f: &fn(&T)) -> bool { unsafe { - f(transmute::<*c_void,&T>(copy self.ptr)); + f(transmute::<*c_void,&T>(*self.ptr)); } true } #[inline(always)] fn visit_inner(&self, inner: *TyDesc) -> bool { - self.visit_ptr_inner(self.ptr, inner) + self.visit_ptr_inner(*self.ptr, inner) } #[inline(always)] @@ -482,8 +484,31 @@ impl TyVisitor for ReprVisitor { true } +<<<<<<< HEAD fn visit_enum_variant_field(&self, i: uint, _offset: uint, inner: *TyDesc) -> bool { match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] { +======= + #[cfg(stage0)] + fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool { + match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { + Degenerate | TagMatch => { + if i != 0 { + self.writer.write_str(", "); + } + if ! self.visit_inner(inner) { + return false; + } + } + TagMismatch => () + } + true + } + + #[cfg(not(stage0))] + fn visit_enum_variant_field(&self, i: uint, _: uint, inner: *TyDesc) + -> bool { + match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { +>>>>>>> libcore: Remove mutable fields from repr Matched => { if i != 0 { self.writer.write_str(", "); @@ -497,11 +522,31 @@ impl TyVisitor for ReprVisitor { true } +<<<<<<< HEAD +======= + #[cfg(stage0)] fn visit_leave_enum_variant(&self, _variant: uint, _disr_val: int, n_fields: uint, _name: &str) -> bool { - match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] { + match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { + Degenerate | TagMatch => { + if n_fields > 0 { + self.writer.write_char(')'); + } + } + TagMismatch => () + } + true + } + + #[cfg(not(stage0))] +>>>>>>> libcore: Remove mutable fields from repr + fn visit_leave_enum_variant(&self, _variant: uint, + _disr_val: int, + n_fields: uint, + _name: &str) -> bool { + match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { Matched => { if n_fields > 0 { self.writer.write_char(')'); From 8919f32f8320847501182e517b26b9755fc97041 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 3 May 2013 16:05:18 -0700 Subject: [PATCH 12/25] Remove mutable fields from comm by using casts. Also mark the cast in cell. --- src/libcore/comm.rs | 91 +++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 36 deletions(-) diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 56c301cd1c75a..072562233de97 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -12,7 +12,7 @@ Message passing */ -use cast::transmute; +use cast::{transmute, transmute_mut}; use cast; use either::{Either, Left, Right}; use kinds::Owned; @@ -119,13 +119,15 @@ pub mod streamp { } /// An endpoint that can send many messages. +#[unsafe_mut_field(endp)] pub struct Chan { - mut endp: Option> + endp: Option> } /// An endpoint that can receive many messages. +#[unsafe_mut_field(endp)] pub struct Port { - mut endp: Option>, + endp: Option>, } /** Creates a `(Port, Chan)` pair. @@ -136,30 +138,39 @@ These allow sending or receiving an unlimited number of messages. pub fn stream() -> (Port, Chan) { let (c, s) = streamp::init(); - (Port { endp: Some(s) }, Chan { endp: Some(c) }) + (Port { + endp: Some(s) + }, Chan { + endp: Some(c) + }) } impl GenericChan for Chan { #[inline(always)] fn send(&self, x: T) { - let mut endp = None; - endp <-> self.endp; - self.endp = Some( - streamp::client::data(endp.unwrap(), x)) + unsafe { + let mut endp = None; + let mut self_endp = transmute_mut(&self.endp); + endp <-> *self_endp; + *self_endp = Some(streamp::client::data(endp.unwrap(), x)) + } } } impl GenericSmartChan for Chan { #[inline(always)] fn try_send(&self, x: T) -> bool { - let mut endp = None; - endp <-> self.endp; - match streamp::client::try_data(endp.unwrap(), x) { - Some(next) => { - self.endp = Some(next); - true + unsafe { + let mut endp = None; + let mut self_endp = transmute_mut(&self.endp); + endp <-> *self_endp; + match streamp::client::try_data(endp.unwrap(), x) { + Some(next) => { + *self_endp = Some(next); + true + } + None => false } - None => false } } } @@ -167,23 +178,29 @@ impl GenericSmartChan for Chan { impl GenericPort for Port { #[inline(always)] fn recv(&self) -> T { - let mut endp = None; - endp <-> self.endp; - let streamp::data(x, endp) = recv(endp.unwrap()); - self.endp = Some(endp); - x + unsafe { + let mut endp = None; + let mut self_endp = transmute_mut(&self.endp); + endp <-> *self_endp; + let streamp::data(x, endp) = recv(endp.unwrap()); + *self_endp = Some(endp); + x + } } #[inline(always)] fn try_recv(&self) -> Option { - let mut endp = None; - endp <-> self.endp; - match try_recv(endp.unwrap()) { - Some(streamp::data(x, endp)) => { - self.endp = Some(endp); - Some(x) + unsafe { + let mut endp = None; + let mut self_endp = transmute_mut(&self.endp); + endp <-> *self_endp; + match try_recv(endp.unwrap()) { + Some(streamp::data(x, endp)) => { + *self_endp = Some(endp); + Some(x) + } + None => None } - None => None } } } @@ -191,14 +208,17 @@ impl GenericPort for Port { impl Peekable for Port { #[inline(always)] fn peek(&self) -> bool { - let mut endp = None; - endp <-> self.endp; - let peek = match endp { - Some(ref mut endp) => peek(endp), - None => fail!(~"peeking empty stream") - }; - self.endp <-> endp; - peek + unsafe { + let mut endp = None; + let mut self_endp = transmute_mut(&self.endp); + endp <-> *self_endp; + let peek = match endp { + Some(ref mut endp) => peek(endp), + None => fail!(~"peeking empty stream") + }; + *self_endp <-> endp; + peek + } } } @@ -219,7 +239,6 @@ pub struct PortSet { } pub impl PortSet { - fn new() -> PortSet { PortSet { ports: ~[] From d12d25534b01632f7b19fae85854032ebb1b319c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 3 May 2013 17:37:08 -0700 Subject: [PATCH 13/25] libcore: Remove more mutable fields from comm --- src/libcore/comm.rs | 50 ++++++++------- src/libcore/io.rs | 102 ++++++++++++++++++++----------- src/librustc/metadata/encoder.rs | 31 +++++----- src/libstd/io_util.rs | 4 +- 4 files changed, 114 insertions(+), 73 deletions(-) diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 072562233de97..5b2bb3a132f72 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -234,8 +234,9 @@ impl Selectable for Port { } /// Treat many ports as one. +#[unsafe_mut_field(ports)] pub struct PortSet { - mut ports: ~[Port], + ports: ~[Port], } pub impl PortSet { @@ -246,7 +247,10 @@ pub impl PortSet { } fn add(&self, port: Port) { - self.ports.push(port) + unsafe { + let self_ports = transmute_mut(&self.ports); + self_ports.push(port) + } } fn chan(&self) -> Chan { @@ -258,25 +262,28 @@ pub impl PortSet { impl GenericPort for PortSet { fn try_recv(&self) -> Option { - let mut result = None; - // we have to swap the ports array so we aren't borrowing - // aliasable mutable memory. - let mut ports = ~[]; - ports <-> self.ports; - while result.is_none() && ports.len() > 0 { - let i = wait_many(ports); - match ports[i].try_recv() { - Some(m) => { - result = Some(m); - } - None => { - // Remove this port. - let _ = ports.swap_remove(i); + unsafe { + let mut self_ports = transmute_mut(&self.ports); + let mut result = None; + // we have to swap the ports array so we aren't borrowing + // aliasable mutable memory. + let mut ports = ~[]; + ports <-> *self_ports; + while result.is_none() && ports.len() > 0 { + let i = wait_many(ports); + match ports[i].try_recv() { + Some(m) => { + result = Some(m); + } + None => { + // Remove this port. + let _ = ports.swap_remove(i); + } } } + ports <-> *self_ports; + result } - ports <-> self.ports; - result } fn recv(&self) -> T { self.try_recv().expect("port_set: endpoints closed") @@ -288,10 +295,9 @@ impl Peekable for PortSet { // It'd be nice to use self.port.each, but that version isn't // pure. for uint::range(0, vec::uniq_len(&const self.ports)) |i| { - // XXX: Botch pending demuting. - unsafe { - let port: &Port = cast::transmute(&mut self.ports[i]); - if port.peek() { return true } + let port: &Port = &self.ports[i]; + if port.peek() { + return true; } } false diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 64b69a7928b5f..63335f7e952cd 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -983,36 +983,50 @@ pub fn file_reader(path: &Path) -> Result<@Reader, ~str> { // Byte readers pub struct BytesReader<'self> { bytes: &'self [u8], - mut pos: uint + pos: @mut uint } impl<'self> Reader for BytesReader<'self> { fn read(&self, bytes: &mut [u8], len: uint) -> uint { - let count = uint::min(len, self.bytes.len() - self.pos); + let count = uint::min(len, self.bytes.len() - *self.pos); - let view = vec::slice(self.bytes, self.pos, self.bytes.len()); + let view = vec::slice(self.bytes, *self.pos, self.bytes.len()); vec::bytes::copy_memory(bytes, view, count); - self.pos += count; + *self.pos += count; count } + fn read_byte(&self) -> int { - if self.pos == self.bytes.len() { return -1; } - let b = self.bytes[self.pos]; - self.pos += 1u; - return b as int; + if *self.pos == self.bytes.len() { + return -1; + } + + let b = self.bytes[*self.pos]; + *self.pos += 1u; + b as int } - fn eof(&self) -> bool { self.pos == self.bytes.len() } + + fn eof(&self) -> bool { + *self.pos == self.bytes.len() + } + fn seek(&self, offset: int, whence: SeekStyle) { - let pos = self.pos; - self.pos = seek_in_buf(offset, pos, self.bytes.len(), whence); + let pos = *self.pos; + *self.pos = seek_in_buf(offset, pos, self.bytes.len(), whence); + } + + fn tell(&self) -> uint { + *self.pos } - fn tell(&self) -> uint { self.pos } } -pub fn with_bytes_reader(bytes: &[u8], f: &fn(@Reader) -> t) -> t { - f(@BytesReader { bytes: bytes, pos: 0u } as @Reader) +pub fn with_bytes_reader(bytes: &[u8], f: &fn(@Reader) -> T) -> T { + f(@BytesReader { + bytes: bytes, + pos: @mut 0 + } as @Reader) } pub fn with_str_reader(s: &str, f: &fn(@Reader) -> T) -> T { @@ -1498,49 +1512,67 @@ pub fn buffered_file_writer(path: &Path) -> Result<@Writer, ~str> { pub fn stdout() -> @Writer { fd_writer(libc::STDOUT_FILENO as c_int, false) } pub fn stderr() -> @Writer { fd_writer(libc::STDERR_FILENO as c_int, false) } -pub fn print(s: &str) { stdout().write_str(s); } -pub fn println(s: &str) { stdout().write_line(s); } +pub fn print(s: &str) { + stdout().write_str(s); +} + +pub fn println(s: &str) { + stdout().write_line(s); +} pub struct BytesWriter { - mut bytes: ~[u8], - mut pos: uint, + bytes: @mut ~[u8], + pos: @mut uint, } impl Writer for BytesWriter { fn write(&self, v: &[u8]) { let v_len = v.len(); - let bytes_len = vec::uniq_len(&const self.bytes); + let bytes_len = vec::uniq_len(&const *self.bytes); - let count = uint::max(bytes_len, self.pos + v_len); - vec::reserve(&mut self.bytes, count); + let count = uint::max(bytes_len, *self.pos + v_len); + vec::reserve(&mut *self.bytes, count); unsafe { - vec::raw::set_len(&mut self.bytes, count); - let view = vec::mut_slice(self.bytes, self.pos, count); + vec::raw::set_len(&mut *self.bytes, count); + let view = vec::mut_slice(*self.bytes, *self.pos, count); vec::bytes::copy_memory(view, v, v_len); } - self.pos += v_len; + *self.pos += v_len; } + fn seek(&self, offset: int, whence: SeekStyle) { - let pos = self.pos; - let len = vec::uniq_len(&const self.bytes); - self.pos = seek_in_buf(offset, pos, len, whence); + let pos = *self.pos; + let len = vec::uniq_len(&const *self.bytes); + *self.pos = seek_in_buf(offset, pos, len, whence); + } + + fn tell(&self) -> uint { + *self.pos + } + + fn flush(&self) -> int { + 0 + } + + fn get_type(&self) -> WriterType { + File } - fn tell(&self) -> uint { self.pos } - fn flush(&self) -> int { 0 } - fn get_type(&self) -> WriterType { File } } pub fn BytesWriter() -> BytesWriter { - BytesWriter { bytes: ~[], mut pos: 0u } + BytesWriter { + bytes: @mut ~[], + pos: @mut 0 + } } pub fn with_bytes_writer(f: &fn(@Writer)) -> ~[u8] { let wr = @BytesWriter(); f(wr as @Writer); - let @BytesWriter{bytes, _} = wr; - return bytes; + let @BytesWriter { bytes, _ } = wr; + copy *bytes } pub fn with_str_writer(f: &fn(@Writer)) -> ~str { @@ -1550,7 +1582,9 @@ pub fn with_str_writer(f: &fn(@Writer)) -> ~str { v.push(0); assert!(str::is_utf8(v)); - unsafe { ::cast::transmute(v) } + unsafe { + ::cast::transmute(v) + } } // Utility functions diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index ccf3ffcdfffcd..c84bebdfd39df 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -1372,41 +1372,40 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] { encode_hash(&mut ebml_w, ecx.link_meta.extras_hash); - let mut i = wr.pos; + let mut i = *wr.pos; let crate_attrs = synthesize_crate_attrs(ecx, crate); encode_attributes(&mut ebml_w, crate_attrs); - ecx.stats.attr_bytes = wr.pos - i; + ecx.stats.attr_bytes = *wr.pos - i; - i = wr.pos; + i = *wr.pos; encode_crate_deps(ecx, &mut ebml_w, ecx.cstore); - ecx.stats.dep_bytes = wr.pos - i; + ecx.stats.dep_bytes = *wr.pos - i; // Encode the language items. - i = wr.pos; + i = *wr.pos; encode_lang_items(ecx, &mut ebml_w); - ecx.stats.lang_item_bytes = wr.pos - i; + ecx.stats.lang_item_bytes = *wr.pos - i; // Encode the link args. - i = wr.pos; + i = *wr.pos; encode_link_args(ecx, &mut ebml_w); - ecx.stats.link_args_bytes = wr.pos - i; + ecx.stats.link_args_bytes = *wr.pos - i; // Encode and index the items. ebml_w.start_tag(tag_items); - i = wr.pos; + i = *wr.pos; let items_index = encode_info_for_items(ecx, &mut ebml_w, crate); - ecx.stats.item_bytes = wr.pos - i; + ecx.stats.item_bytes = *wr.pos - i; - i = wr.pos; + i = *wr.pos; let items_buckets = create_index(items_index); encode_index(&mut ebml_w, items_buckets, write_int); - ecx.stats.index_bytes = wr.pos - i; + ecx.stats.index_bytes = *wr.pos - i; ebml_w.end_tag(); - ecx.stats.total_bytes = wr.pos; + ecx.stats.total_bytes = *wr.pos; if (tcx.sess.meta_stats()) { - do wr.bytes.each |e| { if *e == 0 { ecx.stats.zero_bytes += 1; @@ -1438,9 +1437,11 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] { // // vec::from_slice(metadata_encoding_version) + + let writer_bytes: &mut ~[u8] = wr.bytes; + (do str::as_bytes(&~"rust\x00\x00\x00\x01") |bytes| { vec::slice(*bytes, 0, 8).to_vec() - }) + flate::deflate_bytes(wr.bytes) + }) + flate::deflate_bytes(*writer_bytes) } // Get the encoded string for a type diff --git a/src/libstd/io_util.rs b/src/libstd/io_util.rs index 6ed626202b7e2..7d43663cc808b 100644 --- a/src/libstd/io_util.rs +++ b/src/libstd/io_util.rs @@ -29,13 +29,13 @@ pub impl BufReader { // I can't get the borrowing to work correctly let bytes_reader = BytesReader { bytes: ::core::util::id::<&[u8]>(self.buf), - pos: *self.pos + pos: @mut *self.pos }; let res = f(&bytes_reader); // FIXME #4429: This isn't correct if f fails - *self.pos = bytes_reader.pos; + *self.pos = *bytes_reader.pos; return res; } From c7522417d48c03a110fa8839428424d6dbae1223 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 3 May 2013 17:55:53 -0700 Subject: [PATCH 14/25] libstd: Remove some residual mutable fields --- src/libstd/ebml.rs | 22 +++++++++++++++++++++- src/libstd/json.rs | 13 +++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index af433c6dd9dc8..5e4f708f52fd4 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -600,11 +600,18 @@ pub mod writer { use core::vec; // ebml writing + #[cfg(stage0)] pub struct Encoder { writer: @io::Writer, priv mut size_positions: ~[uint], } + #[cfg(not(stage0))] + pub struct Encoder { + writer: @io::Writer, + priv size_positions: ~[uint], + } + fn write_sized_vuint(w: @io::Writer, n: uint, size: uint) { match size { 1u => w.write(&[0x80u8 | (n as u8)]), @@ -625,9 +632,22 @@ pub mod writer { fail!(fmt!("vint to write too big: %?", n)); } + #[cfg(stage0)] + pub fn Encoder(w: @io::Writer) -> Encoder { + let size_positions: ~[uint] = ~[]; + Encoder { + writer: w, + mut size_positions: size_positions + } + } + + #[cfg(not(stage0))] pub fn Encoder(w: @io::Writer) -> Encoder { let size_positions: ~[uint] = ~[]; - Encoder { writer: w, mut size_positions: size_positions } + Encoder { + writer: w, + size_positions: size_positions + } } // FIXME (#2741): Provide a function to write the standard ebml header. diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 3960a07dfce7b..c815c9dd48062 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -220,11 +220,18 @@ impl serialize::Encoder for Encoder { } } +#[cfg(stage0)] pub struct PrettyEncoder { priv wr: @io::Writer, priv mut indent: uint, } +#[cfg(not(stage0))] +pub struct PrettyEncoder { + priv wr: @io::Writer, + priv indent: uint, +} + pub fn PrettyEncoder(wr: @io::Writer) -> PrettyEncoder { PrettyEncoder { wr: wr, @@ -838,10 +845,16 @@ pub fn from_str(s: &str) -> Result { } } +#[cfg(stage0)] pub struct Decoder { priv mut stack: ~[Json], } +#[cfg(not(stage0))] +pub struct Decoder { + priv stack: ~[Json], +} + pub fn Decoder(json: Json) -> Decoder { Decoder { stack: ~[json] From db4573a7760bd2014b2eca2537b6af15a9803e3d Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 3 May 2013 18:51:58 -0700 Subject: [PATCH 15/25] librustc: Remove mutable fields from the language. They're still parsed though, to get through bootstrapping. --- src/librustc/metadata/decoder.rs | 15 ------- src/librustc/metadata/encoder.rs | 23 ++-------- src/librustc/middle/lint.rs | 23 ---------- src/librustc/middle/mem_categorization.rs | 24 ++--------- src/librustc/middle/region.rs | 12 +----- src/librustc/middle/resolve.rs | 2 +- src/librustc/middle/trans/expr.rs | 14 ++++--- src/librustc/middle/trans/glue.rs | 4 +- src/librustc/middle/ty.rs | 51 +++++------------------ src/librustdoc/extract.rs | 2 +- src/libsyntax/ast.rs | 37 ++++++++++------ src/libsyntax/ast_util.rs | 2 +- src/libsyntax/ext/auto_encode.rs | 12 ++---- src/libsyntax/ext/deriving/decodable.rs | 2 +- src/libsyntax/ext/deriving/encodable.rs | 2 +- src/libsyntax/ext/deriving/iter_bytes.rs | 2 +- src/libsyntax/ext/pipes/pipec.rs | 6 +-- src/libsyntax/parse/parser.rs | 8 ++-- src/libsyntax/print/pprust.rs | 5 +-- 19 files changed, 69 insertions(+), 177 deletions(-) diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 1e6bb39706844..fd35a4425d870 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -204,18 +204,6 @@ fn each_reexport(d: ebml::Doc, f: &fn(ebml::Doc) -> bool) { } } -fn field_mutability(d: ebml::Doc) -> ast::struct_mutability { - // Use maybe_get_doc in case it's a method - reader::maybe_get_doc(d, tag_struct_mut).map_default( - ast::struct_immutable, - |d| { - match reader::doc_as_u8(*d) as char { - 'm' => ast::struct_mutable, - _ => ast::struct_immutable - } - }) -} - fn variant_disr_val(d: ebml::Doc) -> Option { do reader::maybe_get_doc(d, tag_disr_val).chain |val_doc| { int::parse_bytes(reader::doc_data(val_doc), 10u) @@ -923,12 +911,10 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id) if f == PublicField || f == PrivateField || f == InheritedField { let name = item_name(intr, an_item); let did = item_def_id(an_item, cdata); - let mt = field_mutability(an_item); result.push(ty::field_ty { ident: name, id: did, vis: struct_field_family_to_visibility(f), - mutability: mt, }); } } @@ -938,7 +924,6 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id) ident: special_idents::unnamed_field, id: did, vis: ast::inherited, - mutability: ast::struct_immutable, }); } result diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index c84bebdfd39df..87ccd1e45b6f9 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -119,16 +119,6 @@ fn encode_region_param(ecx: @EncodeContext, } } -fn encode_mutability(ebml_w: &mut writer::Encoder, mt: struct_mutability) { - ebml_w.start_tag(tag_struct_mut); - let val = match mt { - struct_immutable => 'a', - struct_mutable => 'm' - }; - ebml_w.writer.write(&[val as u8]); - ebml_w.end_tag(); -} - struct entry { val: T, pos: uint @@ -518,13 +508,9 @@ fn encode_info_for_struct(ecx: @EncodeContext, /* We encode both private and public fields -- need to include private fields to get the offsets right */ for fields.each |field| { - let (nm, mt, vis) = match field.node.kind { - named_field(nm, mt, vis) => (nm, mt, vis), - unnamed_field => ( - special_idents::unnamed_field, - struct_immutable, - inherited - ) + let (nm, vis) = match field.node.kind { + named_field(nm, vis) => (nm, vis), + unnamed_field => (special_idents::unnamed_field, inherited) }; let id = field.node.id; @@ -537,7 +523,6 @@ fn encode_info_for_struct(ecx: @EncodeContext, encode_name(ecx, ebml_w, nm); encode_path(ecx, ebml_w, path, ast_map::path_name(nm)); encode_type(ecx, ebml_w, node_id_to_type(tcx, id)); - encode_mutability(ebml_w, mt); encode_def_id(ebml_w, local_def(id)); ebml_w.end_tag(); } @@ -828,7 +813,7 @@ fn encode_info_for_item(ecx: @EncodeContext, needs to know*/ for struct_def.fields.each |f| { match f.node.kind { - named_field(ident, _, vis) => { + named_field(ident, vis) => { ebml_w.start_tag(tag_item_field); encode_struct_field_family(ebml_w, vis); encode_name(ecx, ebml_w, ident); diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 9ca1cc9b92430..ceb473da52fc0 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -56,7 +56,6 @@ pub enum lint { non_camel_case_types, type_limits, default_methods, - deprecated_mutable_fields, unused_unsafe, managed_heap_memory, @@ -455,7 +454,6 @@ fn check_item(i: @ast::item, cx: ty::ctxt) { check_item_heap(cx, i); check_item_type_limits(cx, i); check_item_default_methods(cx, i); - check_item_deprecated_mutable_fields(cx, i); check_item_unused_unsafe(cx, i); check_item_unused_mut(cx, i); } @@ -640,28 +638,7 @@ fn check_item_default_methods(cx: ty::ctxt, item: @ast::item) { } } -fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) { - match item.node { - ast::item_struct(struct_def, _) => { - for struct_def.fields.each |field| { - match field.node.kind { - ast::named_field(_, ast::struct_mutable, _) => { - cx.sess.span_lint(deprecated_mutable_fields, - item.id, - item.id, - field.span, - "mutable fields are deprecated"); - } - ast::named_field(*) | ast::unnamed_field => {} - } - } - } - _ => {} - } -} - fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) { - fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id, decl: &ast::fn_decl) { let tys = vec::map(decl.inputs, |a| a.ty ); diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index dde4c04479288..26992388b29d3 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -581,17 +581,7 @@ pub impl mem_categorization_ctxt { f_name: ast::ident, f_ty: ty::t, field_id: ast::node_id) -> cmt { - let f_mutbl = match field_mutbl(self.tcx, base_cmt.ty, - f_name, field_id) { - Some(f_mutbl) => f_mutbl, - None => { - self.tcx.sess.span_bug( - node.span(), - fmt!("Cannot find field `%s` in type `%s`", - *self.tcx.sess.str_of(f_name), - ty_to_str(self.tcx, base_cmt.ty))); - } - }; + let f_mutbl = m_imm; let m = self.inherited_mutability(base_cmt.mutbl, f_mutbl); let f_interior = interior_field(f_name, f_mutbl); @cmt_ { @@ -968,11 +958,7 @@ pub fn field_mutbl(tcx: ty::ctxt, ty::ty_struct(did, _) => { for ty::lookup_struct_fields(tcx, did).each |fld| { if fld.ident == f_name { - let m = match fld.mutability { - ast::struct_mutable => ast::m_mutbl, - ast::struct_immutable => ast::m_imm - }; - return Some(m); + return Some(ast::m_imm); } } } @@ -981,11 +967,7 @@ pub fn field_mutbl(tcx: ty::ctxt, ast::def_variant(_, variant_id) => { for ty::lookup_struct_fields(tcx, variant_id).each |fld| { if fld.ident == f_name { - let m = match fld.mutability { - ast::struct_mutable => ast::m_mutbl, - ast::struct_immutable => ast::m_imm - }; - return Some(m); + return Some(ast::m_imm); } } } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index cdc3aa9fedb7e..76d35527104d5 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -894,17 +894,7 @@ pub fn determine_rp_in_struct_field( cm: @ast::struct_field, cx: @mut DetermineRpCtxt, visitor: visit::vt<@mut DetermineRpCtxt>) { - match cm.node.kind { - ast::named_field(_, ast::struct_mutable, _) => { - do cx.with_ambient_variance(rv_invariant) { - visit::visit_struct_field(cm, cx, visitor); - } - } - ast::named_field(_, ast::struct_immutable, _) | - ast::unnamed_field => { - visit::visit_struct_field(cm, cx, visitor); - } - } + visit::visit_struct_field(cm, cx, visitor); } pub fn determine_rp_in_crate(sess: Session, diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index cabe0353b8a48..ff002afd028f5 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -4667,7 +4667,7 @@ pub impl Resolver { for vec::each(class_def.fields) |field| { match field.node.kind { unnamed_field => {}, - named_field(ident, _, _) => { + named_field(ident, _) => { if str::eq_slice(*this.session.str_of(ident), name) { return true diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 2c59d5c6bd635..5f9dc277c51a3 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -120,14 +120,14 @@ lvalues are *never* stored by value. */ use back::abi; -use lib; use lib::llvm::{ValueRef, TypeRef, llvm}; +use lib; use metadata::csearch; use middle::trans::_match; use middle::trans::adt; use middle::trans::asm; -use middle::trans::base; use middle::trans::base::*; +use middle::trans::base; use middle::trans::build::*; use middle::trans::callee::DoAutorefArg; use middle::trans::callee; @@ -142,8 +142,10 @@ use middle::trans::machine; use middle::trans::meth; use middle::trans::tvec; use middle::trans::type_of; +use middle::ty::struct_fields; +use middle::ty::{AutoDerefRef, AutoAddEnv}; +use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef, AutoBorrowFn}; use middle::ty; -use middle::ty::struct_mutable_fields; use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef, AutoBorrowFn, AutoDerefRef, AutoAddEnv, AutoUnsafe}; use util::common::indenter; @@ -1107,7 +1109,7 @@ pub fn with_field_tys(tcx: ty::ctxt, op: &fn(int, (&[ty::field])) -> R) -> R { match ty::get(ty).sty { ty::ty_struct(did, ref substs) => { - op(0, struct_mutable_fields(tcx, did, substs)) + op(0, struct_fields(tcx, did, substs)) } ty::ty_enum(_, ref substs) => { @@ -1124,8 +1126,8 @@ pub fn with_field_tys(tcx: ty::ctxt, ast::def_variant(enum_id, variant_id) => { let variant_info = ty::enum_variant_with_id( tcx, enum_id, variant_id); - op(variant_info.disr_val, struct_mutable_fields( - tcx, variant_id, substs)) + op(variant_info.disr_val, + struct_fields(tcx, variant_id, substs)) } _ => { tcx.sess.bug(~"resolve didn't map this expr to a \ diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index a35c40b852005..3b06f903641d4 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -496,9 +496,7 @@ pub fn trans_struct_drop(bcx: block, Call(bcx, dtor_addr, args); // Drop the fields - let field_tys = - ty::struct_mutable_fields(bcx.tcx(), class_did, - substs); + let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs); for vec::eachi(field_tys) |i, fld| { let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i); bcx = drop_ty(bcx, llfld_a, fld.mt.ty); diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index a49768075dcc9..b2938476d3507 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -106,10 +106,9 @@ pub enum SelfMode { } pub struct field_ty { - ident: ident, - id: def_id, - vis: ast::visibility, - mutability: ast::struct_mutability, + ident: ident, + id: def_id, + vis: ast::visibility, } // Contains information needed to resolve types and (in the future) look up @@ -4027,12 +4026,11 @@ pub fn lookup_struct_field(cx: ctxt, fn struct_field_tys(fields: &[@struct_field]) -> ~[field_ty] { do fields.map |field| { match field.node.kind { - named_field(ident, mutability, visibility) => { + named_field(ident, visibility) => { field_ty { ident: ident, id: ast_util::local_def(field.node.id), vis: visibility, - mutability: mutability, } } unnamed_field => { @@ -4041,51 +4039,22 @@ fn struct_field_tys(fields: &[@struct_field]) -> ~[field_ty] { syntax::parse::token::special_idents::unnamed_field, id: ast_util::local_def(field.node.id), vis: ast::public, - mutability: ast::struct_immutable, } } } } } -// Return a list of fields corresponding to the struct's items -// (as if the struct was a record). trans uses this -// Takes a list of substs with which to instantiate field types -// Keep in mind that this function reports that all fields are -// mutable, regardless of how they were declared. It's meant to -// be used in trans. -pub fn struct_mutable_fields(cx: ctxt, - did: ast::def_id, - substs: &substs) - -> ~[field] { - struct_item_fields(cx, did, substs, |_mt| m_mutbl) -} - -// Same as struct_mutable_fields, but doesn't change -// mutability. -pub fn struct_fields(cx: ctxt, - did: ast::def_id, - substs: &substs) - -> ~[field] { - struct_item_fields(cx, did, substs, |mt| match mt { - struct_mutable => m_mutbl, - struct_immutable => m_imm }) -} - - -fn struct_item_fields(cx:ctxt, - did: ast::def_id, - substs: &substs, - frob_mutability: &fn(struct_mutability) -> mutability) - -> ~[field] { +// Returns a list of fields corresponding to the struct's items. trans uses +// this. Takes a list of substs with which to instantiate field types. +pub fn struct_fields(cx: ctxt, did: ast::def_id, substs: &substs) + -> ~[field] { do lookup_struct_fields(cx, did).map |f| { - // consider all instance vars mut, because the - // constructor may mutate all vars field { - ident: f.ident, + ident: f.ident, mt: mt { ty: lookup_field_type(cx, did, f.id, substs), - mutbl: frob_mutability(f.mutability) + mutbl: m_imm } } } diff --git a/src/librustdoc/extract.rs b/src/librustdoc/extract.rs index ce120f477a523..f04ca4b7a0436 100644 --- a/src/librustdoc/extract.rs +++ b/src/librustdoc/extract.rs @@ -274,7 +274,7 @@ fn structdoc_from_struct( item: itemdoc, fields: do struct_def.fields.map |field| { match field.node.kind { - ast::named_field(ident, _, _) => to_str(ident), + ast::named_field(ident, _) => to_str(ident), ast::unnamed_field => ~"(unnamed)", } }, diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 2216226ecb3ab..c8fc04eaea1a3 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1168,7 +1168,7 @@ pub type struct_field = spanned; #[auto_decode] #[deriving(Eq)] pub enum struct_field_kind { - named_field(ident, struct_mutability, visibility), + named_field(ident, visibility), unnamed_field // element of a tuple-like struct } @@ -1218,17 +1218,6 @@ pub enum item_ { item_mac(mac), } -#[auto_encode] -#[auto_decode] -#[deriving(Eq)] -pub enum struct_mutability { struct_mutable, struct_immutable } - -impl to_bytes::IterBytes for struct_mutability { - fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { - (*self as u8).iter_bytes(lsb0, f) - } -} - #[auto_encode] #[auto_decode] #[deriving(Eq)] @@ -1289,6 +1278,21 @@ mod test { assert_eq! (s,~[14]); } + #[test] fn test_marksof () { + let stopname = uints_to_name(&~[12,14,78]); + assert_eq!(s,~[]); + xorPush(&mut s,14); + assert_eq!(s,~[14]); + xorPush(&mut s,15); + assert_eq!(s,~[14,15]); + xorPush (&mut s,16); + assert_eq! (s,~[14,15,16]); + xorPush (&mut s,16); + assert_eq! (s,~[14,15]); + xorPush (&mut s,15); + assert_eq! (s,~[14]); + } + #[test] fn test_marksof () { let stopname = uints_to_name(&~[12,14,78]); let name1 = uints_to_name(&~[4,9,7]); @@ -1347,3 +1351,12 @@ mod test { } */ +// +// Local Variables: +// mode: rust +// fill-column: 78; +// indent-tabs-mode: nil +// c-basic-offset: 4 +// buffer-file-coding-system: utf-8-unix +// End: +// diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index a6094903d7b79..7b20d71fdc409 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -285,7 +285,7 @@ pub fn split_trait_methods(trait_methods: &[trait_method]) pub fn struct_field_visibility(field: ast::struct_field) -> visibility { match field.node.kind { - ast::named_field(_, _, visibility) => visibility, + ast::named_field(_, visibility) => visibility, ast::unnamed_field => ast::public } } diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index bdf0a2a1dd07c..5bd4f89a3b38b 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -914,19 +914,15 @@ struct field { fn mk_struct_fields(fields: &[@ast::struct_field]) -> ~[field] { do fields.map |field| { - let (ident, mutbl) = match field.node.kind { - ast::named_field(ident, mutbl, _) => (ident, mutbl), - _ => fail!(~"[auto_encode] does not support \ - unnamed fields") + let ident = match field.node.kind { + ast::named_field(ident, _) => ident, + _ => fail!(~"[auto_encode] does not support unnamed fields") }; field { span: field.span, ident: ident, - mutbl: match mutbl { - ast::struct_mutable => ast::m_mutbl, - ast::struct_immutable => ast::m_imm, - }, + mutbl: ast::m_imm, } } } diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 79cc4a3bda84f..2bdfe51c50eab 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -280,7 +280,7 @@ fn expand_deriving_decodable_struct_method( let mut fields = ~[]; for struct_def.fields.each |struct_field| { match struct_field.node.kind { - named_field(ident, _, _) => { + named_field(ident, _) => { fields.push(create_read_struct_field(cx, span, i, ident)); } unnamed_field => { diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index 8b86173dc24e7..54e5687f415ab 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -211,7 +211,7 @@ fn expand_deriving_encodable_struct_method( let mut statements = ~[]; for struct_def.fields.each |struct_field| { match struct_field.node.kind { - named_field(ident, _, _) => { + named_field(ident, _) => { // Create the accessor for this field. let self_field = build::mk_access( cx, diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs index c1c34c9a53a60..3d66506d6ca8f 100644 --- a/src/libsyntax/ext/deriving/iter_bytes.rs +++ b/src/libsyntax/ext/deriving/iter_bytes.rs @@ -90,4 +90,4 @@ fn iter_bytes_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) -> } build::mk_block(cx, span, ~[], stmts, None) -} \ No newline at end of file +} diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index e876972fe6878..00a91bdc46e8a 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -410,10 +410,8 @@ impl gen_init for protocol { @spanned { node: ast::struct_field_ { - kind: ast::named_field( - cx.ident_of(s.name), - ast::struct_immutable, - ast::inherited), + kind: ast::named_field(cx.ident_of(s.name), + ast::inherited), id: cx.next_id(), ty: fty, attrs: ~[], diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 810efd3917765..9eb74f9e52961 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -45,7 +45,7 @@ use ast::{pat_tup, pat_uniq, pat_wild, private}; use ast::{rem, required}; use ast::{ret_style, return_val, self_ty, shl, shr, stmt, stmt_decl}; use ast::{stmt_expr, stmt_semi, stmt_mac, struct_def, struct_field}; -use ast::{struct_immutable, struct_mutable, struct_variant_kind, subtract}; +use ast::{struct_variant_kind, subtract}; use ast::{sty_box, sty_region, sty_static, sty_uniq, sty_value}; use ast::{token_tree, trait_method, trait_ref, tt_delim, tt_seq, tt_tok}; use ast::{tt_nonterminal, tuple_variant_kind, Ty, ty_, ty_bot, ty_box}; @@ -2528,10 +2528,10 @@ pub impl Parser { fn parse_name_and_ty(&self, pr: visibility, attrs: ~[attribute]) -> @struct_field { - let mut is_mutbl = struct_immutable; let lo = self.span.lo; if self.eat_keyword(&~"mut") { - is_mutbl = struct_mutable; + // Do nothing, for backwards compatibility. + // XXX: Remove after snapshot. } if !is_plain_ident(&*self.token) { self.fatal(~"expected ident"); @@ -2540,7 +2540,7 @@ pub impl Parser { self.expect(&token::COLON); let ty = self.parse_ty(false); @spanned(lo, self.last_span.hi, ast::struct_field_ { - kind: named_field(name, is_mutbl, pr), + kind: named_field(name, pr), id: self.get_id(), ty: ty, attrs: attrs, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 6f3d6604d5b98..f12fb21992e85 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -703,14 +703,11 @@ pub fn print_struct(s: @ps, for struct_def.fields.each |field| { match field.node.kind { ast::unnamed_field => fail!(~"unexpected unnamed field"), - ast::named_field(ident, mutability, visibility) => { + ast::named_field(ident, visibility) => { hardbreak_if_not_bol(s); maybe_print_comment(s, field.span.lo); print_outer_attributes(s, field.node.attrs); print_visibility(s, visibility); - if mutability == ast::struct_mutable { - word_nbsp(s, ~"mut"); - } print_ident(s, ident); word_nbsp(s, ~":"); print_type(s, field.node.ty); From 278b487cabcbe52b301a8023cd1362045b1a7132 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 6 May 2013 19:29:04 -0700 Subject: [PATCH 16/25] test: Fix tests and the pipe compiler --- src/libcore/repr.rs | 68 ++++++------------- src/libcore/task/mod.rs | 2 + src/libsyntax/ext/pipes/pipec.rs | 9 +-- src/test/bench/core-map.rs | 2 +- src/test/bench/core-set.rs | 33 +++++---- src/test/bench/core-std.rs | 15 ++-- src/test/bench/graph500-bfs.rs | 17 ++--- src/test/bench/msgsend-pipes-shared.rs | 8 +-- src/test/bench/msgsend-pipes.rs | 6 +- src/test/bench/msgsend-ring-mutex-arcs.rs | 4 +- src/test/bench/msgsend-ring-pipes.rs | 4 +- src/test/bench/msgsend-ring-rw-arcs.rs | 4 +- src/test/bench/noise.rs | 18 +++-- src/test/bench/shootout-fasta.rs | 5 +- src/test/bench/shootout-pfib.rs | 11 +-- src/test/bench/task-perf-linked-failure.rs | 5 +- src/test/run-pass/issue-3176.rs | 3 +- src/test/run-pass/morestack6.rs | 2 +- src/test/run-pass/pipe-peek.rs | 6 +- src/test/run-pass/pipe-pingpong-bounded.rs | 18 ++--- .../run-pass/pipe-presentation-examples.rs | 4 ++ src/test/run-pass/platform_thread.rs | 10 ++- src/test/run-pass/task-comm-12.rs | 4 +- src/test/run-pass/task-comm-3.rs | 6 +- src/test/run-pass/task-comm-9.rs | 5 +- src/test/run-pass/yield.rs | 4 +- src/test/run-pass/yield1.rs | 4 +- 27 files changed, 151 insertions(+), 126 deletions(-) diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs index b75ac60ff28e2..c7e20d2b21f7e 100644 --- a/src/libcore/repr.rs +++ b/src/libcore/repr.rs @@ -448,10 +448,15 @@ impl TyVisitor for ReprVisitor { true } - fn visit_enter_enum(&self, _n_variants: uint, + fn visit_enter_enum(&self, + _n_variants: uint, get_disr: extern unsafe fn(ptr: *Opaque) -> int, - _sz: uint, _align: uint) -> bool { - let disr = unsafe { get_disr(transmute(self.ptr)) }; + _sz: uint, + _align: uint) -> bool { + let var_stk: &mut ~[VariantState] = self.var_stk; + let disr = unsafe { + get_disr(transmute(*self.ptr)) + }; self.var_stk.push(SearchingFor(disr)); true } @@ -484,31 +489,12 @@ impl TyVisitor for ReprVisitor { true } -<<<<<<< HEAD - fn visit_enum_variant_field(&self, i: uint, _offset: uint, inner: *TyDesc) -> bool { - match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] { -======= - #[cfg(stage0)] - fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool { - match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { - Degenerate | TagMatch => { - if i != 0 { - self.writer.write_str(", "); - } - if ! self.visit_inner(inner) { - return false; - } - } - TagMismatch => () - } - true - } - - #[cfg(not(stage0))] - fn visit_enum_variant_field(&self, i: uint, _: uint, inner: *TyDesc) + fn visit_enum_variant_field(&self, + i: uint, + _offset: uint, + inner: *TyDesc) -> bool { - match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { ->>>>>>> libcore: Remove mutable fields from repr + match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] { Matched => { if i != 0 { self.writer.write_str(", "); @@ -522,26 +508,6 @@ impl TyVisitor for ReprVisitor { true } -<<<<<<< HEAD -======= - #[cfg(stage0)] - fn visit_leave_enum_variant(&self, _variant: uint, - _disr_val: int, - n_fields: uint, - _name: &str) -> bool { - match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { - Degenerate | TagMatch => { - if n_fields > 0 { - self.writer.write_char(')'); - } - } - TagMismatch => () - } - true - } - - #[cfg(not(stage0))] ->>>>>>> libcore: Remove mutable fields from repr fn visit_leave_enum_variant(&self, _variant: uint, _disr_val: int, n_fields: uint, @@ -557,9 +523,13 @@ impl TyVisitor for ReprVisitor { true } - fn visit_leave_enum(&self, _n_variants: uint, + fn visit_leave_enum(&self, + _n_variants: uint, _get_disr: extern unsafe fn(ptr: *Opaque) -> int, - _sz: uint, _align: uint) -> bool { + _sz: uint, + _align: uint) + -> bool { + let var_stk: &mut ~[VariantState] = self.var_stk; match self.var_stk.pop() { SearchingFor(*) => fail!(~"enum value matched no variant"), _ => true diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs index 248898001750f..ce1969a14a183 100644 --- a/src/libcore/task/mod.rs +++ b/src/libcore/task/mod.rs @@ -230,12 +230,14 @@ pub impl TaskBuilder { /// the child. fn supervised(&mut self) { self.opts.supervised = true; + self.opts.linked = false; } /// Link the child task's and parent task's failures. If either fails, the /// other will be killed. fn linked(&mut self) { self.opts.linked = true; + self.opts.supervised = false; } /** diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 00a91bdc46e8a..7ac3ea4789d63 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -64,6 +64,7 @@ impl gen_send for message { let mut body = ~"{\n"; body += fmt!("use super::%s;\n", name); + body += ~"let mut pipe = pipe;\n"; if this.proto.is_bounded() { let (sp, rp) = match (this.dir, next.dir) { @@ -73,12 +74,12 @@ impl gen_send for message { (recv, recv) => (~"c", ~"s") }; - body += ~"let b = pipe.reuse_buffer();\n"; + body += ~"let mut b = pipe.reuse_buffer();\n"; body += fmt!("let %s = ::core::pipes::SendPacketBuffered(\ - &(b.buffer.data.%s));\n", + &mut (b.buffer.data.%s));\n", sp, next.name); body += fmt!("let %s = ::core::pipes::RecvPacketBuffered(\ - &(b.buffer.data.%s));\n", + &mut (b.buffer.data.%s));\n", rp, next.name); } else { @@ -366,7 +367,7 @@ impl gen_init for protocol { fmt!("data.%s.set_buffer(buffer)", s.name))), ext_cx.parse_expr(fmt!( - "::core::ptr::to_unsafe_ptr(&(data.%s))", + "::core::ptr::to_mut_unsafe_ptr(&mut (data.%s))", self.states[0].name)))); quote_expr!({ diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index e216215ace7f9..cb494ec9d206a 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -103,7 +103,7 @@ fn main() { let mut rand = vec::with_capacity(n_keys); { - let rng = core::rand::IsaacRng::new_seeded([1, 1, 1, 1, 1, 1, 1]); + let mut rng = core::rand::IsaacRng::new_seeded([1, 1, 1, 1, 1, 1, 1]); let mut set = HashSet::new(); while set.len() != n_keys { let next = rng.next() as uint; diff --git a/src/test/bench/core-set.rs b/src/test/bench/core-set.rs index b3e3d295c0fad..bae21c6d4a325 100644 --- a/src/test/bench/core-set.rs +++ b/src/test/bench/core-set.rs @@ -31,8 +31,13 @@ fn timed(result: &mut float, op: &fn()) { } pub impl Results { - fn bench_int, R: rand::Rng>(&mut self, rng: &R, num_keys: uint, - rand_cap: uint, f: &fn() -> T) { + fn bench_int, + R: rand::Rng>( + &mut self, + rng: &mut R, + num_keys: uint, + rand_cap: uint, + f: &fn() -> T) { { let mut set = f(); do timed(&mut self.sequential_ints) { @@ -69,8 +74,12 @@ pub impl Results { } } - fn bench_str, R: rand::Rng>(&mut self, rng: &R, num_keys: uint, - f: &fn() -> T) { + fn bench_str, + R:rand::Rng>( + &mut self, + rng: &mut R, + num_keys: uint, + f: &fn() -> T) { { let mut set = f(); do timed(&mut self.sequential_strings) { @@ -155,25 +164,25 @@ fn main() { let max = 200000; { - let rng = rand::IsaacRng::new_seeded(seed); + let mut rng = rand::IsaacRng::new_seeded(seed); let mut results = empty_results(); - results.bench_int(&rng, num_keys, max, || HashSet::new::()); - results.bench_str(&rng, num_keys, || HashSet::new::<~str>()); + results.bench_int(&mut rng, num_keys, max, || HashSet::new::()); + results.bench_str(&mut rng, num_keys, || HashSet::new::<~str>()); write_results("core::hashmap::HashSet", &results); } { - let rng = rand::IsaacRng::new_seeded(seed); + let mut rng = rand::IsaacRng::new_seeded(seed); let mut results = empty_results(); - results.bench_int(&rng, num_keys, max, || TreeSet::new::()); - results.bench_str(&rng, num_keys, || TreeSet::new::<~str>()); + results.bench_int(&mut rng, num_keys, max, || TreeSet::new::()); + results.bench_str(&mut rng, num_keys, || TreeSet::new::<~str>()); write_results("std::treemap::TreeSet", &results); } { - let rng = rand::IsaacRng::new_seeded(seed); + let mut rng = rand::IsaacRng::new_seeded(seed); let mut results = empty_results(); - results.bench_int(&rng, num_keys, max, || BitvSet::new()); + results.bench_int(&mut rng, num_keys, max, || BitvSet::new()); write_results("std::bitv::BitvSet", &results); } } diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index 1af3538a0219d..95a83af93d541 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -33,12 +33,15 @@ fn main() { fn maybe_run_test(argv: &[~str], name: ~str, test: &fn()) { let mut run_test = false; - if os::getenv(~"RUST_BENCH").is_some() { run_test = true } - else if argv.len() > 0 { + if os::getenv(~"RUST_BENCH").is_some() { + run_test = true + } else if argv.len() > 0 { run_test = argv.contains(&~"all") || argv.contains(&name) } - if !run_test { return } + if !run_test { + return + } let start = precise_time_s(); test(); @@ -69,7 +72,7 @@ fn read_line() { } fn vec_plus() { - let r = rand::rng(); + let mut r = rand::rng(); let mut v = ~[]; let mut i = 0; @@ -86,7 +89,7 @@ fn vec_plus() { } fn vec_append() { - let r = rand::rng(); + let mut r = rand::rng(); let mut v = ~[]; let mut i = 0; @@ -103,7 +106,7 @@ fn vec_append() { } fn vec_push_all() { - let r = rand::rng(); + let mut r = rand::rng(); let mut v = ~[]; for uint::range(0, 1500) |i| { diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index c8555ab1286b1..83855b142feb7 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -32,19 +32,20 @@ type graph = ~[~[node_id]]; type bfs_result = ~[node_id]; fn make_edges(scale: uint, edgefactor: uint) -> ~[(node_id, node_id)] { - let r = rand::XorShiftRng::new(); - - fn choose_edge(i: node_id, j: node_id, scale: uint, r: &R) - -> (node_id, node_id) { + let mut r = rand::XorShiftRng::new(); + fn choose_edge(i: node_id, + j: node_id, + scale: uint, + r: &mut R) + -> (node_id, node_id) { let A = 0.57; let B = 0.19; let C = 0.19; if scale == 0u { (i, j) - } - else { + } else { let i = i * 2i64; let j = j * 2i64; let scale = scale - 1u; @@ -73,7 +74,7 @@ fn make_edges(scale: uint, edgefactor: uint) -> ~[(node_id, node_id)] { } do vec::from_fn((1u << scale) * edgefactor) |_i| { - choose_edge(0i64, 0i64, scale, &r) + choose_edge(0i64, 0i64, scale, &mut r) } } @@ -103,7 +104,7 @@ fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph { fn gen_search_keys(graph: &[~[node_id]], n: uint) -> ~[node_id] { let mut keys = HashSet::new(); - let r = rand::rng(); + let mut r = rand::rng(); while keys.len() < n { let k = r.gen_uint_range(0u, graph.len()); diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index 6cda0a1945a0d..95758b3fe6406 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -65,15 +65,15 @@ fn run(args: &[~str]) { let mut worker_results = ~[]; for uint::range(0, workers) |_i| { let to_child = to_child.clone(); - do task::task().future_result(|+r| { - worker_results.push(r); - }).spawn || { + let mut builder = task::task(); + builder.future_result(|r| worker_results.push(r)); + do builder.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 || { server(&from_parent, &to_parent); diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index a8fb29a47e2fb..e213a44b49ae7 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -62,9 +62,9 @@ fn run(args: &[~str]) { for uint::range(0, workers) |_i| { let (from_parent_, to_child) = stream(); from_parent.add(from_parent_); - do task::task().future_result(|+r| { - worker_results.push(r); - }).spawn || { + let mut builder = task::task(); + builder.future_result(|r| worker_results.push(r)); + do builder.spawn { for uint::range(0, size / workers) |_i| { //error!("worker %?: sending %? bytes", i, num_bytes); to_child.send(bytes(num_bytes)); diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index 853b057277d8e..ed08297ab3fe3 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -103,7 +103,9 @@ fn main() { thread_ring(0, msg_per_task, num_chan.take(), num_port); // synchronize - for futures.each |f| { f.get() }; + for futures.each_mut |f| { + f.get() + } let stop = time::precise_time_s(); diff --git a/src/test/bench/msgsend-ring-pipes.rs b/src/test/bench/msgsend-ring-pipes.rs index 1288ac290787a..22d58730f58f3 100644 --- a/src/test/bench/msgsend-ring-pipes.rs +++ b/src/test/bench/msgsend-ring-pipes.rs @@ -96,7 +96,9 @@ fn main() { thread_ring(0, msg_per_task, num_chan.take(), num_port); // synchronize - for futures.each |f| { f.get() }; + for futures.each_mut |f| { + let _ = f.get(); + } let stop = time::precise_time_s(); diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index 2cf0fbfc397f3..221177b9dd9a8 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -104,7 +104,9 @@ fn main() { thread_ring(0, msg_per_task, num_chan.take(), num_port); // synchronize - for futures.each |f| { f.get() }; + for futures.each_mut |f| { + let _ = f.get(); + } let stop = time::precise_time_s(); diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index 0da3a2e5d68d0..992ce73a4bff7 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -13,7 +13,7 @@ fn lerp(a: f32, b: f32, v: f32) -> f32 { a * (1.0 - v) + b * v } #[inline(always)] fn smooth(v: f32) -> f32 { v * v * (3.0 - 2.0 * v) } -fn random_gradient(r: &R) -> Vec2 { +fn random_gradient(r: &mut R) -> Vec2 { let v = 2.0 * float::consts::pi * r.gen(); Vec2 { x: float::cos(v) as f32, @@ -33,11 +33,15 @@ struct Noise2DContext { pub impl Noise2DContext { fn new() -> Noise2DContext { - let r = rand::rng(); + let mut r = rand::rng(); let mut rgradients = [ Vec2 { x: 0.0, y: 0.0 }, ..256 ]; - for int::range(0, 256) |i| { rgradients[i] = random_gradient(&r); } + for int::range(0, 256) |i| { + rgradients[i] = random_gradient(&mut r); + } let mut permutations = [ 0, ..256 ]; - for int::range(0, 256) |i| { permutations[i] = i; } + for int::range(0, 256) |i| { + permutations[i] = i; + } r.shuffle_mut(permutations); Noise2DContext { @@ -53,7 +57,11 @@ pub impl Noise2DContext { } #[inline] - fn get_gradients(&self, gradients: &mut [Vec2, ..4], origins: &mut [Vec2, ..4], x: f32, y: f32) { + fn get_gradients(&self, + gradients: &mut [Vec2, ..4], + origins: &mut [Vec2, ..4], + x: f32, + y: f32) { let x0f = f32::floor(x); let y0f = f32::floor(y); let x0 = x0f as int; diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index 0fcf8341ac852..7316b68f8bd42 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -63,7 +63,10 @@ fn make_random_fasta(wr: @io::Writer, genelist: ~[AminoAcids], n: int) { wr.write_line(~">" + id + ~" " + desc); - let rng = @mut MyRandom {last: rand::rng().next()}; + let mut rng = rand::rng(); + let rng = @mut MyRandom { + last: rng.next() + }; let mut op: ~str = ~""; for uint::range(0u, n as uint) |_i| { str::push_char(&mut op, select_random(myrandom_next(rng, 100u32), diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index acb8a6bcbeed6..27a59feedd0a3 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -26,7 +26,6 @@ use core::int::range; use core::comm::*; use core::io::WriterUtil; -use core::result; use core::result::{Ok, Err}; fn fib(n: int) -> int { @@ -80,13 +79,15 @@ fn stress_task(&&id: int) { fn stress(num_tasks: int) { let mut results = ~[]; for range(0, num_tasks) |i| { - do task::task().future_result(|+r| { - results.push(r); - }).spawn { + let mut builder = task::task(); + builder.future_result(|r| results.push(r)); + do builder.spawn { stress_task(i); } } - for results.each |r| { r.recv(); } + for results.each |r| { + r.recv(); + } } fn main() { diff --git a/src/test/bench/task-perf-linked-failure.rs b/src/test/bench/task-perf-linked-failure.rs index 90c9d6b33e4ad..99e7de307279f 100644 --- a/src/test/bench/task-perf-linked-failure.rs +++ b/src/test/bench/task-perf-linked-failure.rs @@ -48,7 +48,10 @@ fn grandchild_group(num_tasks: uint) { fn spawn_supervised_blocking(myname: &str, +f: ~fn()) { let mut res = None; - task::task().future_result(|+r| res = Some(r)).supervised().spawn(f); + let mut builder = task::task(); + builder.future_result(|r| res = Some(r)); + builder.supervised(); + builder.spawn(f); error!("%s group waiting", myname); let x = res.unwrap().recv(); assert!(x == task::Success); diff --git a/src/test/run-pass/issue-3176.rs b/src/test/run-pass/issue-3176.rs index 55d62a5bf8ee3..d22c7e82ad5de 100644 --- a/src/test/run-pass/issue-3176.rs +++ b/src/test/run-pass/issue-3176.rs @@ -26,7 +26,8 @@ pub fn main() { c2.send(()); error!("child blocks"); let (p, c) = comm::stream(); - (p, p3).select(); + let mut tuple = (p, p3); + tuple.select(); c.send(()); }; error!("parent tries"); diff --git a/src/test/run-pass/morestack6.rs b/src/test/run-pass/morestack6.rs index 1f908936aef47..dafdd0fba48c3 100644 --- a/src/test/run-pass/morestack6.rs +++ b/src/test/run-pass/morestack6.rs @@ -62,7 +62,7 @@ pub fn main() { calllink09, calllink10 ]; - let rng = rand::rng(); + let mut rng = rand::rng(); for fns.each |f| { let f = *f; let sz = rng.next() % 256u32 + 256u32; diff --git a/src/test/run-pass/pipe-peek.rs b/src/test/run-pass/pipe-peek.rs index 46fbb88aef2e1..985eaecdc781b 100644 --- a/src/test/run-pass/pipe-peek.rs +++ b/src/test/run-pass/pipe-peek.rs @@ -22,11 +22,11 @@ proto! oneshot ( ) pub fn main() { - let (c, p) = oneshot::init(); + let mut (c, p) = oneshot::init(); - assert!(!pipes::peek(&p)); + assert!(!pipes::peek(&mut p)); oneshot::client::signal(c); - assert!(pipes::peek(&p)); + assert!(pipes::peek(&mut p)); } diff --git a/src/test/run-pass/pipe-pingpong-bounded.rs b/src/test/run-pass/pipe-pingpong-bounded.rs index 69d87804b42dd..d11d5eb47bbb9 100644 --- a/src/test/run-pass/pipe-pingpong-bounded.rs +++ b/src/test/run-pass/pipe-pingpong-bounded.rs @@ -40,7 +40,7 @@ mod pingpong { do pipes::entangle_buffer(buffer) |buffer, data| { data.ping.set_buffer(buffer); data.pong.set_buffer(buffer); - ptr::to_unsafe_ptr(&(data.ping)) + ptr::to_mut_unsafe_ptr(&mut (data.ping)) } } pub struct ping(server::pong); @@ -50,11 +50,11 @@ mod pingpong { use core::pipes::*; use core::ptr; - pub fn ping(+pipe: ping) -> pong { + pub fn ping(mut pipe: ping) -> pong { { - let b = pipe.reuse_buffer(); - let s = SendPacketBuffered(&b.buffer.data.pong); - let c = RecvPacketBuffered(&b.buffer.data.pong); + let mut b = pipe.reuse_buffer(); + let s = SendPacketBuffered(&mut b.buffer.data.pong); + let c = RecvPacketBuffered(&mut b.buffer.data.pong); let message = ::pingpong::ping(s); send(pipe, message); c @@ -72,11 +72,11 @@ mod pingpong { pub type ping = pipes::RecvPacketBuffered<::pingpong::ping, ::pingpong::Packets>; - pub fn pong(+pipe: pong) -> ping { + pub fn pong(mut pipe: pong) -> ping { { - let b = pipe.reuse_buffer(); - let s = SendPacketBuffered(&b.buffer.data.ping); - let c = RecvPacketBuffered(&b.buffer.data.ping); + let mut b = pipe.reuse_buffer(); + let s = SendPacketBuffered(&mut b.buffer.data.ping); + let c = RecvPacketBuffered(&mut b.buffer.data.ping); let message = ::pingpong::pong(s); send(pipe, message); c diff --git a/src/test/run-pass/pipe-presentation-examples.rs b/src/test/run-pass/pipe-presentation-examples.rs index 01f68929b90a7..fcfd77dab0aa3 100644 --- a/src/test/run-pass/pipe-presentation-examples.rs +++ b/src/test/run-pass/pipe-presentation-examples.rs @@ -1,4 +1,8 @@ // xfail-fast +// xfail-test + +// XFAIL'd because this is going to be revamped, and it's not compatible as +// written with the new mutability rules. // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at diff --git a/src/test/run-pass/platform_thread.rs b/src/test/run-pass/platform_thread.rs index 5e4830b0bbdc3..774f2470b3cd3 100644 --- a/src/test/run-pass/platform_thread.rs +++ b/src/test/run-pass/platform_thread.rs @@ -24,9 +24,15 @@ fn run(i: int) { return; } - do task::task().sched_mode(task::PlatformThread).unlinked().spawn { + let mut builder = task::task(); + builder.sched_mode(task::PlatformThread); + builder.unlinked(); + do builder.spawn { task::yield(); - do task::task().sched_mode(task::SingleThreaded).unlinked().spawn { + let mut builder = task::task(); + builder.sched_mode(task::SingleThreaded); + builder.unlinked(); + do builder.spawn { task::yield(); run(i - 1); task::yield(); diff --git a/src/test/run-pass/task-comm-12.rs b/src/test/run-pass/task-comm-12.rs index b426212d872f2..e61a855b42941 100644 --- a/src/test/run-pass/task-comm-12.rs +++ b/src/test/run-pass/task-comm-12.rs @@ -17,7 +17,9 @@ fn start(&&task_number: int) { debug!("Started / Finished task."); } fn test00() { let i: int = 0; let mut result = None; - do task::task().future_result(|+r| { result = Some(r); }).spawn { + let mut builder = task::task(); + builder.future_result(|r| result = Some(r)); + do builder.spawn { start(i) } diff --git a/src/test/run-pass/task-comm-3.rs b/src/test/run-pass/task-comm-3.rs index cf06deb1923a6..fd700475988cf 100644 --- a/src/test/run-pass/task-comm-3.rs +++ b/src/test/run-pass/task-comm-3.rs @@ -40,9 +40,9 @@ fn test00() { let mut results = ~[]; while i < number_of_tasks { let ch = po.chan(); - task::task().future_result(|+r| { - results.push(r); - }).spawn({ + let mut builder = task::task(); + builder.future_result(|r| results.push(r)); + builder.spawn({ let i = i; || test00_start(&ch, i, number_of_messages) }); diff --git a/src/test/run-pass/task-comm-9.rs b/src/test/run-pass/task-comm-9.rs index a3c8dc554a663..798e9d37b5534 100644 --- a/src/test/run-pass/task-comm-9.rs +++ b/src/test/run-pass/task-comm-9.rs @@ -27,8 +27,9 @@ fn test00() { let ch = p.chan(); let mut result = None; - do task::task().future_result(|+r| { result = Some(r); }).spawn - || { + let mut builder = task::task(); + builder.future_result(|r| result = Some(r)); + do builder.spawn { test00_start(&ch, number_of_messages); } diff --git a/src/test/run-pass/yield.rs b/src/test/run-pass/yield.rs index 75d9979807b47..8ed269099520a 100644 --- a/src/test/run-pass/yield.rs +++ b/src/test/run-pass/yield.rs @@ -11,7 +11,9 @@ pub fn main() { let mut result = None; - task::task().future_result(|+r| { result = Some(r); }).spawn(child); + let mut builder = task::task(); + builder.future_result(|+r| { result = Some(r); }); + builder.spawn(child); error!("1"); task::yield(); error!("2"); diff --git a/src/test/run-pass/yield1.rs b/src/test/run-pass/yield1.rs index 51483121f50fc..278ce1c37666f 100644 --- a/src/test/run-pass/yield1.rs +++ b/src/test/run-pass/yield1.rs @@ -11,7 +11,9 @@ pub fn main() { let mut result = None; - task::task().future_result(|+r| { result = Some(r); }).spawn(child); + let mut builder = task::task(); + builder.future_result(|+r| { result = Some(r); }); + builder.spawn(child); error!("1"); task::yield(); result.unwrap().recv(); From 99daec602fc8fa4612320c7c1babe6ae8717759c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 7 May 2013 11:38:08 -0700 Subject: [PATCH 17/25] librustc: Fix merge fallout. --- src/libcore/io.rs | 13 ++++++++----- src/libcore/repr.rs | 6 +++--- src/librustc/middle/resolve_stage0.rs | 2 +- src/libstd/future.rs | 7 +++++++ src/libstd/net_tcp.rs | 18 ++++++++++-------- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 63335f7e952cd..a00de5ff31177 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -1528,14 +1528,17 @@ pub struct BytesWriter { impl Writer for BytesWriter { fn write(&self, v: &[u8]) { let v_len = v.len(); - let bytes_len = vec::uniq_len(&const *self.bytes); - let count = uint::max(bytes_len, *self.pos + v_len); - vec::reserve(&mut *self.bytes, count); + let bytes = &mut *self.bytes; + let count = uint::max(bytes.len(), *self.pos + v_len); + vec::reserve(bytes, count); unsafe { - vec::raw::set_len(&mut *self.bytes, count); - let view = vec::mut_slice(*self.bytes, *self.pos, count); + // Silly stage0 borrow check workaround... + let casted: &mut ~[u8] = cast::transmute_copy(&bytes); + vec::raw::set_len(casted, count); + + let view = vec::mut_slice(*bytes, *self.pos, count); vec::bytes::copy_memory(view, v, v_len); } diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs index c7e20d2b21f7e..a645a7e868076 100644 --- a/src/libcore/repr.rs +++ b/src/libcore/repr.rs @@ -457,7 +457,7 @@ impl TyVisitor for ReprVisitor { let disr = unsafe { get_disr(transmute(*self.ptr)) }; - self.var_stk.push(SearchingFor(disr)); + var_stk.push(SearchingFor(disr)); true } @@ -494,7 +494,7 @@ impl TyVisitor for ReprVisitor { _offset: uint, inner: *TyDesc) -> bool { - match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] { + match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { Matched => { if i != 0 { self.writer.write_str(", "); @@ -530,7 +530,7 @@ impl TyVisitor for ReprVisitor { _align: uint) -> bool { let var_stk: &mut ~[VariantState] = self.var_stk; - match self.var_stk.pop() { + match var_stk.pop() { SearchingFor(*) => fail!(~"enum value matched no variant"), _ => true } diff --git a/src/librustc/middle/resolve_stage0.rs b/src/librustc/middle/resolve_stage0.rs index 2773710ca98fc..484f66ae9921b 100644 --- a/src/librustc/middle/resolve_stage0.rs +++ b/src/librustc/middle/resolve_stage0.rs @@ -4718,7 +4718,7 @@ pub impl Resolver { for vec::each(class_def.fields) |field| { match field.node.kind { unnamed_field => {}, - named_field(ident, _, _) => { + named_field(ident, _) => { if str::eq_slice(*this.session.str_of(ident), name) { return true diff --git a/src/libstd/future.rs b/src/libstd/future.rs index 209859e30961e..eea9d56c97517 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -28,6 +28,13 @@ use core::pipes::recv; use core::task; #[doc = "The future type"] +#[cfg(stage0)] +pub struct Future { + priv mut state: FutureState, +} + +#[doc = "The future type"] +#[cfg(not(stage0))] pub struct Future { priv state: FutureState, } diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index e8c38be74c7d2..560e91f13a721 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -902,8 +902,10 @@ impl io::Reader for TcpSocketBuf { // need to read in data from the socket. Note that the internal // buffer is of no use anymore as we read all bytes from it, // so we can throw it away. - let data = &*self.data; - let read_result = read(&data.sock, 0u); + let read_result = { + let data = &*self.data; + read(&data.sock, 0) + }; if read_result.is_err() { let err_data = read_result.get_err(); @@ -918,8 +920,7 @@ impl io::Reader for TcpSocketBuf { // should show up in a later call to read(). break; } - } - else { + } else { self.data.buf = result::unwrap(read_result); self.data.buf_off = 0; } @@ -935,8 +936,10 @@ impl io::Reader for TcpSocketBuf { return c as int } - let data = &*self.data; - let read_result = read(&data.sock, 0u); + let read_result = { + let data = &*self.data; + read(&data.sock, 0) + }; if read_result.is_err() { let err_data = read_result.get_err(); @@ -948,8 +951,7 @@ impl io::Reader for TcpSocketBuf { err_data.err_name, err_data.err_msg); fail!() } - } - else { + } else { self.data.buf = result::unwrap(read_result); self.data.buf_off = 0; } From 49a66a5c5a0361291db22e08bfa6e8c17209d01c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 7 May 2013 14:20:56 -0700 Subject: [PATCH 18/25] librustc: Stop parsing modes and remove them entirely from the language --- src/libcore/at_vec.rs | 8 ++++---- src/libcore/cast.rs | 2 +- src/libcore/rt/uvll.rs | 26 ++++++++++++++------------ src/libcore/stackwalk.rs | 2 +- src/libcore/task/mod.rs | 6 +++--- src/libcore/unstable/intrinsics.rs | 4 ++-- src/libcore/vec.rs | 12 ++++++------ src/libfuzzer/fuzzer.rc | 2 +- src/librustc/back/upcall.rs | 4 ++-- src/librustc/front/intrinsic.rs | 2 +- src/librustc/lib/llvm.rs | 18 ++++++++++++------ src/librustdoc/extract.rs | 2 +- src/librustdoc/markdown_writer.rs | 4 ++-- src/librustdoc/pass.rs | 2 +- src/libstd/arc.rs | 3 +-- src/libstd/arena.rs | 2 +- src/libstd/flatpipes.rs | 2 +- src/libstd/priority_queue.rs | 2 +- src/libstd/test.rs | 2 +- src/libstd/uv_ll.rs | 29 +++++++++++++++-------------- src/libsyntax/parse/parser.rs | 15 ++++++--------- src/libsyntax/util/interner.rs | 2 +- 22 files changed, 78 insertions(+), 73 deletions(-) diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 9f59f1d8fe48d..75dfe1e780646 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -29,9 +29,9 @@ pub mod rustrt { #[abi = "cdecl"] #[link_name = "rustrt"] pub extern { - pub unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc, - ++v: **vec::raw::VecRepr, - ++n: libc::size_t); + pub unsafe fn vec_reserve_shared_actual(t: *sys::TypeDesc, + v: **vec::raw::VecRepr, + n: libc::size_t); } } @@ -60,7 +60,7 @@ pub fn capacity(v: @[T]) -> uint { pub fn build_sized(size: uint, builder: &fn(push: &fn(v: A))) -> @[A] { let mut vec: @[A] = @[]; unsafe { raw::reserve(&mut vec, size); } - builder(|+x| unsafe { raw::push(&mut vec, x) }); + builder(|x| unsafe { raw::push(&mut vec, x) }); return unsafe { transmute(vec) }; } diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs index 96e1c3bd1249b..9b93cf68622f6 100644 --- a/src/libcore/cast.rs +++ b/src/libcore/cast.rs @@ -17,7 +17,7 @@ pub mod rusti { #[abi = "rust-intrinsic"] #[link_name = "rusti"] pub extern "rust-intrinsic" { - fn forget(+x: T); + fn forget(x: T); fn transmute(e: T) -> U; } diff --git a/src/libcore/rt/uvll.rs b/src/libcore/rt/uvll.rs index 3eb7f8006b9ea..4bff3bff7d3ae 100644 --- a/src/libcore/rt/uvll.rs +++ b/src/libcore/rt/uvll.rs @@ -393,24 +393,26 @@ extern { // FIXME ref #2064 fn rust_uv_tcp_connect(connect_ptr: *uv_connect_t, tcp_handle_ptr: *uv_tcp_t, - ++after_cb: *u8, - ++addr: *sockaddr_in) -> c_int; + after_cb: *u8, + addr: *sockaddr_in) -> c_int; // FIXME ref #2064 - fn rust_uv_tcp_bind(tcp_server: *uv_tcp_t, ++addr: *sockaddr_in) -> c_int; + fn rust_uv_tcp_bind(tcp_server: *uv_tcp_t, addr: *sockaddr_in) -> c_int; // FIXME ref #2064 fn rust_uv_tcp_connect6(connect_ptr: *uv_connect_t, tcp_handle_ptr: *uv_tcp_t, - ++after_cb: *u8, - ++addr: *sockaddr_in6) -> c_int; + after_cb: *u8, + addr: *sockaddr_in6) -> c_int; // FIXME ref #2064 - fn rust_uv_tcp_bind6(tcp_server: *uv_tcp_t, ++addr: *sockaddr_in6) -> c_int; - fn rust_uv_tcp_getpeername(tcp_handle_ptr: *uv_tcp_t, ++name: *sockaddr_in) -> c_int; - fn rust_uv_tcp_getpeername6(tcp_handle_ptr: *uv_tcp_t, ++name: *sockaddr_in6) ->c_int; + fn rust_uv_tcp_bind6(tcp_server: *uv_tcp_t, addr: *sockaddr_in6) -> c_int; + fn rust_uv_tcp_getpeername(tcp_handle_ptr: *uv_tcp_t, + name: *sockaddr_in) -> c_int; + fn rust_uv_tcp_getpeername6(tcp_handle_ptr: *uv_tcp_t, + name: *sockaddr_in6) ->c_int; fn rust_uv_listen(stream: *c_void, backlog: c_int, cb: *u8) -> c_int; fn rust_uv_accept(server: *c_void, client: *c_void) -> c_int; fn rust_uv_write(req: *c_void, stream: *c_void, - ++buf_in: *uv_buf_t, + buf_in: *uv_buf_t, buf_cnt: c_int, cb: *u8) -> c_int; fn rust_uv_read_start(stream: *c_void, @@ -426,7 +428,7 @@ extern { fn rust_uv_timer_stop(handle: *uv_timer_t) -> c_int; fn rust_uv_malloc_buf_base_of(sug_size: size_t) -> *u8; - fn rust_uv_free_base_of_buf(++buf: uv_buf_t); + fn rust_uv_free_base_of_buf(buf: uv_buf_t); fn rust_uv_get_stream_handle_from_connect_req(connect_req: *uv_connect_t) -> *uv_stream_t; fn rust_uv_get_stream_handle_from_write_req(write_req: *uv_write_t) -> *uv_stream_t; fn rust_uv_get_loop_for_uv_handle(handle: *c_void) -> *c_void; @@ -436,6 +438,6 @@ extern { fn rust_uv_set_data_for_uv_handle(handle: *c_void, data: *c_void); fn rust_uv_get_data_for_req(req: *c_void) -> *c_void; fn rust_uv_set_data_for_req(req: *c_void, data: *c_void); - fn rust_uv_get_base_from_buf(++buf: uv_buf_t) -> *u8; - fn rust_uv_get_len_from_buf(++buf: uv_buf_t) -> size_t; + fn rust_uv_get_base_from_buf(buf: uv_buf_t) -> *u8; + fn rust_uv_get_len_from_buf(buf: uv_buf_t) -> size_t; } diff --git a/src/libcore/stackwalk.rs b/src/libcore/stackwalk.rs index 24237694502a8..1958b5b9d80da 100644 --- a/src/libcore/stackwalk.rs +++ b/src/libcore/stackwalk.rs @@ -81,6 +81,6 @@ fn frame_address(f: &fn(x: *u8)) { pub mod rusti { #[abi = "rust-intrinsic"] pub extern "rust-intrinsic" { - pub fn frame_address(+f: &once fn(x: *u8)); + pub fn frame_address(f: &once fn(x: *u8)); } } diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs index ce1969a14a183..aeb669efa58fc 100644 --- a/src/libcore/task/mod.rs +++ b/src/libcore/task/mod.rs @@ -371,7 +371,7 @@ pub impl TaskBuilder { let (po, ch) = stream::(); let mut result = None; - self.future_result(|+r| { result = Some(r); }); + self.future_result(|r| { result = Some(r); }); do self.spawn { ch.send(f()); @@ -791,11 +791,11 @@ fn test_add_wrapper() { #[ignore(cfg(windows))] fn test_future_result() { let mut result = None; - do task().future_result(|+r| { result = Some(r); }).spawn { } + do task().future_result(|r| { result = Some(r); }).spawn { } assert!(result.unwrap().recv() == Success); result = None; - do task().future_result(|+r| + do task().future_result(|r| { result = Some(r); }).unlinked().spawn { fail!(); } diff --git a/src/libcore/unstable/intrinsics.rs b/src/libcore/unstable/intrinsics.rs index 65cfc6ec1fe05..363dbb84c1c3e 100644 --- a/src/libcore/unstable/intrinsics.rs +++ b/src/libcore/unstable/intrinsics.rs @@ -34,8 +34,8 @@ pub extern "rust-intrinsic" { pub fn size_of() -> uint; - pub fn move_val(dst: &mut T, +src: T); - pub fn move_val_init(dst: &mut T, +src: T); + pub fn move_val(dst: &mut T, src: T); + pub fn move_val_init(dst: &mut T, src: T); pub fn min_align_of() -> uint; pub fn pref_align_of() -> uint; diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 947146dee0e74..36acbdf4b5619 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -42,13 +42,13 @@ pub mod rustrt { // These names are terrible. reserve_shared applies // to ~[] and reserve_shared_actual applies to @[]. #[fast_ffi] - unsafe fn vec_reserve_shared(++t: *sys::TypeDesc, - ++v: **raw::VecRepr, - ++n: libc::size_t); + unsafe fn vec_reserve_shared(t: *sys::TypeDesc, + v: **raw::VecRepr, + n: libc::size_t); #[fast_ffi] - unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc, - ++v: **raw::VecRepr, - ++n: libc::size_t); + unsafe fn vec_reserve_shared_actual(t: *sys::TypeDesc, + v: **raw::VecRepr, + n: libc::size_t); } } diff --git a/src/libfuzzer/fuzzer.rc b/src/libfuzzer/fuzzer.rc index 7c93d867f5040..33e970c305adc 100644 --- a/src/libfuzzer/fuzzer.rc +++ b/src/libfuzzer/fuzzer.rc @@ -263,7 +263,7 @@ pub fn under(n: uint, it: &fn(uint)) { while i < n { it(i); i += 1u; } } -pub fn as_str(f: @fn(+x: @io::Writer)) -> ~str { +pub fn as_str(f: @fn(x: @io::Writer)) -> ~str { io::with_str_writer(f) } diff --git a/src/librustc/back/upcall.rs b/src/librustc/back/upcall.rs index 8fcc5234e8b51..4d2ea4eb4a642 100644 --- a/src/librustc/back/upcall.rs +++ b/src/librustc/back/upcall.rs @@ -34,9 +34,9 @@ pub fn declare_upcalls(targ_cfg: @session::config, fn nothrow(f: ValueRef) -> ValueRef { base::set_no_unwind(f); f } - let d: &fn(+a: ~str, +b: ~[TypeRef], +c: TypeRef) -> ValueRef = + let d: &fn(a: ~str, b: ~[TypeRef], c: TypeRef) -> ValueRef = |a,b,c| decl(llmod, ~"upcall_", a, b, c); - let dv: &fn(+a: ~str, +b: ~[TypeRef]) -> ValueRef = + let dv: &fn(a: ~str, b: ~[TypeRef]) -> ValueRef = |a,b| decl(llmod, ~"upcall_", a, b, T_void()); let int_t = T_int(targ_cfg); diff --git a/src/librustc/front/intrinsic.rs b/src/librustc/front/intrinsic.rs index 452623c2742b9..ece53451ccf80 100644 --- a/src/librustc/front/intrinsic.rs +++ b/src/librustc/front/intrinsic.rs @@ -132,7 +132,7 @@ pub mod intrinsic { #[abi = "rust-intrinsic"] pub extern "rust-intrinsic" { pub fn get_tydesc() -> *(); - pub fn visit_tydesc(++td: *TyDesc, ++tv: @TyVisitor); + pub fn visit_tydesc(td: *TyDesc, tv: @TyVisitor); } } } diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index fbb3380554d9e..36d5a8e3cfe9e 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -1561,12 +1561,18 @@ pub mod llvm { Name: *c_char) -> ValueRef; /* Atomic Operations */ - pub unsafe fn LLVMBuildAtomicCmpXchg(B: BuilderRef, LHS: ValueRef, - CMP: ValueRef, RHS: ValueRef, - ++Order: AtomicOrdering) -> ValueRef; - pub unsafe fn LLVMBuildAtomicRMW(B: BuilderRef, ++Op: AtomicBinOp, - LHS: ValueRef, RHS: ValueRef, - ++Order: AtomicOrdering) -> ValueRef; + pub unsafe fn LLVMBuildAtomicCmpXchg(B: BuilderRef, + LHS: ValueRef, + CMP: ValueRef, + RHS: ValueRef, + Order: AtomicOrdering) + -> ValueRef; + pub unsafe fn LLVMBuildAtomicRMW(B: BuilderRef, + Op: AtomicBinOp, + LHS: ValueRef, + RHS: ValueRef, + Order: AtomicOrdering) + -> ValueRef; /* Selected entries from the downcasts. */ #[fast_ffi] diff --git a/src/librustdoc/extract.rs b/src/librustdoc/extract.rs index f04ca4b7a0436..34faf6cefa32b 100644 --- a/src/librustdoc/extract.rs +++ b/src/librustdoc/extract.rs @@ -22,7 +22,7 @@ use syntax; * there. */ macro_rules! interner_key ( () => (cast::transmute::<(uint, uint), - &fn(+v: @@syntax::parse::token::ident_interner)>((-3 as uint, 0u))) + &fn(v: @@syntax::parse::token::ident_interner)>((-3 as uint, 0u))) ) // Hack; rather than thread an interner through everywhere, rely on diff --git a/src/librustdoc/markdown_writer.rs b/src/librustdoc/markdown_writer.rs index fc5a9a60df290..e56b0fb60cd12 100644 --- a/src/librustdoc/markdown_writer.rs +++ b/src/librustdoc/markdown_writer.rs @@ -26,8 +26,8 @@ pub type Writer = ~fn(v: WriteInstr); pub type WriterFactory = ~fn(page: doc::Page) -> Writer; pub trait WriterUtils { - fn put_str(&self, +str: ~str); - fn put_line(&self, +str: ~str); + fn put_str(&self, str: ~str); + fn put_line(&self, str: ~str); fn put_done(&self); } diff --git a/src/librustdoc/pass.rs b/src/librustdoc/pass.rs index 94db038bdec4b..b80f43a7bbd06 100644 --- a/src/librustdoc/pass.rs +++ b/src/librustdoc/pass.rs @@ -17,7 +17,7 @@ use time; /// A single operation on the document model pub struct Pass { name: ~str, - f: @fn(srv: astsrv::Srv, +doc: doc::Doc) -> doc::Doc + f: @fn(srv: astsrv::Srv, doc: doc::Doc) -> doc::Doc } pub fn run_passes( diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index 6c39fa1f9dcbb..35cfd6c90bc76 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -673,8 +673,7 @@ mod tests { let mut children = ~[]; for 5.times { let arc3 = (*arc).clone(); - do task::task().future_result(|+r| children.push(r)).spawn - || { + do task::task().future_result(|r| children.push(r)).spawn { do arc3.read |num| { assert!(*num >= 0); } diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs index da882d53fcffa..d6380551da91b 100644 --- a/src/libstd/arena.rs +++ b/src/libstd/arena.rs @@ -47,7 +47,7 @@ use core::vec; pub mod rusti { #[abi = "rust-intrinsic"] pub extern "rust-intrinsic" { - fn move_val_init(dst: &mut T, +src: T); + fn move_val_init(dst: &mut T, src: T); fn needs_drop() -> bool; } } diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs index b091a951af178..012f5c47830a9 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -928,7 +928,7 @@ mod test { test_try_recv_none3(pipe_port_loader); } - fn test_try_recv_none4(+loader: PortLoader

) { + fn test_try_recv_none4(loader: PortLoader

) { assert!(do task::try || { static CONTINUE: [u8, ..4] = [0xAA, 0xBB, 0xCC, 0xDD]; // The control word is followed by a valid length, diff --git a/src/libstd/priority_queue.rs b/src/libstd/priority_queue.rs index 33fe1cfff8e59..9bf7db07ac9dd 100644 --- a/src/libstd/priority_queue.rs +++ b/src/libstd/priority_queue.rs @@ -14,7 +14,7 @@ use core::old_iter::BaseIter; #[abi = "rust-intrinsic"] extern "rust-intrinsic" mod rusti { - fn move_val_init(dst: &mut T, +src: T); + fn move_val_init(dst: &mut T, src: T); fn init() -> T; } diff --git a/src/libstd/test.rs b/src/libstd/test.rs index b3523b8ad8019..7d24262aea600 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -559,7 +559,7 @@ pub fn run_test(force_ignore: bool, let mut task = task::task(); task.unlinked(); - task.future_result(|+r| { result_future = Some(r) }); + task.future_result(|r| { result_future = Some(r) }); task.spawn(testfn_cell.take()); let task_result = result_future.unwrap().recv(); diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index 8d7a97e2e483c..ad3cfeb4a990d 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -780,23 +780,24 @@ extern mod rustrt { // FIXME ref #2064 unsafe fn rust_uv_tcp_connect(connect_ptr: *uv_connect_t, tcp_handle_ptr: *uv_tcp_t, - ++after_cb: *u8, - ++addr: *sockaddr_in) -> libc::c_int; + after_cb: *u8, + addr: *sockaddr_in) + -> libc::c_int; // FIXME ref #2064 unsafe fn rust_uv_tcp_bind(tcp_server: *uv_tcp_t, - ++addr: *sockaddr_in) -> libc::c_int; + addr: *sockaddr_in) -> libc::c_int; // FIXME ref #2064 unsafe fn rust_uv_tcp_connect6(connect_ptr: *uv_connect_t, tcp_handle_ptr: *uv_tcp_t, - ++after_cb: *u8, - ++addr: *sockaddr_in6) -> libc::c_int; + after_cb: *u8, + addr: *sockaddr_in6) -> libc::c_int; // FIXME ref #2064 unsafe fn rust_uv_tcp_bind6(tcp_server: *uv_tcp_t, - ++addr: *sockaddr_in6) -> libc::c_int; + addr: *sockaddr_in6) -> libc::c_int; unsafe fn rust_uv_tcp_getpeername(tcp_handle_ptr: *uv_tcp_t, - ++name: *sockaddr_in) -> libc::c_int; + name: *sockaddr_in) -> libc::c_int; unsafe fn rust_uv_tcp_getpeername6(tcp_handle_ptr: *uv_tcp_t, - ++name: *sockaddr_in6) ->libc::c_int; + name: *sockaddr_in6) ->libc::c_int; unsafe fn rust_uv_listen(stream: *libc::c_void, backlog: libc::c_int, cb: *u8) -> libc::c_int; @@ -804,7 +805,7 @@ extern mod rustrt { -> libc::c_int; unsafe fn rust_uv_write(req: *libc::c_void, stream: *libc::c_void, - ++buf_in: *uv_buf_t, + buf_in: *uv_buf_t, buf_cnt: libc::c_int, cb: *u8) -> libc::c_int; @@ -843,7 +844,7 @@ extern mod rustrt { unsafe fn rust_uv_addrinfo_as_sockaddr_in6(input: *addrinfo) -> *sockaddr_in6; unsafe fn rust_uv_malloc_buf_base_of(sug_size: libc::size_t) -> *u8; - unsafe fn rust_uv_free_base_of_buf(++buf: uv_buf_t); + unsafe fn rust_uv_free_base_of_buf(buf: uv_buf_t); unsafe fn rust_uv_get_stream_handle_from_connect_req( connect_req: *uv_connect_t) -> *uv_stream_t; @@ -864,8 +865,8 @@ extern mod rustrt { -> *libc::c_void; unsafe fn rust_uv_set_data_for_req(req: *libc::c_void, data: *libc::c_void); - unsafe fn rust_uv_get_base_from_buf(++buf: uv_buf_t) -> *u8; - unsafe fn rust_uv_get_len_from_buf(++buf: uv_buf_t) -> libc::size_t; + unsafe fn rust_uv_get_base_from_buf(buf: uv_buf_t) -> *u8; + unsafe fn rust_uv_get_len_from_buf(buf: uv_buf_t) -> libc::size_t; // sizeof testing helpers unsafe fn rust_uv_helper_uv_tcp_t_size() -> libc::c_uint; @@ -1258,7 +1259,7 @@ mod test { extern fn on_read_cb(stream: *uv_stream_t, nread: libc::ssize_t, - ++buf: uv_buf_t) { + buf: uv_buf_t) { unsafe { let nread = nread as int; debug!("CLIENT entering on_read_cb nred: %d", @@ -1444,7 +1445,7 @@ mod test { extern fn on_server_read_cb(client_stream_ptr: *uv_stream_t, nread: libc::ssize_t, - ++buf: uv_buf_t) { + buf: uv_buf_t) { unsafe { let nread = nread as int; if (nread > 0) { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9eb74f9e52961..0543295eb4e6d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -390,8 +390,8 @@ pub impl Parser { // parse a ty_closure type fn parse_ty_closure(&self, sigil: ast::Sigil, - region: Option<@ast::Lifetime>) -> ty_ - { + region: Option<@ast::Lifetime>) + -> ty_ { /* (&|~|@) ['r] [pure|unsafe] [once] fn <'lt> (S) -> T @@ -773,20 +773,17 @@ pub impl Parser { return ty_rptr(opt_lifetime, mt); } - // parse an optional mode. - // XXX: Remove after snapshot. + // parse an optional, obsolete argument mode. fn parse_arg_mode(&self) { if self.eat(&token::BINOP(token::MINUS)) { self.obsolete(*self.span, ObsoleteMode); } else if self.eat(&token::ANDAND) { - // Ignore. + self.obsolete(*self.span, ObsoleteMode); } else if self.eat(&token::BINOP(token::PLUS)) { if self.eat(&token::BINOP(token::PLUS)) { - // ++ mode is obsolete, but we need a snapshot - // to stop parsing it. - // Ignore. + self.obsolete(*self.span, ObsoleteMode); } else { - // Ignore. + self.obsolete(*self.span, ObsoleteMode); } } else { // Ignore. diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index e3a8727762218..23084c34209e9 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -84,7 +84,7 @@ pub impl Interner { * for another case of this. */ macro_rules! interner_key ( () => (cast::transmute::<(uint, uint), - &fn(+v: @@::parse::token::ident_interner)>( + &fn(v: @@::parse::token::ident_interner)>( (-3 as uint, 0u))) ) From 16a0125e4169628ea74a486f53571b358c505fc6 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 7 May 2013 17:57:58 -0700 Subject: [PATCH 19/25] libcore: Fix tests. --- src/libcore/comm.rs | 7 ++- src/libcore/flate.rs | 5 +- src/libcore/hash.rs | 6 +- src/libcore/io.rs | 6 +- src/libcore/os.rs | 2 +- src/libcore/pipes.rs | 7 ++- src/libcore/rand.rs | 44 +++++++------- src/libcore/task/mod.rs | 99 ++++++++++++++++--------------- src/libcore/unstable/weak_task.rs | 8 ++- src/librustc/middle/astencode.rs | 2 +- src/libstd/arc.rs | 12 +++- src/libstd/bitv.rs | 16 ++--- src/libstd/flatpipes.rs | 4 +- src/libstd/future.rs | 7 ++- src/libstd/net_tcp.rs | 2 +- src/libstd/sort.rs | 14 +++-- src/libstd/timer.rs | 5 +- src/libstd/treemap.rs | 2 +- 18 files changed, 135 insertions(+), 113 deletions(-) diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 5b2bb3a132f72..7eaa853549336 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -596,9 +596,10 @@ mod test { c1.send(~"abc"); - match (p1, p2).select() { - Right(_) => fail!(), - _ => () + let mut tuple = (p1, p2); + match tuple.select() { + Right(_) => fail!(), + _ => (), } c2.send(123); diff --git a/src/libcore/flate.rs b/src/libcore/flate.rs index ba10f97e626c4..29d0eb422d50a 100644 --- a/src/libcore/flate.rs +++ b/src/libcore/flate.rs @@ -84,10 +84,11 @@ pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] { #[test] #[allow(non_implicitly_copyable_typarams)] fn test_flate_round_trip() { - let r = rand::rng(); + let mut r = rand::rng(); let mut words = ~[]; for 20.times { - words.push(r.gen_bytes(r.gen_uint_range(1, 10))); + let range = r.gen_uint_range(1, 10); + words.push(r.gen_bytes(range)); } for 20.times { let mut in = ~[]; diff --git a/src/libcore/hash.rs b/src/libcore/hash.rs index 486f0e096e8ac..d535abf8ead7c 100644 --- a/src/libcore/hash.rs +++ b/src/libcore/hash.rs @@ -473,10 +473,10 @@ mod tests { let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08_u64; let mut buf : ~[u8] = ~[]; let mut t = 0; - let stream_inc = &State(k0,k1); - let stream_full = &State(k0,k1); + let mut stream_inc = SipState::new(k0, k1); + let mut stream_full = SipState::new(k0, k1); - fn to_hex_str(r: &[u8, ..8]) -> ~str { + fn to_hex_str(r: &[u8, ..8]) -> ~str { let mut s = ~""; for vec::each(*r) |b| { s += uint::to_str_radix(*b as uint, 16u); diff --git a/src/libcore/io.rs b/src/libcore/io.rs index a00de5ff31177..1bb754fc2be42 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -1886,15 +1886,15 @@ mod tests { fn bytes_buffer_overwrite() { let wr = BytesWriter(); wr.write(~[0u8, 1u8, 2u8, 3u8]); - assert!(wr.bytes == ~[0u8, 1u8, 2u8, 3u8]); + assert!(*wr.bytes == ~[0u8, 1u8, 2u8, 3u8]); wr.seek(-2, SeekCur); wr.write(~[4u8, 5u8, 6u8, 7u8]); - assert!(wr.bytes == ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]); + assert!(*wr.bytes == ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]); wr.seek(-2, SeekEnd); wr.write(~[8u8]); wr.seek(1, SeekSet); wr.write(~[9u8]); - assert!(wr.bytes == ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]); + assert!(*wr.bytes == ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]); } #[test] diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 5a7f01706b4f4..afb9641485859 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -1435,7 +1435,7 @@ mod tests { } fn make_rand_name() -> ~str { - let rng = rand::rng(); + let mut rng = rand::rng(); let n = ~"TEST" + rng.gen_str(10u); assert!(getenv(n).is_none()); n diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 1fda5a97a375a..8301254fbdd18 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -894,9 +894,10 @@ mod test { c1.send(~"abc"); - match (p1, p2).select() { - Right(_) => fail!(), - _ => () + let mut tuple = (p1, p2); + match tuple.select() { + Right(_) => fail!(), + _ => (), } c2.send(123); diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index cb212efa363e2..f11840c95d5ac 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -879,8 +879,8 @@ mod tests { #[test] fn test_rng_seeded() { let seed = seed(); - let ra = IsaacRng::new_seeded(seed); - let rb = IsaacRng::new_seeded(seed); + let mut ra = IsaacRng::new_seeded(seed); + let mut rb = IsaacRng::new_seeded(seed); assert!(ra.gen_str(100u) == rb.gen_str(100u)); } @@ -888,15 +888,15 @@ mod tests { fn test_rng_seeded_custom_seed() { // much shorter than generated seeds which are 1024 bytes let seed = [2u8, 32u8, 4u8, 32u8, 51u8]; - let ra = IsaacRng::new_seeded(seed); - let rb = IsaacRng::new_seeded(seed); + let mut ra = IsaacRng::new_seeded(seed); + let mut rb = IsaacRng::new_seeded(seed); assert!(ra.gen_str(100u) == rb.gen_str(100u)); } #[test] fn test_rng_seeded_custom_seed2() { let seed = [2u8, 32u8, 4u8, 32u8, 51u8]; - let ra = IsaacRng::new_seeded(seed); + let mut ra = IsaacRng::new_seeded(seed); // Regression test that isaac is actually using the above vector let r = ra.next(); error!("%?", r); @@ -906,7 +906,7 @@ mod tests { #[test] fn test_gen_int_range() { - let r = rng(); + let mut r = rng(); let a = r.gen_int_range(-3, 42); assert!(a >= -3 && a < 42); assert!(r.gen_int_range(0, 1) == 0); @@ -917,12 +917,13 @@ mod tests { #[should_fail] #[ignore(cfg(windows))] fn test_gen_int_from_fail() { - rng().gen_int_range(5, -2); + let mut r = rng(); + r.gen_int_range(5, -2); } #[test] fn test_gen_uint_range() { - let r = rng(); + let mut r = rng(); let a = r.gen_uint_range(3u, 42u); assert!(a >= 3u && a < 42u); assert!(r.gen_uint_range(0u, 1u) == 0u); @@ -933,12 +934,13 @@ mod tests { #[should_fail] #[ignore(cfg(windows))] fn test_gen_uint_range_fail() { - rng().gen_uint_range(5u, 2u); + let mut r = rng(); + r.gen_uint_range(5u, 2u); } #[test] fn test_gen_float() { - let r = rng(); + let mut r = rng(); let a = r.gen::(); let b = r.gen::(); debug!((a, b)); @@ -946,14 +948,14 @@ mod tests { #[test] fn test_gen_weighted_bool() { - let r = rng(); + let mut r = rng(); assert!(r.gen_weighted_bool(0u) == true); assert!(r.gen_weighted_bool(1u) == true); } #[test] fn test_gen_str() { - let r = rng(); + let mut r = rng(); debug!(r.gen_str(10u)); debug!(r.gen_str(10u)); debug!(r.gen_str(10u)); @@ -964,7 +966,7 @@ mod tests { #[test] fn test_gen_bytes() { - let r = rng(); + let mut r = rng(); assert!(r.gen_bytes(0u).len() == 0u); assert!(r.gen_bytes(10u).len() == 10u); assert!(r.gen_bytes(16u).len() == 16u); @@ -972,13 +974,13 @@ mod tests { #[test] fn test_choose() { - let r = rng(); + let mut r = rng(); assert!(r.choose([1, 1, 1]) == 1); } #[test] fn test_choose_option() { - let r = rng(); + let mut r = rng(); let x: Option = r.choose_option([]); assert!(x.is_none()); assert!(r.choose_option([1, 1, 1]) == Some(1)); @@ -986,7 +988,7 @@ mod tests { #[test] fn test_choose_weighted() { - let r = rng(); + let mut r = rng(); assert!(r.choose_weighted(~[ Weighted { weight: 1u, item: 42 }, ]) == 42); @@ -998,7 +1000,7 @@ mod tests { #[test] fn test_choose_weighted_option() { - let r = rng(); + let mut r = rng(); assert!(r.choose_weighted_option(~[ Weighted { weight: 1u, item: 42 }, ]) == Some(42)); @@ -1012,7 +1014,7 @@ mod tests { #[test] fn test_weighted_vec() { - let r = rng(); + let mut r = rng(); let empty: ~[int] = ~[]; assert!(r.weighted_vec(~[]) == empty); assert!(r.weighted_vec(~[ @@ -1024,7 +1026,7 @@ mod tests { #[test] fn test_shuffle() { - let r = rng(); + let mut r = rng(); let empty: ~[int] = ~[]; assert!(r.shuffle(~[]) == empty); assert!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]); @@ -1032,7 +1034,7 @@ mod tests { #[test] fn test_task_rng() { - let r = task_rng(); + let mut r = task_rng(); r.gen::(); assert!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]); assert!(r.gen_uint_range(0u, 1u) == 0u); @@ -1079,7 +1081,7 @@ mod tests { let rt_rng = do vec::as_imm_buf(seed) |p, sz| { rustrt::rand_new_seeded(p, sz as size_t) }; - let rng = IsaacRng::new_seeded(seed); + let mut rng = IsaacRng::new_seeded(seed); for 10000.times { assert_eq!(rng.next(), rustrt::rand_next(rt_rng)); diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs index aeb669efa58fc..e58aa14572b7e 100644 --- a/src/libcore/task/mod.rs +++ b/src/libcore/task/mod.rs @@ -597,12 +597,13 @@ pub unsafe fn atomically(f: &fn() -> U) -> U { #[test] #[should_fail] #[ignore(cfg(windows))] fn test_cant_dup_task_builder() { - let b = task().unlinked(); - do b.spawn { } + let mut builder = task(); + builder.unlinked(); + do builder.spawn {} // FIXME(#3724): For now, this is a -runtime- failure, because we haven't // got move mode on self. When 3724 is fixed, this test should fail to // compile instead, and should go in tests/compile-fail. - do b.spawn { } // b should have been consumed by the previous call + do builder.spawn {} // b should have been consumed by the previous call } // The following 8 tests test the following 2^3 combinations: @@ -645,43 +646,31 @@ fn test_spawn_unlinked_sup_fail_down() { #[test] #[should_fail] #[ignore(cfg(windows))] fn test_spawn_linked_sup_fail_up() { // child fails; parent fails let (po, _ch) = stream::<()>(); + // Unidirectional "parenting" shouldn't override bidirectional linked. // We have to cheat with opts - the interface doesn't support them because // they don't make sense (redundant with task().supervised()). - let opts = { - let mut opts = default_task_opts(); - opts.linked = true; - opts.supervised = true; - opts - }; + let mut b0 = task(); + b0.opts.linked = true; + b0.opts.supervised = true; - let b0 = task(); - let b1 = TaskBuilder { - opts: opts, - can_not_copy: None, - .. b0 - }; - do b1.spawn { fail!(); } + do b0.spawn { + fail!(); + } po.recv(); // We should get punted awake } #[test] #[should_fail] #[ignore(cfg(windows))] fn test_spawn_linked_sup_fail_down() { // parent fails; child fails // We have to cheat with opts - the interface doesn't support them because // they don't make sense (redundant with task().supervised()). - let opts = { - let mut opts = default_task_opts(); - opts.linked = true; - opts.supervised = true; - opts - }; - - let b0 = task(); - let b1 = TaskBuilder { - opts: opts, - can_not_copy: None, - .. b0 - }; - do b1.spawn { loop { task::yield(); } } + let mut b0 = task(); + b0.opts.linked = true; + b0.opts.supervised = true; + do b0.spawn { + loop { + task::yield(); + } + } fail!(); // *both* mechanisms would be wrong if this didn't kill the child } #[test] #[should_fail] #[ignore(cfg(windows))] @@ -700,7 +689,13 @@ fn test_spawn_linked_unsup_fail_down() { // parent fails; child fails #[test] #[should_fail] #[ignore(cfg(windows))] fn test_spawn_linked_unsup_default_opts() { // parent fails; child fails // Make sure the above test is the same as this one. - do task().linked().spawn { loop { task::yield(); } } + let mut builder = task(); + builder.linked(); + do builder.spawn { + loop { + task::yield(); + } + } fail!(); } @@ -758,7 +753,8 @@ fn test_spawn_linked_sup_propagate_sibling() { #[test] fn test_run_basic() { let (po, ch) = stream::<()>(); - do task().spawn { + let mut builder = task(); + do builder.spawn { ch.send(()); } po.recv(); @@ -772,18 +768,18 @@ struct Wrapper { #[test] fn test_add_wrapper() { let (po, ch) = stream::<()>(); - let b0 = task(); - let ch = Wrapper { f: Some(ch) }; - let b1 = do b0.add_wrapper |body| { - let ch = Wrapper { f: Some(ch.f.swap_unwrap()) }; + let mut b0 = task(); + let ch = Cell(ch); + do b0.add_wrapper |body| { + let ch = Cell(ch.take()); let result: ~fn() = || { - let ch = ch.f.swap_unwrap(); + let mut ch = ch.take(); body(); ch.send(()); }; result }; - do b1.spawn { } + do b0.spawn { } po.recv(); } @@ -791,12 +787,16 @@ fn test_add_wrapper() { #[ignore(cfg(windows))] fn test_future_result() { let mut result = None; - do task().future_result(|r| { result = Some(r); }).spawn { } + let mut builder = task(); + builder.future_result(|r| result = Some(r)); + do builder.spawn {} assert!(result.unwrap().recv() == Success); result = None; - do task().future_result(|r| - { result = Some(r); }).unlinked().spawn { + let mut builder = task(); + builder.future_result(|r| result = Some(r)); + builder.unlinked(); + do builder.spawn { fail!(); } assert!(result.unwrap().recv() == Failure); @@ -804,7 +804,9 @@ fn test_future_result() { #[test] #[should_fail] #[ignore(cfg(windows))] fn test_back_to_the_future_result() { - let _ = task().future_result(util::ignore).future_result(util::ignore); + let mut builder = task(); + builder.future_result(util::ignore); + builder.future_result(util::ignore); } #[test] @@ -866,12 +868,12 @@ fn test_spawn_sched_childs_on_default_sched() { // Assuming tests run on the default scheduler let default_id = unsafe { rt::rust_get_sched_id() }; - let ch = Wrapper { f: Some(ch) }; + let ch = Cell(ch); do spawn_sched(SingleThreaded) { let parent_sched_id = unsafe { rt::rust_get_sched_id() }; - let ch = Wrapper { f: Some(ch.f.swap_unwrap()) }; + let ch = Cell(ch.take()); do spawn { - let ch = ch.f.swap_unwrap(); + let ch = ch.take(); let child_sched_id = unsafe { rt::rust_get_sched_id() }; assert!(parent_sched_id != child_sched_id); assert!(child_sched_id == default_id); @@ -979,7 +981,8 @@ fn test_avoid_copying_the_body_spawn() { #[test] fn test_avoid_copying_the_body_task_spawn() { do avoid_copying_the_body |f| { - do task().spawn || { + let mut builder = task(); + do builder.spawn || { f(); } } @@ -1006,7 +1009,9 @@ fn test_avoid_copying_the_body_unlinked() { #[test] fn test_platform_thread() { let (po, ch) = stream(); - do task().sched_mode(PlatformThread).spawn { + let mut builder = task(); + builder.sched_mode(PlatformThread); + do builder.spawn { ch.send(()); } po.recv(); diff --git a/src/libcore/unstable/weak_task.rs b/src/libcore/unstable/weak_task.rs index 381083e6031b4..8670bcfcd9a05 100644 --- a/src/libcore/unstable/weak_task.rs +++ b/src/libcore/unstable/weak_task.rs @@ -191,12 +191,14 @@ fn test_select_stream_and_oneshot() { use comm::select2i; use either::{Left, Right}; - let (port, chan) = stream(); + let mut (port, chan) = stream(); + let port = Cell(port); let (waitport, waitchan) = stream(); do spawn { unsafe { - do weaken_task |signal| { - match select2i(&port, &signal) { + do weaken_task |mut signal| { + let mut port = port.take(); + match select2i(&mut port, &mut signal) { Left(*) => (), Right(*) => fail!() } diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index f3eac7995e8a1..c223ff821c268 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -1237,7 +1237,7 @@ fn test_simplification() { let ext_cx = mk_ctxt(); let item_in = ast::ii_item(quote_item!( fn new_int_alist() -> alist { - fn eq_int(&&a: int, &&b: int) -> bool { a == b } + fn eq_int(a: int, b: int) -> bool { a == b } return alist {eq_fn: eq_int, data: ~[]}; } ).get()); diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index 35cfd6c90bc76..d69839faa64bc 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -673,7 +673,9 @@ mod tests { let mut children = ~[]; for 5.times { let arc3 = (*arc).clone(); - do task::task().future_result(|r| children.push(r)).spawn { + let mut builder = task::task(); + builder.future_result(|r| children.push(r)); + do builder.spawn { do arc3.read |num| { assert!(*num >= 0); } @@ -681,11 +683,15 @@ mod tests { } // Wait for children to pass their asserts - for vec::each(children) |r| { r.recv(); } + for vec::each(children) |r| { + r.recv(); + } // Wait for writer to finish p.recv(); - do arc.read |num| { assert!(*num == 10); } + do arc.read |num| { + assert!(*num == 10); + } } #[test] fn test_rw_downgrade() { diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index ceb67fcabfa5b..461fb61ed5665 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -1426,7 +1426,7 @@ mod tests { #[bench] fn bench_uint_small(b: &mut BenchHarness) { - let r = rng(); + let mut r = rng(); let mut bitv = 0 as uint; do b.iter { bitv |= (1 << ((r.next() as uint) % uint::bits)); @@ -1435,7 +1435,7 @@ mod tests { #[bench] fn bench_small_bitv_small(b: &mut BenchHarness) { - let r = rng(); + let mut r = rng(); let mut bitv = SmallBitv::new(uint::bits); do b.iter { bitv.set((r.next() as uint) % uint::bits, true); @@ -1444,7 +1444,7 @@ mod tests { #[bench] fn bench_big_bitv_small(b: &mut BenchHarness) { - let r = rng(); + let mut r = rng(); let mut bitv = BigBitv::new(~[0]); do b.iter { bitv.set((r.next() as uint) % uint::bits, true); @@ -1453,7 +1453,7 @@ mod tests { #[bench] fn bench_big_bitv_big(b: &mut BenchHarness) { - let r = rng(); + let mut r = rng(); let mut storage = ~[]; storage.grow(bench_bits / uint::bits, &0); let mut bitv = BigBitv::new(storage); @@ -1464,7 +1464,7 @@ mod tests { #[bench] fn bench_bitv_big(b: &mut BenchHarness) { - let r = rng(); + let mut r = rng(); let mut bitv = Bitv::new(bench_bits, false); do b.iter { bitv.set((r.next() as uint) % bench_bits, true); @@ -1473,7 +1473,7 @@ mod tests { #[bench] fn bench_bitv_small(b: &mut BenchHarness) { - let r = rng(); + let mut r = rng(); let mut bitv = Bitv::new(uint::bits, false); do b.iter { bitv.set((r.next() as uint) % uint::bits, true); @@ -1482,7 +1482,7 @@ mod tests { #[bench] fn bench_bitv_set_small(b: &mut BenchHarness) { - let r = rng(); + let mut r = rng(); let mut bitv = BitvSet::new(); do b.iter { bitv.insert((r.next() as uint) % uint::bits); @@ -1491,7 +1491,7 @@ mod tests { #[bench] fn bench_bitv_set_big(b: &mut BenchHarness) { - let r = rng(); + let mut r = rng(); let mut bitv = BitvSet::new(); do b.iter { bitv.insert((r.next() as uint) % bench_bits); diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs index 012f5c47830a9..0d4ef69a2753b 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -645,7 +645,7 @@ mod test { chan.send(10); - let bytes = copy chan.byte_chan.writer.bytes; + let bytes = copy *chan.byte_chan.writer.bytes; let reader = BufReader::new(bytes); let port = serial::reader_port(reader); @@ -692,7 +692,7 @@ mod test { chan.send(10); - let bytes = copy chan.byte_chan.writer.bytes; + let bytes = copy *chan.byte_chan.writer.bytes; let reader = BufReader::new(bytes); let port = pod::reader_port(reader); diff --git a/src/libstd/future.rs b/src/libstd/future.rs index eea9d56c97517..37eb1e02a8014 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -184,9 +184,9 @@ pub fn spawn(blk: ~fn() -> A) -> Future { #[allow(non_implicitly_copyable_typarams)] #[cfg(test)] mod test { - use future::*; + use core::cell::Cell; use core::comm::{oneshot, send_one}; use core::task; @@ -239,8 +239,9 @@ mod test { #[test] fn test_sendable_future() { let expected = ~"schlorf"; - let mut f = do spawn { copy expected }; - do task::spawn || { + let f = Cell(do spawn { copy expected }); + do task::spawn { + let mut f = f.take(); let actual = f.get(); assert!(actual == expected); } diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 560e91f13a721..bc4168ba7f875 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -1963,7 +1963,7 @@ mod test { } fn tcp_write_single(sock: &TcpSocket, val: ~[u8]) { - let write_result_future = sock.write_future(val); + let mut write_result_future = sock.write_future(val); let write_result = write_result_future.get(); if result::is_err(&write_result) { debug!("tcp_write_single: write failed!"); diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index a18e2f47a7721..6994ca4aedb6d 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -946,8 +946,10 @@ mod test_tim_sort { impl Ord for CVal { fn lt(&self, other: &CVal) -> bool { - let rng = rand::rng(); - if rng.gen::() > 0.995 { fail!(~"It's happening!!!"); } + let mut rng = rand::rng(); + if rng.gen::() > 0.995 { + fail!(~"It's happening!!!"); + } (*self).val < other.val } fn le(&self, other: &CVal) -> bool { (*self).val <= other.val } @@ -995,7 +997,7 @@ mod test_tim_sort { #[should_fail] #[cfg(unix)] fn crash_test() { - let rng = rand::rng(); + let mut rng = rand::rng(); let mut arr = do vec::from_fn(1000) |_i| { CVal { val: rng.gen() } }; @@ -1015,7 +1017,7 @@ mod test_tim_sort { #[test] fn test_bad_Ord_impl() { - let rng = rand::rng(); + let mut rng = rand::rng(); let mut arr = do vec::from_fn(500) |_i| { DVal { val: rng.gen() } }; @@ -1067,7 +1069,7 @@ mod big_tests { } } - let rng = rand::rng(); + let mut rng = rand::rng(); for uint::range(lo, hi) |i| { let n = 1 << i; @@ -1138,7 +1140,7 @@ mod big_tests { } } - let rng = rand::rng(); + let mut rng = rand::rng(); for uint::range(lo, hi) |i| { let n = 1 << i; diff --git a/src/libstd/timer.rs b/src/libstd/timer.rs index 76aa4d615e1dc..0d15bbb54d321 100644 --- a/src/libstd/timer.rs +++ b/src/libstd/timer.rs @@ -219,7 +219,7 @@ mod test { let hl_loop_clone = hl_loop.clone(); do task::spawn { use core::rand::*; - let rng = rng(); + let mut rng = rng(); for old_iter::repeat(times) { sleep(&hl_loop_clone, rng.next() as uint % maxms); } @@ -276,7 +276,8 @@ mod test { let hl_loop = uv::global_loop::get(); for old_iter::repeat(times as uint) { - let expected = rand::rng().gen_str(16u); + let mut rng = rand::rng(); + let expected = rng.gen_str(16u); let (test_po, test_ch) = stream::<~str>(); let hl_loop_clone = hl_loop.clone(); do task::spawn() { diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index c8ab48e65c065..06ac1a71bacd0 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -848,7 +848,7 @@ mod test_treemap { check_equal(ctrl, &map); assert!(map.find(&5).is_none()); - let rng = rand::IsaacRng::new_seeded(&[42]); + let mut rng = rand::IsaacRng::new_seeded(&[42]); for 3.times { for 90.times { From 9d011ebf67272879b9883013f7796b7639ecfda3 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 7 May 2013 21:33:31 -0700 Subject: [PATCH 20/25] test: Fix tests. --- src/llvm | 2 +- src/test/auxiliary/cci_class_6.rs | 2 +- src/test/compile-fail/block-coerce-no.rs | 6 ++--- src/test/compile-fail/borrowck-pat-enum.rs | 4 ++-- src/test/compile-fail/borrowck-unary-move.rs | 4 ++-- ...lowed-deconstructing-destructing-struct.rs | 2 +- src/test/compile-fail/issue-2766-a.rs | 4 ++-- src/test/compile-fail/issue-3296.rs | 2 +- .../compile-fail/liveness-use-after-send.rs | 2 +- .../compile-fail/mutable-huh-ptr-assign.rs | 2 +- src/test/compile-fail/unique-vec-res.rs | 2 +- src/test/run-fail/morestack3.rs | 2 +- src/test/run-fail/morestack4.rs | 2 +- src/test/run-fail/unwind-move.rs | 2 +- src/test/run-pass/argument-passing.rs | 6 +++-- src/test/run-pass/auto-ref-sliceable.rs | 4 ++-- src/test/run-pass/bind-by-move.rs | 2 +- src/test/run-pass/borrowck-lend-args.rs | 4 ++-- .../run-pass/borrowck-mut-vec-as-imm-slice.rs | 2 +- .../run-pass/borrowck-newtype-issue-2573.rs | 2 +- src/test/run-pass/capture_nil.rs | 2 +- src/test/run-pass/child-outlives-parent.rs | 6 +++-- src/test/run-pass/class-poly-methods.rs | 2 +- src/test/run-pass/cleanup-copy-mode.rs | 2 +- src/test/run-pass/extern-pass-TwoU64s-ref.rs | 2 +- src/test/run-pass/extern-pub.rs | 6 ++--- src/test/run-pass/fn-bare-spawn.rs | 2 +- src/test/run-pass/foreign-struct.rs | 2 +- src/test/run-pass/intrinsic-move-val.rs | 4 ++-- src/test/run-pass/issue-2633-2.rs | 2 +- src/test/run-pass/issue-2718.rs | 24 +++++++++---------- src/test/run-pass/issue-2904.rs | 2 +- src/test/run-pass/issue-3656.rs | 2 +- src/test/run-pass/iter-min-max.rs | 2 +- src/test/run-pass/liveness-move-in-loop.rs | 2 +- src/test/run-pass/morestack5.rs | 2 +- src/test/run-pass/move-arg-2-unique.rs | 2 +- src/test/run-pass/move-arg-2.rs | 2 +- src/test/run-pass/move-arg.rs | 2 +- src/test/run-pass/move-nullary-fn.rs | 4 ++-- src/test/run-pass/operator-overloading.rs | 2 +- src/test/run-pass/option-unwrap.rs | 2 +- src/test/run-pass/pass-by-copy.rs | 4 ++-- src/test/run-pass/pipe-bank-proto.rs | 10 ++++---- src/test/run-pass/pipe-pingpong-bounded.rs | 4 ++-- src/test/run-pass/pipe-pingpong-proto.rs | 4 ++-- src/test/run-pass/reflect-visit-data.rs | 2 +- src/test/run-pass/regions-copy-closure.rs | 2 +- src/test/run-pass/regions-static-closure.rs | 2 +- src/test/run-pass/sendfn-spawn-with-fn-arg.rs | 2 +- src/test/run-pass/spawn.rs | 2 +- src/test/run-pass/spawn2.rs | 2 +- src/test/run-pass/static-method-test.rs | 14 +++++------ src/test/run-pass/struct-return.rs | 4 ++-- src/test/run-pass/task-comm-12.rs | 2 +- src/test/run-pass/task-life-0.rs | 2 +- src/test/run-pass/threads.rs | 2 +- src/test/run-pass/unique-fn-arg-move.rs | 2 +- src/test/run-pass/yield.rs | 2 +- src/test/run-pass/yield1.rs | 2 +- 60 files changed, 102 insertions(+), 98 deletions(-) diff --git a/src/llvm b/src/llvm index 2e9f0d21fe321..56dd407f4f97a 160000 --- a/src/llvm +++ b/src/llvm @@ -1 +1 @@ -Subproject commit 2e9f0d21fe321849a4759a01fc28eae82ef196d6 +Subproject commit 56dd407f4f97a01b8df6554c569170d2fc276fcb diff --git a/src/test/auxiliary/cci_class_6.rs b/src/test/auxiliary/cci_class_6.rs index b09606ea1e21d..7ad617cebdbb3 100644 --- a/src/test/auxiliary/cci_class_6.rs +++ b/src/test/auxiliary/cci_class_6.rs @@ -23,7 +23,7 @@ pub mod kitties { fn meow_count(&mut self) -> uint { self.meows } } - pub fn cat(in_x : uint, in_y : int, +in_info: ~[U]) -> cat { + pub fn cat(in_x : uint, in_y : int, in_info: ~[U]) -> cat { cat { meows: in_x, how_hungry: in_y, diff --git a/src/test/compile-fail/block-coerce-no.rs b/src/test/compile-fail/block-coerce-no.rs index bdde5144b04d1..f3ec875340550 100644 --- a/src/test/compile-fail/block-coerce-no.rs +++ b/src/test/compile-fail/block-coerce-no.rs @@ -12,9 +12,9 @@ // other tycons. fn coerce(b: &fn()) -> extern fn() { - fn lol(+f: extern fn(+v: &fn()) -> extern fn(), - +g: &fn()) -> extern fn() { return f(g); } - fn fn_id(+f: extern fn()) -> extern fn() { return f } + fn lol(f: extern fn(+v: &fn()) -> extern fn(), + g: &fn()) -> extern fn() { return f(g); } + fn fn_id(f: extern fn()) -> extern fn() { return f } return lol(fn_id, b); //~^ ERROR mismatched types } diff --git a/src/test/compile-fail/borrowck-pat-enum.rs b/src/test/compile-fail/borrowck-pat-enum.rs index c50357e8b9c62..f1cca89b227d6 100644 --- a/src/test/compile-fail/borrowck-pat-enum.rs +++ b/src/test/compile-fail/borrowck-pat-enum.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn match_ref(&&v: Option) -> int { +fn match_ref(v: Option) -> int { match v { Some(ref i) => { *i @@ -17,7 +17,7 @@ fn match_ref(&&v: Option) -> int { } } -fn match_ref_unused(&&v: Option) { +fn match_ref_unused(v: Option) { match v { Some(_) => {} None => {} diff --git a/src/test/compile-fail/borrowck-unary-move.rs b/src/test/compile-fail/borrowck-unary-move.rs index 107e478004abb..cf7529865118a 100644 --- a/src/test/compile-fail/borrowck-unary-move.rs +++ b/src/test/compile-fail/borrowck-unary-move.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(+x: ~int) -> int { +fn foo(x: ~int) -> int { let y = &*x; free(x); //~ ERROR cannot move out of `*x` because it is borrowed *y } -fn free(+_x: ~int) { +fn free(_x: ~int) { } fn main() { diff --git a/src/test/compile-fail/disallowed-deconstructing-destructing-struct.rs b/src/test/compile-fail/disallowed-deconstructing-destructing-struct.rs index 9019d338d0903..fa34c056794fc 100644 --- a/src/test/compile-fail/disallowed-deconstructing-destructing-struct.rs +++ b/src/test/compile-fail/disallowed-deconstructing-destructing-struct.rs @@ -18,7 +18,7 @@ impl Drop for X { } } -fn unwrap(+x: X) -> ~str { +fn unwrap(x: X) -> ~str { let X { x: y } = x; //~ ERROR deconstructing struct not allowed in pattern y } diff --git a/src/test/compile-fail/issue-2766-a.rs b/src/test/compile-fail/issue-2766-a.rs index 5e3eb9ef09bc6..5b55cc772fde8 100644 --- a/src/test/compile-fail/issue-2766-a.rs +++ b/src/test/compile-fail/issue-2766-a.rs @@ -15,10 +15,10 @@ pub mod stream { use core::pipes; pub impl Stream { - pub fn recv() -> extern fn(+v: Stream) -> ::stream::Stream { + pub fn recv() -> extern fn(v: Stream) -> ::stream::Stream { // resolve really should report just one error here. // Change the test case when it changes. - pub fn recv(+pipe: Stream) -> ::stream::Stream { //~ ERROR attempt to use a type argument out of scope + pub fn recv(pipe: Stream) -> ::stream::Stream { //~ ERROR attempt to use a type argument out of scope //~^ ERROR use of undeclared type name //~^^ ERROR attempt to use a type argument out of scope //~^^^ ERROR use of undeclared type name diff --git a/src/test/compile-fail/issue-3296.rs b/src/test/compile-fail/issue-3296.rs index 00425825e3ff2..062ee8fd01e46 100644 --- a/src/test/compile-fail/issue-3296.rs +++ b/src/test/compile-fail/issue-3296.rs @@ -18,7 +18,7 @@ struct Foo { a: () } -fn deserialize_foo<__D: std::serialization::deserializer>(&&__d: __D) { +fn deserialize_foo<__D: std::serialization::deserializer>(__d: __D) { } fn main() { let des = Deserializer(); let foo = deserialize_foo(des); } diff --git a/src/test/compile-fail/liveness-use-after-send.rs b/src/test/compile-fail/liveness-use-after-send.rs index fdc0392a74c7c..23d3fff01cf3c 100644 --- a/src/test/compile-fail/liveness-use-after-send.rs +++ b/src/test/compile-fail/liveness-use-after-send.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn send(ch: _chan, +data: T) { +fn send(ch: _chan, data: T) { debug!(ch); debug!(data); fail!(); diff --git a/src/test/compile-fail/mutable-huh-ptr-assign.rs b/src/test/compile-fail/mutable-huh-ptr-assign.rs index 6b3fd4f715384..c907eb4be49f8 100644 --- a/src/test/compile-fail/mutable-huh-ptr-assign.rs +++ b/src/test/compile-fail/mutable-huh-ptr-assign.rs @@ -11,7 +11,7 @@ extern mod std; fn main() { - unsafe fn f(&&v: *const int) { + unsafe fn f(v: *const int) { *v = 1 //~ ERROR cannot assign } diff --git a/src/test/compile-fail/unique-vec-res.rs b/src/test/compile-fail/unique-vec-res.rs index a3c51e2b7b1fc..003e8ccf30956 100644 --- a/src/test/compile-fail/unique-vec-res.rs +++ b/src/test/compile-fail/unique-vec-res.rs @@ -21,7 +21,7 @@ impl Drop for r { } } -fn f(+_i: ~[T], +_j: ~[T]) { +fn f(_i: ~[T], _j: ~[T]) { } fn main() { diff --git a/src/test/run-fail/morestack3.rs b/src/test/run-fail/morestack3.rs index 14fc40a43cc9a..012e9d19b1218 100644 --- a/src/test/run-fail/morestack3.rs +++ b/src/test/run-fail/morestack3.rs @@ -14,7 +14,7 @@ extern mod std; -fn getbig_and_fail(&&i: int) { +fn getbig_and_fail(i: int) { let _r = and_then_get_big_again(5); if i != 0 { getbig_and_fail(i - 1); diff --git a/src/test/run-fail/morestack4.rs b/src/test/run-fail/morestack4.rs index e45853937037e..6fc187491cf8c 100644 --- a/src/test/run-fail/morestack4.rs +++ b/src/test/run-fail/morestack4.rs @@ -14,7 +14,7 @@ extern mod std; -fn getbig_and_fail(&&i: int) { +fn getbig_and_fail(i: int) { let r = and_then_get_big_again(5); if i != 0 { getbig_and_fail(i - 1); diff --git a/src/test/run-fail/unwind-move.rs b/src/test/run-fail/unwind-move.rs index 51e2eaa44fa37..8f1b34d17cd99 100644 --- a/src/test/run-fail/unwind-move.rs +++ b/src/test/run-fail/unwind-move.rs @@ -9,7 +9,7 @@ // except according to those terms. // error-pattern:fail -fn f(+_a: @int) { +fn f(_a: @int) { fail!(); } diff --git a/src/test/run-pass/argument-passing.rs b/src/test/run-pass/argument-passing.rs index d61c1214633fc..8c84187ff6f06 100644 --- a/src/test/run-pass/argument-passing.rs +++ b/src/test/run-pass/argument-passing.rs @@ -10,9 +10,11 @@ // xfail-fast -struct X { x: int } +struct X { + x: int +} -fn f1(a: &mut X, b: &mut int, +c: int) -> int { +fn f1(a: &mut X, b: &mut int, c: int) -> int { let r = a.x + *b + c; a.x = 0; *b = 10; diff --git a/src/test/run-pass/auto-ref-sliceable.rs b/src/test/run-pass/auto-ref-sliceable.rs index 03e847e237d3a..f74d78f99d0b2 100644 --- a/src/test/run-pass/auto-ref-sliceable.rs +++ b/src/test/run-pass/auto-ref-sliceable.rs @@ -9,11 +9,11 @@ // except according to those terms. trait Pushable { - fn push_val(&mut self, +t: T); + fn push_val(&mut self, t: T); } impl Pushable for ~[T] { - fn push_val(&mut self, +t: T) { + fn push_val(&mut self, t: T) { self.push(t); } } diff --git a/src/test/run-pass/bind-by-move.rs b/src/test/run-pass/bind-by-move.rs index d3d0e48f5b0f7..8752102c3a513 100644 --- a/src/test/run-pass/bind-by-move.rs +++ b/src/test/run-pass/bind-by-move.rs @@ -11,7 +11,7 @@ // xfail-fast extern mod std; use std::arc; -fn dispose(+_x: arc::ARC) { unsafe { } } +fn dispose(_x: arc::ARC) { unsafe { } } pub fn main() { let p = arc::ARC(true); diff --git a/src/test/run-pass/borrowck-lend-args.rs b/src/test/run-pass/borrowck-lend-args.rs index 0d51993e226ef..a912e1ef65c42 100644 --- a/src/test/run-pass/borrowck-lend-args.rs +++ b/src/test/run-pass/borrowck-lend-args.rs @@ -10,7 +10,7 @@ fn borrow(_v: &int) {} -fn borrow_from_arg_imm_ref(&&v: ~int) { +fn borrow_from_arg_imm_ref(v: ~int) { borrow(v); } @@ -18,7 +18,7 @@ fn borrow_from_arg_mut_ref(v: &mut ~int) { borrow(*v); } -fn borrow_from_arg_copy(+v: ~int) { +fn borrow_from_arg_copy(v: ~int) { borrow(v); } diff --git a/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs b/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs index 6929a98d9e1a9..8f66faab01451 100644 --- a/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs +++ b/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs @@ -14,7 +14,7 @@ fn want_slice(v: &[int]) -> int { return sum; } -fn has_mut_vec(+v: ~[int]) -> int { +fn has_mut_vec(v: ~[int]) -> int { want_slice(v) } diff --git a/src/test/run-pass/borrowck-newtype-issue-2573.rs b/src/test/run-pass/borrowck-newtype-issue-2573.rs index 7724836b5db9e..5f0c7cad6191c 100644 --- a/src/test/run-pass/borrowck-newtype-issue-2573.rs +++ b/src/test/run-pass/borrowck-newtype-issue-2573.rs @@ -25,7 +25,7 @@ impl frob for foo { } // Override default mode so that we are passing by value -fn really_impure(++bar: baz) { +fn really_impure(bar: baz) { bar.baz = 3; } diff --git a/src/test/run-pass/capture_nil.rs b/src/test/run-pass/capture_nil.rs index 99d8fab4bba50..817891c114640 100644 --- a/src/test/run-pass/capture_nil.rs +++ b/src/test/run-pass/capture_nil.rs @@ -26,7 +26,7 @@ use core::comm::*; -fn foo(&&x: ()) -> Port<()> { +fn foo(x: ()) -> Port<()> { let (p, c) = stream::<()>(); do task::spawn() { c.send(x); diff --git a/src/test/run-pass/child-outlives-parent.rs b/src/test/run-pass/child-outlives-parent.rs index 50c6b82114326..4eb3cea3a2586 100644 --- a/src/test/run-pass/child-outlives-parent.rs +++ b/src/test/run-pass/child-outlives-parent.rs @@ -12,6 +12,8 @@ extern mod std; -fn child2(&&s: ~str) { } +fn child2(s: ~str) { } -pub fn main() { let x = task::spawn(|| child2(~"hi") ); } +pub fn main() { + let x = task::spawn(|| child2(~"hi")); +} diff --git a/src/test/run-pass/class-poly-methods.rs b/src/test/run-pass/class-poly-methods.rs index adcab8b40aa47..9774d8d14882e 100644 --- a/src/test/run-pass/class-poly-methods.rs +++ b/src/test/run-pass/class-poly-methods.rs @@ -22,7 +22,7 @@ pub impl cat { fn meow_count(&mut self) -> uint { self.meows } } -fn cat(in_x : uint, in_y : int, +in_info: ~[U]) -> cat { +fn cat(in_x : uint, in_y : int, in_info: ~[U]) -> cat { cat { meows: in_x, how_hungry: in_y, diff --git a/src/test/run-pass/cleanup-copy-mode.rs b/src/test/run-pass/cleanup-copy-mode.rs index b334f32f344b5..cb378da13ea60 100644 --- a/src/test/run-pass/cleanup-copy-mode.rs +++ b/src/test/run-pass/cleanup-copy-mode.rs @@ -9,7 +9,7 @@ // except according to those terms. // xfail-win32 -fn adder(+x: @int, +y: @int) -> int { return *x + *y; } +fn adder(x: @int, y: @int) -> int { return *x + *y; } fn failer() -> @int { fail!(); } pub fn main() { assert!(result::is_err(&task::try(|| { diff --git a/src/test/run-pass/extern-pass-TwoU64s-ref.rs b/src/test/run-pass/extern-pass-TwoU64s-ref.rs index 2b18dba90f7fe..19b99eaccc956 100644 --- a/src/test/run-pass/extern-pass-TwoU64s-ref.rs +++ b/src/test/run-pass/extern-pass-TwoU64s-ref.rs @@ -16,7 +16,7 @@ struct TwoU64s { } pub extern { - pub fn rust_dbg_extern_identity_TwoU64s(&&u: TwoU64s) -> TwoU64s; + pub fn rust_dbg_extern_identity_TwoU64s(u: TwoU64s) -> TwoU64s; } pub fn main() { diff --git a/src/test/run-pass/extern-pub.rs b/src/test/run-pass/extern-pub.rs index f9b0ccbb5480e..1cd709ee91b9d 100644 --- a/src/test/run-pass/extern-pub.rs +++ b/src/test/run-pass/extern-pub.rs @@ -1,7 +1,7 @@ extern { - pub unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc, - ++v: **vec::raw::VecRepr, - ++n: libc::size_t); + pub unsafe fn vec_reserve_shared_actual(t: *sys::TypeDesc, + v: **vec::raw::VecRepr, + n: libc::size_t); } pub fn main() { diff --git a/src/test/run-pass/fn-bare-spawn.rs b/src/test/run-pass/fn-bare-spawn.rs index 857a8cdb3d02f..b78bd488bc6ea 100644 --- a/src/test/run-pass/fn-bare-spawn.rs +++ b/src/test/run-pass/fn-bare-spawn.rs @@ -14,7 +14,7 @@ fn spawn(val: T, f: extern fn(T)) { f(val); } -fn f(+i: int) { +fn f(i: int) { assert!(i == 100); } diff --git a/src/test/run-pass/foreign-struct.rs b/src/test/run-pass/foreign-struct.rs index 9ac17c27ed4ad..2dbc60e9a14ac 100644 --- a/src/test/run-pass/foreign-struct.rs +++ b/src/test/run-pass/foreign-struct.rs @@ -18,7 +18,7 @@ mod bindgen { #[nolink] pub extern { - pub fn printf(++v: void); + pub fn printf(v: void); } } diff --git a/src/test/run-pass/intrinsic-move-val.rs b/src/test/run-pass/intrinsic-move-val.rs index 966061a80856d..9f683d2089877 100644 --- a/src/test/run-pass/intrinsic-move-val.rs +++ b/src/test/run-pass/intrinsic-move-val.rs @@ -11,8 +11,8 @@ mod rusti { #[abi = "rust-intrinsic"] pub extern "rust-intrinsic" { - pub fn move_val_init(dst: &mut T, +src: T); - pub fn move_val(dst: &mut T, +src: T); + pub fn move_val_init(dst: &mut T, src: T); + pub fn move_val(dst: &mut T, src: T); } } diff --git a/src/test/run-pass/issue-2633-2.rs b/src/test/run-pass/issue-2633-2.rs index 2c3b4b71bb8e3..71a491b8a3955 100644 --- a/src/test/run-pass/issue-2633-2.rs +++ b/src/test/run-pass/issue-2633-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn a_val(&&x: ~int, +y: ~int) -> int { +fn a_val(x: ~int, y: ~int) -> int { *x + *y } diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index f54d3d39831f4..acd26a88a7361 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -53,23 +53,23 @@ pub mod pipes { // We should consider moving this to ::core::unsafe, although I // suspect graydon would want us to use void pointers instead. - pub unsafe fn uniquify(+x: *T) -> ~T { + pub unsafe fn uniquify(x: *T) -> ~T { unsafe { cast::transmute(x) } } - pub fn swap_state_acq(+dst: &mut state, src: state) -> state { + pub fn swap_state_acq(dst: &mut state, src: state) -> state { unsafe { transmute(rusti::atomic_xchg_acq(transmute(dst), src as int)) } } - pub fn swap_state_rel(+dst: &mut state, src: state) -> state { + pub fn swap_state_rel(dst: &mut state, src: state) -> state { unsafe { transmute(rusti::atomic_xchg_rel(transmute(dst), src as int)) } } - pub fn send(mut p: send_packet, +payload: T) { + pub fn send(mut p: send_packet, payload: T) { let mut p = p.unwrap(); let mut p = unsafe { uniquify(p) }; assert!((*p).payload.is_none()); @@ -229,7 +229,7 @@ pub mod pingpong { pub struct ping(::pipes::send_packet); pub struct pong(::pipes::send_packet); - pub fn liberate_ping(+p: ping) -> ::pipes::send_packet { + pub fn liberate_ping(p: ping) -> ::pipes::send_packet { unsafe { let addr : *::pipes::send_packet = match &p { &ping(ref x) => { cast::transmute(x) } @@ -240,7 +240,7 @@ pub mod pingpong { } } - pub fn liberate_pong(+p: pong) -> ::pipes::send_packet { + pub fn liberate_pong(p: pong) -> ::pipes::send_packet { unsafe { let addr : *::pipes::send_packet = match &p { &pong(ref x) => { cast::transmute(x) } @@ -262,14 +262,14 @@ pub mod pingpong { pub type ping = ::pipes::send_packet; pub type pong = ::pipes::recv_packet; - pub fn do_ping(+c: ping) -> pong { + pub fn do_ping(c: ping) -> pong { let (sp, rp) = ::pipes::entangle(); ::pipes::send(c, pingpong::ping(sp)); rp } - pub fn do_pong(+c: pong) -> (ping, ()) { + pub fn do_pong(c: pong) -> (ping, ()) { let packet = ::pipes::recv(c); if packet.is_none() { fail!(~"sender closed the connection") @@ -284,7 +284,7 @@ pub mod pingpong { pub type ping = ::pipes::recv_packet; pub type pong = ::pipes::send_packet; - pub fn do_ping(+c: ping) -> (pong, ()) { + pub fn do_ping(c: ping) -> (pong, ()) { let packet = ::pipes::recv(c); if packet.is_none() { fail!(~"sender closed the connection") @@ -292,7 +292,7 @@ pub mod pingpong { (pingpong::liberate_ping(packet.unwrap()), ()) } - pub fn do_pong(+c: pong) -> ping { + pub fn do_pong(c: pong) -> ping { let (sp, rp) = ::pipes::entangle(); ::pipes::send(c, pingpong::pong(sp)); rp @@ -300,14 +300,14 @@ pub mod pingpong { } } -fn client(+chan: pingpong::client::ping) { +fn client(chan: pingpong::client::ping) { let chan = pingpong::client::do_ping(chan); error!(~"Sent ping"); let (_chan, _data) = pingpong::client::do_pong(chan); error!(~"Received pong"); } -fn server(+chan: pingpong::server::ping) { +fn server(chan: pingpong::server::ping) { let (chan, _data) = pingpong::server::do_ping(chan); error!(~"Received ping"); let _chan = pingpong::server::do_pong(chan); diff --git a/src/test/run-pass/issue-2904.rs b/src/test/run-pass/issue-2904.rs index 77cc6b3e1b5b5..112aab597f029 100644 --- a/src/test/run-pass/issue-2904.rs +++ b/src/test/run-pass/issue-2904.rs @@ -59,7 +59,7 @@ fn square_from_char(c: char) -> square { } } -fn read_board_grid(+in: rdr) -> ~[~[square]] { +fn read_board_grid(in: rdr) -> ~[~[square]] { let in = @in as @io::Reader; let mut grid = ~[]; for in.each_line |line| { diff --git a/src/test/run-pass/issue-3656.rs b/src/test/run-pass/issue-3656.rs index b59810fc18875..895e90beef4aa 100644 --- a/src/test/run-pass/issue-3656.rs +++ b/src/test/run-pass/issue-3656.rs @@ -24,7 +24,7 @@ struct KEYGEN { extern { // Bogus signature, just need to test if it compiles. - pub fn malloc(++data: KEYGEN); + pub fn malloc(data: KEYGEN); } pub fn main() { diff --git a/src/test/run-pass/iter-min-max.rs b/src/test/run-pass/iter-min-max.rs index a8831a9c5ad59..5f427861e7917 100644 --- a/src/test/run-pass/iter-min-max.rs +++ b/src/test/run-pass/iter-min-max.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn is_even(&&x: uint) -> bool { (x % 2u) == 0u } +fn is_even(x: uint) -> bool { (x % 2u) == 0u } pub fn main() { assert!([1u, 3u].min() == 1u); diff --git a/src/test/run-pass/liveness-move-in-loop.rs b/src/test/run-pass/liveness-move-in-loop.rs index 658885124c2ef..acdf388a8ff03 100644 --- a/src/test/run-pass/liveness-move-in-loop.rs +++ b/src/test/run-pass/liveness-move-in-loop.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn take(+x: int) -> int {x} +fn take(x: int) -> int {x} fn the_loop() { let mut list = ~[]; diff --git a/src/test/run-pass/morestack5.rs b/src/test/run-pass/morestack5.rs index 1d232cc5cbd8d..e1561db8b9162 100644 --- a/src/test/run-pass/morestack5.rs +++ b/src/test/run-pass/morestack5.rs @@ -12,7 +12,7 @@ extern mod std; -fn getbig(&&i: int) { +fn getbig(i: int) { if i != 0 { getbig(i - 1); } diff --git a/src/test/run-pass/move-arg-2-unique.rs b/src/test/run-pass/move-arg-2-unique.rs index dbc73c20e6b21..ed3cdc81c3179 100644 --- a/src/test/run-pass/move-arg-2-unique.rs +++ b/src/test/run-pass/move-arg-2-unique.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn test(+foo: ~~[int]) { assert!((foo[0] == 10)); } +fn test(foo: ~~[int]) { assert!((foo[0] == 10)); } pub fn main() { let x = ~~[10]; diff --git a/src/test/run-pass/move-arg-2.rs b/src/test/run-pass/move-arg-2.rs index 5cc309d1a3ea4..fc909da8b0323 100644 --- a/src/test/run-pass/move-arg-2.rs +++ b/src/test/run-pass/move-arg-2.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn test(+foo: @~[int]) { assert!((foo[0] == 10)); } +fn test(foo: @~[int]) { assert!((foo[0] == 10)); } pub fn main() { let x = @~[10]; diff --git a/src/test/run-pass/move-arg.rs b/src/test/run-pass/move-arg.rs index ca3a5509c5cfd..87db5cbe2f13e 100644 --- a/src/test/run-pass/move-arg.rs +++ b/src/test/run-pass/move-arg.rs @@ -8,6 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn test(+foo: int) { assert!((foo == 10)); } +fn test(foo: int) { assert!((foo == 10)); } pub fn main() { let x = 10; test(x); } diff --git a/src/test/run-pass/move-nullary-fn.rs b/src/test/run-pass/move-nullary-fn.rs index eb4c5f871af48..ab66bb936354f 100644 --- a/src/test/run-pass/move-nullary-fn.rs +++ b/src/test/run-pass/move-nullary-fn.rs @@ -9,9 +9,9 @@ // except according to those terms. // Issue #922 -fn f2(+thing: @fn()) { } +fn f2(thing: @fn()) { } -fn f(+thing: @fn()) { +fn f(thing: @fn()) { f2(thing); } diff --git a/src/test/run-pass/operator-overloading.rs b/src/test/run-pass/operator-overloading.rs index ffd6903d7f7a4..8c26dfa1fac56 100644 --- a/src/test/run-pass/operator-overloading.rs +++ b/src/test/run-pass/operator-overloading.rs @@ -40,7 +40,7 @@ impl ops::Not for Point { } impl ops::Index for Point { - fn index(&self, +x: &bool) -> int { + fn index(&self, x: &bool) -> int { if *x { self.x } else { self.y } } } diff --git a/src/test/run-pass/option-unwrap.rs b/src/test/run-pass/option-unwrap.rs index 0efed2708f485..8698d1f39a88f 100644 --- a/src/test/run-pass/option-unwrap.rs +++ b/src/test/run-pass/option-unwrap.rs @@ -23,7 +23,7 @@ impl Drop for dtor { } } -fn unwrap(+o: Option) -> T { +fn unwrap(o: Option) -> T { match o { Some(v) => v, None => fail!() diff --git a/src/test/run-pass/pass-by-copy.rs b/src/test/run-pass/pass-by-copy.rs index c3ab589b66cf7..c4f328940c49f 100644 --- a/src/test/run-pass/pass-by-copy.rs +++ b/src/test/run-pass/pass-by-copy.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn magic(+x: A) { debug!(x); } -fn magic2(+x: @int) { debug!(x); } +fn magic(x: A) { debug!(x); } +fn magic2(x: @int) { debug!(x); } struct A { a: @int } diff --git a/src/test/run-pass/pipe-bank-proto.rs b/src/test/run-pass/pipe-bank-proto.rs index c4ce1434165e3..5e2be7e6d081a 100644 --- a/src/test/run-pass/pipe-bank-proto.rs +++ b/src/test/run-pass/pipe-bank-proto.rs @@ -48,12 +48,12 @@ macro_rules! move_it ( { $x:expr } => { unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } } ) -fn switch(+endp: pipes::RecvPacket, - f: &fn(+v: Option) -> U) -> U { +fn switch(endp: pipes::RecvPacket, + f: &fn(v: Option) -> U) -> U { f(pipes::try_recv(endp)) } -fn move_it(+x: T) -> T { x } +fn move_it(x: T) -> T { x } macro_rules! follow ( { @@ -68,7 +68,7 @@ macro_rules! follow ( ); ) -fn client_follow(+bank: bank::client::login) { +fn client_follow(bank: bank::client::login) { use bank::*; let bank = client::login(bank, ~"theincredibleholk", ~"1234"); @@ -89,7 +89,7 @@ fn client_follow(+bank: bank::client::login) { )); } -fn bank_client(+bank: bank::client::login) { +fn bank_client(bank: bank::client::login) { use bank::*; let bank = client::login(bank, ~"theincredibleholk", ~"1234"); diff --git a/src/test/run-pass/pipe-pingpong-bounded.rs b/src/test/run-pass/pipe-pingpong-bounded.rs index d11d5eb47bbb9..3c37371a5371c 100644 --- a/src/test/run-pass/pipe-pingpong-bounded.rs +++ b/src/test/run-pass/pipe-pingpong-bounded.rs @@ -91,7 +91,7 @@ mod test { use core::pipes::recv; use pingpong::{ping, pong}; - pub fn client(+chan: ::pingpong::client::ping) { + pub fn client(chan: ::pingpong::client::ping) { use pingpong::client; let chan = client::ping(chan); return; @@ -100,7 +100,7 @@ mod test { error!("Received pong"); } - pub fn server(+chan: ::pingpong::server::ping) { + pub fn server(chan: ::pingpong::server::ping) { use pingpong::server; let ping(chan) = recv(chan); return; diff --git a/src/test/run-pass/pipe-pingpong-proto.rs b/src/test/run-pass/pipe-pingpong-proto.rs index d1198f3611d15..5978438ef7635 100644 --- a/src/test/run-pass/pipe-pingpong-proto.rs +++ b/src/test/run-pass/pipe-pingpong-proto.rs @@ -29,7 +29,7 @@ mod test { use core::pipes::recv; use pingpong::{ping, pong}; - pub fn client(+chan: ::pingpong::client::ping) { + pub fn client(chan: ::pingpong::client::ping) { use pingpong::client; let chan = client::ping(chan); @@ -38,7 +38,7 @@ mod test { error!(~"Received pong"); } - pub fn server(+chan: ::pingpong::server::ping) { + pub fn server(chan: ::pingpong::server::ping) { use pingpong::server; let ping(chan) = recv(chan); diff --git a/src/test/run-pass/reflect-visit-data.rs b/src/test/run-pass/reflect-visit-data.rs index 5b01d24aa8be1..5255c13bead62 100644 --- a/src/test/run-pass/reflect-visit-data.rs +++ b/src/test/run-pass/reflect-visit-data.rs @@ -633,7 +633,7 @@ impl TyVisitor for my_visitor { fn visit_closure_ptr(&self, _ck: uint) -> bool { true } } -fn get_tydesc_for(&&_t: T) -> *TyDesc { +fn get_tydesc_for(_t: T) -> *TyDesc { get_tydesc::() } diff --git a/src/test/run-pass/regions-copy-closure.rs b/src/test/run-pass/regions-copy-closure.rs index 308528ef57200..2e9ff88f96e90 100644 --- a/src/test/run-pass/regions-copy-closure.rs +++ b/src/test/run-pass/regions-copy-closure.rs @@ -12,7 +12,7 @@ struct closure_box<'self> { cl: &'self fn(), } -fn box_it<'r>(+x: &'r fn()) -> closure_box<'r> { +fn box_it<'r>(x: &'r fn()) -> closure_box<'r> { closure_box {cl: x} } diff --git a/src/test/run-pass/regions-static-closure.rs b/src/test/run-pass/regions-static-closure.rs index 5221bc28fb838..eab057548ef5e 100644 --- a/src/test/run-pass/regions-static-closure.rs +++ b/src/test/run-pass/regions-static-closure.rs @@ -12,7 +12,7 @@ struct closure_box<'self> { cl: &'self fn(), } -fn box_it<'r>(+x: &'r fn()) -> closure_box<'r> { +fn box_it<'r>(x: &'r fn()) -> closure_box<'r> { closure_box {cl: x} } diff --git a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs index afed0bd9ac3f8..2a69b2ca01779 100644 --- a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs +++ b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs @@ -12,7 +12,7 @@ use core::cell::Cell; pub fn main() { test05(); } -fn test05_start(&&f: ~fn(int)) { +fn test05_start(f: ~fn(int)) { f(22); } diff --git a/src/test/run-pass/spawn.rs b/src/test/run-pass/spawn.rs index 63c2b7da38f2f..9a5131ef23000 100644 --- a/src/test/run-pass/spawn.rs +++ b/src/test/run-pass/spawn.rs @@ -17,4 +17,4 @@ pub fn main() { task::spawn(|| child(10) ); } -fn child(&&i: int) { error!(i); assert!((i == 10)); } +fn child(i: int) { error!(i); assert!((i == 10)); } diff --git a/src/test/run-pass/spawn2.rs b/src/test/run-pass/spawn2.rs index e748a1636ea80..642babb5a1e5c 100644 --- a/src/test/run-pass/spawn2.rs +++ b/src/test/run-pass/spawn2.rs @@ -11,7 +11,7 @@ pub fn main() { task::spawn(|| child((10, 20, 30, 40, 50, 60, 70, 80, 90)) ); } -fn child(&&args: (int, int, int, int, int, int, int, int, int)) { +fn child(args: (int, int, int, int, int, int, int, int, int)) { let (i1, i2, i3, i4, i5, i6, i7, i8, i9) = args; error!(i1); error!(i2); diff --git a/src/test/run-pass/static-method-test.rs b/src/test/run-pass/static-method-test.rs index 973897cd14521..e06d09c564c00 100644 --- a/src/test/run-pass/static-method-test.rs +++ b/src/test/run-pass/static-method-test.rs @@ -13,7 +13,7 @@ // A trait for objects that can be used to do an if-then-else // (No actual need for this to be static, but it is a simple test.) trait bool_like { - fn select(b: Self, +x1: A, +x2: A) -> A; + fn select(b: Self, x1: A, x2: A) -> A; } fn andand(x1: T, x2: T) -> T { @@ -21,38 +21,38 @@ fn andand(x1: T, x2: T) -> T { } impl bool_like for bool { - fn select(&&b: bool, +x1: A, +x2: A) -> A { + fn select(b: bool, x1: A, x2: A) -> A { if b { x1 } else { x2 } } } impl bool_like for int { - fn select(&&b: int, +x1: A, +x2: A) -> A { + fn select(b: int, x1: A, x2: A) -> A { if b != 0 { x1 } else { x2 } } } // A trait for sequences that can be constructed imperatively. trait buildable { - fn build_sized(size: uint, builder: &fn(push: &fn(+v: A))) -> Self; + fn build_sized(size: uint, builder: &fn(push: &fn(v: A))) -> Self; } impl buildable for @[A] { #[inline(always)] - fn build_sized(size: uint, builder: &fn(push: &fn(+v: A))) -> @[A] { + fn build_sized(size: uint, builder: &fn(push: &fn(v: A))) -> @[A] { at_vec::build_sized(size, builder) } } impl buildable for ~[A] { #[inline(always)] - fn build_sized(size: uint, builder: &fn(push: &fn(+v: A))) -> ~[A] { + fn build_sized(size: uint, builder: &fn(push: &fn(v: A))) -> ~[A] { vec::build_sized(size, builder) } } #[inline(always)] -fn build>(builder: &fn(push: &fn(+v: A))) -> B { +fn build>(builder: &fn(push: &fn(v: A))) -> B { buildable::build_sized(4, builder) } diff --git a/src/test/run-pass/struct-return.rs b/src/test/run-pass/struct-return.rs index 5427ee38b430c..7ac74fd52175f 100644 --- a/src/test/run-pass/struct-return.rs +++ b/src/test/run-pass/struct-return.rs @@ -16,8 +16,8 @@ mod rustrt { #[nolink] pub extern { - pub fn debug_abi_1(++q: Quad) -> Quad; - pub fn debug_abi_2(++f: Floats) -> Floats; + pub fn debug_abi_1(q: Quad) -> Quad; + pub fn debug_abi_2(f: Floats) -> Floats; } } diff --git a/src/test/run-pass/task-comm-12.rs b/src/test/run-pass/task-comm-12.rs index e61a855b42941..0f0b82d7c21df 100644 --- a/src/test/run-pass/task-comm-12.rs +++ b/src/test/run-pass/task-comm-12.rs @@ -12,7 +12,7 @@ extern mod std; pub fn main() { test00(); } -fn start(&&task_number: int) { debug!("Started / Finished task."); } +fn start(task_number: int) { debug!("Started / Finished task."); } fn test00() { let i: int = 0; diff --git a/src/test/run-pass/task-life-0.rs b/src/test/run-pass/task-life-0.rs index 3e27ffb415239..9885c5d6f3fc0 100644 --- a/src/test/run-pass/task-life-0.rs +++ b/src/test/run-pass/task-life-0.rs @@ -13,6 +13,6 @@ pub fn main() { task::spawn(|| child(~"Hello") ); } -fn child(&&s: ~str) { +fn child(s: ~str) { } diff --git a/src/test/run-pass/threads.rs b/src/test/run-pass/threads.rs index 288a23b855b60..a72d3dd40f4ca 100644 --- a/src/test/run-pass/threads.rs +++ b/src/test/run-pass/threads.rs @@ -18,4 +18,4 @@ pub fn main() { debug!("main thread exiting"); } -fn child(&&x: int) { debug!(x); } +fn child(x: int) { debug!(x); } diff --git a/src/test/run-pass/unique-fn-arg-move.rs b/src/test/run-pass/unique-fn-arg-move.rs index bbb33560e32dd..4a6386244f177 100644 --- a/src/test/run-pass/unique-fn-arg-move.rs +++ b/src/test/run-pass/unique-fn-arg-move.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(+i: ~int) { +fn f(i: ~int) { assert!(*i == 100); } diff --git a/src/test/run-pass/yield.rs b/src/test/run-pass/yield.rs index 8ed269099520a..2d916abf0da69 100644 --- a/src/test/run-pass/yield.rs +++ b/src/test/run-pass/yield.rs @@ -12,7 +12,7 @@ pub fn main() { let mut result = None; let mut builder = task::task(); - builder.future_result(|+r| { result = Some(r); }); + builder.future_result(|r| { result = Some(r); }); builder.spawn(child); error!("1"); task::yield(); diff --git a/src/test/run-pass/yield1.rs b/src/test/run-pass/yield1.rs index 278ce1c37666f..f3ca5b1211899 100644 --- a/src/test/run-pass/yield1.rs +++ b/src/test/run-pass/yield1.rs @@ -12,7 +12,7 @@ pub fn main() { let mut result = None; let mut builder = task::task(); - builder.future_result(|+r| { result = Some(r); }); + builder.future_result(|r| { result = Some(r); }); builder.spawn(child); error!("1"); task::yield(); From 3affc6ed4071a183da81bcc2048fff82d3e35e81 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 8 May 2013 09:03:31 -0700 Subject: [PATCH 21/25] librustc: Fix merge fallout. --- src/librustc/middle/lint.rs | 7 ------- src/libsyntax/ext/deriving/generic.rs | 8 ++------ src/libsyntax/ext/deriving/mod.rs | 4 ++-- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index ceb473da52fc0..b3bd60d8ac7be 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -196,13 +196,6 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[ default: deny }), - ("deprecated_mutable_fields", - LintSpec { - lint: deprecated_mutable_fields, - desc: "deprecated mutable fields in structures", - default: deny - }), - ("unused_unsafe", LintSpec { lint: unused_unsafe, diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 565d6dd59baac..d785f3816de30 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -818,12 +818,8 @@ fn summarise_struct(cx: @ext_ctxt, span: span, let mut unnamed_count = 0; for struct_def.fields.each |field| { match field.node.kind { - ast::named_field(ident, _, _) => { - named_idents.push(ident) - } - ast::unnamed_field => { - unnamed_count += 1; - } + ast::named_field(ident, _) => named_idents.push(ident), + ast::unnamed_field => unnamed_count += 1, } } diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index d48ff98be06ee..2bd45e1466ce7 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -281,8 +281,8 @@ pub fn create_struct_pattern(cx: @ext_ctxt, for struct_def.fields.eachi |i, struct_field| { let opt_id = match struct_field.node.kind { - ast::named_field(ident, _, _) if (struct_type == Unknown || - struct_type == Record) => { + ast::named_field(ident, _) if (struct_type == Unknown || + struct_type == Record) => { struct_type = Record; Some(ident) } From 72868450df54ff1ec80e92e3f2fc827cfb1e9f02 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 8 May 2013 12:26:34 -0700 Subject: [PATCH 22/25] libcore: Fix more merge fallout. --- src/libcore/rt/local_services.rs | 4 ++-- src/libsyntax/ext/build.rs | 18 ++++++++++++++++++ src/libsyntax/ext/deriving/rand.rs | 15 ++++++++++----- src/libsyntax/fold.rs | 1 + 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/libcore/rt/local_services.rs b/src/libcore/rt/local_services.rs index b83e1d2464890..5ca7a72e84e86 100644 --- a/src/libcore/rt/local_services.rs +++ b/src/libcore/rt/local_services.rs @@ -225,8 +225,8 @@ mod test { fn rng() { do run_in_newsched_task() { use rand::{rng, Rng}; - let r = rng(); + let mut r = rng(); let _ = r.next(); } } -} \ No newline at end of file +} diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index c1163fda844f6..3097cb799a204 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -11,6 +11,7 @@ use ast; use codemap; use codemap::span; +use fold; use ext::base::ext_ctxt; use ext::build; @@ -516,3 +517,20 @@ pub fn mk_unreachable(cx: @ext_ctxt, span: span) -> @ast::expr { pub fn mk_unreachable_arm(cx: @ext_ctxt, span: span) -> ast::arm { mk_arm(cx, span, ~[mk_pat_wild(cx, span)], mk_unreachable(cx, span)) } + +// +// Duplication functions +// +// These functions just duplicate AST nodes. +// + +pub fn duplicate_expr(cx: @ext_ctxt, expr: @ast::expr) -> @ast::expr { + let folder = fold::default_ast_fold(); + let folder = @fold::AstFoldFns { + new_id: |_| cx.next_id(), + ..*folder + }; + let folder = fold::make_fold(folder); + folder.fold_expr(expr) +} + diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 03202801d206d..604686f442fd7 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -35,7 +35,7 @@ pub fn expand_deriving_rand(cx: @ext_ctxt, self_ty: None, args: ~[ Ptr(~Literal(Path::new_local(~"R")), - Borrowed(None, ast::m_imm)) + Borrowed(None, ast::m_mutbl)) ], ret_ty: Self, const_nonmatching: false, @@ -59,8 +59,10 @@ fn rand_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) -> @expr cx.ident_of(~"rand") ]; let rand_call = || { - build::mk_call_global(cx, span, - copy rand_ident, copy rng) + build::mk_call_global(cx, + span, + copy rand_ident, + ~[ build::duplicate_expr(cx, rng[0]) ]) }; return match *substr.fields { @@ -80,7 +82,10 @@ fn rand_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) -> @expr let rand_name = build::mk_raw_path_(span, copy rand_ident, None, ~[ u32_ty, r_ty ]); let rand_name = build::mk_path_raw(cx, span, rand_name); - let rv_call = build::mk_call_(cx, span, rand_name, copy rng); + let rv_call = build::mk_call_(cx, + span, + rand_name, + ~[ build::duplicate_expr(cx, rng[0]) ]); // rand() % variants.len() let rand_variant = build::mk_binary(cx, span, ast::rem, @@ -133,4 +138,4 @@ fn rand_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) -> @expr } } } -} \ No newline at end of file +} diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 229a8664d0c35..d181dd87e38d1 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -859,3 +859,4 @@ impl AstFoldExtensions for @ast_fold { pub fn make_fold(afp: ast_fold_fns) -> @ast_fold { afp as @ast_fold } + From 36fbf71686c54c608b7570d55d22f6145bc38610 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 8 May 2013 12:28:22 -0700 Subject: [PATCH 23/25] llvm: Unrevert change --- src/llvm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llvm b/src/llvm index 56dd407f4f97a..2e9f0d21fe321 160000 --- a/src/llvm +++ b/src/llvm @@ -1 +1 @@ -Subproject commit 56dd407f4f97a01b8df6554c569170d2fc276fcb +Subproject commit 2e9f0d21fe321849a4759a01fc28eae82ef196d6 From 85d9409b206284847bec802866ad85234f7d8e25 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 8 May 2013 14:16:43 -0700 Subject: [PATCH 24/25] test: Fix broken test --- src/test/compile-fail/block-coerce-no.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/compile-fail/block-coerce-no.rs b/src/test/compile-fail/block-coerce-no.rs index f3ec875340550..df9eb9fdda69b 100644 --- a/src/test/compile-fail/block-coerce-no.rs +++ b/src/test/compile-fail/block-coerce-no.rs @@ -12,7 +12,7 @@ // other tycons. fn coerce(b: &fn()) -> extern fn() { - fn lol(f: extern fn(+v: &fn()) -> extern fn(), + fn lol(f: extern fn(v: &fn()) -> extern fn(), g: &fn()) -> extern fn() { return f(g); } fn fn_id(f: extern fn()) -> extern fn() { return f } return lol(fn_id, b); From d20e63ab65f7ba28db36ae43379706ca9dba1ca5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 8 May 2013 17:03:17 -0700 Subject: [PATCH 25/25] test: Fix modes in the benchmarks. --- src/test/bench/graph500-bfs.rs | 4 ++-- src/test/bench/msgsend-ring-mutex-arcs.rs | 5 +---- src/test/bench/msgsend-ring-pipes.rs | 4 ++-- src/test/bench/msgsend-ring-rw-arcs.rs | 5 +---- src/test/bench/pingpong.rs | 5 +++-- src/test/bench/shootout-pfib.rs | 2 +- src/test/bench/task-perf-linked-failure.rs | 2 +- src/test/bench/task-perf-spawnalot.rs | 2 +- 8 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 83855b142feb7..1842a8ff42e52 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -273,7 +273,7 @@ fn pbfs(graph: &arc::ARC, key: node_id) -> bfs_result { colors = do par::mapi(*color_vec) { let colors = arc::clone(&color); let graph = arc::clone(graph); - let result: ~fn(+x: uint, +y: &color) -> color = |i, c| { + let result: ~fn(x: uint, y: &color) -> color = |i, c| { let colors = arc::get(&colors); let graph = arc::get(&graph); match *c { @@ -395,7 +395,7 @@ fn validate(edges: ~[(node_id, node_id)], let status = do par::alli(tree) { let edges = copy edges; - let result: ~fn(+x: uint, v: &i64) -> bool = |u, v| { + let result: ~fn(x: uint, v: &i64) -> bool = |u, v| { let u = u as node_id; if *v == -1i64 || u == root { true diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index ed08297ab3fe3..2d234634cc8ba 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -45,10 +45,7 @@ fn init() -> (pipe,pipe) { } -fn thread_ring(i: uint, - count: uint, - +num_chan: pipe, - +num_port: pipe) { +fn thread_ring(i: uint, count: uint, num_chan: pipe, num_port: pipe) { let mut num_chan = Some(num_chan); let mut num_port = Some(num_port); // Send/Receive lots of messages. diff --git a/src/test/bench/msgsend-ring-pipes.rs b/src/test/bench/msgsend-ring-pipes.rs index 22d58730f58f3..aef5c18499ac3 100644 --- a/src/test/bench/msgsend-ring-pipes.rs +++ b/src/test/bench/msgsend-ring-pipes.rs @@ -35,8 +35,8 @@ macro_rules! move_out ( fn thread_ring(i: uint, count: uint, - +num_chan: ring::client::num, - +num_port: ring::server::num) { + num_chan: ring::client::num, + num_port: ring::server::num) { let mut num_chan = Some(num_chan); let mut num_port = Some(num_port); // Send/Receive lots of messages. diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index 221177b9dd9a8..02415c4bcfce7 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -46,10 +46,7 @@ fn init() -> (pipe,pipe) { } -fn thread_ring(i: uint, - count: uint, - +num_chan: pipe, - +num_port: pipe) { +fn thread_ring(i: uint, count: uint, num_chan: pipe, num_port: pipe) { let mut num_chan = Some(num_chan); let mut num_port = Some(num_port); // Send/Receive lots of messages. diff --git a/src/test/bench/pingpong.rs b/src/test/bench/pingpong.rs index 09e663325ed49..cfad253cfed5b 100644 --- a/src/test/bench/pingpong.rs +++ b/src/test/bench/pingpong.rs @@ -117,8 +117,9 @@ pub fn spawn_service_recv( client } -fn switch(+endp: core::pipes::RecvPacketBuffered, - f: &fn(+v: Option) -> U) -> U { +fn switch(endp: core::pipes::RecvPacketBuffered, + f: &fn(v: Option) -> U) + -> U { f(core::pipes::try_recv(endp)) } diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 27a59feedd0a3..b7ae331c8f376 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -66,7 +66,7 @@ fn parse_opts(argv: ~[~str]) -> Config { } } -fn stress_task(&&id: int) { +fn stress_task(id: int) { let mut i = 0; loop { let n = 15; diff --git a/src/test/bench/task-perf-linked-failure.rs b/src/test/bench/task-perf-linked-failure.rs index 99e7de307279f..6015f21be727f 100644 --- a/src/test/bench/task-perf-linked-failure.rs +++ b/src/test/bench/task-perf-linked-failure.rs @@ -46,7 +46,7 @@ fn grandchild_group(num_tasks: uint) { // Master grandchild task exits early. } -fn spawn_supervised_blocking(myname: &str, +f: ~fn()) { +fn spawn_supervised_blocking(myname: &str, f: ~fn()) { let mut res = None; let mut builder = task::task(); builder.future_result(|r| res = Some(r)); diff --git a/src/test/bench/task-perf-spawnalot.rs b/src/test/bench/task-perf-spawnalot.rs index 8c5bbe257bdd2..e6da898a03493 100644 --- a/src/test/bench/task-perf-spawnalot.rs +++ b/src/test/bench/task-perf-spawnalot.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(&&n: uint) { +fn f(n: uint) { let mut i = 0u; while i < n { task::try(|| g() );