From f2125434d86669d3086094397855f80c2bf636ac Mon Sep 17 00:00:00 2001 From: Olivier Saut Date: Fri, 24 May 2013 21:38:12 +0200 Subject: [PATCH 1/2] Remove the get function Rust is now preferring methods over functions and there is no legacy with ARC --- src/libextra/arc.rs | 25 ++++++++-------------- src/test/bench/graph500-bfs.rs | 14 ++++++------ src/test/compile-fail/no-capture-arc.rs | 6 +++--- src/test/compile-fail/no-reuse-move-arc.rs | 6 +++--- 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index 648089a5524..820b85f4544 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -107,7 +107,7 @@ pub impl<'self> Condvar<'self> { ****************************************************************************/ /// An atomically reference counted wrapper for shared immutable state. -struct ARC { x: UnsafeAtomicRcBox } +pub struct ARC { x: UnsafeAtomicRcBox } /// Create an atomically reference counted wrapper. pub fn ARC(data: T) -> ARC { @@ -118,12 +118,8 @@ pub fn ARC(data: T) -> ARC { * Access the underlying data in an atomically reference counted * wrapper. */ -pub fn get<'a, T:Const + Owned>(rc: &'a ARC) -> &'a T { - rc.get() -} - -impl ARC { - pub fn get<'a>(&'a self) -> &'a T { +pub impl ARC { + fn get<'a>(&'a self) -> &'a T { unsafe { &*self.x.get_immut() } } } @@ -512,17 +508,14 @@ pub impl<'self, T:Const + Owned> RWReadMode<'self, T> { #[cfg(test)] mod tests { use core::prelude::*; - + use core::cell::Cell; use arc::*; use arc; - use core::cell::Cell; - use core::task; - #[test] fn manually_share_arc() { let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - let arc_v = arc::ARC(v); + let arc_v = ARC(v); let (p, c) = comm::stream(); @@ -530,16 +523,16 @@ mod tests { let p = comm::PortSet::new(); c.send(p.chan()); - let arc_v = p.recv(); + let arc_v : ARC<~[int]> = p.recv(); - let v = copy *arc::get::<~[int]>(&arc_v); + let v = copy (*arc_v.get()); assert_eq!(v[3], 4); }; let c = p.recv(); - c.send(arc::clone(&arc_v)); + c.send(arc_v.clone()); - assert_eq!((*arc::get(&arc_v))[2], 3); + assert_eq!(arc_v.get()[2], 3); assert_eq!(arc_v.get()[4], 5); info!(arc_v); diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 734b5a0006f..06c8d0c145b 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -1,6 +1,6 @@ // xfail-pretty -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -234,7 +234,7 @@ fn pbfs(graph: &arc::ARC, key: node_id) -> bfs_result { black(node_id) }; - let graph_vec = arc::get(graph); // FIXME #3387 requires this temp + let graph_vec = graph.get(); // FIXME #3387 requires this temp let mut colors = do vec::from_fn(graph_vec.len()) |i| { if i as node_id == key { gray(key) @@ -266,13 +266,13 @@ fn pbfs(graph: &arc::ARC, key: node_id) -> bfs_result { let color = arc::ARC(colors); - let color_vec = arc::get(&color); // FIXME #3387 requires this temp + let color_vec = color.get(); // FIXME #3387 requires this temp colors = do par::mapi(*color_vec) { - let colors = arc::clone(&color); - let graph = arc::clone(graph); + let colors = color.clone(); + let graph = graph.clone(); let result: ~fn(x: uint, y: &color) -> color = |i, c| { - let colors = arc::get(&colors); - let graph = arc::get(&graph); + let colors = colors.get(); + let graph = graph.get(); match *c { white => { let i = i as node_id; diff --git a/src/test/compile-fail/no-capture-arc.rs b/src/test/compile-fail/no-capture-arc.rs index 132a5326a88..2a83e479e87 100644 --- a/src/test/compile-fail/no-capture-arc.rs +++ b/src/test/compile-fail/no-capture-arc.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -18,11 +18,11 @@ fn main() { let arc_v = arc::ARC(v); do task::spawn() { - let v = *arc::get(&arc_v); + let v = arc_v.get(); assert_eq!(v[3], 4); }; - assert_eq!((*arc::get(&arc_v))[2], 3); + assert_eq!((arc_v.get())[2], 3); info!(arc_v); } diff --git a/src/test/compile-fail/no-reuse-move-arc.rs b/src/test/compile-fail/no-reuse-move-arc.rs index 8bed4e6da47..607127f2fee 100644 --- a/src/test/compile-fail/no-reuse-move-arc.rs +++ b/src/test/compile-fail/no-reuse-move-arc.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -16,11 +16,11 @@ fn main() { let arc_v = arc::ARC(v); do task::spawn() { //~ NOTE `arc_v` moved into closure environment here - let v = *arc::get(&arc_v); + let v = arc_v.get(); assert_eq!(v[3], 4); }; - assert!((*arc::get(&arc_v))[2] == 3); //~ ERROR use of moved value: `arc_v` + assert_eq!((arc_v.get())[2], 3); //~ ERROR use of moved value: `arc_v` info!(arc_v); } From ff28bb7839a039641788436b21130ae2d378609b Mon Sep 17 00:00:00 2001 From: Olivier Saut Date: Fri, 24 May 2013 22:54:58 +0200 Subject: [PATCH 2/2] Remove the clone function for the method --- src/libextra/arc.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index 820b85f4544..123e7275935 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -123,6 +123,7 @@ pub impl ARC { unsafe { &*self.x.get_immut() } } } + /** * Duplicate an atomically reference counted wrapper. * @@ -130,13 +131,9 @@ pub impl ARC { * object. However, one of the `arc` objects can be sent to another task, * allowing them to share the underlying data. */ -pub fn clone(rc: &ARC) -> ARC { - ARC { x: rc.x.clone() } -} - impl Clone for ARC { fn clone(&self) -> ARC { - clone(self) + ARC { x: self.x.clone() } } }