test: Update all tests with the sync changes
This commit is contained in:
parent
eff025797a
commit
5163a26d30
27 changed files with 80 additions and 324 deletions
|
@ -359,7 +359,7 @@ fn main() {
|
||||||
|
|
||||||
spawn(proc() {
|
spawn(proc() {
|
||||||
let local_arc : Arc<~[f64]> = rx.recv();
|
let local_arc : Arc<~[f64]> = rx.recv();
|
||||||
let task_numbers = local_arc.get();
|
let task_numbers = &*local_arc;
|
||||||
println!("{}-norm = {}", num, pnorm(task_numbers, num));
|
println!("{}-norm = {}", num, pnorm(task_numbers, num));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -411,7 +411,7 @@ Each task recovers the underlying data by
|
||||||
# let (tx, rx) = channel();
|
# let (tx, rx) = channel();
|
||||||
# tx.send(numbers_arc.clone());
|
# tx.send(numbers_arc.clone());
|
||||||
# let local_arc : Arc<~[f64]> = rx.recv();
|
# let local_arc : Arc<~[f64]> = rx.recv();
|
||||||
let task_numbers = local_arc.get();
|
let task_numbers = &*local_arc;
|
||||||
# }
|
# }
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
|
|
|
@ -208,8 +208,8 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
|
||||||
let loc = loc.unwrap();
|
let loc = loc.unwrap();
|
||||||
|
|
||||||
local_data::get(cache_key, |cache| {
|
local_data::get(cache_key, |cache| {
|
||||||
let cache = cache.unwrap().get();
|
let cache = cache.unwrap();
|
||||||
let abs_root = root(cache, loc.as_slice());
|
let abs_root = root(&**cache, loc.as_slice());
|
||||||
let rel_root = match path.segments.get(0).name.as_slice() {
|
let rel_root = match path.segments.get(0).name.as_slice() {
|
||||||
"self" => Some(~"./"),
|
"self" => Some(~"./"),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -241,7 +241,7 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match info(cache) {
|
match info(&**cache) {
|
||||||
// This is a documented path, link to it!
|
// This is a documented path, link to it!
|
||||||
Some((ref fqp, shortty)) if abs_root.is_some() => {
|
Some((ref fqp, shortty)) if abs_root.is_some() => {
|
||||||
let mut url = abs_root.unwrap();
|
let mut url = abs_root.unwrap();
|
||||||
|
@ -301,7 +301,7 @@ impl fmt::Show for clean::Type {
|
||||||
match *self {
|
match *self {
|
||||||
clean::TyParamBinder(id) | clean::Generic(id) => {
|
clean::TyParamBinder(id) | clean::Generic(id) => {
|
||||||
local_data::get(cache_key, |cache| {
|
local_data::get(cache_key, |cache| {
|
||||||
let m = cache.unwrap().get();
|
let m = cache.unwrap();
|
||||||
f.buf.write(m.typarams.get(&id).as_bytes())
|
f.buf.write(m.typarams.get(&id).as_bytes())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1265,7 +1265,7 @@ fn item_trait(w: &mut Writer, it: &clean::Item,
|
||||||
}
|
}
|
||||||
|
|
||||||
local_data::get(cache_key, |cache| {
|
local_data::get(cache_key, |cache| {
|
||||||
let cache = cache.unwrap().get();
|
let cache = cache.unwrap();
|
||||||
match cache.implementors.find(&it.id) {
|
match cache.implementors.find(&it.id) {
|
||||||
Some(implementors) => {
|
Some(implementors) => {
|
||||||
try!(write!(w, "
|
try!(write!(w, "
|
||||||
|
@ -1496,7 +1496,7 @@ fn render_struct(w: &mut Writer, it: &clean::Item,
|
||||||
|
|
||||||
fn render_methods(w: &mut Writer, it: &clean::Item) -> fmt::Result {
|
fn render_methods(w: &mut Writer, it: &clean::Item) -> fmt::Result {
|
||||||
local_data::get(cache_key, |cache| {
|
local_data::get(cache_key, |cache| {
|
||||||
let c = cache.unwrap().get();
|
let c = cache.unwrap();
|
||||||
match c.impls.find(&it.id) {
|
match c.impls.find(&it.id) {
|
||||||
Some(v) => {
|
Some(v) => {
|
||||||
let mut non_trait = v.iter().filter(|p| {
|
let mut non_trait = v.iter().filter(|p| {
|
||||||
|
@ -1576,7 +1576,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl,
|
||||||
Some(id) => id,
|
Some(id) => id,
|
||||||
};
|
};
|
||||||
try!(local_data::get(cache_key, |cache| {
|
try!(local_data::get(cache_key, |cache| {
|
||||||
let cache = cache.unwrap().get();
|
let cache = cache.unwrap();
|
||||||
match cache.traits.find(&trait_id) {
|
match cache.traits.find(&trait_id) {
|
||||||
Some(t) => {
|
Some(t) => {
|
||||||
let name = meth.name.clone();
|
let name = meth.name.clone();
|
||||||
|
@ -1606,7 +1606,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl,
|
||||||
None => {}
|
None => {}
|
||||||
Some(id) => {
|
Some(id) => {
|
||||||
try!(local_data::get(cache_key, |cache| {
|
try!(local_data::get(cache_key, |cache| {
|
||||||
let cache = cache.unwrap().get();
|
let cache = cache.unwrap();
|
||||||
match cache.traits.find(&id) {
|
match cache.traits.find(&id) {
|
||||||
Some(t) => {
|
Some(t) => {
|
||||||
for method in t.methods.iter() {
|
for method in t.methods.iter() {
|
||||||
|
|
|
@ -26,7 +26,7 @@ extern crate sync;
|
||||||
use serialize::json;
|
use serialize::json;
|
||||||
use serialize::json::ToJson;
|
use serialize::json::ToJson;
|
||||||
use serialize::{Encoder, Encodable, Decoder, Decodable};
|
use serialize::{Encoder, Encodable, Decoder, Decodable};
|
||||||
use sync::{Arc,RWArc};
|
use sync::{Arc, RWLock};
|
||||||
use collections::TreeMap;
|
use collections::TreeMap;
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
@ -225,7 +225,7 @@ pub type FreshnessMap = TreeMap<~str,extern fn(&str,&str)->bool>;
|
||||||
|
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
db: RWArc<Database>,
|
db: Arc<RWLock<Database>>,
|
||||||
priv cfg: Arc<json::Object>,
|
priv cfg: Arc<json::Object>,
|
||||||
/// Map from kinds (source, exe, url, etc.) to a freshness function.
|
/// Map from kinds (source, exe, url, etc.) to a freshness function.
|
||||||
/// The freshness function takes a name (e.g. file path) and value
|
/// The freshness function takes a name (e.g. file path) and value
|
||||||
|
@ -269,12 +269,12 @@ fn json_decode<T:Decodable<json::Decoder>>(s: &str) -> T {
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
|
|
||||||
pub fn new(db: RWArc<Database>,
|
pub fn new(db: Arc<RWLock<Database>>,
|
||||||
cfg: Arc<json::Object>) -> Context {
|
cfg: Arc<json::Object>) -> Context {
|
||||||
Context::new_with_freshness(db, cfg, Arc::new(TreeMap::new()))
|
Context::new_with_freshness(db, cfg, Arc::new(TreeMap::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_freshness(db: RWArc<Database>,
|
pub fn new_with_freshness(db: Arc<RWLock<Database>>,
|
||||||
cfg: Arc<json::Object>,
|
cfg: Arc<json::Object>,
|
||||||
freshness: Arc<FreshnessMap>) -> Context {
|
freshness: Arc<FreshnessMap>) -> Context {
|
||||||
Context {
|
Context {
|
||||||
|
@ -364,7 +364,7 @@ impl<'a> Prep<'a> {
|
||||||
fn is_fresh(&self, cat: &str, kind: &str,
|
fn is_fresh(&self, cat: &str, kind: &str,
|
||||||
name: &str, val: &str) -> bool {
|
name: &str, val: &str) -> bool {
|
||||||
let k = kind.to_owned();
|
let k = kind.to_owned();
|
||||||
let f = self.ctxt.freshness.get().find(&k);
|
let f = self.ctxt.freshness.deref().find(&k);
|
||||||
debug!("freshness for: {}/{}/{}/{}", cat, kind, name, val)
|
debug!("freshness for: {}/{}/{}/{}", cat, kind, name, val)
|
||||||
let fresh = match f {
|
let fresh = match f {
|
||||||
None => fail!("missing freshness-function for '{}'", kind),
|
None => fail!("missing freshness-function for '{}'", kind),
|
||||||
|
@ -406,9 +406,10 @@ impl<'a> Prep<'a> {
|
||||||
|
|
||||||
debug!("exec_work: looking up {} and {:?}", self.fn_name,
|
debug!("exec_work: looking up {} and {:?}", self.fn_name,
|
||||||
self.declared_inputs);
|
self.declared_inputs);
|
||||||
let cached = self.ctxt.db.read(|db| {
|
let cached = {
|
||||||
db.prepare(self.fn_name, &self.declared_inputs)
|
let db = self.ctxt.db.deref().read();
|
||||||
});
|
db.deref().prepare(self.fn_name, &self.declared_inputs)
|
||||||
|
};
|
||||||
|
|
||||||
match cached {
|
match cached {
|
||||||
Some((ref disc_in, ref disc_out, ref res))
|
Some((ref disc_in, ref disc_out, ref res))
|
||||||
|
@ -460,13 +461,12 @@ impl<'a, T:Send +
|
||||||
WorkFromTask(prep, port) => {
|
WorkFromTask(prep, port) => {
|
||||||
let (exe, v) = port.recv();
|
let (exe, v) = port.recv();
|
||||||
let s = json_encode(&v);
|
let s = json_encode(&v);
|
||||||
prep.ctxt.db.write(|db| {
|
let mut db = prep.ctxt.db.deref().write();
|
||||||
db.cache(prep.fn_name,
|
db.deref_mut().cache(prep.fn_name,
|
||||||
&prep.declared_inputs,
|
&prep.declared_inputs,
|
||||||
&exe.discovered_inputs,
|
&exe.discovered_inputs,
|
||||||
&exe.discovered_outputs,
|
&exe.discovered_outputs,
|
||||||
s)
|
s);
|
||||||
});
|
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -496,7 +496,7 @@ fn test() {
|
||||||
|
|
||||||
let db_path = make_path(~"db.json");
|
let db_path = make_path(~"db.json");
|
||||||
|
|
||||||
let cx = Context::new(RWArc::new(Database::new(db_path)),
|
let cx = Context::new(Arc::new(RWLock::new(Database::new(db_path))),
|
||||||
Arc::new(TreeMap::new()));
|
Arc::new(TreeMap::new()));
|
||||||
|
|
||||||
let s = cx.with_prep("test1", |prep| {
|
let s = cx.with_prep("test1", |prep| {
|
||||||
|
|
|
@ -18,36 +18,28 @@
|
||||||
extern crate sync;
|
extern crate sync;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
||||||
use sync::Arc;
|
use sync::{Arc, Future, Mutex};
|
||||||
use sync::MutexArc;
|
|
||||||
use sync::Future;
|
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::uint;
|
use std::uint;
|
||||||
|
|
||||||
// A poor man's pipe.
|
// A poor man's pipe.
|
||||||
type pipe = MutexArc<Vec<uint> >;
|
type pipe = Arc<Mutex<Vec<uint>>>;
|
||||||
|
|
||||||
fn send(p: &pipe, msg: uint) {
|
fn send(p: &pipe, msg: uint) {
|
||||||
unsafe {
|
let mut arr = p.lock();
|
||||||
p.access_cond(|state, cond| {
|
arr.push(msg);
|
||||||
state.push(msg);
|
arr.cond.signal();
|
||||||
cond.signal();
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fn recv(p: &pipe) -> uint {
|
fn recv(p: &pipe) -> uint {
|
||||||
unsafe {
|
let mut arr = p.lock();
|
||||||
p.access_cond(|state, cond| {
|
while arr.is_empty() {
|
||||||
while state.is_empty() {
|
arr.cond.wait();
|
||||||
cond.wait();
|
|
||||||
}
|
|
||||||
state.pop().unwrap()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
arr.pop().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init() -> (pipe,pipe) {
|
fn init() -> (pipe,pipe) {
|
||||||
let m = MutexArc::new(Vec::new());
|
let m = Arc::new(Mutex::new(Vec::new()));
|
||||||
((&m).clone(), m)
|
((&m).clone(), m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,31 +18,29 @@
|
||||||
extern crate sync;
|
extern crate sync;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
||||||
use sync::RWArc;
|
use sync::{RWLock, Arc};
|
||||||
use sync::Future;
|
use sync::Future;
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::uint;
|
use std::uint;
|
||||||
|
|
||||||
// A poor man's pipe.
|
// A poor man's pipe.
|
||||||
type pipe = RWArc<Vec<uint> >;
|
type pipe = Arc<RWLock<Vec<uint>>>;
|
||||||
|
|
||||||
fn send(p: &pipe, msg: uint) {
|
fn send(p: &pipe, msg: uint) {
|
||||||
p.write_cond(|state, cond| {
|
let mut arr = p.write();
|
||||||
state.push(msg);
|
arr.push(msg);
|
||||||
cond.signal();
|
arr.cond.signal();
|
||||||
})
|
|
||||||
}
|
}
|
||||||
fn recv(p: &pipe) -> uint {
|
fn recv(p: &pipe) -> uint {
|
||||||
p.write_cond(|state, cond| {
|
let mut arr = p.write();
|
||||||
while state.is_empty() {
|
while arr.is_empty() {
|
||||||
cond.wait();
|
arr.cond.wait();
|
||||||
}
|
}
|
||||||
state.pop().unwrap()
|
arr.pop().unwrap()
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init() -> (pipe,pipe) {
|
fn init() -> (pipe,pipe) {
|
||||||
let x = RWArc::new(Vec::new());
|
let x = Arc::new(RWLock::new(Vec::new()));
|
||||||
((&x).clone(), x)
|
((&x).clone(), x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,8 @@ use std::from_str::FromStr;
|
||||||
use std::iter::count;
|
use std::iter::count;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::os;
|
use std::os;
|
||||||
use sync::RWArc;
|
use std::slice::from_elem;
|
||||||
|
use sync::{Arc, RWLock};
|
||||||
|
|
||||||
fn A(i: uint, j: uint) -> f64 {
|
fn A(i: uint, j: uint) -> f64 {
|
||||||
((i + j) * (i + j + 1) / 2 + i + 1) as f64
|
((i + j) * (i + j + 1) / 2 + i + 1) as f64
|
||||||
|
@ -28,17 +29,16 @@ fn dot(v: &[f64], u: &[f64]) -> f64 {
|
||||||
sum
|
sum
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mult(v: RWArc<Vec<f64>>,
|
fn mult(v: Arc<RWLock<Vec<f64>>>, out: Arc<RWLock<Vec<f64>>>,
|
||||||
out: RWArc<Vec<f64>>,
|
|
||||||
f: fn(&Vec<f64>, uint) -> f64) {
|
f: fn(&Vec<f64>, uint) -> f64) {
|
||||||
// We launch in different tasks the work to be done. To finish
|
// We lanch in different tasks the work to be done. To finish
|
||||||
// this fuction, we need to wait for the completion of every
|
// this fuction, we need to wait for the completion of every
|
||||||
// tasks. To do that, we give to each tasks a wait_chan that we
|
// tasks. To do that, we give to each tasks a wait_chan that we
|
||||||
// drop at the end of the work. At the end of this function, we
|
// drop at the end of the work. At the end of this function, we
|
||||||
// wait until the channel hang up.
|
// wait until the channel hang up.
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
|
||||||
let len = out.read(|out| out.len());
|
let len = out.read().len();
|
||||||
let chunk = len / 100 + 1;
|
let chunk = len / 100 + 1;
|
||||||
for chk in count(0, chunk) {
|
for chk in count(0, chunk) {
|
||||||
if chk >= len {break;}
|
if chk >= len {break;}
|
||||||
|
@ -47,8 +47,8 @@ fn mult(v: RWArc<Vec<f64>>,
|
||||||
let out = out.clone();
|
let out = out.clone();
|
||||||
spawn(proc() {
|
spawn(proc() {
|
||||||
for i in range(chk, min(len, chk + chunk)) {
|
for i in range(chk, min(len, chk + chunk)) {
|
||||||
let val = v.read(|v| f(v, i));
|
let val = f(&*v.read(), i);
|
||||||
out.write(|out| *out.get_mut(i) = val);
|
*out.write().get_mut(i) = val;
|
||||||
}
|
}
|
||||||
drop(tx)
|
drop(tx)
|
||||||
});
|
});
|
||||||
|
@ -67,7 +67,7 @@ fn mult_Av_impl(v: &Vec<f64> , i: uint) -> f64 {
|
||||||
sum
|
sum
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mult_Av(v: RWArc<Vec<f64> >, out: RWArc<Vec<f64> >) {
|
fn mult_Av(v: Arc<RWLock<Vec<f64>>>, out: Arc<RWLock<Vec<f64>>>) {
|
||||||
mult(v, out, mult_Av_impl);
|
mult(v, out, mult_Av_impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,11 +79,12 @@ fn mult_Atv_impl(v: &Vec<f64> , i: uint) -> f64 {
|
||||||
sum
|
sum
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mult_Atv(v: RWArc<Vec<f64> >, out: RWArc<Vec<f64> >) {
|
fn mult_Atv(v: Arc<RWLock<Vec<f64>>>, out: Arc<RWLock<Vec<f64>>>) {
|
||||||
mult(v, out, mult_Atv_impl);
|
mult(v, out, mult_Atv_impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mult_AtAv(v: RWArc<Vec<f64> >, out: RWArc<Vec<f64> >, tmp: RWArc<Vec<f64> >) {
|
fn mult_AtAv(v: Arc<RWLock<Vec<f64>>>, out: Arc<RWLock<Vec<f64>>>,
|
||||||
|
tmp: Arc<RWLock<Vec<f64>>>) {
|
||||||
mult_Av(v, tmp.clone());
|
mult_Av(v, tmp.clone());
|
||||||
mult_Atv(tmp, out);
|
mult_Atv(tmp, out);
|
||||||
}
|
}
|
||||||
|
@ -97,16 +98,16 @@ fn main() {
|
||||||
} else {
|
} else {
|
||||||
FromStr::from_str(args[1]).unwrap()
|
FromStr::from_str(args[1]).unwrap()
|
||||||
};
|
};
|
||||||
let u = RWArc::new(Vec::from_elem(n, 1.));
|
let u = Arc::new(RWLock::new(Vec::from_elem(n, 1.)));
|
||||||
let v = RWArc::new(Vec::from_elem(n, 1.));
|
let v = Arc::new(RWLock::new(Vec::from_elem(n, 1.)));
|
||||||
let tmp = RWArc::new(Vec::from_elem(n, 1.));
|
let tmp = Arc::new(RWLock::new(Vec::from_elem(n, 1.)));
|
||||||
for _ in range(0, 10) {
|
for _ in range(0, 10) {
|
||||||
mult_AtAv(u.clone(), v.clone(), tmp.clone());
|
mult_AtAv(u.clone(), v.clone(), tmp.clone());
|
||||||
mult_AtAv(v.clone(), u.clone(), tmp.clone());
|
mult_AtAv(v.clone(), u.clone(), tmp.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
u.read(|u| v.read(|v| {
|
let u = u.read();
|
||||||
println!("{:.9f}",
|
let v = v.read();
|
||||||
(dot(u.as_slice(), v.as_slice()) / dot(v.as_slice(), v.as_slice())).sqrt());
|
println!("{:.9f}", (dot(u.as_slice(), v.as_slice()) /
|
||||||
}))
|
dot(v.as_slice(), v.as_slice())).sqrt());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
extern crate sync;
|
|
||||||
use sync::RWArc;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let arc1 = RWArc::new(true);
|
|
||||||
let _arc2 = RWArc::new(arc1); //~ ERROR instantiating a type parameter with an incompatible type
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
// error-pattern: lifetime of return value does not outlive the function call
|
|
||||||
extern crate sync;
|
|
||||||
use sync::RWArc;
|
|
||||||
fn main() {
|
|
||||||
let x = ~RWArc::new(1);
|
|
||||||
let mut y = None;
|
|
||||||
x.write_cond(|_one, cond| y = Some(cond));
|
|
||||||
y.unwrap().wait();
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
extern crate sync;
|
|
||||||
use sync::RWArc;
|
|
||||||
fn main() {
|
|
||||||
let x = ~RWArc::new(1);
|
|
||||||
let mut y = None;
|
|
||||||
x.write_downgrade(|write_mode| {
|
|
||||||
y = Some(x.downgrade(write_mode));
|
|
||||||
//~^ ERROR cannot infer
|
|
||||||
});
|
|
||||||
y.unwrap();
|
|
||||||
// Adding this line causes a method unification failure instead
|
|
||||||
// (&option::unwrap(y)).read(|state| { assert!(*state == 1); })
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
extern crate sync;
|
|
||||||
use sync::RWArc;
|
|
||||||
fn main() {
|
|
||||||
let x = ~RWArc::new(1);
|
|
||||||
let mut y = None; //~ ERROR lifetime of variable does not enclose its declaration
|
|
||||||
x.write(|one| y = Some(one));
|
|
||||||
*y.unwrap() = 2;
|
|
||||||
//~^ ERROR lifetime of return value does not outlive the function call
|
|
||||||
//~^^ ERROR dereference of reference outside its lifetime
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
// error-pattern: lifetime of variable does not enclose its declaration
|
|
||||||
extern crate sync;
|
|
||||||
use sync::RWArc;
|
|
||||||
fn main() {
|
|
||||||
let x = ~RWArc::new(1);
|
|
||||||
let mut y = None;
|
|
||||||
x.write_downgrade(|write_mode| {
|
|
||||||
(&write_mode).write_cond(|_one, cond| {
|
|
||||||
y = Some(cond);
|
|
||||||
})
|
|
||||||
});
|
|
||||||
y.unwrap().wait();
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
// error-pattern: lifetime of variable does not enclose its declaration
|
|
||||||
extern crate sync;
|
|
||||||
use sync::RWArc;
|
|
||||||
fn main() {
|
|
||||||
let x = ~RWArc::new(1);
|
|
||||||
let mut y = None;
|
|
||||||
x.write_downgrade(|write_mode| y = Some(write_mode));
|
|
||||||
y.unwrap();
|
|
||||||
// Adding this line causes a method unification failure instead
|
|
||||||
// (&option::unwrap(y)).write(|state| { assert!(*state == 1); })
|
|
||||||
}
|
|
|
@ -17,7 +17,7 @@ use sync::Arc;
|
||||||
struct A { y: Arc<int>, x: Arc<int> }
|
struct A { y: Arc<int>, x: Arc<int> }
|
||||||
|
|
||||||
impl Drop for A {
|
impl Drop for A {
|
||||||
fn drop(&mut self) { println!("x={:?}", self.x.get()); }
|
fn drop(&mut self) { println!("x={}", *self.x); }
|
||||||
}
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = A { y: Arc::new(1), x: Arc::new(2) };
|
let a = A { y: Arc::new(1), x: Arc::new(2) };
|
||||||
|
|
|
@ -20,11 +20,10 @@ fn main() {
|
||||||
let arc_v = Arc::new(v);
|
let arc_v = Arc::new(v);
|
||||||
|
|
||||||
task::spawn(proc() {
|
task::spawn(proc() {
|
||||||
let v = arc_v.get();
|
assert_eq!(*arc_v.get(3), 4);
|
||||||
assert_eq!(*v.get(3), 4);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(*(arc_v.get()).get(2), 3);
|
assert_eq!(*arc_v.get(2), 3);
|
||||||
|
|
||||||
println!("{:?}", arc_v);
|
println!("{}", *arc_v);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,10 @@ fn main() {
|
||||||
let arc_v = Arc::new(v);
|
let arc_v = Arc::new(v);
|
||||||
|
|
||||||
task::spawn(proc() {
|
task::spawn(proc() {
|
||||||
let v = arc_v.get();
|
assert_eq!(*arc_v.get(3), 4);
|
||||||
assert_eq!(*v.get(3), 4);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert_eq!(*(arc_v.get()).get(2), 3); //~ ERROR use of moved value: `arc_v`
|
assert_eq!(*arc_v.get(2), 3); //~ ERROR use of moved value: `arc_v`
|
||||||
|
|
||||||
println!("{:?}", arc_v); //~ ERROR use of moved value: `arc_v`
|
println!("{}", *arc_v); //~ ERROR use of moved value: `arc_v`
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ fn foo(blk: proc()) {
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = Arc::new(true);
|
let x = Arc::new(true);
|
||||||
foo(proc() {
|
foo(proc() {
|
||||||
assert!(*x.get());
|
assert!(*x);
|
||||||
drop(x);
|
drop(x);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ fn foo(blk: once ||) {
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = Arc::new(true);
|
let x = Arc::new(true);
|
||||||
foo(|| {
|
foo(|| {
|
||||||
assert!(*x.get());
|
assert!(*x);
|
||||||
drop(x);
|
drop(x);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ fn foo(blk: ||) {
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = Arc::new(true);
|
let x = Arc::new(true);
|
||||||
foo(|| {
|
foo(|| {
|
||||||
assert!(*x.get());
|
assert!(*x);
|
||||||
drop(x); //~ ERROR cannot move out of captured outer variable
|
drop(x); //~ ERROR cannot move out of captured outer variable
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
// error-pattern: lifetime of variable does not enclose its declaration
|
|
||||||
extern crate sync;
|
|
||||||
use sync::Mutex;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let m = ~sync::Mutex::new();
|
|
||||||
let mut cond = None;
|
|
||||||
m.lock_cond(|c| {
|
|
||||||
cond = Some(c);
|
|
||||||
});
|
|
||||||
cond.unwrap().signal();
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
// error-pattern: lifetime of method receiver does not outlive the method call
|
|
||||||
extern crate sync;
|
|
||||||
use sync::RWLock;
|
|
||||||
fn main() {
|
|
||||||
let x = ~RWLock::new();
|
|
||||||
let mut y = None;
|
|
||||||
x.write_cond(|cond| {
|
|
||||||
y = Some(cond);
|
|
||||||
});
|
|
||||||
y.unwrap().wait();
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
// error-pattern: cannot infer
|
|
||||||
extern crate sync;
|
|
||||||
use sync::RWLock;
|
|
||||||
fn main() {
|
|
||||||
let x = ~RWLock::new();
|
|
||||||
let mut y = None;
|
|
||||||
x.write_downgrade(|write_mode| {
|
|
||||||
y = Some(x.downgrade(write_mode));
|
|
||||||
})
|
|
||||||
// Adding this line causes a method unification failure instead
|
|
||||||
// (&option::unwrap(y)).read(proc() { });
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
// error-pattern: lifetime of variable does not enclose its declaration
|
|
||||||
extern crate sync;
|
|
||||||
use sync::RWLock;
|
|
||||||
fn main() {
|
|
||||||
let x = ~RWLock::new();
|
|
||||||
let mut y = None;
|
|
||||||
x.write_downgrade(|write_mode| {
|
|
||||||
(&write_mode).write_cond(|cond| {
|
|
||||||
y = Some(cond);
|
|
||||||
})
|
|
||||||
});
|
|
||||||
y.unwrap().wait();
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
// error-pattern: lifetime of variable does not enclose its declaration
|
|
||||||
extern crate sync;
|
|
||||||
use sync::RWLock;
|
|
||||||
fn main() {
|
|
||||||
let x = ~RWLock::new();
|
|
||||||
let mut y = None;
|
|
||||||
x.write_downgrade(|write_mode| {
|
|
||||||
y = Some(write_mode);
|
|
||||||
});
|
|
||||||
// Adding this line causes a method unification failure instead
|
|
||||||
// (&option::unwrap(y)).write(proc() { })
|
|
||||||
}
|
|
|
@ -23,7 +23,7 @@ fn foo(blk: proc()) {
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = Arc::new(true);
|
let x = Arc::new(true);
|
||||||
foo(proc() {
|
foo(proc() {
|
||||||
assert!(*x.get());
|
assert!(*x);
|
||||||
drop(x);
|
drop(x);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ fn foo(blk: once ||) {
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let x = Arc::new(true);
|
let x = Arc::new(true);
|
||||||
foo(|| {
|
foo(|| {
|
||||||
assert!(*x.get());
|
assert!(*x);
|
||||||
drop(x);
|
drop(x);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,20 +85,20 @@ pub fn main() {
|
||||||
|
|
||||||
fn check_legs(arc: Arc<Vec<~Pet:Share+Send>>) {
|
fn check_legs(arc: Arc<Vec<~Pet:Share+Send>>) {
|
||||||
let mut legs = 0;
|
let mut legs = 0;
|
||||||
for pet in arc.get().iter() {
|
for pet in arc.iter() {
|
||||||
legs += pet.num_legs();
|
legs += pet.num_legs();
|
||||||
}
|
}
|
||||||
assert!(legs == 12);
|
assert!(legs == 12);
|
||||||
}
|
}
|
||||||
fn check_names(arc: Arc<Vec<~Pet:Share+Send>>) {
|
fn check_names(arc: Arc<Vec<~Pet:Share+Send>>) {
|
||||||
for pet in arc.get().iter() {
|
for pet in arc.iter() {
|
||||||
pet.name(|name| {
|
pet.name(|name| {
|
||||||
assert!(name[0] == 'a' as u8 && name[1] == 'l' as u8);
|
assert!(name[0] == 'a' as u8 && name[1] == 'l' as u8);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn check_pedigree(arc: Arc<Vec<~Pet:Share+Send>>) {
|
fn check_pedigree(arc: Arc<Vec<~Pet:Share+Send>>) {
|
||||||
for pet in arc.get().iter() {
|
for pet in arc.iter() {
|
||||||
assert!(pet.of_good_pedigree());
|
assert!(pet.of_good_pedigree());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue