Skip to content

Commit f5e06dd

Browse files
committed
---
yaml --- r: 65272 b: refs/heads/master c: ac6c15a h: refs/heads/master v: v3
1 parent a94600d commit f5e06dd

File tree

7 files changed

+53
-26
lines changed

7 files changed

+53
-26
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: ff28bb7839a039641788436b21130ae2d378609b
2+
refs/heads/master: ac6c15aecea4bb9a328cf8f80e1cbb9f0104d98b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/libextra/arc.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub impl<'self> Condvar<'self> {
107107
****************************************************************************/
108108

109109
/// An atomically reference counted wrapper for shared immutable state.
110-
pub struct ARC<T> { x: UnsafeAtomicRcBox<T> }
110+
struct ARC<T> { x: UnsafeAtomicRcBox<T> }
111111

112112
/// Create an atomically reference counted wrapper.
113113
pub fn ARC<T:Const + Owned>(data: T) -> ARC<T> {
@@ -118,22 +118,29 @@ pub fn ARC<T:Const + Owned>(data: T) -> ARC<T> {
118118
* Access the underlying data in an atomically reference counted
119119
* wrapper.
120120
*/
121-
pub impl<T:Const+Owned> ARC<T> {
122-
fn get<'a>(&'a self) -> &'a T {
121+
pub fn get<'a, T:Const + Owned>(rc: &'a ARC<T>) -> &'a T {
122+
rc.get()
123+
}
124+
125+
impl<T:Const+Owned> ARC<T> {
126+
pub fn get<'a>(&'a self) -> &'a T {
123127
unsafe { &*self.x.get_immut() }
124128
}
125129
}
126-
127130
/**
128131
* Duplicate an atomically reference counted wrapper.
129132
*
130133
* The resulting two `arc` objects will point to the same underlying data
131134
* object. However, one of the `arc` objects can be sent to another task,
132135
* allowing them to share the underlying data.
133136
*/
137+
pub fn clone<T:Const + Owned>(rc: &ARC<T>) -> ARC<T> {
138+
ARC { x: rc.x.clone() }
139+
}
140+
134141
impl<T:Const + Owned> Clone for ARC<T> {
135142
fn clone(&self) -> ARC<T> {
136-
ARC { x: self.x.clone() }
143+
clone(self)
137144
}
138145
}
139146

@@ -505,31 +512,34 @@ pub impl<'self, T:Const + Owned> RWReadMode<'self, T> {
505512
#[cfg(test)]
506513
mod tests {
507514
use core::prelude::*;
508-
use core::cell::Cell;
515+
509516
use arc::*;
510517
use arc;
511518

519+
use core::cell::Cell;
520+
use core::task;
521+
512522
#[test]
513523
fn manually_share_arc() {
514524
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
515-
let arc_v = ARC(v);
525+
let arc_v = arc::ARC(v);
516526

517527
let (p, c) = comm::stream();
518528

519529
do task::spawn() || {
520530
let p = comm::PortSet::new();
521531
c.send(p.chan());
522532

523-
let arc_v : ARC<~[int]> = p.recv();
533+
let arc_v = p.recv();
524534

525-
let v = copy (*arc_v.get());
535+
let v = copy *arc::get::<~[int]>(&arc_v);
526536
assert_eq!(v[3], 4);
527537
};
528538

529539
let c = p.recv();
530-
c.send(arc_v.clone());
540+
c.send(arc::clone(&arc_v));
531541

532-
assert_eq!(arc_v.get()[2], 3);
542+
assert_eq!((*arc::get(&arc_v))[2], 3);
533543
assert_eq!(arc_v.get()[4], 5);
534544

535545
info!(arc_v);

trunk/src/librustc/front/config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ fn fold_block(
136136
) -> ast::blk_ {
137137
let filtered_stmts =
138138
b.stmts.filter_mapped(|a| filter_stmt(cx, *a));
139+
let filtered_view_items =
140+
b.view_items.filter_mapped(|a| filter_view_item(cx, *a));
139141
ast::blk_ {
140-
view_items: /*bad*/copy b.view_items,
142+
view_items: vec::map(filtered_view_items, |x| fld.fold_view_item(*x)),
141143
stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)),
142144
expr: b.expr.map(|x| fld.fold_expr(*x)),
143145
id: b.id,

trunk/src/test/bench/graph500-bfs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// xfail-pretty
22

3-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
3+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
44
// file at the top-level directory of this distribution and at
55
// http://rust-lang.org/COPYRIGHT.
66
//
@@ -234,7 +234,7 @@ fn pbfs(graph: &arc::ARC<graph>, key: node_id) -> bfs_result {
234234
black(node_id)
235235
};
236236

237-
let graph_vec = graph.get(); // FIXME #3387 requires this temp
237+
let graph_vec = arc::get(graph); // FIXME #3387 requires this temp
238238
let mut colors = do vec::from_fn(graph_vec.len()) |i| {
239239
if i as node_id == key {
240240
gray(key)
@@ -266,13 +266,13 @@ fn pbfs(graph: &arc::ARC<graph>, key: node_id) -> bfs_result {
266266

267267
let color = arc::ARC(colors);
268268

269-
let color_vec = color.get(); // FIXME #3387 requires this temp
269+
let color_vec = arc::get(&color); // FIXME #3387 requires this temp
270270
colors = do par::mapi(*color_vec) {
271-
let colors = color.clone();
272-
let graph = graph.clone();
271+
let colors = arc::clone(&color);
272+
let graph = arc::clone(graph);
273273
let result: ~fn(x: uint, y: &color) -> color = |i, c| {
274-
let colors = colors.get();
275-
let graph = graph.get();
274+
let colors = arc::get(&colors);
275+
let graph = arc::get(&graph);
276276
match *c {
277277
white => {
278278
let i = i as node_id;

trunk/src/test/compile-fail/no-capture-arc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -18,11 +18,11 @@ fn main() {
1818
let arc_v = arc::ARC(v);
1919

2020
do task::spawn() {
21-
let v = arc_v.get();
21+
let v = *arc::get(&arc_v);
2222
assert_eq!(v[3], 4);
2323
};
2424

25-
assert_eq!((arc_v.get())[2], 3);
25+
assert_eq!((*arc::get(&arc_v))[2], 3);
2626

2727
info!(arc_v);
2828
}

trunk/src/test/compile-fail/no-reuse-move-arc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -16,11 +16,11 @@ fn main() {
1616
let arc_v = arc::ARC(v);
1717

1818
do task::spawn() { //~ NOTE `arc_v` moved into closure environment here
19-
let v = arc_v.get();
19+
let v = *arc::get(&arc_v);
2020
assert_eq!(v[3], 4);
2121
};
2222

23-
assert_eq!((arc_v.get())[2], 3); //~ ERROR use of moved value: `arc_v`
23+
assert!((*arc::get(&arc_v))[2] == 3); //~ ERROR use of moved value: `arc_v`
2424

2525
info!(arc_v);
2626
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
// Make sure that this view item is filtered out because otherwise it would
13+
// trigger a compilation error
14+
#[cfg(not_present)] use foo = bar;
15+
}

0 commit comments

Comments
 (0)