auto merge of #8257 : mozilla/rust/rollup, r=thestinger
1f9c392 r=brson 54e685d r=graydon 1992765 r=thestinger 75155cd r=bblum def8891 r=graydon
This commit is contained in:
commit
20fad0f5ff
@ -140,14 +140,14 @@ impl<T:Freeze+Send> Arc<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate an atomically reference counted wrapper.
|
||||
*
|
||||
* The resulting two `arc` objects will point to the same underlying data
|
||||
* object. However, one of the `arc` objects can be sent to another task,
|
||||
* allowing them to share the underlying data.
|
||||
*/
|
||||
impl<T:Freeze + Send> Clone for Arc<T> {
|
||||
/**
|
||||
* Duplicate an atomically reference counted wrapper.
|
||||
*
|
||||
* The resulting two `arc` objects will point to the same underlying data
|
||||
* object. However, one of the `arc` objects can be sent to another task,
|
||||
* allowing them to share the underlying data.
|
||||
*/
|
||||
fn clone(&self) -> Arc<T> {
|
||||
Arc { x: self.x.clone() }
|
||||
}
|
||||
@ -164,7 +164,7 @@ struct MutexArc<T> { priv x: UnsafeAtomicRcBox<MutexArcInner<T>> }
|
||||
|
||||
|
||||
impl<T:Send> Clone for MutexArc<T> {
|
||||
/// Duplicate a mutex-protected Arc, as arc::clone.
|
||||
/// Duplicate a mutex-protected Arc. See arc::clone for more details.
|
||||
fn clone(&self) -> MutexArc<T> {
|
||||
// NB: Cloning the underlying mutex is not necessary. Its reference
|
||||
// count would be exactly the same as the shared state's.
|
||||
@ -312,12 +312,10 @@ struct RWArc<T> {
|
||||
priv x: UnsafeAtomicRcBox<RWArcInner<T>>,
|
||||
}
|
||||
|
||||
impl<T:Freeze + Send> RWArc<T> {
|
||||
/// Duplicate a rwlock-protected Arc, as arc::clone.
|
||||
pub fn clone(&self) -> RWArc<T> {
|
||||
RWArc {
|
||||
x: self.x.clone(),
|
||||
}
|
||||
impl<T:Freeze + Send> Clone for RWArc<T> {
|
||||
/// Duplicate a rwlock-protected Arc. See arc::clone for more details.
|
||||
fn clone(&self) -> RWArc<T> {
|
||||
RWArc { x: self.x.clone() }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1638,9 +1638,9 @@ mod tests {
|
||||
fn bench_btv_small_iter(b: &mut BenchHarness) {
|
||||
let bitv = Bitv::new(uint::bits, false);
|
||||
do b.iter {
|
||||
let mut sum = 0;
|
||||
let mut _sum = 0;
|
||||
foreach pres in bitv.iter() {
|
||||
sum += pres as uint;
|
||||
_sum += pres as uint;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1649,9 +1649,9 @@ mod tests {
|
||||
fn bench_bitv_big_iter(b: &mut BenchHarness) {
|
||||
let bitv = Bitv::new(BENCH_BITS, false);
|
||||
do b.iter {
|
||||
let mut sum = 0;
|
||||
let mut _sum = 0;
|
||||
foreach pres in bitv.iter() {
|
||||
sum += pres as uint;
|
||||
_sum += pres as uint;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1661,9 +1661,9 @@ mod tests {
|
||||
let bitv = BitvSet::from_bitv(from_fn(BENCH_BITS,
|
||||
|idx| {idx % 3 == 0}));
|
||||
do b.iter {
|
||||
let mut sum = 0;
|
||||
let mut _sum = 0;
|
||||
foreach idx in bitv.iter() {
|
||||
sum += idx;
|
||||
_sum += idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -633,16 +633,12 @@ pub mod bytepipes {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
use flatpipes::{Flattener, Unflattener};
|
||||
use flatpipes::bytepipes::*;
|
||||
use flatpipes::BytePort;
|
||||
use flatpipes::pod;
|
||||
use flatpipes::serial;
|
||||
use io_util::BufReader;
|
||||
use flatpipes::{BytePort, FlatChan, FlatPort};
|
||||
|
||||
use std::comm;
|
||||
use std::io::BytesWriter;
|
||||
use std::result;
|
||||
use std::task;
|
||||
|
||||
#[test]
|
||||
@ -727,7 +723,11 @@ mod test {
|
||||
|
||||
// FIXME #2064: Networking doesn't work on x86
|
||||
// XXX Broken until networking support is added back
|
||||
/*#[test]
|
||||
/*
|
||||
use flatpipes::{Flattener, Unflattener, FlatChan, FlatPort};
|
||||
use flatpipes::bytepipes::*;
|
||||
|
||||
#[test]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
fn test_pod_tcp_stream() {
|
||||
fn reader_port(buf: TcpSocketBuf
|
||||
@ -767,6 +767,8 @@ mod test {
|
||||
port: uint) {
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::comm;
|
||||
use std::result;
|
||||
use net::ip;
|
||||
use net::tcp;
|
||||
use uv;
|
||||
|
@ -1159,7 +1159,7 @@ fn store_non_ref_bindings(bcx: @mut Block,
|
||||
add_clean_temp_mem(bcx, lldest, binding_info.ty);
|
||||
temp_cleanups.push(lldest);
|
||||
temp_cleanups
|
||||
}
|
||||
};
|
||||
}
|
||||
TrByRef => {}
|
||||
}
|
||||
|
@ -2750,13 +2750,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
||||
}
|
||||
ast::expr_vec(ref args, mutbl) => {
|
||||
let t: ty::t = fcx.infcx().next_ty_var();
|
||||
let mut arg_is_bot = false;
|
||||
let mut arg_is_err = false;
|
||||
foreach e in args.iter() {
|
||||
check_expr_has_type(fcx, *e, t);
|
||||
let arg_t = fcx.expr_ty(*e);
|
||||
arg_is_bot |= ty::type_is_bot(arg_t);
|
||||
arg_is_err |= ty::type_is_error(arg_t);
|
||||
}
|
||||
let typ = ty::mk_evec(tcx, ty::mt {ty: t, mutbl: mutbl},
|
||||
ty::vstore_fixed(args.len()));
|
||||
|
@ -85,6 +85,16 @@ pub fn log_type<T>(level: u32, object: &T) {
|
||||
fn newsched_log_str(msg: ~str) {
|
||||
use rt::task::Task;
|
||||
use rt::local::Local;
|
||||
use str::StrSlice;
|
||||
use container::Container;
|
||||
|
||||
// Truncate the string
|
||||
let buf_bytes = 256;
|
||||
let msg = if msg.len() > buf_bytes {
|
||||
msg.slice(0, buf_bytes) + "[...]"
|
||||
} else {
|
||||
msg
|
||||
};
|
||||
|
||||
unsafe {
|
||||
match Local::try_unsafe_borrow::<Task>() {
|
||||
|
@ -235,19 +235,24 @@ impl<T> Option<T> {
|
||||
self.take().map_consume_default(def, blk)
|
||||
}
|
||||
|
||||
/// Apply a function to the contained value or do nothing
|
||||
pub fn mutate(&mut self, f: &fn(T) -> T) {
|
||||
/// Apply a function to the contained value or do nothing.
|
||||
/// Returns true if the contained value was mutated.
|
||||
pub fn mutate(&mut self, f: &fn(T) -> T) -> bool {
|
||||
if self.is_some() {
|
||||
*self = Some(f(self.take_unwrap()));
|
||||
}
|
||||
true
|
||||
} else { false }
|
||||
}
|
||||
|
||||
/// Apply a function to the contained value or set it to a default
|
||||
pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) {
|
||||
/// Apply a function to the contained value or set it to a default.
|
||||
/// Returns true if the contained value was mutated, or false if set to the default.
|
||||
pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) -> bool {
|
||||
if self.is_some() {
|
||||
*self = Some(f(self.take_unwrap()));
|
||||
true
|
||||
} else {
|
||||
*self = Some(def);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@ -575,4 +580,18 @@ mod tests {
|
||||
assert_eq!(it.size_hint(), (0, Some(0)));
|
||||
assert!(it.next().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mutate() {
|
||||
let mut x = Some(3i);
|
||||
assert!(x.mutate(|i| i+1));
|
||||
assert_eq!(x, Some(4i));
|
||||
assert!(x.mutate_default(0, |i| i+1));
|
||||
assert_eq!(x, Some(5i));
|
||||
x = None;
|
||||
assert!(!x.mutate(|i| i+1));
|
||||
assert_eq!(x, None);
|
||||
assert!(!x.mutate_default(0i, |i| i+1));
|
||||
assert_eq!(x, Some(0i));
|
||||
}
|
||||
}
|
||||
|
@ -2141,11 +2141,15 @@ macro_rules! iterator {
|
||||
None
|
||||
} else {
|
||||
let old = self.ptr;
|
||||
// purposefully don't use 'ptr.offset' because for
|
||||
// vectors with 0-size elements this would return the
|
||||
// same pointer.
|
||||
self.ptr = cast::transmute(self.ptr as uint +
|
||||
sys::nonzero_size_of::<T>());
|
||||
self.ptr = if sys::size_of::<T>() == 0 {
|
||||
// purposefully don't use 'ptr.offset' because for
|
||||
// vectors with 0-size elements this would return the
|
||||
// same pointer.
|
||||
cast::transmute(self.ptr as uint + 1)
|
||||
} else {
|
||||
self.ptr.offset(1)
|
||||
};
|
||||
|
||||
Some(cast::transmute(old))
|
||||
}
|
||||
}
|
||||
@ -2171,9 +2175,12 @@ macro_rules! double_ended_iterator {
|
||||
if self.end == self.ptr {
|
||||
None
|
||||
} else {
|
||||
// See above for why 'ptr.offset' isn't used
|
||||
self.end = cast::transmute(self.end as uint -
|
||||
sys::nonzero_size_of::<T>());
|
||||
self.end = if sys::size_of::<T>() == 0 {
|
||||
// See above for why 'ptr.offset' isn't used
|
||||
cast::transmute(self.end as uint - 1)
|
||||
} else {
|
||||
self.end.offset(-1)
|
||||
};
|
||||
Some(cast::transmute(self.end))
|
||||
}
|
||||
}
|
||||
@ -3566,3 +3573,39 @@ mod tests {
|
||||
assert!(cnt == 3);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
use extra::test::BenchHarness;
|
||||
use vec;
|
||||
use option::*;
|
||||
|
||||
#[bench]
|
||||
fn iterator(bh: &mut BenchHarness) {
|
||||
// peculiar numbers to stop LLVM from optimising the summation
|
||||
// out.
|
||||
let v = vec::from_fn(100, |i| i ^ (i << 1) ^ (i >> 1));
|
||||
|
||||
do bh.iter {
|
||||
let mut sum = 0;
|
||||
foreach x in v.iter() {
|
||||
sum += *x;
|
||||
}
|
||||
// sum == 11806, to stop dead code elimination.
|
||||
if sum == 0 {fail!()}
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn mut_iterator(bh: &mut BenchHarness) {
|
||||
let mut v = vec::from_elem(100, 0);
|
||||
|
||||
do bh.iter {
|
||||
let mut i = 0;
|
||||
foreach x in v.mut_iter() {
|
||||
*x = i;
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:task failed at 'assertion failed: false'
|
||||
// error-pattern:failed at 'assertion failed: false'
|
||||
|
||||
fn main() {
|
||||
assert!(false);
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:task failed at 'test-assert-fmt 42 rust'
|
||||
// error-pattern:failed at 'test-assert-fmt 42 rust'
|
||||
|
||||
fn main() {
|
||||
assert!(false, "test-assert-fmt %d %s", 42, "rust");
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:task failed at 'test-assert-owned'
|
||||
// error-pattern:failed at 'test-assert-owned'
|
||||
|
||||
fn main() {
|
||||
assert!(false, ~"test-assert-owned");
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:task failed at 'test-assert-static'
|
||||
// error-pattern:failed at 'test-assert-static'
|
||||
|
||||
fn main() {
|
||||
assert!(false, "test-assert-static");
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:task failed at 'explicit failure'
|
||||
// error-pattern:failed at 'explicit failure'
|
||||
|
||||
fn main() {
|
||||
fail!();
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:task failed at 'test-fail-fmt 42 rust'
|
||||
// error-pattern:failed at 'test-fail-fmt 42 rust'
|
||||
|
||||
fn main() {
|
||||
fail!("test-fail-fmt %d %s", 42, "rust");
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:task failed at 'test-fail-owned'
|
||||
// error-pattern:failed at 'test-fail-owned'
|
||||
|
||||
fn main() {
|
||||
fail!("test-fail-owned");
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:task failed at 'test-fail-static'
|
||||
// error-pattern:failed at 'test-fail-static'
|
||||
|
||||
fn main() {
|
||||
fail!("test-fail-static");
|
||||
|
Loading…
x
Reference in New Issue
Block a user